decompiled_code:
__int64 __fastcall async_duplex_bridge(int a1, int a2, __int64 (__fastcall *a3)(void **, signed __int64), __int64 (__fastcall *a4)(void **, signed __int64), const void *a5, signed int a6)
{
__int64 v6; // r12
char *v7; // r12
int v8; // ebp
__int64 v9; // r13
int v10; // er15
__int64 v11; // r14
int v12; // eax
int v13; // ebx
int v14; // eax
int v15; // eax
char *v16; // rax
const char *v17; // rax
size_t v18; // rax
int v19; // eax
char *v20; // rax
const char *v21; // rax
const char *v22; // rbx
size_t v23; // rax
char *buf; // [rsp+0h] [rbp-1178h]
unsigned int v26; // [rsp+8h] [rbp-1170h]
unsigned int v27; // [rsp+Ch] [rbp-116Ch]
const char *v29; // [rsp+20h] [rbp-1158h]
fd_set writefds; // [rsp+30h] [rbp-1148h] BYREF
fd_set readfds; // [rsp+B0h] [rbp-10C8h] BYREF
void *v33; // [rsp+130h] [rbp-1048h] BYREF
void *v34; // [rsp+138h] [rbp-1040h] BYREF
char dest[2048]; // [rsp+140h] [rbp-1038h] BYREF
char v36[2104]; // [rsp+940h] [rbp-838h] BYREF

v27 = a6;
v34 = dest;
v33 = v36;
if ( a5 )
{
v6 = a6;
memcpy(dest, a5, a6);
v7 = &dest[v6];
}
else
{
v27 = 0;
v7 = dest;
}
v8 = a2 / 64;
v9 = 1LL << (a2 % 64);
v10 = a1 / 64;
v11 = 1LL << (a1 % 64);
v26 = 0;
buf = v36;
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
if ( v26 <= 0x7FE )
readfds.fds_bits[v8] |= v9;
if ( v34 < v7 )
writefds.fds_bits[v8] |= v9;
if ( v27 <= 0x7FE )
readfds.fds_bits[v10] |= v11;
if ( v33 < buf )
writefds.fds_bits[v10] |= v11;
v13 = select(256, &readfds, &writefds, 0LL, 0LL);
if ( v13 <= 0 )
return (unsigned int)v13;
if ( (readfds.fds_bits[v8] & v9) == 0 )
goto LABEL_36;
v12 = read(a2, buf, 2048LL - (int)v26);
if ( v12 == -1 )
{
if ( *_errno_location() != 11 )
return (unsigned int)-1;
goto LABEL_36;
}
if ( !v12 )
return 0;
if ( v12 > 0 )
{
v26 += v12;
buf += v12;
if ( !--v13 )
continue;
}
LABEL_36:
if ( (readfds.fds_bits[v10] & v11) == 0 )
goto LABEL_37;
v14 = read(a1, v7, 2048LL - (int)v27);
if ( v14 == -1 )
{
if ( *_errno_location() != 11 )
return (unsigned int)-1;
goto LABEL_37;
}
if ( !v14 )
return 0;
if ( v14 > 0 )
{
v27 += v14;
v7 += v14;
if ( !--v13 )
continue;
}
LABEL_37:
if ( (writefds.fds_bits[v8] & v9) == 0 )
goto LABEL_46;
if ( a4 )
{
v17 = (const char *)a4(&v34, v7 - (_BYTE *)v34);
if ( v17 )
{
v29 = v17;
v18 = strlen(v17);
write(a2, v29, v18);
}
}
v19 = write(a2, v34, v7 - (_BYTE *)v34);
if ( v19 == -1 )
{
if ( *_errno_location() != 11 )
return (unsigned int)-1;
LABEL_46:
if ( (writefds.fds_bits[v10] & v11) != 0 )
{
if ( a3 )
{
v21 = (const char *)a3(&v33, buf - (_BYTE *)v33);
v22 = v21;
if ( v21 )
{
v23 = strlen(v21);
write(a1, v22, v23);
}
}
v15 = write(a1, v33, buf - (_BYTE *)v33);
v13 = v15;
if ( v15 == -1 )
{
if ( *_errno_location() != 11 )
return (unsigned int)v13;
}
else if ( v15 > 0 )
{
v16 = (char *)v33 + v15;
if ( v16 == buf )
{
v33 = v36;
v26 = 0;
buf = v36;
}
else
{
v33 = v16;
}
}
}
}
else
{
if ( v19 <= 0 )
goto LABEL_46;
v20 = (char *)v34 + v19;
if ( v20 == v7 )
{
v7 = dest;
v34 = dest;
v27 = 0;
}
else
{
v34 = v20;
}
if ( v13 != 1 )
goto LABEL_46;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, __int64 (__fastcall *a3)(void **, signed __int64), __int64 (__fastcall *a4)(void **, signed __int64), const void *a5, signed int a6)
{
__int64 v6; // r12
char *v7; // r12
int v8; // ebp
__int64 v9; // r13
int v10; // er15
__int64 v11; // r14
int v12; // eax
int v13; // ebx
int v14; // eax
int v15; // eax
char *v16; // rax
const char *v17; // rax
size_t v18; // rax
int v19; // eax
char *v20; // rax
const char *v21; // rax
const char *v22; // rbx
size_t v23; // rax
char *buf; // [rsp+0h] [rbp-1178h]
unsigned int v26; // [rsp+8h] [rbp-1170h]
unsigned int v27; // [rsp+Ch] [rbp-116Ch]
const char *v29; // [rsp+20h] [rbp-1158h]
fd_set writefds; // [rsp+30h] [rbp-1148h] BYREF
fd_set readfds; // [rsp+B0h] [rbp-10C8h] BYREF
void *v33; // [rsp+130h] [rbp-1048h] BYREF
void *v34; // [rsp+138h] [rbp-1040h] BYREF
char dest[2048]; // [rsp+140h] [rbp-1038h] BYREF
char v36[2104]; // [rsp+940h] [rbp-838h] BYREF

v27 = a6;
v34 = dest;
v33 = v36;
if ( a5 )
{
v6 = a6;
memcpy(dest, a5, a6);
v7 = &dest[v6];
}
else
{
v27 = 0;
v7 = dest;
}
v8 = a2 / 64;
v9 = 1LL << (a2 % 64);
v10 = a1 / 64;
v11 = 1LL << (a1 % 64);
v26 = 0;
buf = v36;
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
memset(&writefds, 0, sizeof(writefds));
if ( v26 <= 0x7FE )
readfds.fds_bits[v8] |= v9;
if ( v34 < v7 )
writefds.fds_bits[v8] |= v9;
if ( v27 <= 0x7FE )
readfds.fds_bits[v10] |= v11;
if ( v33 < buf )
writefds.fds_bits[v10] |= v11;
v13 = select(256, &readfds, &writefds, 0LL, 0LL);
if ( v13 <= 0 )
return (unsigned int)v13;
if ( (readfds.fds_bits[v8] & v9) == 0 )
goto LABEL_36;
v12 = read(a2, buf, 2048LL - (int)v26);
if ( v12 == -1 )
{
if ( *_errno_location() != 11 )
return (unsigned int)-1;
goto LABEL_36;
}
if ( !v12 )
return 0;
if ( v12 > 0 )
{
v26 += v12;
buf += v12;
if ( !--v13 )
continue;
}
LABEL_36:
if ( (readfds.fds_bits[v10] & v11) == 0 )
goto LABEL_37;
v14 = read(a1, v7, 2048LL - (int)v27);
if ( v14 == -1 )
{
if ( *_errno_location() != 11 )
return (unsigned int)-1;
goto LABEL_37;
}
if ( !v14 )
return 0;
if ( v14 > 0 )
{
v27 += v14;
v7 += v14;
if ( !--v13 )
continue;
}
LABEL_37:
if ( (writefds.fds_bits[v8] & v9) == 0 )
goto LABEL_46;
if ( a4 )
{
v17 = (const char *)a4(&v34, v7 - (_BYTE *)v34);
if ( v17 )
{
v29 = v17;
v18 = strlen(v17);
write(a2, v29, v18);
}
}
v19 = write(a2, v34, v7 - (_BYTE *)v34);
if ( v19 == -1 )
{
if ( *_errno_location() != 11 )
return (unsigned int)-1;
LABEL_46:
if ( (writefds.fds_bits[v10] & v11) != 0 )
{
if ( a3 )
{
v21 = (const char *)a3(&v33, buf - (_BYTE *)v33);
v22 = v21;
if ( v21 )
{
v23 = strlen(v21);
write(a1, v22, v23);
}
}
v15 = write(a1, v33, buf - (_BYTE *)v33);
v13 = v15;
if ( v15 == -1 )
{
if ( *_errno_location() != 11 )
return (unsigned int)v13;
}
else if ( v15 > 0 )
{
v16 = (char *)v33 + v15;
if ( v16 == buf )
{
v33 = v36;
v26 = 0;
buf = v36;
}
else
{
v33 = v16;
}
}
}
}
else
{
if ( v19 <= 0 )
goto LABEL_46;
v20 = (char *)v34 + v19;
if ( v20 == v7 )
{
v7 = dest;
v34 = dest;
v27 = 0;
}
else
{
v34 = v20;
}
if ( v13 != 1 )
goto LABEL_46;
}
}
}

original_code:
int async_duplex_bridge(int cfd, int sfd, void *(*to_client)(char **, int), void *(*to_proxy)(char **, int), char *prebuf, int preblen) {
 char sbuf[2048], cbuf[2048];
     char *chead, *ctail, *shead, *stail, *s_mod_hdr, *c_mod_hdr;
 int num, nfd, spos, cpos;
 fd_set rd, wr;
 chead = ctail = cbuf;
 cpos = spos = 0;
 shead = stail = sbuf;
 if (prebuf) {
  memcpy(chead, prebuf, preblen);
  ctail += preblen;
  cpos += preblen;
 }
 while (1) {
         do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rd)->__fds_bits)[0]) : "memory"); } while (0);
         do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wr)->__fds_bits)[0]) : "memory"); } while (0);
         if (spos < sizeof(sbuf)-1) {
   ((void) (((&rd)->__fds_bits)[((sfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sfd) % (8 * (int) sizeof (__fd_mask)))))));
  }
         if (ctail > chead) {
   ((void) (((&wr)->__fds_bits)[((sfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sfd) % (8 * (int) sizeof (__fd_mask)))))));
  }
         if (cpos < sizeof(cbuf)-1) {
   ((void) (((&rd)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))));
  }
         if (stail > shead) {
   ((void) (((&wr)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))));
  }
         nfd = select(256, &rd, &wr, 0, ((void *)0));
         if (nfd <= 0) {
   return nfd;
  }
         if (((((&rd)->__fds_bits)[((sfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
          num = read(sfd,stail,sizeof(sbuf)-spos);
          if ((num == -1) && ((*__errno_location ()) != 11)) { break; }
          if (num == 0) break;
          if (num > 0) {
                  spos += num;
                  stail += num;
                  if (!--nfd) continue;
           }
         }
         if (((((&rd)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
          num = read(cfd,ctail,sizeof(cbuf)-cpos);
          if ((num == -1) && ((*__errno_location ()) != 11)) { break; }
          if (num == 0) break;
          if (num > 0) {
                  cpos += num;
                   ctail += num;
           if (!--nfd) continue;
              }
         }
         if (((((&wr)->__fds_bits)[((sfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (to_proxy) {
    c_mod_hdr = to_proxy(&chead, ctail-chead);
    if (c_mod_hdr) {
     num = write(sfd, c_mod_hdr, strlen(c_mod_hdr));
    }
   }
   num = write(sfd,chead,ctail-chead);
          if ((num == -1) && ((*__errno_location ()) != 11)) { break; }
          if (num > 0) {
           chead += num;
                  if (chead == ctail) {
                 chead = ctail = cbuf;
                   cpos = 0;
                   }
                  if (!--nfd) continue;
              }
  }
         if (((((&wr)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (to_client) {
    s_mod_hdr = to_client(&shead, stail-shead);
    if (s_mod_hdr) {
     num = write(cfd, s_mod_hdr, strlen(s_mod_hdr));
    }
   }
   num = write(cfd,shead,stail-shead);
          if ((num == -1) && ((*__errno_location ()) != 11)) { break; }
          if (num > 0) {
                  shead += num;
                  if (shead == stail) {
                   shead = stail = sbuf;
                   spos = 0;
                  }
                  if (!--nfd) continue;
           }
         }
    }
    return num;
}

canonical_original_code:
int async_duplex_bridge(int cfd, int sfd, void *(*to_client)(char **, int), void *(*to_proxy)(char **, int), char *prebuf, int preblen) {
 char sbuf[2048]; char cbuf[2048];
     char *chead; char *ctail; char *shead; char *stail; char *s_mod_hdr; char *c_mod_hdr;
 int num; int nfd; int spos; int cpos;
 struct fd_set rd; struct fd_set wr;
 chead = ctail = cbuf;
 cpos = spos = 0;
 shead = stail = sbuf;
 if (prebuf) {
  memcpy(chead, prebuf, preblen);
  ctail += preblen;
  cpos += preblen;
 }
 while (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" (&((&rd)->__fds_bits)[0]) : "memory"); } while (0);
         do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wr)->__fds_bits)[0]) : "memory"); } while (0);
         if (spos < sizeof(sbuf)-1) {
   ((void) (((&rd)->__fds_bits)[((sfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sfd) % (8 * (int) sizeof (__fd_mask)))))));
  }
         if (ctail > chead) {
   ((void) (((&wr)->__fds_bits)[((sfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sfd) % (8 * (int) sizeof (__fd_mask)))))));
  }
         if (cpos < sizeof(cbuf)-1) {
   ((void) (((&rd)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))));
  }
         if (stail > shead) {
   ((void) (((&wr)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))));
  }
         nfd = select(256, &rd, &wr, 0, ((void *)0));
         if (nfd <= 0) {
   return nfd;
  }
         if (((((&rd)->__fds_bits)[((sfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
          num = read(sfd,stail,sizeof(sbuf)-spos);
          if ((num == -1) && ((*__errno_location ()) != 11)) { break; }
          if (num == 0) break;
          if (num > 0) {
                  spos += num;
                  stail += num;
                  if (!--nfd) continue;
           }
         }
         if (((((&rd)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
          num = read(cfd,ctail,sizeof(cbuf)-cpos);
          if ((num == -1) && ((*__errno_location ()) != 11)) { break; }
          if (num == 0) break;
          if (num > 0) {
                  cpos += num;
                   ctail += num;
           if (!--nfd) continue;
              }
         }
         if (((((&wr)->__fds_bits)[((sfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (to_proxy) {
    c_mod_hdr = to_proxy(&chead, ctail-chead);
    if (c_mod_hdr) {
     num = write(sfd, c_mod_hdr, strlen(c_mod_hdr));
    }
   }
   num = write(sfd,chead,ctail-chead);
          if ((num == -1) && ((*__errno_location ()) != 11)) { break; }
          if (num > 0) {
           chead += num;
                  if (chead == ctail) {
                 chead = ctail = cbuf;
                   cpos = 0;
                   }
                  if (!--nfd) continue;
              }
  }
         if (((((&wr)->__fds_bits)[((cfd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((cfd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
   if (to_client) {
    s_mod_hdr = to_client(&shead, stail-shead);
    if (s_mod_hdr) {
     num = write(cfd, s_mod_hdr, strlen(s_mod_hdr));
    }
   }
   num = write(cfd,shead,stail-shead);
          if ((num == -1) && ((*__errno_location ()) != 11)) { break; }
          if (num > 0) {
                  shead += num;
                  if (shead == stail) {
                   shead = stail = sbuf;
                   spos = 0;
                  }
                  if (!--nfd) continue;
           }
         }
    }
    return num;
}

variable_types: cfd int

variable_types: sfd int

variable_types:
prebuf
char *

variable_types: preblen int

variable_types:
sbuf
char [2048]

variable_types:
cbuf
char [2048]

variable_types:
chead
char *

variable_types:
ctail
char *

variable_types:
shead
char *

variable_types:
stail
char *

variable_types: num int

variable_types: nfd int

variable_types: spos int

variable_types: cpos int

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

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


decompiled_code:
__int64 __fastcall net_setononblock(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
BYTE1(v1) |= 8u;
return (fcntl(fd, 4, v1) >> 31) | 1u;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
BYTE1(v1) |= 8u;
return (fcntl(fd, 4, v1) >> 31) | 1u;
}

original_code:
int net_setononblock(int fd) {
 int fl;
        fl = fcntl(fd, 3, 0);
        if (fcntl(fd, 4, fl | 04000) < 0) {
  return -1;
 }
 return 1;
}

variable_types: fd int

variable_types: fl int

return_type: int


decompiled_code:
int __fastcall net_acceptsocket(int a1)
{
struct sockaddr v2; // [rsp+0h] [rbp-28h] BYREF
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
return accept(a1, &v2, addr_len);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
struct sockaddr v2; // [rsp+0h] [rbp-28h] BYREF
socklen_t addr_len[3]; // [rsp+1Ch] [rbp-Ch] BYREF

addr_len[0] = 16;
return accept(a1, &v2, addr_len);
}

original_code:
int net_acceptsocket(int srv_fd) {
 int addrlen, new_fd;
 struct sockaddr_in client_addr;
 addrlen = sizeof(client_addr);
     new_fd = accept(srv_fd, (struct sockaddr *)&client_addr, &addrlen);
 return new_fd;
}

canonical_original_code:
int net_acceptsocket(int srv_fd) {
 int addrlen; int new_fd;
 struct sockaddr_in client_addr;
 addrlen = sizeof(client_addr);
     new_fd = accept(srv_fd, (struct sockaddr *)&client_addr, &addrlen);
 return new_fd;
}

variable_types: addrlen int

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

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

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


decompiled_code:
__int64 __fastcall net_mastersocket(char *cp, char *nptr)
{
int v2; // eax
unsigned int v3; // ebx
__int16 v4; // ax
in_addr_t v5; // eax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v2 = socket(2, 1, 6);
if ( v2 < 0 )
{
lerror("socket");
v3 = -1;
}
else
{
v3 = v2;
*(_QWORD *)&v7.sa_family = 2LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
v4 = atoi(nptr);
*(_WORD *)v7.sa_data = _bswap_16(v4);
v5 = 0;
if ( cp )
v5 = inet_addr(cp);
*(_DWORD *)&v7.sa_data[2] = v5;
if ( setsockopt(v3, 1, 2, optval, 4u) < 0 )
{
lerror("setsockopt");
close(v3);
v3 = -1;
}
else if ( bind(v3, &v7, 0x10u) == -1 || listen(v3, 5) < 0 )
{
lerror(cp);
close(v3);
v3 = -1;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *cp, char *nptr)
{
int v2; // eax
unsigned int v3; // ebx
__int16 v4; // ax
in_addr_t v5; // eax
struct sockaddr v7; // [rsp+0h] [rbp-38h] BYREF
int optval[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

optval[0] = 1;
v2 = socket(2, 1, 6);
if ( v2 < 0 )
{
lerror("socket");
v3 = -1;
}
else
{
v3 = v2;
*(_QWORD *)&v7.sa_family = 2LL;
*(_QWORD *)&v7.sa_data[6] = 0LL;
v4 = atoi(nptr);
*(_WORD *)v7.sa_data = func0(v4);
v5 = 0;
if ( cp )
v5 = inet_addr(cp);
*(_DWORD *)&v7.sa_data[2] = v5;
if ( setsockopt(v3, 1, 2, optval, 4u) < 0 )
{
lerror("setsockopt");
close(v3);
v3 = -1;
}
else if ( bind(v3, &v7, 0x10u) == -1 || listen(v3, 5) < 0 )
{
lerror(cp);
close(v3);
v3 = -1;
}
}
return v3;
}

original_code:
int net_mastersocket(char *host, char *port) {
 int srv_fd, yes = 1;
 struct sockaddr_in srv_addr;
 srv_fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (srv_fd < 0) {
  lerror("socket");
  return -1;
 }
 memset((void*)&srv_addr, 0x0, sizeof(srv_addr));
 srv_addr.sin_family = 2;
 srv_addr.sin_port = htons(atoi(port));
 srv_addr.sin_addr.s_addr = (host) ? inet_addr(host) : ((in_addr_t) 0x00000000);
        if (setsockopt(srv_fd, 1, 2, &yes, sizeof(int)) < 0) {
  lerror("setsockopt");
  close(srv_fd);
                return -1;
        }
        if (bind(srv_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)) == -1) {
                lerror(host);
  close(srv_fd);
                return -1;
        }
        if (listen(srv_fd, 5) < 0) {
                lerror(host);
  close(srv_fd);
                return -1;
        }
 return srv_fd;
}

canonical_original_code:
int net_mastersocket(char *host, char *port) {
 int srv_fd; int yes = 1;
 struct sockaddr_in srv_addr;
 srv_fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
 if (srv_fd < 0) {
  lerror("socket");
  return -1;
 }
 memset((void *)&srv_addr, 0x0, sizeof(srv_addr));
 srv_addr.sin_family = 2;
 srv_addr.sin_port = htons(atoi(port));
 srv_addr.sin_addr.s_addr = (host) ? inet_addr(host) : ((unsigned int) 0x00000000);
        if (setsockopt(srv_fd, 1, 2, &yes, sizeof(int)) < 0) {
  lerror("setsockopt");
  close(srv_fd);
                return -1;
        }
        if (bind(srv_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)) == -1) {
                lerror(host);
  close(srv_fd);
                return -1;
        }
        if (listen(srv_fd, 5) < 0) {
                lerror(host);
  close(srv_fd);
                return -1;
        }
 return srv_fd;
}

variable_types:
host
char *

variable_types:
port
char *

variable_types: yes int


decompiled_code:
char *__fastcall net_getpeeraddr(int a1)
{
int v1; // edx
char *result; // rax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
v1 = getpeername(a1, &addr, &len);
result = 0LL;
if ( v1 >= 0 )
result = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
return result;
}

canonical_decompiled_code:
char *__fastcall func5(int a1)
{
int v1; // edx
char *result; // rax
socklen_t len; // [rsp+Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

len = 16;
v1 = getpeername(a1, &addr, &len);
result = 0LL;
if ( v1 >= 0 )
result = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
return result;
}

original_code:
char *net_getpeeraddr(int peer) {
        struct sockaddr_in peer_addr;
        int addrlen, retval;
        addrlen = sizeof(struct sockaddr_in);
        retval = getpeername (peer, (struct sockaddr *)&peer_addr, &addrlen);
        if (retval < 0) {
                return ((void *)0);
        }
        return inet_ntoa(peer_addr.sin_addr);
}

canonical_original_code:
char *net_getpeeraddr(int peer) {
        struct sockaddr_in peer_addr;
        int addrlen; int retval;
        addrlen = sizeof(struct sockaddr_in);
        retval = getpeername (peer, (struct sockaddr *)&peer_addr, &addrlen);
        if (retval < 0) {
                return ((void *)0);
        }
        return inet_ntoa(peer_addr.sin_addr);
}

variable_types: peer int

variable_types: retval int

return_type: char *


decompiled_code:
__int64 __fastcall net_opensocket(char *name, __int16 a2, unsigned int a3)
{
int v4; // ebx
struct hostent *v5; // rax
struct hostent *v6; // rbp
struct sockaddr dest[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 6);
v5 = gethostbyname(name);
if ( v4 >= 0 && (v6 = v5) != 0LL )
{
*(_QWORD *)&dest[0].sa_family = 2LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
*(_WORD *)dest[0].sa_data = _bswap_16(a2);
memmove(&dest[0].sa_data[2], *(const void **)v6->h_addr_list, v6->h_length);
if ( (int)net_setononblock(v4) < 0 )
{
close(v4);
v4 = -1;
}
else
{
connect(v4, dest, 0x10u);
sleep(a3);
if ( connect(v4, dest, 0x10u) )
{
close(v4);
v4 = -1;
}
}
}
else
{
v4 = -1;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *name, __int16 a2, unsigned int a3)
{
int v4; // ebx
struct hostent *v5; // rax
struct hostent *v6; // rbp
struct sockaddr dest[3]; // [rsp+0h] [rbp-38h] BYREF

v4 = socket(2, 1, 6);
v5 = gethostbyname(name);
if ( v4 >= 0 && (v6 = v5) != 0LL )
{
*(_QWORD *)&dest[0].sa_family = 2LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
*(_WORD *)dest[0].sa_data = func0(a2);
memmove(&dest[0].sa_data[2], *(const void **)v6->h_addr_list, v6->h_length);
if ( (int)func2(v4) < 0 )
{
close(v4);
v4 = -1;
}
else
{
connect(v4, dest, 0x10u);
sleep(a3);
if ( connect(v4, dest, 0x10u) )
{
close(v4);
v4 = -1;
}
}
}
else
{
v4 = -1;
}
return (unsigned int)v4;
}

original_code:
int net_opensocket(char *addr, int port, int tout) {
        int fd, retval;
        struct sockaddr_in sin;
        struct hostent *he;
        fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
 he = gethostbyname(addr);
        if (fd < 0 || !he) {
             return -1;
        }
 memset((void*)&sin, 0x0, sizeof(sin));
        sin.sin_family = 2;
        sin.sin_port = htons(port);
        bcopy(he->h_addr_list[0], (char *)&sin.sin_addr, he->h_length);
 if (net_setononblock(fd) < 0) {
  close(fd);
  return -1;
 }
        retval = connect(fd, (struct sockaddr*)&sin, sizeof(sin));
 sleep(tout);
        retval = connect(fd, (struct sockaddr*)&sin, sizeof(sin));
        if (retval == 0) {
         return fd;
        }
        close(fd);
        return -1;
}

canonical_original_code:
int net_opensocket(char *addr, int port, int tout) {
        int fd; int retval;
        struct sockaddr_in sin;
        struct hostent *he;
        fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
 he = gethostbyname(addr);
        if (fd < 0 || !he) {
             return -1;
        }
 memset((void *)&sin, 0x0, sizeof(sin));
        sin.sin_family = 2;
        sin.sin_port = htons(port);
        bcopy(he->h_addr_list[0], (char *)&sin.sin_addr, he->h_length);
 if (net_setononblock(fd) < 0) {
  close(fd);
  return -1;
 }
        retval = connect(fd, (struct sockaddr *)&sin, sizeof(sin));
 sleep(tout);
        retval = connect(fd, (struct sockaddr *)&sin, sizeof(sin));
        if (retval == 0) {
         return fd;
        }
        close(fd);
        return -1;
}

variable_types:
addr
char *

variable_types: port int

variable_types: tout int

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


decompiled_code:
__int64 __fastcall async_read(int fd, void *buf, int a3, int a4)
{
int v5; // ebp
size_t v6; // r12
int v8; // [rsp+Ch] [rbp-3Ch]

v5 = 0;
v6 = a3;
do
{
v8 = read(fd, buf, v6);
sleep(1u);
++v5;
}
while ( v8 < 0 && *_errno_location() == 11 && v5 < a4 );
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, void *buf, int a3, int a4)
{
int v5; // ebp
size_t v6; // r12
int v8; // [rsp+Ch] [rbp-3Ch]

v5 = 0;
v6 = a3;
do
{
v8 = read(fd, buf, v6);
sleep(1u);
++v5;
}
while ( v8 < 0 && *_errno_location() == 11 && v5 < a4 );
return (unsigned int)v8;
}

original_code:
int async_read(int fd, char *buf, int len, int tout) {
 int rval, eta = 0;
        do {
  rval = read(fd, buf, len);
  sleep(1);
  eta++;
        } while ( (rval < 0 && (*__errno_location ()) == 11) && (eta < tout) );
 return rval;
}

canonical_original_code:
int async_read(int fd, char *buf, int len, int tout) {
 int rval; int eta = 0;
        do {
  rval = read(fd, buf, len);
  sleep(1);
  eta++;
        } while ( (rval < 0 && (*__errno_location ()) == 11) && (eta < tout) );
 return rval;
}

variable_types:
buf
char *

variable_types: len int

variable_types: rval int

variable_types: eta int


decompiled_code:
__int64 __fastcall async_write(int fd, void *buf, int a3, int a4)
{
int v5; // ebp
size_t v6; // r12
int v8; // [rsp+Ch] [rbp-3Ch]

v5 = 0;
v6 = a3;
do
{
v8 = write(fd, buf, v6);
sleep(1u);
++v5;
}
while ( v8 < 0 && *_errno_location() == 11 && v5 < a4 );
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd, void *buf, int a3, int a4)
{
int v5; // ebp
size_t v6; // r12
int v8; // [rsp+Ch] [rbp-3Ch]

v5 = 0;
v6 = a3;
do
{
v8 = write(fd, buf, v6);
sleep(1u);
++v5;
}
while ( v8 < 0 && *_errno_location() == 11 && v5 < a4 );
return (unsigned int)v8;
}

original_code:
int async_write(int fd, char *buf, int len, int tout) {
 int rval, eta = 0;
        do {
  rval = write(fd, buf, len);
  sleep(1);
  eta++;
        } while ( (rval < 0 && (*__errno_location ()) == 11) && (eta < tout) );
 return rval;
}

canonical_original_code:
int async_write(int fd, char *buf, int len, int tout) {
 int rval; int eta = 0;
        do {
  rval = write(fd, buf, len);
  sleep(1);
  eta++;
        } while ( (rval < 0 && (*__errno_location ()) == 11) && (eta < tout) );
 return rval;
}

variable_types: fd int


decompiled_code:
_BOOL8 __fastcall cfg_typechk_boolean(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "on") )
v1 = strcmp(a1, "off") == 0;
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "on") )
v1 = strcmp(a1, "off") == 0;
return v1;
}

original_code:
int cfg_typechk_boolean(char *buf, int len) {
 if (!strcmp(buf, "on") || !strcmp(buf, "off")) {
  return 1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall cfg_typechk_string(char *a1, int a2)
{
const unsigned __int16 *v2; // rcx
char *v3; // rax
__int64 v4; // rsi

if ( a2 <= 0 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
while ( (v2[*v3] & 0x4000) != 0 )
{
if ( ++v3 == (char *)v4 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, int a2)
{
const unsigned __int16 *v2; // rcx
char *v3; // rax
__int64 v4; // rsi

if ( a2 <= 0 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
while ( (v2[*v3] & 0x4000) != 0 )
{
if ( ++v3 == (char *)v4 )
return 1LL;
}
return 0LL;
}

original_code:
int cfg_typechk_string(char *buf, int len) {
 int j;
 for (j = 0; j < len; j++) {
  if (!((*__ctype_b_loc ())[(int) ((buf[j]))] & (unsigned short int) _ISprint)) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int cfg_typechk_string(char *buf, int len) {
 int j;
 for (j = 0; j < len; j++) {
  if (!((*__ctype_b_loc ())[(int) ((buf[j]))] & (unsigned short) _ISprint)) {
   return 0;
  }
 }
 return 1;
}

variable_types: j int


decompiled_code:
__int64 __fastcall cfg_typechk_url(char *a1, int a2)
{
__int64 result; // rax

result = cfg_typechk_string(a1, a2);
if ( (_DWORD)result )
result = a1[a2 - 1] == 47;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
__int64 result; // rax

result = func1(a1, a2);
if ( (_DWORD)result )
result = a1[a2 - 1] == 47;
return result;
}

original_code:
int cfg_typechk_url(char *buf, int len) {
 int prev_tst;
 prev_tst = cfg_typechk_string(buf, len);
 if (!prev_tst || buf[len-1] != '/') {
  return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall cfg_typechk_numeric(char *a1, int a2)
{
const unsigned __int16 *v2; // rcx
char *v3; // rax
__int64 v4; // rsi

if ( a2 <= 0 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
while ( (v2[*v3] & 0x800) != 0 )
{
if ( ++v3 == (char *)v4 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, int a2)
{
const unsigned __int16 *v2; // rcx
char *v3; // rax
__int64 v4; // rsi

if ( a2 <= 0 )
return 1LL;
v2 = *_ctype_b_loc();
v3 = a1;
v4 = (__int64)&a1[a2 - 1 + 1];
while ( (v2[*v3] & 0x800) != 0 )
{
if ( ++v3 == (char *)v4 )
return 1LL;
}
return 0LL;
}

original_code:
int cfg_typechk_numeric(char *buf, int len) {
 int j;
 for (j = 0; j < len; j++) {
  if (!((*__ctype_b_loc ())[(int) ((buf[j]))] & (unsigned short int) _ISdigit)) {
   return 0;
  }
 }
 return 1;
}

canonical_original_code:
int cfg_typechk_numeric(char *buf, int len) {
 int j;
 for (j = 0; j < len; j++) {
  if (!((*__ctype_b_loc ())[(int) ((buf[j]))] & (unsigned short) _ISdigit)) {
   return 0;
  }
 }
 return 1;
}


decompiled_code:
__int64 cfg_get_proxyopts()
{
return threadsafe_conf_get(cfg_proxy_opts);
}

canonical_decompiled_code:
__int64 func4()
{
return threadsafe_conf_get(cfg_proxy_opts);
}

original_code:
int cfg_get_proxyopts(void) {
 return (int) _threadsafe_conf_get((int *)cfg_proxy_opts);
}

canonical_original_code:
int cfg_get_proxyopts() {
 return (int) _threadsafe_conf_get((int *)cfg_proxy_opts);
}


decompiled_code:
__int64 cfg_get_clientopts()
{
return threadsafe_conf_get(cfg_client_opts);
}

canonical_decompiled_code:
__int64 func5()
{
return threadsafe_conf_get(cfg_client_opts);
}

original_code:
int cfg_get_clientopts(void) {
 return (int) _threadsafe_conf_get((int *)cfg_client_opts);
}

canonical_original_code:
int cfg_get_clientopts() {
 return (int) _threadsafe_conf_get((int *)cfg_client_opts);
}


decompiled_code:
__int64 __fastcall cfg_validate(int a1, char *a2)
{
__int64 v3; // r14
const char *v4; // r13
int v5; // esi
unsigned int v6; // ebx

v3 = SLODWORD((&cfg_truthtable)[4 * a1 + 1]);
v4 = (const char *)cfg_typechecker[3 * v3 + 1];
v5 = strlen(a2);
v6 = 1;
if ( !((unsigned int (__fastcall *)(char *, int))cfg_typechecker[3 * v3 + 2])(a2, v5) )
{
v6 = 0;
if ( v4 )
lprintf("*** %s : given value (%s) isn't matchs tag type (%s)\n", (&cfg_truthtable)[4 * a1], a2, v4);
else
lerror(a2);
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, char *a2)
{
__int64 v3; // r14
const char *v4; // r13
int v5; // esi
unsigned int v6; // ebx

v3 = SLODWORD((&cfg_truthtable)[4 * a1 + 1]);
v4 = (const char *)cfg_typechecker[3 * v3 + 1];
v5 = strlen(a2);
v6 = 1;
if ( !((unsigned int (__fastcall *)(char *, int))cfg_typechecker[3 * v3 + 2])(a2, v5) )
{
v6 = 0;
if ( v4 )
lprintf("*** %s : given value (%s) isn't matchs tag type (%s)\n", (&cfg_truthtable)[4 * a1], a2, v4);
else
lerror(a2);
}
return v6;
}

original_code:
int cfg_validate(int idx, char *val) {
 cfg_validate_cb type_check;
 type_check = cfg_typechecker[cfg_truthtable[idx].tag_type];
 if (!type_check.validate(val, strlen(val))) {
  if (type_check.type_name) {
   lprintf("*** %s : given value (%s) isn't matchs tag type (%s)\n",
    cfg_truthtable[idx].tag, val, type_check.type_name);
  } else {
   lerror(val);
  }
  return 0;
 }
 return 1;
}

canonical_original_code:
int cfg_validate(int idx, char *val) {
 struct cfg_validate_cb type_check;
 type_check = cfg_typechecker[cfg_truthtable[idx].tag_type];
 if (!type_check.validate(val, strlen(val))) {
  if (type_check.type_name) {
   lprintf("*** %s : given value (%s) isn't matchs tag type (%s)\n",
    cfg_truthtable[idx].tag, val, type_check.type_name);
  } else {
   lerror(val);
  }
  return 0;
 }
 return 1;
}

variable_types: idx int

variable_types:
val
char *

variable_types: struct cfg_validate_cb { int tag_type; char *type_name; int (*validate)(char *, int); }


lbanner

decompiled_code:
__int64 lbanner()
{
return lprintf("[ghost/notice] --- Ghost (v%s) Started! ---\n", "0.1beta");
}

canonical_decompiled_code:
__int64 func2()
{
return lprintf("[ghost/notice] --- Ghost (v%s) Started! ---\n", "0.1beta");
}

original_code:
void lbanner(void) {
        lprintf("[ghost/notice] --- Ghost (v%s) Started! ---\n", "0.1beta");
 return ;
}

canonical_original_code:
void lbanner() {
        lprintf("[ghost/notice] --- Ghost (v%s) Started! ---\n", "0.1beta");
 return ;
}

return_type: void


ctrlc

decompiled_code:
void __noreturn ctrlc()
{
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
exit(1);
}

original_code:
void ctrlc() {
        exit(1);
}

canonical_original_code:
void ctrlc() {
        exit(1);
}


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
fprintf(stderr, "ghost (v%s) <mailto:ik@ikotler.org>\n", "0.1beta");
return fprintf(stderr, "usage: %s <cfgfile>\n", a1);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
fprintf(stderr, "ghost (v%s) <mailto:ik@ikotler.org>\n", "0.1beta");
return fprintf(stderr, "usage: %s <cfgfile>\n", a1);
}

original_code:
void usage(char *basename) {
 fprintf(stderr, "ghost (v%s) <mailto:ik@ikotler.org>\n", "0.1beta");
 fprintf(stderr, "usage: %s <cfgfile>\n", basename);
 return ;
}

variable_types:
basename
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
int result; // eax
__pid_t v5; // eax
bool v6; // zf
const char *v7; // rax

signal(2, (__sighandler_t)ctrlc);
if ( argc <= 1 )
{
usage(*argv);
result = 0;
}
else
{
v3 = cfg_parse(argv[1]);
cfg = v3;
if ( v3 )
{
result = cfg_validate_all(v3, 0LL);
if ( result )
{
if ( (unsigned int)log_open() )
lbanner();
result = proxy_parse();
if ( result )
{
v5 = fork();
v6 = v5 == 0;
if ( v5 < 0 )
{
perror("fork");
result = 0;
}
else
{
result = 1;
if ( v6 )
{
daemon_start();
v7 = (const char *)hashtable_lookup(cfg, "daemon-logfile");
fprintf(stderr, "*** An error occurred. Please check %s for more details! ***\n", v7);
log_close();
exit(1);
}
}
}
}
}
else
{
result = 0;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdi
int result; // eax
__pid_t v5; // eax
bool v6; // zf
const char *v7; // rax

signal(2, (__sighandler_t)ctrlc);
if ( argc <= 1 )
{
func1(*argv);
result = 0;
}
else
{
v3 = cfg_parse(argv[1]);
cfg = v3;
if ( v3 )
{
result = cfg_validate_all(v3, 0LL);
if ( result )
{
if ( (unsigned int)log_open() )
func2();
result = proxy_parse();
if ( result )
{
v5 = fork();
v6 = v5 == 0;
if ( v5 < 0 )
{
perror("fork");
result = 0;
}
else
{
result = 1;
if ( v6 )
{
daemon_start();
v7 = (const char *)hashtable_lookup(cfg, "daemon-logfile");
fprintf(stderr, "*** An error occurred. Please check %s for more details! ***\n", v7);
log_close();
exit(1);
}
}
}
}
}
else
{
result = 0;
}
}
return result;
}

original_code:
int main(int argc, char **argv) {
 int retval;
        signal(2, (void *)ctrlc);
 if (argc < 2) {
  usage(argv[0]);
  return 0;
 }
 cfg = cfg_parse(argv[1]);
 if (!cfg || !cfg_validate_all(cfg, ERROR_MODE)) {
  return 0;
 }
 if (log_open()) {
  lbanner();
 }
 if (!proxy_parse()) {
  return 0;
 }
 retval = fork();
 if (retval < 0) {
  perror("fork");
  return 0;
 } else {
  if (!retval) {
   daemon_start();
   fprintf(stderr, "*** An error occurred. Please check %s for more details! ***\n",
    (char *) hashtable_lookup(cfg, "daemon-logfile"));
   log_close();
   _exit(1);
  }
 }
 return 1;
}

variable_types: argc int

variable_types:
argv
char **


stoa

decompiled_code:
unsigned __int64 __fastcall stoa(const char *a1)
{
return strtoul(a1, 0LL, 16);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(const char *a1)
{
return strtoul(a1, 0LL, 16);
}

original_code:
void *stoa(char *str) {
 return (void *) strtoul(str, ((void *)0), 16);
}

variable_types:
str
char *

return_type: void *


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

result = a1 - a2;
if ( direction )
result = a1 + a2;
return result;
}

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

result = a1 - a2;
if ( direction )
result = a1 + a2;
return result;
}

original_code:
void *addr_increase(void *addr, int bytes) {
 if (direction) {
  return (addr + bytes);
 }
 return (addr - bytes);
}

variable_types:
addr
void *

variable_types: bytes int


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

result = a1 + a2;
if ( direction )
result = a1 - a2;
return result;
}

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

result = a1 + a2;
if ( direction )
result = a1 - a2;
return result;
}

original_code:
void *addr_decrease(void *addr, int bytes) {
 if (direction) {
  return (addr - bytes);
 }
 return (addr + bytes);
}


decompiled_code:
_BOOL8 __fastcall addr_cmp(unsigned __int64 a1, unsigned __int64 a2)
{
_BOOL8 result; // rax

result = a2 < a1;
if ( direction )
result = a2 > a1;
return result;
}

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

result = a2 < a1;
if ( direction )
result = a2 > a1;
return result;
}

original_code:
int addr_cmp(void *src, void *dst) {
 if (direction) {
  return (src < dst);
 }
 return (dst < src);
}

variable_types:
src
void *

variable_types:
dst
void *


decompiled_code:
__int64 __fastcall addr_substruct(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdi

result = a2 - a1;
v3 = a1 - a2;
if ( !direction )
result = v3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdi

result = a2 - a1;
v3 = a1 - a2;
if ( !direction )
result = v3;
return result;
}

original_code:
unsigned long addr_substruct(void *src, void *dst) {
 if (direction) {
  return (dst - src);
 }
 return (src - dst);
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall addr_transdirection(const char *a1)
{
unsigned int v1; // edx

if ( !strcmp(a1, "up") || (v1 = -1, !strcmp(a1, "down")) )
v1 = *a1 != 100;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
unsigned int v1; // edx

if ( !strcmp(a1, "up") || (v1 = -1, !strcmp(a1, "down")) )
v1 = *a1 != 100;
return v1;
}

original_code:
int addr_transdirection(char *str) {
 int retval = 1;
 if (strcmp(str, "up") && strcmp(str, "down")) {
  return -1;
 }
 if (str[0] == 'd') {
  retval = 0;
 }
 return retval;
}

variable_types: retval int


decompiled_code:
void __fastcall addr_setdirection(int a1)
{
direction = a1;
}

canonical_decompiled_code:
void __fastcall func6(int a1)
{
direction = a1;
}

original_code:
void addr_setdirection(int flag) {
 direction = flag;
 return ;
}

variable_types: flag int


getpasswd

decompiled_code:
char *__fastcall getpasswd(char *prompt)
{
char *v1; // rax
char *v2; // rbx
char *v3; // rax
char *v4; // rbp
size_t v5; // rax

while ( 1 )
{
while ( 1 )
{
v1 = getpass(prompt);
v2 = v1;
if ( v1 )
break;
fwrite("* INVALID PASSWORD, RETRY AGAIN!\n", 1uLL, 0x21uLL, stderr);
}
if ( strlen(v1) - 2 <= 0xF )
break;
fwrite(
"* INVALID PASSWORD, LENGTH IS EITHER SHORTER THEN 1 BYTE OR LONGER THEN 16 BYTES, RETRY AGAIN!\n",
1uLL,
0x5FuLL,
stderr);
}
v3 = strdup(v2);
v4 = v3;
if ( v3 )
{
v5 = strlen(v3);
memset(v2, 0, v5);
}
else
{
perror("strdup");
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(char *prompt)
{
char *v1; // rax
char *v2; // rbx
char *v3; // rax
char *v4; // rbp
size_t v5; // rax

while ( 1 )
{
while ( 1 )
{
v1 = getpass(prompt);
v2 = v1;
if ( v1 )
break;
fwrite("* INVALID PASSWORD, RETRY AGAIN!\n", 1uLL, 0x21uLL, stderr);
}
if ( strlen(v1) - 2 <= 0xF )
break;
fwrite(
"* INVALID PASSWORD, LENGTH IS EITHER SHORTER THEN 1 BYTE OR LONGER THEN 16 BYTES, RETRY AGAIN!\n",
1uLL,
0x5FuLL,
stderr);
}
v3 = strdup(v2);
v4 = v3;
if ( v3 )
{
v5 = strlen(v3);
memset(v2, 0, v5);
}
else
{
perror("strdup");
}
return v4;
}

original_code:
char *getpasswd(char *str) {
        char *ptr, *passwd;
        while(1) {
                ptr = getpass(str);
                if (!ptr) {
                        fprintf(stderr, "* INVALID PASSWORD, RETRY AGAIN!\n");
                        continue;
                }
                if (strlen(ptr) < 2 || strlen(ptr) > 17) {
                        fprintf(stderr, "* INVALID PASSWORD, LENGTH IS EITHER SHORTER THEN 1 BYTE OR LONGER THEN 16 BYTES, RETRY AGAIN!\n");
                        continue;
                }
                passwd = strdup(ptr);
                if (!passwd) {
                        perror("strdup");
                        return ((void *)0);
                }
                memset(ptr, 0x0, strlen(passwd));
                break;
        }
        return passwd;
}

canonical_original_code:
char *getpasswd(char *str) {
        char *ptr; char *passwd;
        while(1) {
                ptr = getpass(str);
                if (!ptr) {
                        fprintf(stderr, "* INVALID PASSWORD, RETRY AGAIN!\n");
                        continue;
                }
                if (strlen(ptr) < 2 || strlen(ptr) > 17) {
                        fprintf(stderr, "* INVALID PASSWORD, LENGTH IS EITHER SHORTER THEN 1 BYTE OR LONGER THEN 16 BYTES, RETRY AGAIN!\n");
                        continue;
                }
                passwd = strdup(ptr);
                if (!passwd) {
                        perror("strdup");
                        return ((void *)0);
                }
                memset(ptr, 0x0, strlen(passwd));
                break;
        }
        return passwd;
}

variable_types:
ptr
char *

variable_types:
passwd
char *


passwdloop

decompiled_code:
char *passwdloop()
{
char *v0; // rbx
char *v2; // rax
char *v3; // rbp

while ( 1 )
{
v0 = getpasswd("* ENTER PASSWORD: ");
if ( !v0 )
break;
v2 = getpasswd("* ENTER PASSWORD AGAIN: ");
v3 = v2;
if ( !v2 )
{
free(v0);
return 0LL;
}
if ( !strcmp(v0, v2) )
{
free(v3);
return v0;
}
fwrite("*** PASSWORDS DOES NOT MATCH, RETRY AGAIN! ***\n", 1uLL, 0x2FuLL, stderr);
free(v0);
free(v3);
}
return v0;
}

canonical_decompiled_code:
char *func1()
{
char *v0; // rbx
char *v2; // rax
char *v3; // rbp

while ( 1 )
{
v0 = func0("* ENTER PASSWORD: ");
if ( !v0 )
break;
v2 = func0("* ENTER PASSWORD AGAIN: ");
v3 = v2;
if ( !v2 )
{
free(v0);
return 0LL;
}
if ( !strcmp(v0, v2) )
{
free(v3);
return v0;
}
fwrite("*** PASSWORDS DOES NOT MATCH, RETRY AGAIN! ***\n", 1uLL, 0x2FuLL, stderr);
free(v0);
free(v3);
}
return v0;
}

original_code:
char *passwdloop(void) {
 char *passwd, *v_passwd;
        while(1) {
                passwd = getpasswd("* ENTER PASSWORD: ");
                if (!passwd) {
   break;
                }
                v_passwd = getpasswd("* ENTER PASSWORD AGAIN: ");
                if (!v_passwd) {
                        free(passwd);
                        return ((void *)0);
                }
                if (!strcmp(passwd, v_passwd)) {
                        free(v_passwd);
                        break;
                }
                fprintf(stderr, "*** PASSWORDS DOES NOT MATCH, RETRY AGAIN! ***\n");
                free(passwd);
                free(v_passwd);
        }
 return passwd;
}

canonical_original_code:
char *passwdloop() {
 char *passwd; char *v_passwd;
        while(1) {
                passwd = getpasswd("* ENTER PASSWORD: ");
                if (!passwd) {
   break;
                }
                v_passwd = getpasswd("* ENTER PASSWORD AGAIN: ");
                if (!v_passwd) {
                        free(passwd);
                        return ((void *)0);
                }
                if (!strcmp(passwd, v_passwd)) {
                        free(v_passwd);
                        break;
                }
                fprintf(stderr, "*** PASSWORDS DOES NOT MATCH, RETRY AGAIN! ***\n");
                free(passwd);
                free(v_passwd);
        }
 return passwd;
}


isnumeric

decompiled_code:
int __fastcall isnumeric(char *nptr)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax

if ( !nptr )
return -1;
v1 = strlen(nptr);
if ( v1 <= 0 )
return atoi(nptr);
v2 = *_ctype_b_loc();
v3 = nptr;
while ( (v2[*v3] & 0x800) != 0 )
{
if ( ++v3 == &nptr[v1 - 1 + 1] )
return atoi(nptr);
}
return -1;
}

canonical_decompiled_code:
int __fastcall func2(char *nptr)
{
int v1; // ebp
const unsigned __int16 *v2; // rcx
char *v3; // rax

if ( !nptr )
return -1;
v1 = strlen(nptr);
if ( v1 <= 0 )
return atoi(nptr);
v2 = *_ctype_b_loc();
v3 = nptr;
while ( (v2[*v3] & 0x800) != 0 )
{
if ( ++v3 == &nptr[v1 - 1 + 1] )
return atoi(nptr);
}
return -1;
}

original_code:
int isnumeric(char *str) {
 int j, len;
 if (!str) {
  return -1;
 }
 len = strlen(str);
 for (j = 0; j < len; j++) {
  if (!((*__ctype_b_loc ())[(int) ((str[j]))] & (unsigned short int) _ISdigit)) {
   return -1;
  }
 }
 return atoi(str);
}

canonical_original_code:
int isnumeric(char *str) {
 int j; int len;
 if (!str) {
  return -1;
 }
 len = strlen(str);
 for (j = 0; j < len; j++) {
  if (!((*__ctype_b_loc ())[(int) ((str[j]))] & (unsigned short) _ISdigit)) {
   return -1;
  }
 }
 return atoi(str);
}

variable_types: len int


decompiled_code:
__int64 __fastcall http_gethdrsize(const char *a1)
{
char *v1; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = strstr(a1, "\r\n\r\n");
if ( v1 )
result = (unsigned int)((_DWORD)v1 + 4 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
char *v1; // rax
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = strstr(a1, "\r\n\r\n");
if ( v1 )
result = (unsigned int)((_DWORD)v1 + 4 - (_DWORD)a1);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int http_gethdrsize(char *chunk) {
 char *greenmile;
 if (!chunk) {
  return -1;
 }
 greenmile = strstr(chunk, "\r\n\r\n");
 if (!greenmile) {
  return -1;
 }
 return ((greenmile+4) - chunk);
}

variable_types:
chunk
char *

variable_types:
greenmile
char *


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

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

original_code:
int is_http_header(char *chunk, int len) {
 if (!strstr(chunk, "HTTP/")) {
  return 0;
 }
 return 1;
}


decompiled_code:
char *__fastcall http_modify_header(char *string, int a2, char a3)
{
char *v4; // rbp
char *v5; // r13
char *v6; // rax
char *v7; // rbx
char *save_ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v4 = 0LL;
if ( is_http_header(string) )
{
v5 = strndup(string, a2);
if ( v5 )
{
v4 = (char *)calloc(1uLL, 2 * a2);
if ( v4 )
{
save_ptr[0] = (char *)calloc(1uLL, a2 + 1);
if ( save_ptr[0] )
{
v6 = strtok_r(v5, "\r\n", save_ptr);
if ( v6 )
{
strcat(v4, v6);
strcat(v4, "\r\n");
v7 = strtok_r(0LL, "\r\n", save_ptr);
while ( v7 )
{
if ( (a3 & 1) != 0 && (strstr(v7, "Cookie:") || strstr(v7, "Set-Cookie:"))
|| (a3 & 0x11) != 0
&& (strstr(v7, "Proxy-Connection:") || strstr(v7, "Connection:") || strstr(v7, "Keep-Alive")) )
{
v7 = strtok_r(0LL, "\r\n", save_ptr);
}
else
{
strcat(v4, v7);
strcat(v4, "\r\n");
v7 = strtok_r(0LL, "\r\n", save_ptr);
}
}
if ( (a3 & 0x11) != 0 && !strstr(v4, "Host:") && !strstr(v4, "User-Agent:") )
{
strcat(v4, "Proxy-Connection: close\r\n");
strcat(v4, "Connection: close\r\n");
}
strcat(v4, "\r\n");
}
else
{
free(v4);
free(v5);
free(save_ptr[0]);
v4 = 0LL;
}
}
else
{
perror("calloc");
free(v4);
free(v5);
v4 = 0LL;
}
}
else
{
lerror("calloc");
free(v5);
}
}
else
{
lerror("calloc");
v4 = 0LL;
}
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func2(char *string, int a2, char a3)
{
char *v4; // rbp
char *v5; // r13
char *v6; // rax
char *v7; // rbx
char *save_ptr[6]; // [rsp+8h] [rbp-30h] BYREF

v4 = 0LL;
if ( func1(string) )
{
v5 = strndup(string, a2);
if ( v5 )
{
v4 = (char *)calloc(1uLL, 2 * a2);
if ( v4 )
{
save_ptr[0] = (char *)calloc(1uLL, a2 + 1);
if ( save_ptr[0] )
{
v6 = strtok_r(v5, "\r\n", save_ptr);
if ( v6 )
{
strcat(v4, v6);
strcat(v4, "\r\n");
v7 = strtok_r(0LL, "\r\n", save_ptr);
while ( v7 )
{
if ( (a3 & 1) != 0 && (strstr(v7, "Cookie:") || strstr(v7, "Set-Cookie:"))
|| (a3 & 0x11) != 0
&& (strstr(v7, "Proxy-Connection:") || strstr(v7, "Connection:") || strstr(v7, "Keep-Alive")) )
{
v7 = strtok_r(0LL, "\r\n", save_ptr);
}
else
{
strcat(v4, v7);
strcat(v4, "\r\n");
v7 = strtok_r(0LL, "\r\n", save_ptr);
}
}
if ( (a3 & 0x11) != 0 && !strstr(v4, "Host:") && !strstr(v4, "User-Agent:") )
{
strcat(v4, "Proxy-Connection: close\r\n");
strcat(v4, "Connection: close\r\n");
}
strcat(v4, "\r\n");
}
else
{
free(v4);
free(v5);
free(save_ptr[0]);
v4 = 0LL;
}
}
else
{
perror("calloc");
free(v4);
free(v5);
v4 = 0LL;
}
}
else
{
lerror("calloc");
free(v5);
}
}
else
{
lerror("calloc");
v4 = 0LL;
}
}
return v4;
}

original_code:
char *http_modify_header(char *buf, int len, int flags) {
 char *orig_hdr, *mod_hdr, *strtok_buf, *field;
 if (!is_http_header(buf, len)) {
  return ((void *)0);
 }
 orig_hdr = strndup(buf, len);
 if (!orig_hdr) {
  lerror("calloc");
  return ((void *)0);
 }
 mod_hdr = calloc(1, len * 2);
 if (!mod_hdr) {
  lerror("calloc");
  free(orig_hdr);
  return ((void *)0);
 }
 strtok_buf = calloc(1, len + 1);
 if (!strtok_buf) {
  perror("calloc");
  free(mod_hdr);
  free(orig_hdr);
  return ((void *)0);
 }
 field = strtok_r(orig_hdr, "\r\n", &strtok_buf);
 if (!field) {
  free(mod_hdr);
  free(orig_hdr);
  free(strtok_buf);
  return ((void *)0);
 }
 strcat(mod_hdr, field);
 strcat(mod_hdr, "\r\n");
 field = strtok_r(((void *)0), "\r\n", &strtok_buf);
 while (field) {
  if (flags & 0x0000001) {
   if (strstr(field, "Cookie:") || strstr(field, "Set-Cookie:")) {
    field = strtok_r(((void *)0), "\r\n", &strtok_buf);
    continue;
   }
  }
  if (flags & 0x0000011) {
   if (strstr(field, "Proxy-Connection:") || strstr(field, "Connection:") || strstr(field, "Keep-Alive")) {
    field = strtok_r(((void *)0), "\r\n", &strtok_buf);
    continue;
   }
  }
  strcat(mod_hdr, field);
  strcat(mod_hdr, "\r\n");
  field = strtok_r(((void *)0), "\r\n", &strtok_buf);
 }
 if (flags & 0x0000011) {
  if (!strstr(mod_hdr, "Host:") && !strstr(mod_hdr, "User-Agent:")) {
   strcat(mod_hdr, "Proxy-Connection: close\r\n");
   strcat(mod_hdr, "Connection: close\r\n");
  }
 }
 strcat(mod_hdr, "\r\n");
 return mod_hdr;
}

canonical_original_code:
char *http_modify_header(char *buf, int len, int flags) {
 char *orig_hdr; char *mod_hdr; char *strtok_buf; char *field;
 if (!is_http_header(buf, len)) {
  return ((void *)0);
 }
 orig_hdr = strndup(buf, len);
 if (!orig_hdr) {
  lerror("calloc");
  return ((void *)0);
 }
 mod_hdr = calloc(1, len * 2);
 if (!mod_hdr) {
  lerror("calloc");
  free(orig_hdr);
  return ((void *)0);
 }
 strtok_buf = calloc(1, len + 1);
 if (!strtok_buf) {
  perror("calloc");
  free(mod_hdr);
  free(orig_hdr);
  return ((void *)0);
 }
 field = strtok_r(orig_hdr, "\r\n", &strtok_buf);
 if (!field) {
  free(mod_hdr);
  free(orig_hdr);
  free(strtok_buf);
  return ((void *)0);
 }
 strcat(mod_hdr, field);
 strcat(mod_hdr, "\r\n");
 field = strtok_r(((void *)0), "\r\n", &strtok_buf);
 while (field) {
  if (flags & 0x0000001) {
   if (strstr(field, "Cookie:") || strstr(field, "Set-Cookie:")) {
    field = strtok_r(((void *)0), "\r\n", &strtok_buf);
    continue;
   }
  }
  if (flags & 0x0000011) {
   if (strstr(field, "Proxy-Connection:") || strstr(field, "Connection:") || strstr(field, "Keep-Alive")) {
    field = strtok_r(((void *)0), "\r\n", &strtok_buf);
    continue;
   }
  }
  strcat(mod_hdr, field);
  strcat(mod_hdr, "\r\n");
  field = strtok_r(((void *)0), "\r\n", &strtok_buf);
 }
 if (flags & 0x0000011) {
  if (!strstr(mod_hdr, "Host:") && !strstr(mod_hdr, "User-Agent:")) {
   strcat(mod_hdr, "Proxy-Connection: close\r\n");
   strcat(mod_hdr, "Connection: close\r\n");
  }
 }
 strcat(mod_hdr, "\r\n");
 return mod_hdr;
}

variable_types:
buf
char *

variable_types: flags int

variable_types:
field
char *


decompiled_code:
char *__fastcall http_modify_chunk(const char **a1, __int64 a2, char a3)
{
char *v3; // rbx
int v5; // eax
int v6; // ebp

v3 = (char *)*a1;
if ( *a1 )
{
v5 = http_gethdrsize(*a1);
v6 = v5;
if ( v5 <= 7 )
{
v3 = 0LL;
}
else
{
v3 = http_modify_header(v3, v5, a3);
if ( v3 )
*a1 += v6;
}
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(const char **a1, __int64 a2, char a3)
{
char *v3; // rbx
int v5; // eax
int v6; // ebp

v3 = (char *)*a1;
if ( *a1 )
{
v5 = func0(*a1);
v6 = v5;
if ( v5 <= 7 )
{
v3 = 0LL;
}
else
{
v3 = func2(v3, v5, a3);
if ( v3 )
*a1 += v6;
}
}
return v3;
}

original_code:
char *http_modify_chunk(char **buf, int len, int flags) {
 char *hdr, *r_buf;
 int hdr_length;
 r_buf = (*buf);
 if (!r_buf) {
  return ((void *)0);
 }
 hdr_length = http_gethdrsize(r_buf);
 if (hdr_length < 8) {
  return ((void *)0);
 }
 hdr = http_modify_header(r_buf, hdr_length, flags);
 if (!hdr) {
  return ((void *)0);
 }
 (*buf) += hdr_length;
 return hdr;
}

canonical_original_code:
char *http_modify_chunk(char **buf, int len, int flags) {
 char *hdr; char *r_buf;
 int hdr_length;
 r_buf = (*buf);
 if (!r_buf) {
  return ((void *)0);
 }
 hdr_length = http_gethdrsize(r_buf);
 if (hdr_length < 8) {
  return ((void *)0);
 }
 hdr = http_modify_header(r_buf, hdr_length, flags);
 if (!hdr) {
  return ((void *)0);
 }
 (*buf) += hdr_length;
 return hdr;
}

variable_types:
buf
char **

variable_types:
hdr
char *


decompiled_code:
char *__fastcall http_get_url(const char *a1)
{
char *v1; // rax
char *v2; // rbp
char *v3; // rax
char *v4; // rbx
int v5; // eax
size_t v6; // r12
char *v7; // rax

if ( !a1 )
return 0LL;
v1 = strstr(a1, "http://");
v2 = v1;
if ( !v1 )
return 0LL;
v3 = strchr(v1, 32);
v4 = v3;
if ( v3 )
{
v5 = (_DWORD)v3 - (_DWORD)v2;
v4 = 0LL;
if ( v5 > 0 )
{
v6 = v5;
v7 = (char *)calloc(1uLL, v5);
v4 = v7;
if ( v7 )
memcpy(v7, v2, v6);
}
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1)
{
char *v1; // rax
char *v2; // rbp
char *v3; // rax
char *v4; // rbx
int v5; // eax
size_t v6; // r12
char *v7; // rax

if ( !a1 )
return 0LL;
v1 = strstr(a1, "http://");
v2 = v1;
if ( !v1 )
return 0LL;
v3 = strchr(v1, 32);
v4 = v3;
if ( v3 )
{
v5 = (_DWORD)v3 - (_DWORD)v2;
v4 = 0LL;
if ( v5 > 0 )
{
v6 = v5;
v7 = (char *)calloc(1uLL, v5);
v4 = v7;
if ( v7 )
memcpy(v7, v2, v6);
}
}
return v4;
}

original_code:
char *http_get_url(char *buf) {
 char *tmp, *url, *eou;
 int url_length;
 if (!buf) {
  return ((void *)0);
 }
 tmp = strstr(buf, "http://");
 if (!tmp) {
  return ((void *)0);
 }
 eou = strchr(tmp, ' ');
 if (!eou) {
  return ((void *)0);
 }
 url_length = eou - tmp;
 if (url_length < 1) {
  return ((void *)0);
 }
 url = calloc(1, url_length);
 if (!url) {
  return ((void *)0);
 }
 memcpy(url, tmp, url_length);
 return url;
}

canonical_original_code:
char *http_get_url(char *buf) {
 char *tmp; char *url; char *eou;
 int url_length;
 if (!buf) {
  return ((void *)0);
 }
 tmp = strstr(buf, "http://");
 if (!tmp) {
  return ((void *)0);
 }
 eou = strchr(tmp, ' ');
 if (!eou) {
  return ((void *)0);
 }
 url_length = eou - tmp;
 if (url_length < 1) {
  return ((void *)0);
 }
 url = calloc(1, url_length);
 if (!url) {
  return ((void *)0);
 }
 memcpy(url, tmp, url_length);
 return url;
}

variable_types:
tmp
char *

variable_types:
url
char *

variable_types:
eou
char *


decompiled_code:
__int64 shells_init()
{
return 4LL;
}

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

original_code:
int shells_init(void) {
 return 4;
}

canonical_original_code:
int shells_init() {
 return 4;
}


decompiled_code:
__int64 __fastcall shells_foreach(__int64 (__fastcall *a1)(_QWORD))
{
unsigned int i; // ebx
__int64 result; // rax

for ( i = 0; i != 4; ++i )
result = a1(i);
return result;
}

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

for ( i = 0; i != 4; ++i )
result = a1(i);
return result;
}

original_code:
void shells_foreach(void (*cb)(int, gizmo_shcode)) {
 int j;
 for (j = 0; j < 4; j++) {
  cb(j, gizmos[j]);
 }
 return ;
}

canonical_original_code:
void shells_foreach(void (*cb)(int, struct gizmo_shcode)) {
 int j;
 for (j = 0; j < 4; j++) {
  cb(j, gizmos[j]);
 }
 return ;
}

variable_types: void (*)(int, struct gizmo_shcode { char *arch; char *platform; char *desc; int sh_len; char *sh; int data_len; struct shbuf { char *buf; int index; } *(*gizmo_preproc)(void *, void *); void *(*gizmo_postproc)(void *, void *); })

variable_types: j int

user_defined_types: struct gizmo_shcode { char *arch; char *platform; char *desc; int sh_len; char *sh; int data_len; struct shbuf *(*gizmo_preproc)(void *, void *); void *(*gizmo_postproc)(void *, void *); }


decompiled_code:
int __fastcall shells_shrtdesc(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, const char *a7, const char *a8, const char *a9, unsigned int a10)
{
return printf("\t #%d: %s/%s - %s (%d bytes)\n", a1, a8, a7, a9, a10);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, const char *a7, const char *a8, const char *a9, unsigned int a10)
{
return printf("\t #%d: %s/%s - %s (%d bytes)\n", a1, a8, a7, a9, a10);
}

original_code:
void shells_shrtdesc(int idx, gizmo_shcode gizmo) {
 printf("\t #%d: %s/%s - %s (%d bytes)\n", idx, gizmo.platform, gizmo.arch, gizmo.desc, gizmo.sh_len);
 return ;
}

canonical_original_code:
void shells_shrtdesc(int idx, struct gizmo_shcode gizmo) {
 printf("\t #%d: %s/%s - %s (%d bytes)\n", idx, gizmo.platform, gizmo.arch, gizmo.desc, gizmo.sh_len);
 return ;
}

variable_types: idx int

variable_types: struct gizmo_shcode { char *arch; char *platform; char *desc; int sh_len; char *sh; int data_len; struct shbuf { char *buf; int index; } *(*gizmo_preproc)(void *, void *); void *(*gizmo_postproc)(void *, void *); }


decompiled_code:
int __fastcall shells_fulldesc(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, const char *a7, const char *a8, const char *a9, int a10, __int64 a11)
{
int result; // eax
__int64 v12; // rbx
int v13; // ebp
int v14; // er12

gfx_box("(#%d) %s/%s - %s", a1, a8, a7, a9);
printf("\nchar GIZMOCODE[%d] =\n", (unsigned int)a10);
result = printf("\t\"");
if ( a10 > 0 )
{
v12 = 0LL;
v13 = 0;
v14 = a10 - 1;
do
{
++v13;
result = printf("\\x%02x", *(unsigned __int8 *)(a11 + v12));
if ( v13 == 16 )
{
if ( v14 == (_DWORD)v12 )
return puts("\";\n");
result = printf("\"\n\t\"");
v13 = 0;
}
else if ( v14 == (_DWORD)v12 )
{
return puts("\";\n");
}
++v12;
}
while ( v12 != a10 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(unsigned int a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, const char *a7, const char *a8, const char *a9, int a10, __int64 a11)
{
int result; // eax
__int64 v12; // rbx
int v13; // ebp
int v14; // er12

gfx_box("(#%d) %s/%s - %s", a1, a8, a7, a9);
printf("\nchar GIZMOCODE[%d] =\n", (unsigned int)a10);
result = printf("\t\"");
if ( a10 > 0 )
{
v12 = 0LL;
v13 = 0;
v14 = a10 - 1;
do
{
++v13;
result = printf("\\x%02x", *(unsigned __int8 *)(a11 + v12));
if ( v13 == 16 )
{
if ( v14 == (_DWORD)v12 )
return puts("\";\n");
result = printf("\"\n\t\"");
v13 = 0;
}
else if ( v14 == (_DWORD)v12 )
{
return puts("\";\n");
}
++v12;
}
while ( v12 != a10 );
}
return result;
}

original_code:
void shells_fulldesc(int idx, gizmo_shcode gizmo) {
 int bytes, j = 0;
 gfx_box("(#%d) %s/%s - %s", idx, gizmo.platform, gizmo.arch, gizmo.desc);
 printf("\nchar GIZMOCODE[%d] =\n", gizmo.sh_len);
 printf("\t\"");
 for (bytes = 0; bytes < gizmo.sh_len; bytes++) {
  j++;
  printf("\\x%02x", gizmo.sh[bytes] & 0xFF);
  if (j == 16 || bytes == gizmo.sh_len-1) {
   if (bytes == gizmo.sh_len-1) {
    printf("\";\n\n");
    break;
   }
   printf("\"\n\t\"");
   j = 0;
  }
 }
 return ;
}

canonical_original_code:
void shells_fulldesc(int idx, struct gizmo_shcode gizmo) {
 int bytes; int j = 0;
 gfx_box("(#%d) %s/%s - %s", idx, gizmo.platform, gizmo.arch, gizmo.desc);
 printf("\nchar GIZMOCODE[%d] =\n", gizmo.sh_len);
 printf("\t\"");
 for (bytes = 0; bytes < gizmo.sh_len; bytes++) {
  j++;
  printf("\\x%02x", gizmo.sh[bytes] & 0xFF);
  if (j == 16 || bytes == gizmo.sh_len-1) {
   if (bytes == gizmo.sh_len-1) {
    printf("\";\n\n");
    break;
   }
   printf("\"\n\t\"");
   j = 0;
  }
 }
 return ;
}

variable_types: bytes int


decompiled_code:
char **__fastcall shells_get(int a1)
{
return &gizmos[8 * (__int64)a1];
}

canonical_decompiled_code:
char **__fastcall func4(int a1)
{
return &gizmos[8 * (__int64)a1];
}

original_code:
gizmo_shcode *shells_get(int idx) {
 return (gizmo_shcode *) &gizmos[idx];
}

canonical_original_code:
struct gizmo_shcode *shells_get(int idx) {
 return (struct gizmo_shcode *) &gizmos[idx];
}

return_type: struct gizmo_shcode { char *arch; char *platform; char *desc; int sh_len; char *sh; int data_len; struct shbuf { char *buf; int index; } *(*gizmo_preproc)(void *, void *); void *(*gizmo_postproc)(void *, void *); } *


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

v4 = calloc(1uLL, 0x28uLL);
stack = (__int64)v4;
if ( v4 )
{
v4[5] = a1;
*((_QWORD *)v4 + 3) = a2;
*((_QWORD *)v4 + 4) = a3;
result = 1LL;
}
else
{
perror("calloc");
result = 0xFFFFFFFFLL;
}
return result;
}

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

v4 = calloc(1uLL, 0x28uLL);
stack = (__int64)v4;
if ( v4 )
{
v4[5] = a1;
*((_QWORD *)v4 + 3) = a2;
*((_QWORD *)v4 + 4) = a3;
result = 1LL;
}
else
{
perror("calloc");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int hexdump_initialization(int bir, void *s_addr, void *e_addr) {
 stack = calloc(1, sizeof(hex_stack));
 if (!stack) {
  perror("calloc");
  return -1;
 }
 stack->bir = bir;
 stack->baddr = s_addr;
 stack->eaddr = e_addr;
 return 1;
}

variable_types: bir int


decompiled_code:
void hexdump_finialization()
{
_QWORD *v0; // rbx
void *v1; // rdi

if ( stack )
{
v0 = *(_QWORD **)stack;
if ( *(_QWORD *)stack )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[1];
free(v1);
}
while ( v0 );
}
}
}

canonical_decompiled_code:
void func1()
{
_QWORD *v0; // rbx
void *v1; // rdi

if ( stack )
{
v0 = *(_QWORD **)stack;
if ( *(_QWORD *)stack )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[1];
free(v1);
}
while ( v0 );
}
}
}

original_code:
void hexdump_finialization(void) {
 hex_entry *ptr, *ptr_nxt;
 if (!stack || !stack->head) {
  return ;
 }
 ptr = stack->head;
 while (ptr) {
  ptr_nxt = ptr->next;
  free(ptr);
  ptr = ptr_nxt;
 }
 return ;
}

canonical_original_code:
void hexdump_finialization() {
 struct hex_entry *ptr; struct hex_entry *ptr_nxt;
 if (!stack || !stack->head) {
  return ;
 }
 ptr = stack->head;
 while (ptr) {
  ptr_nxt = ptr->next;
  free(ptr);
  ptr = ptr_nxt;
 }
 return ;
}

variable_types: struct hex_entry { char data; struct hex_entry *next; } *


decompiled_code:
__int64 __fastcall hexdump_recursive_psh(__int64 a1, int a2)
{
_BYTE *v2; // rax
__int64 result; // rax

v2 = (_BYTE *)hexdump_getcurrentptr();
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a1;
++*(_DWORD *)(stack + 16);
result = 1LL;
if ( (unsigned int)(a2 + 1) <= 7 )
result = hexdump_recursive_psh(a1 >> 8);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2)
{
_BYTE *v2; // rax
__int64 result; // rax

v2 = (_BYTE *)hexdump_getcurrentptr();
if ( !v2 )
return 0xFFFFFFFFLL;
*v2 = a1;
++*(_DWORD *)(stack + 16);
result = 1LL;
if ( (unsigned int)(a2 + 1) <= 7 )
result = func2(a1 >> 8);
return result;
}

original_code:
int hexdump_recursive_psh(long data, int shifts) {
 hex_entry *cur;
 cur = hexdump_getcurrentptr();
 if (!cur) {
  return -1;
 }
 cur->data = (data & 0xFF);
 stack->totbytes++;
 if (shifts+1 < sizeof(long)) {
  return hexdump_recursive_psh((data >> 8), shifts+1);
 }
 return 1;
}

canonical_original_code:
int hexdump_recursive_psh(long data, int shifts) {
 struct hex_entry *cur;
 cur = hexdump_getcurrentptr();
 if (!cur) {
  return -1;
 }
 cur->data = (data & 0xFF);
 stack->totbytes++;
 if (shifts+1 < sizeof(long)) {
  return hexdump_recursive_psh((data >> 8), shifts+1);
 }
 return 1;
}

variable_types: data long

variable_types: shifts int

user_defined_types: struct hex_entry { char data; struct hex_entry *next; }


decompiled_code:
__int64 __fastcall hexdump_push(__int64 a1)
{
return hexdump_recursive_psh(a1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return func2(a1, 0);
}

original_code:
int hexdump_push(long data) {
 return hexdump_recursive_psh(data, 0);
}


original_code:
int hexdump_display(void) {
 int idx, pad_length = 0;
 char *hdisplay, c;
 hex_entry *ptr;
 if (stack->baddr == stack->eaddr) {
  return 0;
 }
 if (stack->totbytes < stack->bir) {
  if ( ( stack->totbytes < addr_substruct(stack->baddr, stack->eaddr) ) ||
       ( addr_substruct(stack->baddr, stack->eaddr) > stack->bir ) )
  {
   return 0;
  }
 }
 hdisplay = calloc(1, stack->bir);
 if (!hdisplay) {
  perror("calloc");
  return 0;
 }
 printf("%p: \t", stack->baddr);
 ptr = stack->head;
 for (idx = 0; (idx < stack->bir && ptr); idx++) {
  printf("%02x ", (ptr->data & 0xFF));
  c = ptr->data;
  if (!((*__ctype_b_loc ())[(int) ((ptr->data))] & (unsigned short int) _ISgraph)) {
                 c = '.';
  }
  hdisplay[idx] = c;
  ptr = ptr->next;
  free(stack->head);
  stack->head = ptr;
  stack->totbytes--;
  stack->baddr = addr_increase(stack->baddr, 1);
  if (stack->baddr == stack->eaddr) {
   pad_length = stack->bir - idx - 1;
   break;
  }
 }
 while (pad_length) {
  printf("   ");
  hdisplay[idx] = ' ';
  idx++;
  pad_length--;
 }
 printf("| %s\n", hdisplay);
 free(hdisplay);
 return 1;
}

canonical_original_code:
int hexdump_display() {
 int idx; int pad_length = 0;
 char *hdisplay; char c;
 struct hex_entry *ptr;
 if (stack->baddr == stack->eaddr) {
  return 0;
 }
 if (stack->totbytes < stack->bir) {
  if ( ( stack->totbytes < addr_substruct(stack->baddr, stack->eaddr) ) ||
       ( addr_substruct(stack->baddr, stack->eaddr) > stack->bir ) )
  {
   return 0;
  }
 }
 hdisplay = calloc(1, stack->bir);
 if (!hdisplay) {
  perror("calloc");
  return 0;
 }
 printf("%p: \t", stack->baddr);
 ptr = stack->head;
 for (idx = 0; (idx < stack->bir && ptr); idx++) {
  printf("%02x ", (ptr->data & 0xFF));
  c = ptr->data;
  if (!((*__ctype_b_loc ())[(int) ((ptr->data))] & (unsigned short) _ISgraph)) {
                 c = '.';
  }
  hdisplay[idx] = c;
  ptr = ptr->next;
  free(stack->head);
  stack->head = ptr;
  stack->totbytes--;
  stack->baddr = addr_increase(stack->baddr, 1);
  if (stack->baddr == stack->eaddr) {
   pad_length = stack->bir - idx - 1;
   break;
  }
 }
 while (pad_length) {
  printf("   ");
  hdisplay[idx] = ' ';
  idx++;
  pad_length--;
 }
 printf("| %s\n", hdisplay);
 free(hdisplay);
 return 1;
}

variable_types:
hdisplay
char *

variable_types: c char


decompiled_code:
ssize_t __fastcall httpd_css_playback(int a1)
{
return write(
a1,
" \tbody { font-family: monospace; background: #000000; color: #FFFFFF; } \n"
" \ta:link { color:#FFFFFF; text-decoration: none; } \n"
" \ta:visited { color:#FFFFFF; text-decoration:none; } \n"
" \ta:hover { color:#404040; text-decoration:none; } \n"
" \ttd { padding: 2px; } \n"
" \ttable { empty-cells: hide } \n"
" \t.fullheight { height: 100% } \n"
" \tinput { font-family: monospace; border:0px; background: #000000; color: #FFFFFF; } ",
0x193uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(int a1)
{
return write(
a1,
" \tbody { font-family: monospace; background: #000000; color: #FFFFFF; } \n"
" \ta:link { color:#FFFFFF; text-decoration: none; } \n"
" \ta:visited { color:#FFFFFF; text-decoration:none; } \n"
" \ta:hover { color:#404040; text-decoration:none; } \n"
" \ttd { padding: 2px; } \n"
" \ttable { empty-cells: hide } \n"
" \t.fullheight { height: 100% } \n"
" \tinput { font-family: monospace; border:0px; background: #000000; color: #FFFFFF; } ",
0x193uLL);
}

original_code:
int httpd_css_playback(int fd, char *raw, char *cgi) {
 return write(fd, WWW_CSS_FILE, strlen(WWW_CSS_FILE));
}

variable_types: fd int

variable_types:
raw
char *

variable_types:
cgi
char *


wprintf

decompiled_code:
ssize_t wprintf(int fd, char *format, ...)
{
size_t v2; // rax
char v4[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(v4, 0x400uLL, format, arg);
v2 = strlen(v4);
return write(fd, v4, v2);
}

canonical_decompiled_code:
ssize_t func1(int fd, char *format, ...)
{
size_t v2; // rax
char v4[1032]; // [rsp+0h] [rbp-4D8h] BYREF
gcc_va_list arg; // [rsp+408h] [rbp-D0h] BYREF

va_start(arg, format);
vsnprintf(v4, 0x400uLL, format, arg);
v2 = strlen(v4);
return write(fd, v4, v2);
}

original_code:
int wprintf(int fd, char *fmt, ...) {
        va_list ap;
        char buf[1024];
        __builtin_va_start(ap,fmt);
        vsnprintf(buf, sizeof(buf), fmt, ap);
        __builtin_va_end(ap);
 return write(fd, buf, strlen(buf));
}

canonical_original_code:
int wprintf(int fd, char *fmt, ...) {
        __builtin_va_list ap;
        char buf[1024];
        __builtin_va_start(ap,fmt);
        vsnprintf(buf, sizeof(buf), fmt, ap);
        __builtin_va_end(ap);
 return write(fd, buf, strlen(buf));
}

variable_types:
fmt
char *

variable_types:
buf
char [1024]


decompiled_code:
ssize_t httpd_msg_page(int fd, const char *a2, unsigned int a3, const char *a4, const char *a5, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4F0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4D8h] BYREF

va_start(arg, a5);
vsnprintf(s, 0x400uLL, a5, arg);
write(
fd,
" <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> \n"
"  \n"
"  \n"
" \t\t<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=ISO-8859-1\"> \n"
" ",
0xB9uLL);
if ( a3 )
wprintf(fd, "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"%d; URL=%s\">\n", a3, a4);
wprintf(fd, "<TITLE>%s</TITLE>\r\n", a2);
wprintf(fd, "\r\n");
wprintf(fd, "\r\n\r\n");
wprintf(fd, "
\r\n");
wprintf(fd, "
\r\n");
wprintf(fd, "\r\n");
wprintf(fd, "
%s
\r\n", a2);
wprintf(fd, "%s\r\n", s);
wprintf(fd, "	\r\n");
wprintf(fd, "
\r\n");
wprintf(fd, "
\r\n");
return write(fd, " \t \n \t \n ", 0x17uLL);
}

canonical_decompiled_code:
ssize_t func2(int fd, const char *a2, unsigned int a3, const char *a4, const char *a5, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-4F0h] BYREF
char s[1024]; // [rsp+20h] [rbp-4D8h] BYREF

va_start(arg, a5);
vsnprintf(s, 0x400uLL, a5, arg);
write(
fd,
" <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> \n"
"  \n"
"  \n"
" \t\t<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=ISO-8859-1\"> \n"
" ",
0xB9uLL);
if ( a3 )
func1(fd, "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"%d; URL=%s\">\n", a3, a4);
func1(fd, "<TITLE>%s</TITLE>\r\n", a2);
func1(fd, "\r\n");
func1(fd, "\r\n\r\n");
func1(fd, "
\r\n");
func1(fd, "
\r\n");
func1(fd, "\r\n");
func1(fd, "
%s
\r\n", a2);
func1(fd, "%s\r\n", s);
func1(fd, "	\r\n");
func1(fd, "
\r\n");
func1(fd, "
\r\n");
return write(fd, " \t \n \t \n ", 0x17uLL);
}

original_code:
void httpd_msg_page(int fd, char *title, int rsecs, char *rurl, char *msg, ...) {
 char buf[1024];
        va_list ap;
        __builtin_va_start(ap,msg);
        vsnprintf(buf, sizeof(buf), msg, ap);
        __builtin_va_end(ap);
 write(fd, WWW_HTML_START, strlen(WWW_HTML_START));
 if (rsecs ) {
  wprintf(fd, "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"%d; URL=%s\">\n", rsecs, rurl);
 }
 wprintf(fd, "<TITLE>%s</TITLE>\r\n", title);
 wprintf(fd, "\r\n");
 wprintf(fd, "\r\n\r\n");
 wprintf(fd, "
\r\n");
 wprintf(fd, "
\r\n");
 wprintf(fd, "\r\n");
 wprintf(fd, "
%s
\r\n", title);
 wprintf(fd, "%s\r\n", buf);
 wprintf(fd, "	\r\n");
 wprintf(fd, "
\r\n");
 wprintf(fd, "
\r\n");
 write(fd, WWW_HTML_END, strlen(WWW_HTML_END));
 return ;
}

canonical_original_code:
void httpd_msg_page(int fd, char *title, int rsecs, char *rurl, char *msg, ...) {
 char buf[1024];
        __builtin_va_list ap;
        __builtin_va_start(ap,msg);
        vsnprintf(buf, sizeof(buf), msg, ap);
        __builtin_va_end(ap);
 write(fd, WWW_HTML_START, strlen(WWW_HTML_START));
 if (rsecs ) {
  wprintf(fd, "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"%d; URL=%s\">\n", rsecs, rurl);
 }
 wprintf(fd, "<TITLE>%s</TITLE>\r\n", title);
 wprintf(fd, "\r\n");
 wprintf(fd, "\r\n\r\n");
 wprintf(fd, "
\r\n");
 wprintf(fd, "
\r\n");
 wprintf(fd, "\r\n");
 wprintf(fd, "
%s
\r\n", title);
 wprintf(fd, "%s\r\n", buf);
 wprintf(fd, "	\r\n");
 wprintf(fd, "
\r\n");
 wprintf(fd, "
\r\n");
 write(fd, WWW_HTML_END, strlen(WWW_HTML_END));
 return ;
}

variable_types:
title
char *

variable_types: rsecs int

variable_types:
rurl
char *

variable_types:
msg
char *


decompiled_code:
ssize_t __fastcall httpd_www_noproxies_msg(int fd)
{
const char *v1; // rax
const char *v2; // rax
const char *v4; // rsi

v1 = (const char *)hashtable_lookup(cfg, "http-analyzer");
if ( v1 && strcmp(v1, "off") )
{
v4 = (const char *)hashtable_lookup(cfg, "http-admin-mode");
if ( !v4 || !strcmp(v4, "off") )
{
hashtable_insert(cfg, "http-admin-mode", "on");
hashtable_insert(cfg, "http-admin-url", "http://ghost/");
}
}
else
{
hashtable_insert(cfg, "http-analyzer", "on");
hashtable_insert(cfg, "http-admin-mode", "on");
hashtable_insert(cfg, "http-admin-url", "http://ghost/");
}
v2 = (const char *)hashtable_lookup(cfg, "http-admin-url");
return httpd_msg_page(
fd,
"Out of Proxies!",
0xFFFFFFFF,
0LL,
"There are currectly no proxies or no working proxies in the database.
\n"
" \t Please click here to access the database
 \n",
v2);
}

canonical_decompiled_code:
ssize_t __fastcall func3(int fd)
{
const char *v1; // rax
const char *v2; // rax
const char *v4; // rsi

v1 = (const char *)hashtable_lookup(cfg, "http-analyzer");
if ( v1 && strcmp(v1, "off") )
{
v4 = (const char *)hashtable_lookup(cfg, "http-admin-mode");
if ( !v4 || !strcmp(v4, "off") )
{
hashtable_insert(cfg, "http-admin-mode", "on");
hashtable_insert(cfg, "http-admin-url", "http://ghost/");
}
}
else
{
hashtable_insert(cfg, "http-analyzer", "on");
hashtable_insert(cfg, "http-admin-mode", "on");
hashtable_insert(cfg, "http-admin-url", "http://ghost/");
}
v2 = (const char *)hashtable_lookup(cfg, "http-admin-url");
return func2(
fd,
"Out of Proxies!",
0xFFFFFFFF,
0LL,
"There are currectly no proxies or no working proxies in the database.
\n"
" \t Please click here to access the database
 \n",
v2);
}

original_code:
void httpd_www_noproxies_msg(int fd) {
 char *retval;
 retval = hashtable_lookup(cfg, "http-analyzer");
 if (!retval || !strcmp(retval, "off")) {
  hashtable_insert(cfg, "http-analyzer", "on");
  hashtable_insert(cfg, "http-admin-mode", "on");
  hashtable_insert(cfg, "http-admin-url", "http://ghost/");
 } else {
  retval = hashtable_lookup(cfg, "http-admin-mode");
  if (!retval || !strcmp(retval, "off")) {
   hashtable_insert(cfg, "http-admin-mode", "on");
   hashtable_insert(cfg, "http-admin-url", "http://ghost/");
  }
 }
 httpd_msg_page(fd, "Out of Proxies!", -1, ((void *)0),
  "There are currectly no proxies or no working proxies in the database.
\n 	        Please click here to access the database
 \n",
   hashtable_lookup(cfg, "http-admin-url"));
 return ;
}

variable_types:
retval
char *


decompiled_code:
ssize_t __fastcall httpd_start_html(int fd)
{
write(
fd,
" <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> \n"
"  \n"
"  \n"
" \t\t<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=ISO-8859-1\"> \n"
" ",
0xB9uLL);
wprintf(fd, "\r\n");
write(fd, " \t\t<TITLE>GHOST</TITLE> \n \t \n \t \n ", 0x2FuLL);
return write(
fd,
" \t
 \n"
" \t
 \n"
" \t  \n"
" \t
Ghost
 \n"
" \t 	 \n"
" \t
 \n"
" \t
 \n"
" ",
0xBEuLL);
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd)
{
write(
fd,
" <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\"> \n"
"  \n"
"  \n"
" \t\t<META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=ISO-8859-1\"> \n"
" ",
0xB9uLL);
func1(fd, "\r\n");
write(fd, " \t\t<TITLE>GHOST</TITLE> \n \t \n \t \n ", 0x2FuLL);
return write(
fd,
" \t
 \n"
" \t
 \n"
" \t  \n"
" \t
Ghost
 \n"
" \t 	 \n"
" \t
 \n"
" \t
 \n"
" ",
0xBEuLL);
}

original_code:
void httpd_start_html(int fd) {
 write(fd, WWW_HTML_START, strlen(WWW_HTML_START));
        wprintf(fd, "<STYLE TYPE=\"text/css\">\r\n");
        write(fd, WWW_CSS_FILE, strlen(WWW_CSS_FILE));
        wprintf(fd, "</STYLE>\r\n");
 write(fd, WWW_HTML_PAGE, strlen(WWW_HTML_PAGE));
 write(fd, WWW_HTML_LOGO, strlen(WWW_HTML_LOGO));
 return ;
}


decompiled_code:
ssize_t __fastcall httpd_end_html(int a1)
{
return write(a1, " \t \n \t \n ", 0x17uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func5(int a1)
{
return write(a1, " \t \n \t \n ", 0x17uLL);
}

original_code:
void httpd_end_html(int fd) {
 write(fd, WWW_HTML_END, strlen(WWW_HTML_END));
 return ;
}


decompiled_code:
ssize_t __fastcall httpd_header(int fd, int a2, const char *a3)
{
size_t v4; // rax
size_t v5; // rax
__int64 v7[131]; // [rsp+0h] [rbp-418h] BYREF

memset(v7, 0, 0x400uLL);
switch ( a2 )
{
case 302:
strcat((char *)v7, "HTTP/1.1 302 Found\r\n");
break;
case 404:
strcat((char *)v7, "HTTP/1.1 404 Not Found\r\n");
break;
case 200:
strcat((char *)v7, "HTTP/1.1 200 OK\r\n");
break;
}
strcat((char *)v7, "Date: Sun, 01 Jan 1970 00:00:00 GMT\r\n");
v4 = strlen((const char *)v7);
*(__int64 *)((char *)v7 + v4) = 0x203A726576726553LL;
*(__int64 *)((char *)&v7[1] + v4) = 0xA0D74736F6847LL;
if ( a3 )
{
strcat((char *)v7, "Location: ");
strcat((char *)v7, a3);
strcat((char *)v7, "\r\n");
}
strcat((char *)v7, "Content-Type: text/html; charset=iso-8859-1\r\n");
strcat((char *)v7, "Connection: close\r\n");
strcat((char *)v7, "Proxy-Connection: close\r\n");
strcat((char *)v7, "\r\n");
v5 = strlen((const char *)v7);
return write(fd, v7, v5);
}

canonical_decompiled_code:
ssize_t __fastcall func6(int fd, int a2, const char *a3)
{
size_t v4; // rax
size_t v5; // rax
__int64 v7[131]; // [rsp+0h] [rbp-418h] BYREF

memset(v7, 0, 0x400uLL);
switch ( a2 )
{
case 302:
strcat((char *)v7, "HTTP/1.1 302 Found\r\n");
break;
case 404:
strcat((char *)v7, "HTTP/1.1 404 Not Found\r\n");
break;
case 200:
strcat((char *)v7, "HTTP/1.1 200 OK\r\n");
break;
}
strcat((char *)v7, "Date: Sun, 01 Jan 1970 00:00:00 GMT\r\n");
v4 = strlen((const char *)v7);
*(__int64 *)((char *)v7 + v4) = 0x203A726576726553LL;
*(__int64 *)((char *)&v7[1] + v4) = 0xA0D74736F6847LL;
if ( a3 )
{
strcat((char *)v7, "Location: ");
strcat((char *)v7, a3);
strcat((char *)v7, "\r\n");
}
strcat((char *)v7, "Content-Type: text/html; charset=iso-8859-1\r\n");
strcat((char *)v7, "Connection: close\r\n");
strcat((char *)v7, "Proxy-Connection: close\r\n");
strcat((char *)v7, "\r\n");
v5 = strlen((const char *)v7);
return write(fd, v7, v5);
}

original_code:
void httpd_header(int fd, int code, char *redirect) {
 char hdr[1024];
 memset((void *)hdr, 0x0, 1024);
 switch (code) {
  case 302:
   strcat(hdr, "HTTP/1.1 302 Found\r\n");
   break;
  case 200:
   strcat(hdr, "HTTP/1.1 200 OK\r\n");
   break;
  case 404:
   strcat(hdr, "HTTP/1.1 404 Not Found\r\n");
   break;
 }
 strcat(hdr, "Date: Sun, 01 Jan 1970 00:00:00 GMT\r\n");
 strcat(hdr, "Server: Ghost\r\n");
 if (redirect) {
  strcat(hdr, "Location: ");
  strcat(hdr, redirect);
  strcat(hdr, "\r\n");
 }
 strcat(hdr, "Content-Type: text/html; charset=iso-8859-1\r\n");
 strcat(hdr, "Connection: close\r\n");
 strcat(hdr, "Proxy-Connection: close\r\n");
 strcat(hdr, "\r\n");
 write (fd, hdr, strlen(hdr));
 return ;
}

variable_types: code int

variable_types:
redirect
char *

variable_types:
hdr
char [1024]


decompiled_code:
ssize_t __fastcall httpd_handler(int fd, char *s1, __int64 a3)
{
char *v4; // r14
int v5; // er12
const char *v6; // rsi
__int64 v7; // rbx
int v8; // ebp
ssize_t result; // rax

v4 = strchr(s1, 63);
v5 = strlen(s1);
if ( v4 )
v5 -= strlen(v4);
v6 = pages;
if ( !pages )
return httpd_www_404((unsigned int)fd, s1, a3);
v7 = (unsigned int)((_DWORD)&pages + 24);
v8 = 0;
while ( strncmp(s1, v6, v5) )
{
++v8;
v7 += 24LL;
v6 = *(const char **)(v7 - 24);
if ( !v6 )
return httpd_www_404((unsigned int)fd, s1, a3);
}
result = LODWORD((&pages)[3 * v8 + 2]);
if ( (_DWORD)result == 2 )
goto LABEL_16;
if ( (int)result <= 2 )
{
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = ((__int64 (__fastcall *)(_QWORD, __int64, char *))(&pages)[3 * v8 + 1])((unsigned int)fd, a3, v4);
return result;
}
LABEL_16:
httpd_header(fd, 200, 0LL);
httpd_start_html(fd);
((void (__fastcall *)(_QWORD, __int64, char *))(&pages)[3 * v8 + 1])((unsigned int)fd, a3, v4);
return httpd_end_html(fd);
}
if ( (_DWORD)result == 3 )
{
httpd_header(fd, 200, 0LL);
result = ((__int64 (__fastcall *)(_QWORD, __int64, char *))(&pages)[3 * v8 + 1])((unsigned int)fd, a3, v4);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func7(int fd, char *s1, __int64 a3)
{
char *v4; // r14
int v5; // er12
const char *v6; // rsi
__int64 v7; // rbx
int v8; // ebp
ssize_t result; // rax

v4 = strchr(s1, 63);
v5 = strlen(s1);
if ( v4 )
v5 -= strlen(v4);
v6 = pages;
if ( !pages )
return httpd_www_404((unsigned int)fd, s1, a3);
v7 = (unsigned int)((_DWORD)&pages + 24);
v8 = 0;
while ( strncmp(s1, v6, v5) )
{
++v8;
v7 += 24LL;
v6 = *(const char **)(v7 - 24);
if ( !v6 )
return httpd_www_404((unsigned int)fd, s1, a3);
}
result = LODWORD((&pages)[3 * v8 + 2]);
if ( (_DWORD)result == 2 )
goto LABEL_16;
if ( (int)result <= 2 )
{
if ( (_DWORD)result )
{
if ( (_DWORD)result == 1 )
result = ((__int64 (__fastcall *)(_QWORD, __int64, char *))(&pages)[3 * v8 + 1])((unsigned int)fd, a3, v4);
return result;
}
LABEL_16:
func6(fd, 200, 0LL);
func4(fd);
((void (__fastcall *)(_QWORD, __int64, char *))(&pages)[3 * v8 + 1])((unsigned int)fd, a3, v4);
return func5(fd);
}
if ( (_DWORD)result == 3 )
{
func6(fd, 200, 0LL);
result = ((__int64 (__fastcall *)(_QWORD, __int64, char *))(&pages)[3 * v8 + 1])((unsigned int)fd, a3, v4);
}
return result;
}

original_code:
void httpd_handler(int fd, char *url, char *buf) {
 int idx, url_length;
 char *cgi_params;
 cgi_params = strchr(url, '?');
 url_length = strlen(url);
 if (cgi_params) {
  url_length -= strlen(cgi_params);
 }
 for (idx = 0; pages[idx].page != ((void *)0); idx++) {
  if (!strncmp(url, pages[idx].page, url_length)) {
   switch (pages[idx].type) {
    case HTTPD_CGI:
    case HTTPD_WWW:
     httpd_header(fd, 200, ((void *)0));
     httpd_start_html(fd);
     pages[idx].proc(fd, buf, cgi_params);
     httpd_end_html(fd);
     break;
    case HTTPD_RAW:
     httpd_header(fd, 200, ((void *)0));
     pages[idx].proc(fd, buf, cgi_params);
     break;
    case HTTPD_CGI_REDIRECT:
     pages[idx].proc(fd, buf, cgi_params);
     break;
   }
   return ;
  }
 }
 httpd_www_404(fd, url, buf);
 return ;
}

canonical_original_code:
void httpd_handler(int fd, char *url, char *buf) {
 int idx; int url_length;
 char *cgi_params;
 cgi_params = strchr(url, '?');
 url_length = strlen(url);
 if (cgi_params) {
  url_length -= strlen(cgi_params);
 }
 for (idx = 0; pages[idx].page != ((void *)0); idx++) {
  if (!strncmp(url, pages[idx].page, url_length)) {
   switch (pages[idx].type) {
    case HTTPD_CGI:
    case HTTPD_WWW:
     httpd_header(fd, 200, ((void *)0));
     httpd_start_html(fd);
     pages[idx].proc(fd, buf, cgi_params);
     httpd_end_html(fd);
     break;
    case HTTPD_RAW:
     httpd_header(fd, 200, ((void *)0));
     pages[idx].proc(fd, buf, cgi_params);
     break;
    case HTTPD_CGI_REDIRECT:
     pages[idx].proc(fd, buf, cgi_params);
     break;
   }
   return ;
  }
 }
 httpd_www_404(fd, url, buf);
 return ;
}

variable_types:
url
char *

variable_types:
buf
char *

variable_types: idx int


decompiled_code:
char *__fastcall httpd_url_decode(char *s)
{
size_t i; // rbx
size_t j; // r12
size_t v3; // rax
char v4; // r12
char v5; // r14
const unsigned __int16 *v6; // rax
char v8[2]; // [rsp+Ah] [rbp-2Eh] BYREF
int v9; // [rsp+Ch] [rbp-2Ch] BYREF

if ( s )
{
for ( i = 0LL; ; ++i )
{
v3 = strlen(s);
if ( v3 <= i )
break;
if ( s[i] == 37 )
{
if ( (int)i + 2 > v3 )
return s;
v8[0] = s[i + 1];
v4 = v8[0];
v5 = s[i + 2];
v8[1] = v5;
v6 = *_ctype_b_loc();
if ( (v6[v4] & 0x1000) != 0 && (v6[v5] & 0x1000) != 0 )
{
_isoc99_sscanf(v8, "%x", &v9);
s[i] = v9;
for ( j = (int)i + 3; strlen(s) + 1 > j; ++j )
s[j - 2] = s[j];
}
}
}
}
return s;
}

original_code:
char *httpd_url_decode(char *url) {
        int j, i, val;
        char buf[2];
 if (!url) {
  return url;
 }
        for (j = 0; j < strlen(url); j++) {
                if (url[j] == '%') {
                        if (j+2 > strlen(url)) {
                                break;
                        }
                        buf[0] = url[j+1];
                        buf[1] = url[j+2];
                        if (((*__ctype_b_loc ())[(int) ((buf[0]))] & (unsigned short int) _ISxdigit) && ((*__ctype_b_loc ())[(int) ((buf[1]))] & (unsigned short int) _ISxdigit)) {
                                sscanf(buf, "%x", &val);
                                url[j] = val;
                                for (i = j+3; i < strlen(url) + 1; i++) {
                                        url[i-2] = url[i];
                                }
                        }
                }
        }
        return url;
}

canonical_original_code:
char *httpd_url_decode(char *url) {
        int j; int i; int val;
        char buf[2];
 if (!url) {
  return url;
 }
        for (j = 0; j < strlen(url); j++) {
                if (url[j] == '%') {
                        if (j+2 > strlen(url)) {
                                break;
                        }
                        buf[0] = url[j+1];
                        buf[1] = url[j+2];
                        if (((*__ctype_b_loc ())[(int) ((buf[0]))] & (unsigned short) _ISxdigit) && ((*__ctype_b_loc ())[(int) ((buf[1]))] & (unsigned short) _ISxdigit)) {
                                sscanf(buf, "%x", &val);
                                url[j] = val;
                                for (i = j+3; i < strlen(url) + 1; i++) {
                                        url[i-2] = url[i];
                                }
                        }
                }
        }
        return url;
}

variable_types: j int

variable_types: i int

variable_types: val int

variable_types:
buf
char [2]


original_code:
void gizmo_asmgen(char *buf, int len) {
 int j;
 for (j = 0; j < len; j++) {
  srand((time(((void *)0)) * (j+1))-j);
  buf[j] = (rand()+1) % 255;
 }
 return ;
}

variable_types: len int


decompiled_code:
__int64 io_init()
{
return io_fclose_recursive(0LL);
}

canonical_decompiled_code:
__int64 func0()
{
return io_fclose_recursive(0LL);
}

original_code:
void io_init(void) {
 io_fclose_recursive(0);
 return ;
}

canonical_original_code:
void io_init() {
 io_fclose_recursive(0);
 return ;
}


decompiled_code:
__int64 io_fini()
{
return io_fclose_recursive(0LL);
}

canonical_decompiled_code:
__int64 func1()
{
return io_fclose_recursive(0LL);
}

original_code:
void io_fini(void) {
 io_fclose_recursive(0);
 return ;
}

canonical_original_code:
void io_fini() {
 io_fclose_recursive(0);
 return ;
}


decompiled_code:
__int64 __fastcall io_out_init(__int64 a1)
{
return io_openfile(a1, 1LL, &unk_72);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return io_openfile(a1, 1LL, &unk_72);
}

original_code:
int io_out_init(char *file) {
 return io_openfile(file, FSTDOUT, "w");
}

variable_types:
file
char *


decompiled_code:
__int64 __fastcall io_in_init(__int64 a1)
{
return io_openfile(a1, 0LL, &unk_74);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return io_openfile(a1, 0LL, &unk_74);
}

original_code:
int io_in_init(char *file) {
 return io_openfile(file, FSTDIN, "r");
}


decompiled_code:
__int64 io_out_write()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func4()
{
return 0xFFFFFFFFLL;
}

original_code:
int io_out_write(long data) {
 if (streams[FSTDOUT]) {
  return fwrite(&data, sizeof(long), 1, streams[FSTDOUT]);
 }
 return -1;
}

variable_types: data long


decompiled_code:
__int64 io_in_totbytes()
{
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 func5()
{
return 0xFFFFFFFFLL;
}

original_code:
int io_in_totbytes(void) {
 struct stat buf;
 if (streams[FSTDIN]) {
  if (fstat(fileno(streams[FSTDIN]), &buf) < 0) {
   return -1;
  }
  return buf.st_size;
 }
 return -1;
}

canonical_original_code:
int io_in_totbytes() {
 struct stat buf;
 if (streams[FSTDIN]) {
  if (fstat(fileno(streams[FSTDIN]), &buf) < 0) {
   return -1;
  }
  return buf.st_size;
 }
 return -1;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 io_in_read()
{
return -1LL;
}

canonical_decompiled_code:
__int64 func6()
{
return -1LL;
}

original_code:
long io_in_read(void) {
 long data;
 if (streams[FSTDIN]) {
  if (!fread(&data, sizeof(long), 1, streams[FSTDIN])) {
   return -1;
  }
  return data;
 }
 return -1;
}

canonical_original_code:
long io_in_read() {
 long data;
 if (streams[FSTDIN]) {
  if (!fread(&data, sizeof(long), 1, streams[FSTDIN])) {
   return -1;
  }
  return data;
 }
 return -1;
}

return_type: long


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

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

original_code:
int io_has_in(void) {
 if (streams[FSTDIN]) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int io_has_in() {
 if (streams[FSTDIN]) {
  return 1;
 }
 return 0;
}


decompiled_code:
_DWORD *opts_alloc_default()
{
_DWORD *result; // rax

result = calloc(1uLL, 0x20uLL);
if ( result )
{
*result = 4;
result[1] = -1;
result[3] = -1;
}
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = calloc(1uLL, 0x20uLL);
if ( result )
{
*result = 4;
result[1] = -1;
result[3] = -1;
}
return result;
}

original_code:
opts *opts_alloc_default(void) {
 opts *ptr;
 ptr = calloc(1, sizeof(struct sinister_opts));
 if (!ptr) {
  return ((void *)0);
 }
 ptr->bir = 4;
 ptr->direction = -1;
 ptr->cmdparams = -1;
 return ptr;
}

canonical_original_code:
struct sinister_opts *opts_alloc_default() {
 struct sinister_opts *ptr;
 ptr = calloc(1, sizeof(struct sinister_opts));
 if (!ptr) {
  return ((void *)0);
 }
 ptr->bir = 4;
 ptr->direction = -1;
 ptr->cmdparams = -1;
 return ptr;
}

variable_types: struct sinister_opts { int bir; int direction; int action; int cmdparams; void *s_addr; void *e_addr; } *


decompiled_code:
void __fastcall opts_free(void *a1)
{
if ( a1 )
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
if ( a1 )
free(a1);
}

original_code:
void opts_free(opts *optz) {
 if (optz) {
  free(optz);
 }
 return ;
}

canonical_original_code:
void opts_free(struct sinister_opts *optz) {
 if (optz) {
  free(optz);
 }
 return ;
}

user_defined_types: struct sinister_opts { int bir; int direction; int action; int cmdparams; void *s_addr; void *e_addr; }


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

result = 1LL;
if ( *(int *)(a1 + 4) < 0 )
{
fwrite("*** missing direction option, please use '-m' to set direction!\n", 1uLL, 0x40uLL, stderr);
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( *(int *)(a1 + 4) < 0 )
{
fwrite("*** missing direction option, please use '-m' to set direction!\n", 1uLL, 0x40uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int opts_has_direction(opts *opt) {
 if (opt->direction < 0) {
  fprintf(stderr, "*** missing direction option, please use '-m' to set direction!\n");
  return 0;
 }
 return 1;
}

canonical_original_code:
int opts_has_direction(struct sinister_opts *opt) {
 if (opt->direction < 0) {
  fprintf(stderr, "*** missing direction option, please use '-m' to set direction!\n");
  return 0;
 }
 return 1;
}


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

v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
return 1;
fwrite("*** missing action option, select one of the ('-d','-p','-s') options!\n", 1uLL, 0x47uLL, stderr);
return v1;
}

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

v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
return 1;
fwrite("*** missing action option, select one of the ('-d','-p','-s') options!\n", 1uLL, 0x47uLL, stderr);
return v1;
}

original_code:
int opts_has_action(opts *opt) {
 if (!opt->action) {
  fprintf(stderr, "*** missing action option, select one of the ('-d','-p','-s') options!\n");
  return 0;
 }
 return 1;
}

canonical_original_code:
int opts_has_action(struct sinister_opts *opt) {
 if (!opt->action) {
  fprintf(stderr, "*** missing action option, select one of the ('-d','-p','-s') options!\n");
  return 0;
 }
 return 1;
}


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

result = 1LL;
if ( *(int *)(a1 + 12) <= 0 )
{
fwrite("*** missing program filename or pid parameter!\n", 1uLL, 0x2FuLL, stderr);
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( *(int *)(a1 + 12) <= 0 )
{
fwrite("*** missing program filename or pid parameter!\n", 1uLL, 0x2FuLL, stderr);
result = 0LL;
}
return result;
}

original_code:
int opts_has_cmdparams(opts *opt) {
 if (opt->cmdparams < 1) {
  fprintf(stderr, "*** missing program filename or pid parameter!\n");
  return 0;
 }
 return 1;
}

canonical_original_code:
int opts_has_cmdparams(struct sinister_opts *opt) {
 if (opt->cmdparams < 1) {
  fprintf(stderr, "*** missing program filename or pid parameter!\n");
  return 0;
 }
 return 1;
}


decompiled_code:
int __fastcall opts_err_badaddr(const char *a1)
{
return fprintf(stderr, "*** (%s): given address is malformed/invalid!\n", a1);
}

canonical_decompiled_code:
int __fastcall func5(const char *a1)
{
return fprintf(stderr, "*** (%s): given address is malformed/invalid!\n", a1);
}

original_code:
void opts_err_badaddr(char *addr) {
 fprintf(stderr, "*** (%s): given address is malformed/invalid!\n", addr);
 return ;
}

variable_types:
addr
char *


decompiled_code:
size_t opts_err_actconflict()
{
return fwrite("**** an action already been selected!\n", 1uLL, 0x26uLL, stderr);
}

canonical_decompiled_code:
size_t func6()
{
return fwrite("**** an action already been selected!\n", 1uLL, 0x26uLL, stderr);
}

original_code:
void opts_err_actconflict(void) {
 fprintf(stderr, "**** an action already been selected!\n");
 return ;
}

canonical_original_code:
void opts_err_actconflict() {
 fprintf(stderr, "**** an action already been selected!\n");
 return ;
}


decompiled_code:
__int64 __fastcall daemon_to_proxy(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = cfg_get_proxyopts();
return daemon_chunk_judge(a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = cfg_get_proxyopts();
return daemon_chunk_judge(a1, a2, v2);
}

original_code:
void *daemon_to_proxy(char **buf, int len) {
 return daemon_chunk_judge(buf, len, cfg_get_proxyopts());
}

variable_types:
buf
char **


decompiled_code:
__int64 __fastcall daemon_to_client(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = cfg_get_clientopts();
return daemon_chunk_judge(a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax

v2 = cfg_get_clientopts();
return daemon_chunk_judge(a1, a2, v2);
}

original_code:
void *daemon_to_client(char **buf, int len) {
 return daemon_chunk_judge(buf, len, cfg_get_clientopts());
}