decompiled_code:
void __fastcall udp_input(__int64 a1, int a2)
{
size_t i; // rdx
ssize_t v3; // rax
socklen_t n[5]; // [rsp+Ch] [rbp-5FCh] BYREF
char buf[1456]; // [rsp+20h] [rbp-5E8h] BYREF
int v6; // [rsp+5D0h] [rbp-38h]
char v7; // [rsp+5D4h] [rbp-34h]

n[0] = 16;
if ( status == 1 )
{
for ( i = 16LL; ; i = n[0] )
{
memset(&n[1], 0, i);
memset(buf, 0, sizeof(buf));
v6 = 0;
v7 = 0;
v3 = recvfrom(a2, buf, 0x5B4uLL, 0, (struct sockaddr *)&n[1], n);
if ( v3 < 0 )
break;
if ( !v3 )
{
info(log, &n[1], "UDP error 0 bytes");
return;
}
if ( *(_DWORD *)(a1 + 32) == 1 )
{
p2p_parse(buf, v3, &n[1]);
udp_cron(a1);
if ( status != 1 )
return;
}
else
{
r_parse(buf, v3, &n[1]);
if ( status != 1 )
return;
}
}
if ( *_errno_location() != 11 )
info(log, &n[1], "UDP error while recvfrom");
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, int a2)
{
size_t i; // rdx
ssize_t v3; // rax
socklen_t n[5]; // [rsp+Ch] [rbp-5FCh] BYREF
char buf[1456]; // [rsp+20h] [rbp-5E8h] BYREF
int v6; // [rsp+5D0h] [rbp-38h]
char v7; // [rsp+5D4h] [rbp-34h]

n[0] = 16;
if ( status == 1 )
{
for ( i = 16LL; ; i = n[0] )
{
memset(&n[1], 0, i);
memset(buf, 0, sizeof(buf));
v6 = 0;
v7 = 0;
v3 = recvfrom(a2, buf, 0x5B4uLL, 0, (struct sockaddr *)&n[1], n);
if ( v3 < 0 )
break;
if ( !v3 )
{
info(log, &n[1], "UDP error 0 bytes");
return;
}
if ( *(_DWORD *)(a1 + 32) == 1 )
{
p2p_parse(buf, v3, &n[1]);
func8(a1);
if ( status != 1 )
return;
}
else
{
r_parse(buf, v3, &n[1]);
if ( status != 1 )
return;
}
}
if ( *_errno_location() != 11 )
info(log, &n[1], "UDP error while recvfrom");
}
}

original_code:
void udp_input(UDP * udp, int sockfd)
{
 UCHAR buffer[1460 + 1];
 ssize_t bytes = 0;
 IP c_addr;
 socklen_t c_addrlen = sizeof(IP);
 while (status == 1) {
  memset(&c_addr, '\0', c_addrlen);
  memset(buffer, '\0', 1460 + 1);
  bytes = recvfrom(sockfd, buffer, 1460, 0,
     (struct sockaddr *)&c_addr, &c_addrlen);
  if (bytes < 0) {
   if ((*__errno_location ()) != 11 && (*__errno_location ()) != 11) {
    info(_log, &c_addr, "UDP error while recvfrom");
   }
   return;
  }
  if (bytes == 0) {
   info(_log, &c_addr, "UDP error 0 bytes");
   return;
  }
  if (udp->type == udp_p2p_worker) {
   p2p_parse(buffer, bytes, &c_addr);
   udp_cron(udp);
  } else {
   r_parse(buffer, bytes, &c_addr);
  }
 }
}

canonical_original_code:
void udp_input(struct obj_udp *udp, int sockfd)
{
 unsigned char buffer[-1];
 long bytes = 0;
 struct sockaddr_in c_addr;
 unsigned int c_addrlen = sizeof(IP);
 while (status == 1) {
  memset(&c_addr, '\0', c_addrlen);
  memset(buffer, '\0', 1460 + 1);
  bytes = recvfrom(sockfd, buffer, 1460, 0,
     (struct sockaddr *)&c_addr, &c_addrlen);
  if (bytes < 0) {
   if ((*__errno_location ()) != 11 && (*__errno_location ()) != 11) {
    info(_log, &c_addr, "UDP error while recvfrom");
   }
   return;
  }
  if (bytes == 0) {
   info(_log, &c_addr, "UDP error 0 bytes");
   return;
  }
  if (udp->type == udp_p2p_worker) {
   p2p_parse(buffer, bytes, &c_addr);
   udp_cron(udp);
  } else {
   r_parse(buffer, bytes, &c_addr);
  }
 }
}

variable_types:
buffer
unsigned char [-1]

variable_types: bytes long


repo: torrentkino/torrentkino

decompiled_code:
int __fastcall udp_worker(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
int *v4; // rbx
int v5; // esi
int result; // eax

if ( a3 > 0 )
{
v3 = a2 + 12LL * (unsigned int)(a3 - 1) + 16;
v4 = (int *)(a2 + 4);
do
{
while ( (*(_BYTE *)(v4 - 1) & 1) != 0 )
{
v5 = *v4;
v4 += 3;
udp_input(a1, v5);
result = udp_rearm(a1, *(v4 - 3));
if ( v4 == (int *)v3 )
return result;
}
v4 += 3;
result = info(log, 0LL, "udp_worker: Unknown event");
}
while ( v4 != (int *)v3 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
int *v4; // rbx
int v5; // esi
int result; // eax

if ( a3 > 0 )
{
v3 = a2 + 12LL * (unsigned int)(a3 - 1) + 16;
v4 = (int *)(a2 + 4);
do
{
while ( (*(_BYTE *)(v4 - 1) & 1) != 0 )
{
v5 = *v4;
v4 += 3;
func9(a1, v5);
result = func6(a1, *(v4 - 3));
if ( v4 == (int *)v3 )
return result;
}
v4 += 3;
result = info(log, 0LL, "udp_worker: Unknown event");
}
while ( v4 != (int *)v3 );
}
return result;
}

original_code:
void udp_worker(UDP * udp, struct epoll_event *events, int nfds)
{
 int i;
 for (i = 0; i < nfds; i++) {
  if ((events[i].events & EPOLLIN) == EPOLLIN) {
   udp_input(udp, events[i].data.fd);
   udp_rearm(udp, events[i].data.fd);
  } else {
   info(_log, ((void *)0), "udp_worker: Unknown event");
  }
 }
}

canonical_original_code:
void udp_worker(struct obj_udp *udp, struct epoll_event *events, int nfds)
{
 int i;
 for (i = 0; i < nfds; i++) {
  if ((events[i].events & EPOLLIN) == EPOLLIN) {
   udp_input(udp, events[i].data.fd);
   udp_rearm(udp, events[i].data.fd);
  } else {
   info(_log, ((void *)0), "udp_worker: Unknown event");
  }
 }
}

variable_types: struct obj_udp { 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]; } s_addr; unsigned int s_addrlen; int sockfd; int epollfd; int multicast; int type; } *

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *

variable_types: nfds int

variable_types: i int

return_type: void

user_defined_types: struct obj_udp { struct sockaddr_in s_addr; unsigned int s_addrlen; int sockfd; int epollfd; int multicast; int type; }

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

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


decompiled_code:
void __fastcall __noreturn udp_thread(__int64 a1)
{
__int64 v2; // rax
unsigned int v3; // er12
__int64 v4; // rdi
int v5; // eax
int v6; // edi
char *v7; // rax
struct epoll_event v8[34]; // [rsp+0h] [rbp-198h] BYREF

mutex_block(*(_QWORD *)(*((_QWORD *)main + 3) + 80LL));
v2 = *((_QWORD *)main + 3);
v3 = *(_DWORD *)(v2 + 8);
v4 = *(_QWORD *)(v2 + 80);
*(_DWORD *)(v2 + 8) = v3 + 1;
mutex_unblock(v4);
info(log, 0LL, "UDP Thread[%i] - Max events: %i", v3, 32LL);
while ( 1 )
{
while ( 1 )
{
if ( status != 1 )
LABEL_8:
pthread_exit(0LL);
LABEL_3:
v5 = epoll_wait(*(_DWORD *)(a1 + 24), v8, 32, 2000);
if ( status != 1 )
goto LABEL_8;
if ( v5 != -1 )
break;
v6 = *_errno_location();
if ( v6 == 4 )
goto LABEL_3;
v7 = strerror(v6);
fail("udp_thread: epoll_wait() failed / %s", v7);
}
if ( v5 )
{
if ( v5 > 0 )
{
udp_worker(a1, (__int64)v8, v5);
if ( status != 1 )
goto LABEL_8;
}
goto LABEL_3;
}
udp_cron(a1);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func11(__int64 a1)
{
__int64 v2; // rax
unsigned int v3; // er12
__int64 v4; // rdi
int v5; // eax
int v6; // edi
char *v7; // rax
struct epoll_event v8[34]; // [rsp+0h] [rbp-198h] BYREF

mutex_block(*(_QWORD *)(*((_QWORD *)main + 3) + 80LL));
v2 = *((_QWORD *)main + 3);
v3 = *(_DWORD *)(v2 + 8);
v4 = *(_QWORD *)(v2 + 80);
*(_DWORD *)(v2 + 8) = v3 + 1;
mutex_unblock(v4);
info(log, 0LL, "UDP Thread[%i] - Max events: %i", v3, 32LL);
while ( 1 )
{
while ( 1 )
{
if ( status != 1 )
LABEL_8:
pthread_exit(0LL);
LABEL_3:
v5 = epoll_wait(*(_DWORD *)(a1 + 24), v8, 32, 2000);
if ( status != 1 )
goto LABEL_8;
if ( v5 != -1 )
break;
v6 = *_errno_location();
if ( v6 == 4 )
goto LABEL_3;
v7 = strerror(v6);
fail("udp_thread: epoll_wait() failed / %s", v7);
}
if ( v5 )
{
if ( v5 > 0 )
{
func10(a1, (__int64)v8, v5);
if ( status != 1 )
goto LABEL_8;
}
goto LABEL_3;
}
func8(a1);
}
}

original_code:
void *udp_thread(void *arg)
{
 UDP *udp = arg;
 struct epoll_event events[32];
 int nfds;
 int id = 0;
 mutex_block(_main->work->mutex);
 id = _main->work->id++;
 mutex_unblock(_main->work->mutex);
 info(_log, ((void *)0), "UDP Thread[%i] - Max events: %i", id,
      32);
 while (status == 1) {
  nfds = epoll_wait(udp->epollfd, events,
      32, 2000);
  if (status != 1) {
   break;
  }
  if (nfds == -1) {
   if ((*__errno_location ()) != 4) {
    fail("udp_thread: epoll_wait() failed / %s",
         strerror((*__errno_location ())));
   }
  } else if (nfds == 0) {
   udp_cron(udp);
  } else if (nfds > 0) {
   udp_worker(udp, events, nfds);
  }
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
void *udp_thread(void *arg)
{
 struct obj_udp *udp = arg;
 struct epoll_event events[32];
 int nfds;
 int id = 0;
 mutex_block(_main->work->mutex);
 id = _main->work->id++;
 mutex_unblock(_main->work->mutex);
 info(_log, ((void *)0), "UDP Thread[%i] - Max events: %i", id,
      32);
 while (status == 1) {
  nfds = epoll_wait(udp->epollfd, events,
      32, 2000);
  if (status != 1) {
   break;
  }
  if (nfds == -1) {
   if ((*__errno_location ()) != 4) {
    fail("udp_thread: epoll_wait() failed / %s",
         strerror((*__errno_location ())));
   }
  } else if (nfds == 0) {
   udp_cron(udp);
  } else if (nfds > 0) {
   udp_worker(udp, events, nfds);
  }
 }
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } [32]

variable_types: id int

return_type: void *


decompiled_code:
void __fastcall udp_multicast(__int64 a1, int a2, int a3)
{
int v5; // er12
void *v6; // rdx
int v7; // edi
int *v8; // rax
char *v9; // rax
int optval[2]; // [rsp+0h] [rbp-30h] BYREF
__int128 v11; // [rsp+8h] [rbp-28h]

if ( a2 != 1 )
{
v11 = 0LL;
LOWORD(v11) = 2;
v5 = (a3 != 2) + 35;
WORD1(v11) = _bswap_16(*(_WORD *)(*((_QWORD *)main + 2) + 5184LL));
if ( inet_pton(2, "224.0.0.252", v6) )
{
v7 = *(_DWORD *)(a1 + 20);
optval[1] = 0;
optval[0] = DWORD1(v11);
if ( setsockopt(v7, 0, v5, optval, 8u) )
{
v8 = _errno_location();
v9 = strerror(*v8);
info(log, 0LL, "Joining multicast group failed: %s", v9);
}
else
{
*(_DWORD *)(a1 + 28) = a3 == 2;
}
}
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, int a2, int a3)
{
int v5; // er12
void *v6; // rdx
int v7; // edi
int *v8; // rax
char *v9; // rax
int optval[2]; // [rsp+0h] [rbp-30h] BYREF
__int128 v11; // [rsp+8h] [rbp-28h]

if ( a2 != 1 )
{
v11 = 0LL;
LOWORD(v11) = 2;
v5 = (a3 != 2) + 35;
WORD1(v11) = func0(*(_WORD *)(*((_QWORD *)main + 2) + 5184LL));
if ( inet_pton(2, "224.0.0.252", v6) )
{
v7 = *(_DWORD *)(a1 + 20);
optval[1] = 0;
optval[0] = DWORD1(v11);
if ( setsockopt(v7, 0, v5, optval, 8u) )
{
v8 = _errno_location();
v9 = strerror(*v8);
info(log, 0LL, "Joining multicast group failed: %s", v9);
}
else
{
*(_DWORD *)(a1 + 28) = a3 == 2;
}
}
}
}

original_code:
void udp_multicast(UDP * udp, int mode, int runmode)
{
 struct ip_mreq mreq;
 int action;
 IP sin;
 if (mode == multicast_disabled) {
  return;
 }
 action =
     (runmode ==
      multicast_start) ? 35 : 36;
 memset(&sin, '\0', sizeof(IP));
 sin.sin_family = 2;
 sin.sin_port = htons(_main->conf->bootstrap_port);
 if (!inet_pton(2, "224.0.0.252", &(sin.sin_addr))) {
  return;
 }
 memset(&mreq, '\0', sizeof(mreq));
 memcpy(&mreq.imr_multiaddr, &sin.sin_addr, sizeof(mreq.imr_multiaddr));
 mreq.imr_interface.s_addr = ((in_addr_t) 0x00000000);
 if (setsockopt(udp->sockfd, IPPROTO_IP, action,
         &mreq, sizeof(mreq)) != 0) {
  info(_log, ((void *)0), "Joining multicast group failed: %s",
       strerror((*__errno_location ())));
  return;
 }
 udp->multicast = (runmode == multicast_start) ? 1 : 0;
}

canonical_original_code:
void udp_multicast(struct obj_udp *udp, int mode, int runmode)
{
 struct ip_mreq mreq;
 int action;
 struct sockaddr_in sin;
 if (mode == multicast_disabled) {
  return;
 }
 action =
     (runmode ==
      multicast_start) ? 35 : 36;
 memset(&sin, '\0', sizeof(IP));
 sin.sin_family = 2;
 sin.sin_port = htons(_main->conf->bootstrap_port);
 if (!inet_pton(2, "224.0.0.252", &(sin.sin_addr))) {
  return;
 }
 memset(&mreq, '\0', sizeof(mreq));
 memcpy(&mreq.imr_multiaddr, &sin.sin_addr, sizeof(mreq.imr_multiaddr));
 mreq.imr_interface.s_addr = ((unsigned int) 0x00000000);
 if (setsockopt(udp->sockfd, IPPROTO_IP, action,
         &mreq, sizeof(mreq)) != 0) {
  info(_log, ((void *)0), "Joining multicast group failed: %s",
       strerror((*__errno_location ())));
  return;
 }
 udp->multicast = (runmode == multicast_start) ? 1 : 0;
}

variable_types: mode int

variable_types: runmode int

variable_types: struct ip_mreq { struct in_addr { unsigned int s_addr; } imr_multiaddr; struct in_addr imr_interface; }

variable_types: action 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 ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; }


decompiled_code:
int __fastcall udp_start(struct sockaddr *addr, int a2, unsigned int a3)
{
int v5; // eax
int v6; // edx
socklen_t v7; // edx
int v8; // edi

v5 = socket(2, 2, 0);
*(_DWORD *)&addr[1].sa_data[2] = v5;
if ( v5 < 0 )
fail("Creating socket failed.");
addr->sa_family = 2;
*(_WORD *)addr->sa_data = _bswap_16(a2);
*(_DWORD *)&addr->sa_data[2] = _bswap_32_constprop_0(addr, a3);
udp_multicast((__int64)addr, a3, v6);
v7 = *(_DWORD *)&addr[1].sa_family;
v8 = *(_DWORD *)&addr[1].sa_data[2];
*(_DWORD *)&addr[2].sa_family = *(_DWORD *)(*((_QWORD *)main + 2) + 5172LL) == a2;
if ( bind(v8, addr, v7) )
{
fail("bind() to socket failed.");
if ( (int)udp_nonblocking(*(_DWORD *)&addr[1].sa_data[2]) >= 0 )
return udp_event((__int64)addr);
}
else if ( (int)udp_nonblocking(*(_DWORD *)&addr[1].sa_data[2]) >= 0 )
{
return udp_event((__int64)addr);
}
fail("udp_nonblocking() failed");
return udp_event((__int64)addr);
}

canonical_decompiled_code:
int __fastcall func13(struct sockaddr *addr, int a2, unsigned int a3)
{
int v5; // eax
int v6; // edx
socklen_t v7; // edx
int v8; // edi

v5 = socket(2, 2, 0);
*(_DWORD *)&addr[1].sa_data[2] = v5;
if ( v5 < 0 )
fail("Creating socket failed.");
addr->sa_family = 2;
*(_WORD *)addr->sa_data = func0(a2);
*(_DWORD *)&addr->sa_data[2] = func1(addr, a3);
func12((__int64)addr, a3, v6);
v7 = *(_DWORD *)&addr[1].sa_family;
v8 = *(_DWORD *)&addr[1].sa_data[2];
*(_DWORD *)&addr[2].sa_family = *(_DWORD *)(*((_QWORD *)main + 2) + 5172LL) == a2;
if ( bind(v8, addr, v7) )
{
fail("bind() to socket failed.");
if ( (int)func7(*(_DWORD *)&addr[1].sa_data[2]) >= 0 )
return func4((__int64)addr);
}
else if ( (int)func7(*(_DWORD *)&addr[1].sa_data[2]) >= 0 )
{
return func4((__int64)addr);
}
fail("udp_nonblocking() failed");
return func4((__int64)addr);
}

original_code:
void udp_start(UDP * udp, int port, int multicast_mode)
{
 if ((udp->sockfd = socket(2, SOCK_DGRAM, 0)) < 0) {
  fail("Creating socket failed.");
 }
 udp->s_addr.sin_family = 2;
 udp->s_addr.sin_port = htons(port);
 udp->s_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 udp_multicast(udp, multicast_mode, multicast_start);
 udp->type =
     (port == _main->conf->p2p_port) ? udp_p2p_worker : udp_dns_worker;
 if (bind(udp->sockfd, (struct sockaddr *)&udp->s_addr, udp->s_addrlen)) {
  fail("bind() to socket failed.");
 }
 if (udp_nonblocking(udp->sockfd) < 0) {
  fail("udp_nonblocking() failed");
 }
 udp_event(udp);
}

canonical_original_code:
void udp_start(struct obj_udp *udp, int port, int multicast_mode)
{
 if ((udp->sockfd = socket(2, SOCK_DGRAM, 0)) < 0) {
  fail("Creating socket failed.");
 }
 udp->s_addr.sin_family = 2;
 udp->s_addr.sin_port = htons(port);
 udp->s_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 udp_multicast(udp, multicast_mode, multicast_start);
 udp->type =
     (port == _main->conf->p2p_port) ? udp_p2p_worker : udp_dns_worker;
 if (bind(udp->sockfd, (struct sockaddr *)&udp->s_addr, udp->s_addrlen)) {
  fail("bind() to socket failed.");
 }
 if (udp_nonblocking(udp->sockfd) < 0) {
  fail("udp_nonblocking() failed");
 }
 udp_event(udp);
}

variable_types: port int

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


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

udp_multicast(a1, a2, 3);
if ( !close(*(_DWORD *)(a1 + 20)) )
{
result = close(*(_DWORD *)(a1 + 24));
if ( !result )
return result;
return fail("close() failed.");
}
fail("close() failed.");
result = close(*(_DWORD *)(a1 + 24));
if ( result )
return fail("close() failed.");
return result;
}

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

func12(a1, a2, 3);
if ( !close(*(_DWORD *)(a1 + 20)) )
{
result = close(*(_DWORD *)(a1 + 24));
if ( !result )
return result;
return fail("close() failed.");
}
fail("close() failed.");
result = close(*(_DWORD *)(a1 + 24));
if ( result )
return fail("close() failed.");
return result;
}

original_code:
void udp_stop(UDP * udp, int multicast_mode)
{
 udp_multicast(udp, multicast_mode, multicast_stop);
 if (close(udp->sockfd) != 0) {
  fail("close() failed.");
 }
 if (close(udp->epollfd) != 0) {
  fail("close() failed.");
 }
}

canonical_original_code:
void udp_stop(struct obj_udp *udp, int multicast_mode)
{
 udp_multicast(udp, multicast_mode, multicast_stop);
 if (close(udp->sockfd) != 0) {
  fail("close() failed.");
 }
 if (close(udp->epollfd) != 0) {
  fail("close() failed.");
 }
}


decompiled_code:
_QWORD *log_init()
{
_QWORD *result; // rax

result = (_QWORD *)myalloc(8LL);
*result = 0x100000001LL;
return result;
}

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

result = (_QWORD *)myalloc(8LL);
*result = 0x100000001LL;
return result;
}

original_code:
LOG *log_init(void)
{
 LOG *log = myalloc(sizeof(LOG));
 log->verbosity = 1;
 log->mode = 1;
 return log;
}

canonical_original_code:
struct obj_log *log_init()
{
 struct obj_log *log = myalloc(sizeof(LOG));
 log->verbosity = 1;
 log->mode = 1;
 return log;
}

variable_types: struct obj_log { int verbosity; int mode; } *


decompiled_code:
// attributes: thunk
__int64 log_free()
{
return myfree();
}

canonical_decompiled_code:
__int64 func1()
{
return myfree();
}

original_code:
void log_free(LOG * log)
{
 myfree(log);
}

canonical_original_code:
void log_free(struct obj_log *log)
{
 myfree(log);
}

user_defined_types: struct obj_log { int verbosity; int mode; }


decompiled_code:
void __fastcall log_set_mode(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) = a2;
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, int a2)
{
*(_DWORD *)(a1 + 4) = a2;
}

original_code:
void log_set_mode(LOG * log, int mode)
{
 log->mode = mode;
}

canonical_original_code:
void log_set_mode(struct obj_log *log, int mode)
{
 log->mode = mode;
}


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

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

original_code:
int log_verbosely(LOG * log)
{
 return log->verbosity;
}

canonical_original_code:
int log_verbosely(struct obj_log *log)
{
 return log->verbosity;
}

return_type: int


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

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

original_code:
int log_console(LOG * log)
{
 return log->mode;
}

canonical_original_code:
int log_console(struct obj_log *log)
{
 return log->mode;
}


info

decompiled_code:
void info(unsigned int *a1, __int64 a2, __int64 a3, ...)
{
const char *v3; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-910h] BYREF
char v5[48]; // [rsp+20h] [rbp-8F8h] BYREF
char v6[1024]; // [rsp+50h] [rbp-8C8h] BYREF
char s[1024]; // [rsp+450h] [rbp-4C8h] BYREF

if ( (unsigned int)log_verbosely(a1) )
{
va_start(arg, a3);
vsnprintf(s, 0x400uLL, v3, arg);
if ( a2 )
{
ip_sin_to_string(a2, v5);
if ( snprintf(v6, 0x400uLL, "%s %s", v5, s) > 1023 )
return;
if ( (unsigned int)log_console((__int64)a1) )
{
LABEL_6:
puts(v6);
return;
}
}
else
{
snprintf(v6, 0x400uLL, "%s", s);
if ( (unsigned int)log_console((__int64)a1) )
goto LABEL_6;
}
openlog("tumbleweed", 3, 8);
syslog(6, "%s", v6);
closelog();
}
}

canonical_decompiled_code:
void func6(unsigned int *a1, __int64 a2, __int64 a3, ...)
{
const char *v3; // rdx
gcc_va_list arg; // [rsp+8h] [rbp-910h] BYREF
char v5[48]; // [rsp+20h] [rbp-8F8h] BYREF
char v6[1024]; // [rsp+50h] [rbp-8C8h] BYREF
char s[1024]; // [rsp+450h] [rbp-4C8h] BYREF

if ( (unsigned int)func4(a1) )
{
va_start(arg, a3);
vsnprintf(s, 0x400uLL, v3, arg);
if ( a2 )
{
ip_sin_to_string(a2, v5);
if ( snprintf(v6, 0x400uLL, "%s %s", v5, s) > 1023 )
return;
if ( (unsigned int)func5((__int64)a1) )
{
LABEL_6:
puts(v6);
return;
}
}
else
{
snprintf(v6, 0x400uLL, "%s", s);
if ( (unsigned int)func5((__int64)a1) )
goto LABEL_6;
}
openlog("tumbleweed", 3, 8);
syslog(6, "%s", v6);
closelog();
}
}

original_code:
void info(LOG * log, IP * from, const char *format, ...)
{
 char log_buf[1024];
 char va_buf[1024];
 char ip_buf[46 + 1];
 va_list vlist;
 int result;
 if (!log_verbosely(log)) {
  return;
 }
 __builtin_va_start(vlist,format);
 vsnprintf(va_buf, 1024, format, vlist);
 __builtin_va_end(vlist);
 if (from != ((void *)0)) {
  ip_sin_to_string(from, ip_buf);
  result = snprintf(log_buf, 1024, "%s %s", ip_buf, va_buf);
 } else {
  result = snprintf(log_buf, 1024, "%s", va_buf);
 }
 if( result >= 1024 ) {
  return;
 }
 if (log_console(log)) {
  printf("%s\n", log_buf);
 } else {
  openlog("tumbleweed", 0x01 | 0x02, (1<<3));
  syslog(6, "%s", log_buf);
  closelog();
 }
}

canonical_original_code:
void info(struct obj_log *log, struct sockaddr_in6 *from, char *format, ...)
{
 char log_buf[1024];
 char va_buf[1024];
 char ip_buf[-1];
 __builtin_va_list vlist;
 int result;
 if (!log_verbosely(log)) {
  return;
 }
 __builtin_va_start(vlist,format);
 vsnprintf(va_buf, 1024, format, vlist);
 __builtin_va_end(vlist);
 if (from != ((void *)0)) {
  ip_sin_to_string(from, ip_buf);
  result = snprintf(log_buf, 1024, "%s %s", ip_buf, va_buf);
 } else {
  result = snprintf(log_buf, 1024, "%s", va_buf);
 }
 if( result >= 1024 ) {
  return;
 }
 if (log_console(log)) {
  printf("%s\n", log_buf);
 } else {
  openlog("tumbleweed", 0x01 | 0x02, (1<<3));
  syslog(6, "%s", log_buf);
  closelog();
 }
}

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } *

variable_types:
format
char *

variable_types: result int

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


original_code:
void node_update(UDP_NODE * n, IP * sa)
{
 if (n == ((void *)0)) {
  return;
 }
 if (memcmp(&n->c_addr, sa, sizeof(IP)) != 0) {
  memcpy(&n->c_addr, sa, sizeof(IP));
 }
}

canonical_original_code:
void node_update(struct UDP_NODE *n, struct sockaddr_in *sa)
{
 if (n == ((void *)0)) {
  return;
 }
 if (memcmp(&n->c_addr, sa, sizeof(IP)) != 0) {
  memcpy(&n->c_addr, sa, sizeof(IP));
 }
}

variable_types: struct UDP_NODE { unsigned char id[20]; 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]; } c_addr; long time_ping; long time_find; int pinged; } *

variable_types:
sa
struct sockaddr_in *

user_defined_types: struct UDP_NODE { unsigned char id[20]; struct sockaddr_in c_addr; long time_ping; long time_find; int pinged; }


original_code:
int node_equal(const UCHAR * node_a, const UCHAR * node_b)
{
 if (memcmp(node_a, node_b, 20) == 0) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int node_equal(unsigned char *node_a, unsigned char *node_b)
{
 if (memcmp(node_a, node_b, 20) == 0) {
  return 1;
 }
 return 0;
}


decompiled_code:
_BOOL8 __fastcall node_me(__int64 a1)
{
return node_equal(a1, *((_QWORD *)main + 2) + 5124LL);
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return func3(a1, *((_QWORD *)main + 2) + 5124LL);
}

original_code:
int node_me(UCHAR * node_id)
{
 if (node_equal(node_id, _main->conf->node_id)) {
  return 1;
 }
 return 0;
}

canonical_original_code:
int node_me(unsigned char *node_id)
{
 if (node_equal(node_id, _main->conf->node_id)) {
  return 1;
 }
 return 0;
}


decompiled_code:
_BOOL8 __fastcall node_ok(__int64 a1)
{
return *(_DWORD *)(a1 + 56) <= 1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return *(_DWORD *)(a1 + 56) <= 1;
}

original_code:
int node_ok(UDP_NODE * n)
{
 return (n->pinged <= 1) ? 1 : 0;
}

canonical_original_code:
int node_ok(struct UDP_NODE *n)
{
 return (n->pinged <= 1) ? 1 : 0;
}


decompiled_code:
_BOOL8 __fastcall node_bad(__int64 a1)
{
return *(_DWORD *)(a1 + 56) > 3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
return *(_DWORD *)(a1 + 56) > 3;
}

original_code:
int node_bad(UDP_NODE * n)
{
 return (n->pinged >= 4) ? 1 : 0;
}

canonical_original_code:
int node_bad(struct UDP_NODE *n)
{
 return (n->pinged >= 4) ? 1 : 0;
}


decompiled_code:
__int64 __fastcall node_pinged(__int64 a1)
{
++*(_DWORD *)(a1 + 56);
return time_add_5_min_approx(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
++*(_DWORD *)(a1 + 56);
return time_add_5_min_approx(a1 + 40);
}

original_code:
void node_pinged(UDP_NODE * n)
{
 n->pinged++;
 time_add_5_min_approx(&n->time_ping);
}

canonical_original_code:
void node_pinged(struct UDP_NODE *n)
{
 n->pinged++;
 time_add_5_min_approx(&n->time_ping);
}


decompiled_code:
__int64 __fastcall node_ponged(__int64 a1, const __m128i *a2)
{
__int64 v3; // rdi

v3 = a1 + 40;
*(_DWORD *)(v3 + 16) = 0;
time_add_5_min_approx(v3);
return node_update(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const __m128i *a2)
{
__int64 v3; // rdi

v3 = a1 + 40;
*(_DWORD *)(v3 + 16) = 0;
time_add_5_min_approx(v3);
return func1(a1, a2);
}

original_code:
void node_ponged(UDP_NODE * n, IP * from)
{
 n->pinged = 0;
 time_add_5_min_approx(&n->time_ping);
 node_update(n, from);
}

canonical_original_code:
void node_ponged(struct UDP_NODE *n, struct sockaddr_in *from)
{
 n->pinged = 0;
 time_add_5_min_approx(&n->time_ping);
 node_update(n, from);
}

variable_types:
from
struct sockaddr_in *


decompiled_code:
// attributes: thunk
__int64 node_free()
{
return myfree();
}

canonical_decompiled_code:
__int64 func0()
{
return myfree();
}

original_code:
void node_free(UDP_NODE * n)
{
 myfree(n);
}

canonical_original_code:
void node_free(struct UDP_NODE *n)
{
 myfree(n);
}


decompiled_code:
_QWORD *list_init()
{
_QWORD *result; // rax

result = (_QWORD *)myalloc(16LL);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = (_QWORD *)myalloc(16LL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
LIST *list_init(void)
{
 LIST *list = (LIST *) myalloc(sizeof(LIST));
 list->item = ((void *)0);
 list->size = 0;
 return list;
}

canonical_original_code:
struct obj_list *list_init()
{
 struct obj_list *list = (LIST *) myalloc(sizeof(LIST));
 list->item = ((void *)0);
 list->size = 0;
 return list;
}

variable_types: struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *

user_defined_types: struct obj_list { struct obj_item *item; long size; }


decompiled_code:
__int64 __fastcall list_size(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
LONG list_size(LIST * list)
{
 return list->size;
}

canonical_original_code:
long list_size(struct obj_list *list)
{
 return list->size;
}

return_type: long

user_defined_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; }


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

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

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

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

original_code:
ITEM *list_next(ITEM * item)
{
 if (item == ((void *)0)) {
  return ((void *)0);
 }
 return item->next;
}

canonical_original_code:
struct obj_item *list_next(struct obj_item *item)
{
 if (item == ((void *)0)) {
  return ((void *)0);
 }
 return item->next;
}

variable_types:
item
struct obj_item *

return_type: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *


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

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

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

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

original_code:
ITEM *list_prev(ITEM * item)
{
 if (item == ((void *)0)) {
  return ((void *)0);
 }
 return item->prev;
}

canonical_original_code:
struct obj_item *list_prev(struct obj_item *item)
{
 if (item == ((void *)0)) {
  return ((void *)0);
 }
 return item->prev;
}


decompiled_code:
void __fastcall list_clear(__int64 *a1)
{
_QWORD *i; // rbp

if ( a1 )
{
for ( i = (_QWORD *)list_start(a1); i; i = (_QWORD *)list_next((__int64)i) )
myfree(*i);
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 *a1)
{
_QWORD *i; // rbp

if ( a1 )
{
for ( i = (_QWORD *)func5(a1); i; i = (_QWORD *)func2((__int64)i) )
myfree(*i);
}
}

original_code:
void list_clear(LIST * list)
{
 ITEM *item = ((void *)0);
 if (list == ((void *)0)) {
  return;
 }
 item = list_start(list);
 while (item != ((void *)0)) {
  myfree(item->val);
  item = list_next(item);
 }
}

canonical_original_code:
void list_clear(struct obj_list *list)
{
 struct obj_item *item = ((void *)0);
 if (list == ((void *)0)) {
  return;
 }
 item = list_start(list);
 while (item != ((void *)0)) {
  myfree(item->val);
  item = list_next(item);
 }
}

variable_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *


decompiled_code:
__int64 __fastcall list_free(__int64 *a1)
{
__int64 i; // rsi
__int64 result; // rax

if ( a1 )
{
for ( i = *a1; *a1; i = *a1 )
list_del(a1, i);
result = myfree(a1);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 *a1)
{
__int64 i; // rsi
__int64 result; // rax

if ( a1 )
{
for ( i = *a1; *a1; i = *a1 )
func7(a1, i);
result = myfree(a1);
}
return result;
}

original_code:
void list_free(LIST * list)
{
 if (list == ((void *)0)) {
  return;
 }
 while (list->item != ((void *)0)) {
  list_del(list, list->item);
 }
 myfree(list);
}

canonical_original_code:
void list_free(struct obj_list *list)
{
 if (list == ((void *)0)) {
  return;
 }
 while (list->item != ((void *)0)) {
  list_del(list, list->item);
 }
 myfree(list);
}


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

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

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

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

original_code:
void *list_value(ITEM * item)
{
 if (item == ((void *)0)) {
  return ((void *)0);
 }
 return item->val;
}

canonical_original_code:
void *list_value(struct obj_item *item)
{
 if (item == ((void *)0)) {
  return ((void *)0);
 }
 return item->val;
}


original_code:
void list_rotate(LIST * list)
{
 ITEM *start = ((void *)0);
 ITEM *stop = ((void *)0);
 if (list == ((void *)0)) {
  return;
 }
 if (list_size(list) <= 1) {
  return;
 }
 start = list_start(list);
 stop = list_stop(list);
 list->item = start->next;
 start->next->prev = ((void *)0);
 start->next = ((void *)0);
 start->prev = stop;
 stop->next = start;
}

canonical_original_code:
void list_rotate(struct obj_list *list)
{
 struct obj_item *start = ((void *)0);
 struct obj_item *stop = ((void *)0);
 if (list == ((void *)0)) {
  return;
 }
 if (list_size(list) <= 1) {
  return;
 }
 start = list_start(list);
 stop = list_stop(list);
 list->item = start->next;
 start->next->prev = ((void *)0);
 start->next = ((void *)0);
 start->prev = stop;
 stop->next = start;
}


decompiled_code:
// attributes: thunk
__int64 resp_init()
{
return list_init();
}

canonical_decompiled_code:
__int64 func0()
{
return list_init();
}

original_code:
LIST *resp_init(void)
{
 return list_init();
}

canonical_original_code:
struct obj_list *resp_init()
{
 return list_init();
}

return_type: struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *


decompiled_code:
__int64 __fastcall resp_free(__int64 a1)
{
list_clear();
return list_free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
list_clear();
return list_free(a1);
}

original_code:
void resp_free(LIST * list)
{
 list_clear(list);
 list_free(list);
}

canonical_original_code:
void resp_free(struct obj_list *list)
{
 list_clear(list);
 list_free(list);
}


original_code:
RESPONSE *resp_put(LIST * list, int type)
{
 RESPONSE *r = ((void *)0);
 if (list_size(list) > 100) {
  return ((void *)0);
 }
 r = (RESPONSE *) myalloc(sizeof(RESPONSE));
 if (type == 0) {
  r->type = 0;
  memset(r->data.memory.send_buf, '\0', 1024);
  r->data.memory.send_offset = 0;
  r->data.memory.send_size = 0;
 } else {
  r->type = 1;
  memset(r->data.file.filename, '\0', 1024);
  r->data.file.f_offset = 0;
  r->data.file.f_stop = 0;
 }
 list_put(list, r);
 return r;
}

canonical_original_code:
struct RESPONSE *resp_put(struct obj_list *list, int type)
{
 struct RESPONSE *r = ((void *)0);
 if (list_size(list) > 100) {
  return ((void *)0);
 }
 r = (struct RESPONSE *) myalloc(sizeof(RESPONSE));
 if (type == 0) {
  r->type = 0;
  memset(r->data.memory.send_buf, '\0', 1024);
  r->data.memory.send_offset = 0;
  r->data.memory.send_size = 0;
 } else {
  r->type = 1;
  memset(r->data.file.filename, '\0', 1024);
  r->data.file.f_offset = 0;
  r->data.file.f_stop = 0;
 }
 list_put(list, r);
 return r;
}

variable_types: type int

variable_types: struct RESPONSE { int type; union { struct R_MEMORY { char send_buf[1024]; int send_size; int send_offset; } memory; struct R_FILE { char filename[1024]; long f_offset; long f_stop; } file; } data; } *

user_defined_types: struct RESPONSE { int type; union { struct R_MEMORY memory; struct R_FILE file; } data; }


decompiled_code:
void __fastcall resp_del(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( a1 )
{
if ( a2 )
{
v2 = list_value(a2);
myfree(v2);
list_del(a1, a2);
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rax

if ( a1 )
{
if ( a2 )
{
v2 = list_value(a2);
myfree(v2);
list_del(a1, a2);
}
}
}

original_code:
void resp_del(LIST * list, ITEM * item)
{
 RESPONSE *r = ((void *)0);
 if (list == ((void *)0)) {
  return;
 }
 if (item == ((void *)0)) {
  return;
 }
 r = list_value(item);
 myfree(r);
 list_del(list, item);
}

canonical_original_code:
void resp_del(struct obj_list *list, struct obj_item *item)
{
 struct RESPONSE *r = ((void *)0);
 if (list == ((void *)0)) {
  return;
 }
 if (item == ((void *)0)) {
  return;
 }
 r = list_value(item);
 myfree(r);
 list_del(list, item);
}

user_defined_types: struct R_MEMORY { char send_buf[1024]; int send_size; int send_offset; }

user_defined_types: struct R_FILE { char filename[1024]; long f_offset; long f_stop; }


decompiled_code:
size_t resp_set_memory(__int64 a1, const char *a2, ...)
{
size_t result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 1024) = 0LL;
memset(
(void *)((a1 + 16) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 8 - (((_DWORD)a1 + 16) & 0xFFFFFFF8) + 1024) >> 3));
vsnprintf((char *)(a1 + 8), 0x400uLL, a2, arg);
result = strlen((const char *)(a1 + 8));
*(_DWORD *)(a1 + 1032) = result;
return result;
}

canonical_decompiled_code:
size_t func4(__int64 a1, const char *a2, ...)
{
size_t result; // rax
gcc_va_list arg; // [rsp+8h] [rbp-E0h] BYREF

va_start(arg, a2);
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 1024) = 0LL;
memset(
(void *)((a1 + 16) & 0xFFFFFFFFFFFFFFF8LL),
0,
8LL * (((_DWORD)a1 + 8 - (((_DWORD)a1 + 16) & 0xFFFFFFF8) + 1024) >> 3));
vsnprintf((char *)(a1 + 8), 0x400uLL, a2, arg);
result = strlen((const char *)(a1 + 8));
*(_DWORD *)(a1 + 1032) = result;
return result;
}

original_code:
int resp_set_memory(RESPONSE * r, const char *format, ...)
{
 va_list vlist;
 memset(r->data.memory.send_buf, '\0', 1024);
 __builtin_va_start(vlist,format);
 vsnprintf(r->data.memory.send_buf, 1024, format, vlist);
 __builtin_va_end(vlist);
 r->data.memory.send_size = strlen(r->data.memory.send_buf);
 return r->data.memory.send_size;
}

canonical_original_code:
int resp_set_memory(struct RESPONSE *r, char *format, ...)
{
 __builtin_va_list vlist;
 memset(r->data.memory.send_buf, '\0', 1024);
 __builtin_va_start(vlist,format);
 vsnprintf(r->data.memory.send_buf, 1024, format, vlist);
 __builtin_va_end(vlist);
 r->data.memory.send_size = strlen(r->data.memory.send_buf);
 return r->data.memory.send_size;
}


decompiled_code:
// attributes: thunk
__int64 id_init()
{
return list_init();
}

original_code:
LIST *id_init(void)
{
 return list_init();
}

canonical_original_code:
struct obj_list *id_init()
{
 return list_init();
}


decompiled_code:
__int64 __fastcall id_free(__int64 a1)
{
list_clear();
return list_free(a1);
}

original_code:
void id_free(LIST * l)
{
 list_clear(l);
 list_free(l);
}

canonical_original_code:
void id_free(struct obj_list *l)
{
 list_clear(l);
 list_free(l);
}


decompiled_code:
__int64 __fastcall id_put(char *s, __int64 a2, const char *a3, int a4)
{
__int64 v6; // rbp
size_t v7; // rax
__int64 v8; // rax

v6 = myalloc(1056LL);
v7 = strlen(s);
if ( !(unsigned int)str_valid_hostname(s, v7) )
fail("Bad hostname");
snprintf((char *)v6, 0x400uLL, "%s", s);
id_hostid(v6 + 1024, s, a3, a4);
v8 = *(_QWORD *)(v6 + 1024);
*(_QWORD *)(v6 + 1048) = 0LL;
if ( !(*(_QWORD *)a2 ^ v8 | *(_QWORD *)(a2 + 8) ^ *(_QWORD *)(v6 + 1032))
&& *(_DWORD *)(v6 + 1040) == *(_DWORD *)(a2 + 16) )
{
fail("The host id and the node id must not be the same");
}
return list_put(*((_QWORD *)main + 12), v6);
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s, __int64 a2, const char *a3, int a4)
{
__int64 v6; // rbp
size_t v7; // rax
__int64 v8; // rax

v6 = myalloc(1056LL);
v7 = strlen(s);
if ( !(unsigned int)str_valid_hostname(s, v7) )
fail("Bad hostname");
snprintf((char *)v6, 0x400uLL, "%s", s);
func2(v6 + 1024, s, a3, a4);
v8 = *(_QWORD *)(v6 + 1024);
*(_QWORD *)(v6 + 1048) = 0LL;
if ( !(*(_QWORD *)a2 ^ v8 | *(_QWORD *)(a2 + 8) ^ *(_QWORD *)(v6 + 1032))
&& *(_DWORD *)(v6 + 1040) == *(_DWORD *)(a2 + 16) )
{
fail("The host id and the node id must not be the same");
}
return list_put(*((_QWORD *)main + 12), v6);
}

original_code:
void id_put(char *hostname, UCHAR * node_id, char *realm, int bool_realm)
{
 ID *h = myalloc(sizeof(ID));
 if (!str_valid_hostname(hostname, strlen(hostname))) {
  fail("Bad hostname");
 }
 snprintf(h->hostname, 1024, "%s", hostname);
 id_hostid(h->host_id, hostname, realm, bool_realm);
 h->time_announce_host = 0;
 if (memcmp(h->host_id, node_id, 20) == 0) {
  fail("The host id and the node id must not be the same");
 }
 list_put(_main->identity, h);
}

canonical_original_code:
void id_put(char *hostname, unsigned char *node_id, char *realm, int bool_realm)
{
 struct ID *h = myalloc(sizeof(ID));
 if (!str_valid_hostname(hostname, strlen(hostname))) {
  fail("Bad hostname");
 }
 snprintf(h->hostname, 1024, "%s", hostname);
 id_hostid(h->host_id, hostname, realm, bool_realm);
 h->time_announce_host = 0;
 if (memcmp(h->host_id, node_id, 20) == 0) {
  fail("The host id and the node id must not be the same");
 }
 list_put(_main->identity, h);
}

variable_types:
hostname
char *

variable_types:
realm
char *

variable_types: struct ID { char hostname[1024]; unsigned char host_id[20]; long time_announce_host; } *


decompiled_code:
__int64 id_print()
{
__int64 result; // rax
__int64 v1; // rbp
const char *v2; // rbx
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = list_start(*((_QWORD *)main + 12));
if ( result )
{
v1 = result;
do
{
v2 = (const char *)list_value(v1);
hex_hash_encode(v3, v2 + 1024);
info(log, 0LL, "Hostname: %s / %s", v3, v2);
result = list_next(v1);
v1 = result;
}
while ( result );
}
return result;
}

canonical_decompiled_code:
__int64 func4()
{
__int64 result; // rax
__int64 v1; // rbp
const char *v2; // rbx
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

result = list_start(*((_QWORD *)main + 12));
if ( result )
{
v1 = result;
do
{
v2 = (const char *)list_value(v1);
hex_hash_encode(v3, v2 + 1024);
info(log, 0LL, "Hostname: %s / %s", v3, v2);
result = list_next(v1);
v1 = result;
}
while ( result );
}
return result;
}

original_code:
void id_print(void)
{
 ITEM *i = list_start(_main->identity);
 char hex[2*20 +1];
 ID *identity = ((void *)0);
 while (i != ((void *)0)) {
  identity = list_value(i);
  hex_hash_encode(hex, identity->host_id);
  info(_log, ((void *)0), "Hostname: %s / %s", hex, identity->hostname);
  i = list_next(i);
 }
}

canonical_original_code:
void id_print()
{
 struct obj_item *i = list_start(_main->identity);
 char hex[-1];
 struct ID *identity = ((void *)0);
 while (i != ((void *)0)) {
  identity = list_value(i);
  hex_hash_encode(hex, identity->host_id);
  info(_log, ((void *)0), "Hostname: %s / %s", hex, identity->hostname);
  i = list_next(i);
 }
}

variable_types:
hex
char [-1]

user_defined_types: struct ID { char hostname[1024]; unsigned char host_id[20]; long time_announce_host; }


decompiled_code:
__int64 tcp_init()
{
__int64 result; // rax

result = myalloc(40LL);
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)(result + 24) = 0;
*(_QWORD *)(result + 28) = -4294967268LL;
*(_OWORD *)result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 result; // rax

result = myalloc(40LL);
*(_QWORD *)(result + 16) = 0LL;
*(_DWORD *)(result + 24) = 0;
*(_QWORD *)(result + 28) = -4294967268LL;
*(_OWORD *)result = 0LL;
return result;
}

original_code:
struct obj_tcp *tcp_init(void)
{
 struct obj_tcp *tcp = (struct obj_tcp *)myalloc(sizeof(struct obj_tcp));
 tcp->s_addrlen = sizeof(IP);
 memset((char *)&tcp->s_addr, '\0', tcp->s_addrlen);
 tcp->sockfd = -1;
 return tcp;
}

canonical_original_code:
struct obj_tcp *tcp_init()
{
 struct obj_tcp *tcp = (struct obj_tcp *)myalloc(sizeof(struct obj_tcp));
 tcp->s_addrlen = sizeof(IP);
 memset((char *)&tcp->s_addr, '\0', tcp->s_addrlen);
 tcp->sockfd = -1;
 return tcp;
}

variable_types: struct obj_tcp { struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } s_addr; unsigned int s_addrlen; int sockfd; int epollfd; } *

user_defined_types: struct obj_tcp { struct sockaddr_in6 s_addr; unsigned int s_addrlen; int sockfd; int epollfd; }


decompiled_code:
__int64 tcp_free()
{
return myfree(*((_QWORD *)main + 6));
}

canonical_decompiled_code:
__int64 func2()
{
return myfree(*((_QWORD *)main + 6));
}

original_code:
void tcp_free(void)
{
 myfree(_main->tcp);
}

canonical_original_code:
void tcp_free()
{
 myfree(_main->tcp);
}


decompiled_code:
int tcp_stop()
{
int result; // eax

if ( shutdown(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL), 2) )
fail("shutdown() failed.");
if ( close(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL)) )
fail("close() failed.");
result = close(*(_DWORD *)(*((_QWORD *)main + 6) + 36LL));
if ( result )
result = fail("close() failed.");
return result;
}

canonical_decompiled_code:
int func3()
{
int result; // eax

if ( shutdown(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL), 2) )
fail("shutdown() failed.");
if ( close(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL)) )
fail("close() failed.");
result = close(*(_DWORD *)(*((_QWORD *)main + 6) + 36LL));
if ( result )
result = fail("close() failed.");
return result;
}

original_code:
void tcp_stop(void)
{
 if (shutdown(_main->tcp->sockfd, SHUT_RDWR) != 0) {
  fail("shutdown() failed.");
 }
 if (close(_main->tcp->sockfd) != 0) {
  fail("close() failed.");
 }
 if (close(_main->tcp->epollfd) != 0) {
  fail("close() failed.");
 }
}

canonical_original_code:
void tcp_stop()
{
 if (shutdown(_main->tcp->sockfd, SHUT_RDWR) != 0) {
  fail("shutdown() failed.");
 }
 if (close(_main->tcp->sockfd) != 0) {
  fail("close() failed.");
 }
 if (close(_main->tcp->epollfd) != 0) {
  fail("close() failed.");
 }
}


decompiled_code:
int tcp_event()
{
__int64 v0; // rbx
int (__cdecl *v1)(int, const char **, const char **); // rax
__int64 v2; // rax
unsigned int v3; // edx
int v4; // edi
int result; // eax
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v0 = *((_QWORD *)main + 6);
*(_DWORD *)(v0 + 36) = epoll_create(23);
v1 = main;
if ( *(_DWORD *)(*((_QWORD *)main + 6) + 36LL) == -1 )
{
fail("epoll_create() failed");
v1 = main;
}
v2 = *((_QWORD *)v1 + 6);
event.events = -2147483647;
v3 = *(_DWORD *)(v2 + 32);
v4 = *(_DWORD *)(v2 + 36);
event.data.u64 = v3;
result = epoll_ctl(v4, 1, v3, &event);
if ( result == -1 )
result = fail("tcp_event: epoll_ctl() failed");
return result;
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rbx
int (__cdecl *v1)(int, const char **, const char **); // rax
__int64 v2; // rax
unsigned int v3; // edx
int v4; // edi
int result; // eax
struct epoll_event event; // [rsp+4h] [rbp-14h] BYREF

v0 = *((_QWORD *)main + 6);
*(_DWORD *)(v0 + 36) = epoll_create(23);
v1 = main;
if ( *(_DWORD *)(*((_QWORD *)main + 6) + 36LL) == -1 )
{
fail("epoll_create() failed");
v1 = main;
}
v2 = *((_QWORD *)v1 + 6);
event.events = -2147483647;
v3 = *(_DWORD *)(v2 + 32);
v4 = *(_DWORD *)(v2 + 36);
event.data.u64 = v3;
result = epoll_ctl(v4, 1, v3, &event);
if ( result == -1 )
result = fail("tcp_event: epoll_ctl() failed");
return result;
}

original_code:
void tcp_event(void)
{
 struct epoll_event ev;
 _main->tcp->epollfd = epoll_create(23);
 if (_main->tcp->epollfd == -1) {
  fail("epoll_create() failed");
 }
 memset(&ev, '\0', sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = _main->tcp->sockfd;
 if (epoll_ctl
     (_main->tcp->epollfd, 1, _main->tcp->sockfd,
      &ev) == -1) {
  fail("tcp_event: epoll_ctl() failed");
 }
}

canonical_original_code:
void tcp_event()
{
 struct epoll_event ev;
 _main->tcp->epollfd = epoll_create(23);
 if (_main->tcp->epollfd == -1) {
  fail("epoll_create() failed");
 }
 memset(&ev, '\0', sizeof(struct epoll_event));
 ev.events = EPOLLIN | EPOLLET;
 ev.data.fd = _main->tcp->sockfd;
 if (epoll_ctl
     (_main->tcp->epollfd, 1, _main->tcp->sockfd,
      &ev) == -1) {
  fail("tcp_event: epoll_ctl() failed");
 }
}

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }


decompiled_code:
int __fastcall tcp_rearm(epoll_data_t a1, int a2)
{
int v2; // edx
int result; // eax
int *v4; // rax
char *v5; // rax
struct epoll_event event; // [rsp+4h] [rbp-24h] BYREF

event.data = a1;
v2 = *(_DWORD *)list_value();
event.events = a2 == 0 ? -1073741823 : -1073741820;
result = epoll_ctl(*(_DWORD *)(*((_QWORD *)main + 6) + 36LL), 3, v2, &event);
if ( result == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
info(log, 0LL, v5);
result = fail("tcp_rearm: epoll_ctl() failed");
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(epoll_data_t a1, int a2)
{
int v2; // edx
int result; // eax
int *v4; // rax
char *v5; // rax
struct epoll_event event; // [rsp+4h] [rbp-24h] BYREF

event.data = a1;
v2 = *(_DWORD *)list_value();
event.events = a2 == 0 ? -1073741823 : -1073741820;
result = epoll_ctl(*(_DWORD *)(*((_QWORD *)main + 6) + 36LL), 3, v2, &event);
if ( result == -1 )
{
v4 = _errno_location();
v5 = strerror(*v4);
info(log, 0LL, v5);
result = fail("tcp_rearm: epoll_ctl() failed");
}
return result;
}

original_code:
void tcp_rearm(ITEM * listItem, int mode)
{
 TCP_NODE *n = list_value(listItem);
 struct epoll_event ev;
 memset(&ev, '\0', sizeof(struct epoll_event));
 if (mode == 0) {
  ev.events = EPOLLET | EPOLLIN | EPOLLONESHOT;
 } else {
  ev.events = EPOLLET | EPOLLOUT | EPOLLONESHOT;
 }
 ev.data.ptr = listItem;
 if (epoll_ctl(_main->tcp->epollfd, 3, n->connfd, &ev) == -1) {
  info(_log, ((void *)0), strerror((*__errno_location ())));
  fail("tcp_rearm: epoll_ctl() failed");
 }
}

canonical_original_code:
void tcp_rearm(struct obj_item *listItem, int mode)
{
 struct TCP_NODE *n = list_value(listItem);
 struct epoll_event ev;
 memset(&ev, '\0', sizeof(struct epoll_event));
 if (mode == 0) {
  ev.events = EPOLLET | EPOLLIN | EPOLLONESHOT;
 } else {
  ev.events = EPOLLET | EPOLLOUT | EPOLLONESHOT;
 }
 ev.data.ptr = listItem;
 if (epoll_ctl(_main->tcp->epollfd, 3, n->connfd, &ev) == -1) {
  info(_log, ((void *)0), strerror((*__errno_location ())));
  fail("tcp_rearm: epoll_ctl() failed");
 }
}

variable_types: mode int

variable_types: struct TCP_NODE { int connfd; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } c_addr; unsigned int c_addrlen; char recv_buf[1024]; long recv_size; int keepalive; int pipeline; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *response; } *

user_defined_types: struct TCP_NODE { int connfd; struct sockaddr_in6 c_addr; unsigned int c_addrlen; char recv_buf[1024]; long recv_size; int keepalive; int pipeline; struct obj_list *response; }

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }


decompiled_code:
int __fastcall tcp_gate(epoll_data_t a1)
{
int v1; // eax

v1 = *(_DWORD *)(list_value() + 1076);
if ( v1 > 4 )
{
if ( v1 == 5 )
return ((__int64 (__fastcall *)(_QWORD))node_shutdown)((epoll_data_t)a1.u64);
}
else
{
if ( v1 > 1 )
return tcp_rearm(a1, 1);
if ( v1 == 1 )
return tcp_rearm(a1, 0);
}
return fail("No shit");
}

canonical_decompiled_code:
int __fastcall func6(epoll_data_t a1)
{
int v1; // eax

v1 = *(_DWORD *)(list_value() + 1076);
if ( v1 > 4 )
{
if ( v1 == 5 )
return ((__int64 (__fastcall *)(_QWORD))node_shutdown)((epoll_data_t)a1.u64);
}
else
{
if ( v1 > 1 )
return func5(a1, 1);
if ( v1 == 1 )
return func5(a1, 0);
}
return fail("No shit");
}

original_code:
void tcp_gate(ITEM * listItem)
{
 TCP_NODE *n = list_value(listItem);
 switch (n->pipeline) {
 case 5:
  node_shutdown(listItem);
  break;
 case 1:
  tcp_rearm(listItem, 0);
  break;
 case 2:
 case 3:
 case 4:
  tcp_rearm(listItem, 1);
  break;
 default:
  fail("No shit");
 }
}

canonical_original_code:
void tcp_gate(struct obj_item *listItem)
{
 struct TCP_NODE *n = list_value(listItem);
 switch (n->pipeline) {
 case 5:
  node_shutdown(listItem);
  break;
 case 1:
  tcp_rearm(listItem, 0);
  break;
 case 2:
 case 3:
 case 4:
  tcp_rearm(listItem, 1);
  break;
 default:
  fail("No shit");
 }
}

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


decompiled_code:
__int64 __fastcall tcp_nonblocking(int fd)
{
int v1; // eax
int v2; // er8
__int64 result; // rax

v1 = fcntl(fd, 3);
if ( v1 < 0 || (BYTE1(v1) |= 8u, v2 = fcntl(fd, 4, (unsigned int)v1), result = 1LL, v2 < 0) )
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd)
{
int v1; // eax
int v2; // er8
__int64 result; // rax

v1 = fcntl(fd, 3);
if ( v1 < 0 || (BYTE1(v1) |= 8u, v2 = fcntl(fd, 4, (unsigned int)v1), result = 1LL, v2 < 0) )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int tcp_nonblocking(int sock)
{
 int opts = fcntl(sock, 3);
 if (opts < 0) {
  return -1;
 }
 opts = opts | 04000;
 if (fcntl(sock, 4, opts) < 0) {
  return -1;
 }
 return 1;
}

variable_types: sock int

variable_types: opts int


decompiled_code:
int tcp_start()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rax
__int16 v3; // ax
__m128i v4; // xmm0
__int64 v5; // rdx
int v6; // edi
const void *v7; // rcx
socklen_t v8; // er8

v0 = *((_QWORD *)main + 6);
v1 = socket(10, 1, 0);
*(_DWORD *)(v0 + 32) = v1;
if ( v1 < 0 )
fail("Creating socket failed.");
v2 = *((_QWORD *)main + 2);
**((_WORD **)main + 6) = 10;
v3 = _bswap_16(*(_WORD *)(v2 + 2052));
v4 = _mm_loadu_si128((const __m128i *)&in6addr_any);
v6 = *(_DWORD *)(v5 + 32);
*(_WORD *)(v5 + 2) = v3;
*(__m128i *)(v5 + 8) = v4;
if ( setsockopt(v6, 1, 2, v7, v8) == -1 )
fail("Setting SO_REUSEADDR failed");
if ( bind(
*(_DWORD *)(*((_QWORD *)main + 6) + 32LL),
*((const struct sockaddr **)main + 6),
*(_DWORD *)(*((_QWORD *)main + 6) + 28LL)) )
{
fail("bind() to socket failed.");
}
if ( (int)tcp_nonblocking(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL)) < 0 )
fail("tcp_nonblocking( _main->tcp->sockfd ) failed");
if ( listen(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL), 1024) )
fail("listen() to socket failed.");
else
info(log, 0LL, "Listen queue length: %i", 1024LL);
return tcp_event();
}

canonical_decompiled_code:
int func8()
{
__int64 v0; // rbx
int v1; // eax
__int64 v2; // rax
__int16 v3; // ax
__m128i v4; // xmm0
__int64 v5; // rdx
int v6; // edi
const void *v7; // rcx
socklen_t v8; // er8

v0 = *((_QWORD *)main + 6);
v1 = socket(10, 1, 0);
*(_DWORD *)(v0 + 32) = v1;
if ( v1 < 0 )
fail("Creating socket failed.");
v2 = *((_QWORD *)main + 2);
**((_WORD **)main + 6) = 10;
v3 = func0(*(_WORD *)(v2 + 2052));
v4 = _mm_loadu_si128((const __m128i *)&in6addr_any);
v6 = *(_DWORD *)(v5 + 32);
*(_WORD *)(v5 + 2) = v3;
*(__m128i *)(v5 + 8) = v4;
if ( setsockopt(v6, 1, 2, v7, v8) == -1 )
fail("Setting SO_REUSEADDR failed");
if ( bind(
*(_DWORD *)(*((_QWORD *)main + 6) + 32LL),
*((const struct sockaddr **)main + 6),
*(_DWORD *)(*((_QWORD *)main + 6) + 28LL)) )
{
fail("bind() to socket failed.");
}
if ( (int)func7(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL)) < 0 )
fail("tcp_nonblocking( _main->tcp->sockfd ) failed");
if ( listen(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL), 1024) )
fail("listen() to socket failed.");
else
info(log, 0LL, "Listen queue length: %i", 1024LL);
return func4();
}

original_code:
void tcp_start(void)
{
 int listen_queue_length = 128 * 8;
 int optval = 1;
 if ((_main->tcp->sockfd = socket(10, SOCK_STREAM, 0)) < 0) {
  fail("Creating socket failed.");
 }
 _main->tcp->s_addr.sin6_family = 10;
 _main->tcp->s_addr.sin6_port = htons(_main->conf->port);
 _main->tcp->s_addr.sin6_addr = in6addr_any;
 if (setsockopt
     (_main->tcp->sockfd, 1, 2, &optval,
      sizeof(int)) == -1) {
  fail("Setting SO_REUSEADDR failed");
 }
 if (bind
     (_main->tcp->sockfd, (struct sockaddr *)&_main->tcp->s_addr,
      _main->tcp->s_addrlen)) {
  fail("bind() to socket failed.");
 }
 if (tcp_nonblocking(_main->tcp->sockfd) < 0) {
  fail("tcp_nonblocking( _main->tcp->sockfd ) failed");
 }
 if (listen(_main->tcp->sockfd, listen_queue_length)) {
  fail("listen() to socket failed.");
 } else {
  info(_log, ((void *)0), "Listen queue length: %i",
       listen_queue_length);
 }
 tcp_event();
}

canonical_original_code:
void tcp_start()
{
 int listen_queue_length = 128 * 8;
 int optval = 1;
 if ((_main->tcp->sockfd = socket(10, SOCK_STREAM, 0)) < 0) {
  fail("Creating socket failed.");
 }
 _main->tcp->s_addr.sin6_family = 10;
 _main->tcp->s_addr.sin6_port = htons(_main->conf->port);
 _main->tcp->s_addr.sin6_addr = in6addr_any;
 if (setsockopt
     (_main->tcp->sockfd, 1, 2, &optval,
      sizeof(int)) == -1) {
  fail("Setting SO_REUSEADDR failed");
 }
 if (bind
     (_main->tcp->sockfd, (struct sockaddr *)&_main->tcp->s_addr,
      _main->tcp->s_addrlen)) {
  fail("bind() to socket failed.");
 }
 if (tcp_nonblocking(_main->tcp->sockfd) < 0) {
  fail("tcp_nonblocking( _main->tcp->sockfd ) failed");
 }
 if (listen(_main->tcp->sockfd, listen_queue_length)) {
  fail("listen() to socket failed.");
 } else {
  info(_log, ((void *)0), "Listen queue length: %i",
       listen_queue_length);
 }
 tcp_event();
}

variable_types: optval int


decompiled_code:
int *tcp_newconn()
{
size_t v0; // rdx
int v1; // edx
__int64 v2; // rax
int v3; // ebp
int *result; // rax
char *v5; // rdi
__int64 v6; // rax
size_t v7; // r12
int *v8; // rax
size_t v9; // rdx
int *v10; // rbx
int v11; // er13
int *v12; // rax
char *v13; // rax
size_t n[2]; // [rsp+0h] [rbp-58h] BYREF
struct sockaddr s[4]; // [rsp+10h] [rbp-48h] BYREF

v0 = 28LL;
LODWORD(n[0]) = 28;
while ( 1 )
{
memset(s, 0, v0);
v3 = accept(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL), s, (socklen_t *)n);
if ( v3 < 0 )
{
result = _errno_location();
if ( *result == 11 )
return result;
v5 = strerror(*result);
fail(v5);
}
v6 = node_put();
v7 = v6;
if ( !v6 )
break;
v8 = (int *)list_value(v6);
v9 = LODWORD(n[0]);
*v8 = v3;
v10 = v8;
v11 = v9;
memcpy(v8 + 1, s, v9);
v10[8] = v11;
if ( (int)tcp_nonblocking(v3) < 0 )
fail("tcp_nonblocking() failed");
v1 = *v10;
HIDWORD(n[0]) = -1073741823;
v2 = *((_QWORD *)main + 6);
n[1] = v7;
if ( epoll_ctl(*(_DWORD *)(v2 + 36), 1, v1, (struct epoll_event *)((char *)n + 4)) == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
info(log, 0LL, v13);
fail("tcp_newconn: epoll_ctl( ) failed");
}
v0 = LODWORD(n[0]);
}
info(log, 0LL, "The linked list reached its limits");
return (int *)node_disconnect((unsigned int)v3);
}

canonical_decompiled_code:
int *func9()
{
size_t v0; // rdx
int v1; // edx
__int64 v2; // rax
int v3; // ebp
int *result; // rax
char *v5; // rdi
__int64 v6; // rax
size_t v7; // r12
int *v8; // rax
size_t v9; // rdx
int *v10; // rbx
int v11; // er13
int *v12; // rax
char *v13; // rax
size_t n[2]; // [rsp+0h] [rbp-58h] BYREF
struct sockaddr s[4]; // [rsp+10h] [rbp-48h] BYREF

v0 = 28LL;
LODWORD(n[0]) = 28;
while ( 1 )
{
memset(s, 0, v0);
v3 = accept(*(_DWORD *)(*((_QWORD *)main + 6) + 32LL), s, (socklen_t *)n);
if ( v3 < 0 )
{
result = _errno_location();
if ( *result == 11 )
return result;
v5 = strerror(*result);
fail(v5);
}
v6 = node_put();
v7 = v6;
if ( !v6 )
break;
v8 = (int *)list_value(v6);
v9 = LODWORD(n[0]);
*v8 = v3;
v10 = v8;
v11 = v9;
memcpy(v8 + 1, s, v9);
v10[8] = v11;
if ( (int)func7(v3) < 0 )
fail("tcp_nonblocking() failed");
v1 = *v10;
HIDWORD(n[0]) = -1073741823;
v2 = *((_QWORD *)main + 6);
n[1] = v7;
if ( epoll_ctl(*(_DWORD *)(v2 + 36), 1, v1, (struct epoll_event *)((char *)n + 4)) == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
info(log, 0LL, v13);
fail("tcp_newconn: epoll_ctl( ) failed");
}
v0 = LODWORD(n[0]);
}
info(log, 0LL, "The linked list reached its limits");
return (int *)node_disconnect((unsigned int)v3);
}

original_code:
void tcp_newconn(void)
{
 struct epoll_event ev;
 ITEM *listItem = ((void *)0);
 TCP_NODE *n = ((void *)0);
 int connfd;
 IP c_addr;
 socklen_t c_addrlen = sizeof(IP);
 for (;;) {
  memset((char *)&c_addr, '\0', c_addrlen);
  connfd =
      accept(_main->tcp->sockfd, (struct sockaddr *)&c_addr,
      &c_addrlen);
  if (connfd < 0) {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
    break;
   } else {
    fail(strerror((*__errno_location ())));
   }
  }
  if ((listItem = node_put()) == ((void *)0)) {
   info(_log, ((void *)0), "The linked list reached its limits");
   node_disconnect(connfd);
   break;
  }
  n = list_value(listItem);
  n->connfd = connfd;
  memcpy(&n->c_addr, &c_addr, c_addrlen);
  n->c_addrlen = c_addrlen;
  if (tcp_nonblocking(n->connfd) < 0) {
   fail("tcp_nonblocking() failed");
  }
  ev.events = EPOLLET | EPOLLIN | EPOLLONESHOT;
  ev.data.ptr = listItem;
  if (epoll_ctl
      (_main->tcp->epollfd, 1, n->connfd,
       &ev) == -1) {
   info(_log, ((void *)0), strerror((*__errno_location ())));
   fail("tcp_newconn: epoll_ctl( ) failed");
  }
 }
}

canonical_original_code:
void tcp_newconn()
{
 struct epoll_event ev;
 struct obj_item *listItem = ((void *)0);
 struct TCP_NODE *n = ((void *)0);
 int connfd;
 struct sockaddr_in6 c_addr;
 unsigned int c_addrlen = sizeof(IP);
 for (;;) {
  memset((char *)&c_addr, '\0', c_addrlen);
  connfd =
      accept(_main->tcp->sockfd, (struct sockaddr *)&c_addr,
      &c_addrlen);
  if (connfd < 0) {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
    break;
   } else {
    fail(strerror((*__errno_location ())));
   }
  }
  if ((listItem = node_put()) == ((void *)0)) {
   info(_log, ((void *)0), "The linked list reached its limits");
   node_disconnect(connfd);
   break;
  }
  n = list_value(listItem);
  n->connfd = connfd;
  memcpy(&n->c_addr, &c_addr, c_addrlen);
  n->c_addrlen = c_addrlen;
  if (tcp_nonblocking(n->connfd) < 0) {
   fail("tcp_nonblocking() failed");
  }
  ev.events = EPOLLET | EPOLLIN | EPOLLONESHOT;
  ev.data.ptr = listItem;
  if (epoll_ctl
      (_main->tcp->epollfd, 1, n->connfd,
       &ev) == -1) {
   info(_log, ((void *)0), strerror((*__errno_location ())));
   fail("tcp_newconn: epoll_ctl( ) failed");
  }
 }
}

variable_types: connfd int

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }


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

v1 = list_value(a1);
result = (unsigned int)(*(_DWORD *)(v1 + 1076) - 2);
if ( (unsigned int)result <= 2 )
result = send_tcp(v1);
return result;
}

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

v1 = list_value(a1);
result = (unsigned int)(*(_DWORD *)(v1 + 1076) - 2);
if ( (unsigned int)result <= 2 )
result = send_tcp(v1);
return result;
}

original_code:
void tcp_output(ITEM * i)
{
 TCP_NODE *n = list_value(i);
 switch (n->pipeline) {
 case 2:
 case 3:
 case 4:
  send_tcp(n);
  break;
 }
}

canonical_original_code:
void tcp_output(struct obj_item *i)
{
 struct TCP_NODE *n = list_value(i);
 switch (n->pipeline) {
 case 2:
 case 3:
 case 4:
  send_tcp(n);
  break;
 }
}


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

node_appendBuffer();
if ( *(_DWORD *)(a1 + 1076) != 1 )
fail("FIXME tcp_buffer...");
if ( *(__int64 *)(a1 + 1064) > 1022 )
{
info(log, a1 + 4, "Max head buffer exceeded...");
result = node_status(a1, 5LL);
}
else
{
http_buf(a1);
result = http_send(a1);
}
return result;
}

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

node_appendBuffer();
if ( *(_DWORD *)(a1 + 1076) != 1 )
fail("FIXME tcp_buffer...");
if ( *(__int64 *)(a1 + 1064) > 1022 )
{
info(log, a1 + 4, "Max head buffer exceeded...");
result = node_status(a1, 5LL);
}
else
{
http_buf(a1);
result = http_send(a1);
}
return result;
}

original_code:
void tcp_buffer(TCP_NODE * n, char *buffer, ssize_t bytes)
{
 node_appendBuffer(n, buffer, bytes);
 if (n->pipeline != 1) {
  fail("FIXME tcp_buffer...");
 }
 if (n->recv_size >= 1023) {
  info(_log, &n->c_addr, "Max head buffer exceeded...");
  node_status(n, 5);
  return;
 }
 http_buf(n);
 http_send(n);
}

canonical_original_code:
void tcp_buffer(struct TCP_NODE *n, char *buffer, long bytes)
{
 node_appendBuffer(n, buffer, bytes);
 if (n->pipeline != 1) {
  fail("FIXME tcp_buffer...");
 }
 if (n->recv_size >= 1023) {
  info(_log, &n->c_addr, "Max head buffer exceeded...");
  node_status(n, 5);
  return;
 }
 http_buf(n);
 http_send(n);
}

variable_types:
buffer
char *

variable_types: bytes long


decompiled_code:
__int64 __fastcall tcp_input(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
ssize_t v3; // rax
int *v4; // rbx
__int64 v5; // rbp
char *v6; // rax
__int64 v7; // [rsp+0h] [rbp-418h] BYREF

result = list_value(a1);
if ( status == 1 )
{
v2 = result;
v3 = recv(*(_DWORD *)result, &v7, 0x3FFuLL, 0);
if ( v3 < 0 )
{
v4 = _errno_location();
result = (unsigned int)*v4;
if ( (_DWORD)result == 11 )
return result;
if ( (_DWORD)result != 104 )
{
v5 = v2 + 4;
info(log, v5, "recv() failed:");
v6 = strerror(*v4);
return info(log, v5, v6);
}
}
else if ( v3 )
{
return tcp_buffer(v2);
}
result = node_status(v2, 5LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbp
ssize_t v3; // rax
int *v4; // rbx
__int64 v5; // rbp
char *v6; // rax
__int64 v7; // [rsp+0h] [rbp-418h] BYREF

result = list_value(a1);
if ( status == 1 )
{
v2 = result;
v3 = recv(*(_DWORD *)result, &v7, 0x3FFuLL, 0);
if ( v3 < 0 )
{
v4 = _errno_location();
result = (unsigned int)*v4;
if ( (_DWORD)result == 11 )
return result;
if ( (_DWORD)result != 104 )
{
v5 = v2 + 4;
info(log, v5, "recv() failed:");
v6 = strerror(*v4);
return info(log, v5, v6);
}
}
else if ( v3 )
{
return func11(v2);
}
result = node_status(v2, 5LL);
}
return result;
}

original_code:
void tcp_input(ITEM * listItem)
{
 TCP_NODE *n = list_value(listItem);
 char buffer[1024];
 ssize_t bytes = 0;
 while (status == 1) {
  bytes = recv(n->connfd, buffer, 1023, 0);
  if (bytes < 0) {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
    return;
   } else if ((*__errno_location ()) == 104) {
    node_status(n, 5);
    return;
   } else {
    info(_log, &n->c_addr, "recv() failed:");
    info(_log, &n->c_addr, strerror((*__errno_location ())));
    return;
   }
  } else if (bytes == 0) {
   node_status(n, 5);
   return;
  } else {
   tcp_buffer(n, buffer, bytes);
   return;
  }
 }
}

canonical_original_code:
void tcp_input(struct obj_item *listItem)
{
 struct TCP_NODE *n = list_value(listItem);
 char buffer[1024];
 long bytes = 0;
 while (status == 1) {
  bytes = recv(n->connfd, buffer, 1023, 0);
  if (bytes < 0) {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
    return;
   } else if ((*__errno_location ()) == 104) {
    node_status(n, 5);
    return;
   } else {
    info(_log, &n->c_addr, "recv() failed:");
    info(_log, &n->c_addr, strerror((*__errno_location ())));
    return;
   }
  } else if (bytes == 0) {
   node_status(n, 5);
   return;
  } else {
   tcp_buffer(n, buffer, bytes);
   return;
  }
 }
}

variable_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *

variable_types:
buffer
char [1024]


original_code:
void tcp_worker(struct epoll_event *events, int nfds, int thrd_id)
{
 ITEM *listItem = ((void *)0);
 int i;
 mutex_block(_main->work->mutex);
 _main->work->active++;
 mutex_unblock(_main->work->mutex);
 for (i = 0; i < nfds; i++) {
  if (events[i].data.fd == _main->tcp->sockfd) {
   tcp_newconn();
  } else {
   listItem = events[i].data.ptr;
   if (events[i].events & EPOLLIN) {
    tcp_input(listItem);
   } else if (events[i].events & EPOLLOUT) {
    tcp_output(listItem);
   }
   tcp_gate(listItem);
  }
 }
 mutex_block(_main->work->mutex);
 _main->work->active--;
 mutex_unblock(_main->work->mutex);
}

canonical_original_code:
void tcp_worker(struct epoll_event *events, int nfds, int thrd_id)
{
 struct obj_item *listItem = ((void *)0);
 int i;
 mutex_block(_main->work->mutex);
 _main->work->active++;
 mutex_unblock(_main->work->mutex);
 for (i = 0; i < nfds; i++) {
  if (events[i].data.fd == _main->tcp->sockfd) {
   tcp_newconn();
  } else {
   listItem = events[i].data.ptr;
   if (events[i].events & EPOLLIN) {
    tcp_input(listItem);
   } else if (events[i].events & EPOLLOUT) {
    tcp_output(listItem);
   }
   tcp_gate(listItem);
  }
 }
 mutex_block(_main->work->mutex);
 _main->work->active--;
 mutex_unblock(_main->work->mutex);
}

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } *

variable_types: nfds int

variable_types: i int


decompiled_code:
void __noreturn tcp_thread()
{
__int64 v0; // rax
unsigned int v1; // ebx
__int64 v2; // rdi
int v3; // eax
int *v4; // rbp
char *v5; // rax
struct epoll_event v6[34]; // [rsp+0h] [rbp-198h] BYREF

mutex_block(*(_QWORD *)(*((_QWORD *)main + 3) + 80LL));
v0 = *((_QWORD *)main + 3);
v1 = *(_DWORD *)(v0 + 8);
v2 = *(_QWORD *)(v0 + 80);
*(_DWORD *)(v0 + 8) = v1 + 1;
mutex_unblock(v2);
info(log, 0LL, "Thread[%i] - Max events: %i", v1, 32LL);
while ( 1 )
{
v3 = epoll_wait(*(_DWORD *)(*((_QWORD *)main + 6) + 36LL), v6, 32, 1000);
if ( status != 1 )
break;
if ( v3 == -1 )
{
v4 = _errno_location();
if ( *v4 != 4 )
{
info(log, 0LL, "epoll_wait() failed");
v5 = strerror(*v4);
fail(v5);
}
}
else if ( v3 > 0 )
{
tcp_worker((__int64)v6, v3);
}
}
pthread_exit(0LL);
}

canonical_decompiled_code:
void __noreturn func14()
{
__int64 v0; // rax
unsigned int v1; // ebx
__int64 v2; // rdi
int v3; // eax
int *v4; // rbp
char *v5; // rax
struct epoll_event v6[34]; // [rsp+0h] [rbp-198h] BYREF

mutex_block(*(_QWORD *)(*((_QWORD *)main + 3) + 80LL));
v0 = *((_QWORD *)main + 3);
v1 = *(_DWORD *)(v0 + 8);
v2 = *(_QWORD *)(v0 + 80);
*(_DWORD *)(v0 + 8) = v1 + 1;
mutex_unblock(v2);
info(log, 0LL, "Thread[%i] - Max events: %i", v1, 32LL);
while ( 1 )
{
v3 = epoll_wait(*(_DWORD *)(*((_QWORD *)main + 6) + 36LL), v6, 32, 1000);
if ( status != 1 )
break;
if ( v3 == -1 )
{
v4 = _errno_location();
if ( *v4 != 4 )
{
info(log, 0LL, "epoll_wait() failed");
v5 = strerror(*v4);
fail(v5);
}
}
else if ( v3 > 0 )
{
func13((__int64)v6, v3);
}
}
pthread_exit(0LL);
}

original_code:
void *tcp_thread(void *arg)
{
 struct epoll_event events[32];
 int nfds;
 int id = 0;
 mutex_block(_main->work->mutex);
 id = _main->work->id++;
 mutex_unblock(_main->work->mutex);
 info(_log, ((void *)0), "Thread[%i] - Max events: %i", id,
      32);
 for (;;) {
  nfds =
      epoll_wait(_main->tcp->epollfd, events,
          32, 1000);
  if (status != 1) {
   break;
  }
  if (nfds == -1) {
   if ((*__errno_location ()) != 4) {
    info(_log, ((void *)0), "epoll_wait() failed");
    fail(strerror((*__errno_location ())));
   }
  } else if (nfds > 0) {
   tcp_worker(events, nfds, id);
  }
 }
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } [32]

variable_types: id int


decompiled_code:
_QWORD *tkn_init()
{
_QWORD *v0; // r12

v0 = (_QWORD *)myalloc(16LL);
*v0 = list_init();
v0[1] = hash_init(10LL);
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // r12

v0 = (_QWORD *)myalloc(16LL);
*v0 = list_init();
v0[1] = hash_init(10LL);
return v0;
}

original_code:
struct obj_token *tkn_init(void)
{
 struct obj_token *token =
     (struct obj_token *)myalloc(sizeof(struct obj_token));
 token->list = list_init();
 token->hash = hash_init(10);
 return token;
}

canonical_original_code:
struct obj_token *tkn_init()
{
 struct obj_token *token = (struct obj_token *)myalloc(sizeof(struct obj_token));
 token->list = list_init();
 token->hash = hash_init(10);
 return token;
}

variable_types: struct obj_token { struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; } *

user_defined_types: struct obj_token { struct obj_list *list; struct HASH *hash; }

user_defined_types: struct HASH { struct BUCKET *buckets; long size; }

user_defined_types: struct BUCKET { struct PAIR *pairs; long size; }


decompiled_code:
__int64 tkn_free()
{
list_clear(**((_QWORD **)main + 6));
list_free(**((_QWORD **)main + 6));
hash_free(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL));
return myfree(*((_QWORD *)main + 6));
}

canonical_decompiled_code:
__int64 func1()
{
list_clear(**((_QWORD **)main + 6));
list_free(**((_QWORD **)main + 6));
hash_free(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL));
return myfree(*((_QWORD *)main + 6));
}

original_code:
void tkn_free(void)
{
 list_clear(_main->token->list);
 list_free(_main->token->list);
 hash_free(_main->token->hash);
 myfree(_main->token);
}

canonical_original_code:
void tkn_free()
{
 list_clear(_main->token->list);
 list_free(_main->token->list);
 hash_free(_main->token->hash);
 myfree(_main->token);
}


decompiled_code:
__int64 __fastcall tkn_del(__int64 a1)
{
__int64 v1; // rbp

v1 = list_value();
hash_del(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL), v1, 8LL);
list_del(**((_QWORD **)main + 6), a1);
return myfree(v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbp

v1 = list_value();
hash_del(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL), v1, 8LL);
list_del(**((_QWORD **)main + 6), a1);
return myfree(v1);
}

original_code:
void tkn_del(ITEM * item_tkn)
{
 struct obj_tkn *tkn = list_value(item_tkn);
 hash_del(_main->token->hash, tkn->id, 8);
 list_del(_main->token->list, item_tkn);
 myfree(tkn);
}

canonical_original_code:
void tkn_del(struct obj_item *item_tkn)
{
 struct obj_tkn *tkn = list_value(item_tkn);
 hash_del(_main->token->hash, tkn->id, 8);
 list_del(_main->token->list, item_tkn);
 myfree(tkn);
}

variable_types: struct obj_tkn { unsigned char id[8]; long time; } *


decompiled_code:
__int64 __fastcall tkn_expire(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // rbp

result = list_start(**((_QWORD **)main + 6));
if ( result )
{
v2 = result;
do
{
while ( 1 )
{
v3 = v2;
v4 = list_value(v2);
result = list_next(v2);
v2 = result;
if ( *(_QWORD *)(v4 + 8) < a1 )
break;
if ( !result )
return result;
}
result = tkn_del(v3);
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rbx
__int64 v3; // r13
__int64 v4; // rbp

result = list_start(**((_QWORD **)main + 6));
if ( result )
{
v2 = result;
do
{
while ( 1 )
{
v3 = v2;
v4 = list_value(v2);
result = list_next(v2);
v2 = result;
if ( *(_QWORD *)(v4 + 8) < a1 )
break;
if ( !result )
return result;
}
result = func2(v3);
}
while ( v2 );
}
return result;
}

original_code:
void tkn_expire(time_t now)
{
 ITEM *item_tkn = ((void *)0);
 ITEM *next_tkn = ((void *)0);
 struct obj_tkn *tkn = ((void *)0);
 item_tkn = list_start(_main->token->list);
 while (item_tkn != ((void *)0)) {
  tkn = list_value(item_tkn);
  next_tkn = list_next(item_tkn);
  if (now > tkn->time) {
   tkn_del(item_tkn);
  }
  item_tkn = next_tkn;
 }
}

canonical_original_code:
void tkn_expire(long now)
{
 struct obj_item *item_tkn = ((void *)0);
 struct obj_item *next_tkn = ((void *)0);
 struct obj_tkn *tkn = ((void *)0);
 item_tkn = list_start(_main->token->list);
 while (item_tkn != ((void *)0)) {
  tkn = list_value(item_tkn);
  next_tkn = list_next(item_tkn);
  if (now > tkn->time) {
   tkn_del(item_tkn);
  }
  item_tkn = next_tkn;
 }
}

variable_types: now long

user_defined_types: struct obj_tkn { unsigned char id[8]; long time; }


decompiled_code:
_BOOL8 __fastcall tkn_validate(__int64 a1)
{
return hash_get(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL), a1, 8LL) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
return hash_get(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL), a1, 8LL) != 0;
}

original_code:
int tkn_validate(UCHAR * id)
{
 ITEM *item_tkn = ((void *)0);
 if ((item_tkn = hash_get(_main->token->hash, id, 8)) == ((void *)0)) {
  return 0;
 }
 return 1;
}

canonical_original_code:
int tkn_validate(unsigned char *id)
{
 struct obj_item *item_tkn = ((void *)0);
 if ((item_tkn = hash_get(_main->token->hash, id, 8)) == ((void *)0)) {
  return 0;
 }
 return 1;
}

variable_types:
id
unsigned char *


decompiled_code:
__int64 __fastcall tkn_create(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

v1 = 0;
while ( 1 )
{
++v1;
rand_urandom(a1, 8LL);
result = hash_exists(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL), a1, 8LL);
if ( !(_DWORD)result )
break;
if ( v1 == 1000 )
return info(log, 0LL, "Tokens exhausted. Giving up.");
}
if ( v1 != 1000 )
return result;
return info(log, 0LL, "Tokens exhausted. Giving up.");
}

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

v1 = 0;
while ( 1 )
{
++v1;
rand_urandom(a1, 8LL);
result = hash_exists(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL), a1, 8LL);
if ( !(_DWORD)result )
break;
if ( v1 == 1000 )
return info(log, 0LL, "Tokens exhausted. Giving up.");
}
if ( v1 != 1000 )
return result;
return info(log, 0LL, "Tokens exhausted. Giving up.");
}

original_code:
void tkn_create(UCHAR * id)
{
 int i = 0;
 int max = 1000;
 do {
  rand_urandom(id, 8);
  i++;
 } while (hash_exists(_main->token->hash, id, 8) && i < max);
 if (i >= max) {
  info(_log, ((void *)0), "Tokens exhausted. Giving up.");
 }
}

canonical_original_code:
void tkn_create(unsigned char *id)
{
 int i = 0;
 int max = 1000;
 do {
  rand_urandom(id, 8);
  i++;
 } while (hash_exists(_main->token->hash, id, 8) && i < max);
 if (i >= max) {
  info(_log, ((void *)0), "Tokens exhausted. Giving up.");
 }
}

variable_types: max int


decompiled_code:
__int64 tkn_put()
{
__int64 v0; // rbp
__int64 v1; // rax

v0 = myalloc(16LL);
tkn_create(v0);
time_add_30_min(v0 + 8);
v1 = list_put(**((_QWORD **)main + 6), v0);
return hash_put(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL), v0, 8LL, v1);
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rbp
__int64 v1; // rax

v0 = myalloc(16LL);
func5(v0);
time_add_30_min(v0 + 8);
v1 = list_put(**((_QWORD **)main + 6), v0);
return hash_put(*(_QWORD *)(*((_QWORD *)main + 6) + 8LL), v0, 8LL, v1);
}

original_code:
void tkn_put(void)
{
 ITEM *item_tkn = ((void *)0);
 struct obj_tkn *tkn = ((void *)0);
 tkn = (struct obj_tkn *)myalloc(sizeof(struct obj_tkn));
 tkn_create(tkn->id);
 time_add_30_min(&tkn->time);
 item_tkn = list_put(_main->token->list, tkn);
 hash_put(_main->token->hash, tkn->id, 8, item_tkn);
}

canonical_original_code:
void tkn_put()
{
 struct obj_item *item_tkn = ((void *)0);
 struct obj_tkn *tkn = ((void *)0);
 tkn = (struct obj_tkn *)myalloc(sizeof(struct obj_tkn));
 tkn_create(tkn->id);
 time_add_30_min(&tkn->time);
 item_tkn = list_put(_main->token->list, tkn);
 hash_put(_main->token->hash, tkn->id, 8, item_tkn);
}


decompiled_code:
__int64 tkn_read()
{
__int64 v0; // rax

v0 = list_stop(**((_QWORD **)main + 6));
return list_value(v0);
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rax

v0 = list_stop(**((_QWORD **)main + 6));
return list_value(v0);
}

original_code:
UCHAR *tkn_read(void)
{
 ITEM *item_tkn = list_stop(_main->token->list);
 struct obj_tkn *tkn = list_value(item_tkn);
 return tkn->id;
}

canonical_original_code:
unsigned char *tkn_read()
{
 struct obj_item *item_tkn = list_stop(_main->token->list);
 struct obj_tkn *tkn = list_value(item_tkn);
 return tkn->id;
}

return_type: unsigned char *


decompiled_code:
void __fastcall send_cork_start(int *a1)
{
bool v1; // zf
int *v2; // rax
char *v3; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = a1[269] == 2;
optval[0] = 1;
if ( v1 )
{
if ( setsockopt(*a1, 6, 3, optval, 4u) )
{
v2 = _errno_location();
v3 = strerror(*v2);
fail(v3);
}
node_status(a1, 3LL);
}
}

canonical_decompiled_code:
void __fastcall func0(int *a1)
{
bool v1; // zf
int *v2; // rax
char *v3; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = a1[269] == 2;
optval[0] = 1;
if ( v1 )
{
if ( setsockopt(*a1, 6, 3, optval, 4u) )
{
v2 = _errno_location();
v3 = strerror(*v2);
fail(v3);
}
node_status(a1, 3LL);
}
}

original_code:
void send_cork_start(TCP_NODE * n)
{
 int on = 1;
 if (n->pipeline != 2) {
  return;
 }
 if (setsockopt(n->connfd, IPPROTO_TCP, 3, &on, sizeof(on)) != 0) {
  fail(strerror((*__errno_location ())));
 }
 node_status(n, 3);
}

canonical_original_code:
void send_cork_start(struct TCP_NODE *n)
{
 int on = 1;
 if (n->pipeline != 2) {
  return;
 }
 if (setsockopt(n->connfd, IPPROTO_TCP, 3, &on, sizeof(on)) != 0) {
  fail(strerror((*__errno_location ())));
 }
 node_status(n, 3);
}

variable_types: struct TCP_NODE { int connfd; struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; } c_addr; unsigned int c_addrlen; char recv_buf[1024]; long recv_size; int keepalive; int pipeline; struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *response; } *

variable_types: on int

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


decompiled_code:
__int64 __fastcall send_mem(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r13
__int64 v4; // rbx
ssize_t v5; // rax

result = list_value(a2);
v3 = result;
v4 = result + 8;
while ( status == 1 )
{
v5 = send(
*(_DWORD *)a1,
(const void *)(v4 + *(int *)(v3 + 1036)),
*(_DWORD *)(v3 + 1032) - *(_DWORD *)(v3 + 1036),
0);
if ( v5 < 0 )
{
result = (__int64)_errno_location();
if ( *(_DWORD *)result != 11 )
result = node_status(a1, 5LL);
return result;
}
result = (unsigned int)(*(_DWORD *)(v3 + 1036) + v5);
*(_DWORD *)(v3 + 1036) = result;
if ( (int)result >= *(_DWORD *)(v3 + 1032) )
return resp_del(*(_QWORD *)(a1 + 1080), a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r13
__int64 v4; // rbx
ssize_t v5; // rax

result = list_value(a2);
v3 = result;
v4 = result + 8;
while ( status == 1 )
{
v5 = send(
*(_DWORD *)a1,
(const void *)(v4 + *(int *)(v3 + 1036)),
*(_DWORD *)(v3 + 1032) - *(_DWORD *)(v3 + 1036),
0);
if ( v5 < 0 )
{
result = (__int64)_errno_location();
if ( *(_DWORD *)result != 11 )
result = node_status(a1, 5LL);
return result;
}
result = (unsigned int)(*(_DWORD *)(v3 + 1036) + v5);
*(_DWORD *)(v3 + 1036) = result;
if ( (int)result >= *(_DWORD *)(v3 + 1032) )
return resp_del(*(_QWORD *)(a1 + 1080), a2);
}
return result;
}

original_code:
void send_mem(TCP_NODE * n, ITEM * item_r)
{
 RESPONSE *r = list_value(item_r);
 ssize_t bytes_sent = 0;
 ssize_t bytes_todo = 0;
 char *p = ((void *)0);
 while (status == 1) {
  p = r->data.memory.send_buf + r->data.memory.send_offset;
  bytes_todo =
      r->data.memory.send_size - r->data.memory.send_offset;
  bytes_sent = send(n->connfd, p, bytes_todo, 0);
  if (bytes_sent < 0) {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
    return;
   }
   node_status(n, 5);
   return;
  }
  r->data.memory.send_offset += bytes_sent;
  if (r->data.memory.send_offset >= r->data.memory.send_size) {
   resp_del(n->response, item_r);
   return;
  }
 }
}

canonical_original_code:
void send_mem(struct TCP_NODE *n, struct obj_item *item_r)
{
 struct RESPONSE *r = list_value(item_r);
 long bytes_sent = 0;
 long bytes_todo = 0;
 char *p = ((void *)0);
 while (status == 1) {
  p = r->data.memory.send_buf + r->data.memory.send_offset;
  bytes_todo =
      r->data.memory.send_size - r->data.memory.send_offset;
  bytes_sent = send(n->connfd, p, bytes_todo, 0);
  if (bytes_sent < 0) {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
    return;
   }
   node_status(n, 5);
   return;
  }
  r->data.memory.send_offset += bytes_sent;
  if (r->data.memory.send_offset >= r->data.memory.send_size) {
   resp_del(n->response, item_r);
   return;
  }
 }
}

variable_types: struct RESPONSE { int type; union { struct R_MEMORY { char send_buf[1024]; int send_size; int send_offset; } memory; struct R_FILE { char filename[1024]; long f_offset; long f_stop; } file; } data; } *

variable_types:
p
char *


decompiled_code:
int *__fastcall send_file(__int64 a1, __int64 a2)
{
int *result; // rax
int *v3; // r14
const char *v4; // rbx
int v5; // ebp
ssize_t v6; // r15
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax

result = (int *)list_value(a2);
v3 = result;
v4 = (const char *)(result + 2);
while ( status == 1 )
{
v5 = open(v4, 0);
if ( v5 < 0 )
{
info(log, 0LL, "Failed to open %s", v4);
v9 = _errno_location();
v10 = strerror(*v9);
fail(v10);
}
v6 = sendfile(*(_DWORD *)a1, v5, (off_t *)v3 + 129, *((_QWORD *)v3 + 130) + 1LL - *((_QWORD *)v3 + 129));
if ( close(v5) )
{
info(log, 0LL, "Failed to close %s", v4);
v7 = _errno_location();
v8 = strerror(*v7);
fail(v8);
if ( v6 < 0 )
{
LABEL_9:
result = _errno_location();
if ( *result != 11 )
result = (int *)node_status(a1, 5LL);
return result;
}
}
else if ( v6 < 0 )
{
goto LABEL_9;
}
result = (int *)*((_QWORD *)v3 + 130);
if ( *((_QWORD *)v3 + 129) > (__int64)result )
return (int *)resp_del(*(_QWORD *)(a1 + 1080), a2);
}
return result;
}

canonical_decompiled_code:
int *__fastcall func2(__int64 a1, __int64 a2)
{
int *result; // rax
int *v3; // r14
const char *v4; // rbx
int v5; // ebp
ssize_t v6; // r15
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax

result = (int *)list_value(a2);
v3 = result;
v4 = (const char *)(result + 2);
while ( status == 1 )
{
v5 = open(v4, 0);
if ( v5 < 0 )
{
info(log, 0LL, "Failed to open %s", v4);
v9 = _errno_location();
v10 = strerror(*v9);
fail(v10);
}
v6 = sendfile(*(_DWORD *)a1, v5, (off_t *)v3 + 129, *((_QWORD *)v3 + 130) + 1LL - *((_QWORD *)v3 + 129));
if ( close(v5) )
{
info(log, 0LL, "Failed to close %s", v4);
v7 = _errno_location();
v8 = strerror(*v7);
fail(v8);
if ( v6 < 0 )
{
LABEL_9:
result = _errno_location();
if ( *result != 11 )
result = (int *)node_status(a1, 5LL);
return result;
}
}
else if ( v6 < 0 )
{
goto LABEL_9;
}
result = (int *)*((_QWORD *)v3 + 130);
if ( *((_QWORD *)v3 + 129) > (__int64)result )
return (int *)resp_del(*(_QWORD *)(a1 + 1080), a2);
}
return result;
}

original_code:
void send_file(TCP_NODE * n, ITEM * item_r)
{
 RESPONSE *r = list_value(item_r);
 ssize_t bytes_sent = 0;
 ssize_t bytes_todo = 0;
 int fh = 0;
 while (status == 1) {
  fh = open(r->data.file.filename, 00);
  if (fh < 0) {
   info(_log, ((void *)0), "Failed to open %s",
        r->data.file.filename);
   fail(strerror((*__errno_location ())));
  }
  bytes_todo = r->data.file.f_stop + 1 - r->data.file.f_offset;
  bytes_sent =
      sendfile(n->connfd, fh, &r->data.file.f_offset, bytes_todo);
  if (close(fh) != 0) {
   info(_log, ((void *)0), "Failed to close %s",
        r->data.file.filename);
   fail(strerror((*__errno_location ())));
  }
  if (bytes_sent < 0) {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
    return;
   }
   node_status(n, 5);
   return;
  }
  if (r->data.file.f_offset > r->data.file.f_stop) {
   resp_del(n->response, item_r);
   return;
  }
 }
}

canonical_original_code:
void send_file(struct TCP_NODE *n, struct obj_item *item_r)
{
 struct RESPONSE *r = list_value(item_r);
 long bytes_sent = 0;
 long bytes_todo = 0;
 int fh = 0;
 while (status == 1) {
  fh = open(r->data.file.filename, 00);
  if (fh < 0) {
   info(_log, ((void *)0), "Failed to open %s",
        r->data.file.filename);
   fail(strerror((*__errno_location ())));
  }
  bytes_todo = r->data.file.f_stop + 1 - r->data.file.f_offset;
  bytes_sent =
      sendfile(n->connfd, fh, &r->data.file.f_offset, bytes_todo);
  if (close(fh) != 0) {
   info(_log, ((void *)0), "Failed to close %s",
        r->data.file.filename);
   fail(strerror((*__errno_location ())));
  }
  if (bytes_sent < 0) {
   if ((*__errno_location ()) == 11 || (*__errno_location ()) == 11) {
    return;
   }
   node_status(n, 5);
   return;
  }
  if (r->data.file.f_offset > r->data.file.f_stop) {
   resp_del(n->response, item_r);
   return;
  }
 }
}

variable_types: fh int


decompiled_code:
void __fastcall send_data(__int64 a1)
{
__int64 v1; // rsi

if ( *(_DWORD *)(a1 + 1076) == 3 )
{
while ( status == 1 && list_size(*(_QWORD *)(a1 + 1080)) > 0 )
{
v1 = list_start(*(_QWORD *)(a1 + 1080));
if ( *(_DWORD *)list_value(v1) )
{
send_file(a1, v1);
if ( *(_DWORD *)(a1 + 1076) == 5 )
return;
}
else
{
send_mem(a1, v1);
if ( *(_DWORD *)(a1 + 1076) == 5 )
return;
}
}
node_status(a1, 4LL);
}
}

original_code:
void send_data(TCP_NODE * n)
{
 ITEM *i = ((void *)0);
 RESPONSE *r = ((void *)0);
 if (n->pipeline != 3) {
  return;
 }
 while (status == 1 && list_size(n->response) > 0) {
  i = list_start(n->response);
  r = list_value(i);
  if (r->type == 0) {
   send_mem(n, i);
  } else {
   send_file(n, i);
  }
  if (n->pipeline == 5) {
   return;
  }
 }
 node_status(n, 4);
}

canonical_original_code:
void send_data(struct TCP_NODE *n)
{
 struct obj_item *i = ((void *)0);
 struct RESPONSE *r = ((void *)0);
 if (n->pipeline != 3) {
  return;
 }
 while (status == 1 && list_size(n->response) > 0) {
  i = list_start(n->response);
  r = list_value(i);
  if (r->type == 0) {
   send_mem(n, i);
  } else {
   send_file(n, i);
  }
  if (n->pipeline == 5) {
   return;
  }
 }
 node_status(n, 4);
}

variable_types: struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *


decompiled_code:
void __fastcall send_cork_stop(int *a1)
{
bool v1; // zf
int *v2; // rax
char *v3; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = a1[269] == 4;
optval[0] = 0;
if ( v1 )
{
if ( setsockopt(*a1, 6, 3, optval, 4u) )
{
v2 = _errno_location();
v3 = strerror(*v2);
fail(v3);
}
if ( a1[268] == 2 )
node_status(a1, 1LL);
else
node_status(a1, 5LL);
}
}

canonical_decompiled_code:
void __fastcall func4(int *a1)
{
bool v1; // zf
int *v2; // rax
char *v3; // rax
int optval[3]; // [rsp+Ch] [rbp-Ch] BYREF

v1 = a1[269] == 4;
optval[0] = 0;
if ( v1 )
{
if ( setsockopt(*a1, 6, 3, optval, 4u) )
{
v2 = _errno_location();
v3 = strerror(*v2);
fail(v3);
}
if ( a1[268] == 2 )
node_status(a1, 1LL);
else
node_status(a1, 5LL);
}
}

original_code:
void send_cork_stop(TCP_NODE * n)
{
 int off = 0;
 if (n->pipeline != 4) {
  return;
 }
 if (setsockopt(n->connfd, IPPROTO_TCP, 3, &off, sizeof(off)) !=
     0) {
  fail(strerror((*__errno_location ())));
 }
 switch (n->keepalive) {
 case 2:
  node_status(n, 1);
  break;
 default:
  node_status(n, 5);
 }
}

canonical_original_code:
void send_cork_stop(struct TCP_NODE *n)
{
 int off = 0;
 if (n->pipeline != 4) {
  return;
 }
 if (setsockopt(n->connfd, IPPROTO_TCP, 3, &off, sizeof(off)) !=
     0) {
  fail(strerror((*__errno_location ())));
 }
 switch (n->keepalive) {
 case 2:
  node_status(n, 1);
  break;
 default:
  node_status(n, 5);
 }
}

variable_types: off int


decompiled_code:
void __fastcall send_tcp(int *a1)
{
int v1; // eax

v1 = a1[269];
if ( v1 == 3 )
{
LABEL_5:
send_data((__int64)a1);
goto LABEL_6;
}
if ( v1 != 4 )
{
if ( v1 != 2 )
return;
send_cork_start(a1);
goto LABEL_5;
}
LABEL_6:
send_cork_stop(a1);
}

canonical_decompiled_code:
void __fastcall func5(int *a1)
{
int v1; // eax

v1 = a1[269];
if ( v1 == 3 )
{
LABEL_5:
func3((__int64)a1);
goto LABEL_6;
}
if ( v1 != 4 )
{
if ( v1 != 2 )
return;
func0(a1);
goto LABEL_5;
}
LABEL_6:
func4(a1);
}

original_code:
void send_tcp(TCP_NODE * n)
{
 switch (n->pipeline) {
 case 2:
  send_cork_start(n);
 case 3:
  send_data(n);
 case 4:
  send_cork_stop(n);
 }
}

canonical_original_code:
void send_tcp(struct TCP_NODE *n)
{
 switch (n->pipeline) {
 case 2:
  send_cork_start(n);
 case 3:
  send_data(n);
 case 4:
  send_cork_stop(n);
 }
}


original_code:
struct obj_mdb *mime_init(void)
{
 struct obj_mdb *mime =
     (struct obj_mdb *)myalloc(sizeof(struct obj_mdb));
 mime->list = list_init();
 mime->hash = ((void *)0);
 mime->mutex = mutex_init();
 return mime;
}

canonical_original_code:
struct obj_mdb *mime_init()
{
 struct obj_mdb *mime = (struct obj_mdb *)myalloc(sizeof(struct obj_mdb));
 mime->list = list_init();
 mime->hash = ((void *)0);
 mime->mutex = mutex_init();
 return mime;
}

variable_types: struct obj_mdb { struct obj_list { struct obj_item { void *val; struct obj_item *next; struct obj_item *prev; } *item; long size; } *list; struct HASH { struct BUCKET { struct PAIR { unsigned char *key; long size; void *value; } *pairs; long size; } *buckets; long size; } *hash; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } *mutex; } *

user_defined_types: struct obj_mdb { struct obj_list *list; struct HASH *hash; union pthread_mutex_t *mutex; }

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

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


decompiled_code:
__int64 mime_free()
{
list_clear(**((_QWORD **)main + 5));
list_free(**((_QWORD **)main + 5));
hash_free(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL));
mutex_destroy(*(_QWORD *)(*((_QWORD *)main + 5) + 16LL));
return myfree(*((_QWORD *)main + 5));
}

canonical_decompiled_code:
__int64 func1()
{
list_clear(**((_QWORD **)main + 5));
list_free(**((_QWORD **)main + 5));
hash_free(*(_QWORD *)(*((_QWORD *)main + 5) + 8LL));
mutex_destroy(*(_QWORD *)(*((_QWORD *)main + 5) + 16LL));
return myfree(*((_QWORD *)main + 5));
}

original_code:
void mime_free(void)
{
 list_clear(_main->mime->list);
 list_free(_main->mime->list);
 hash_free(_main->mime->hash);
 mutex_destroy(_main->mime->mutex);
 myfree(_main->mime);
}

canonical_original_code:
void mime_free()
{
 list_clear(_main->mime->list);
 list_free(_main->mime->list);
 hash_free(_main->mime->hash);
 mutex_destroy(_main->mime->mutex);
 myfree(_main->mime);
}


decompiled_code:
char *__fastcall mime_add(char *src, char *a2)
{
char *v2; // r12
__int64 v3; // rbp
size_t v4; // rax

v2 = (char *)myalloc(60LL);
strncpy(v2, src, 8uLL);
strncpy(v2 + 9, a2, 0x32uLL);
if ( !list_put(**((_QWORD **)main + 5), v2) )
fail("mime_add: List exhausted");
v3 = *(_QWORD *)(*((_QWORD *)main + 5) + 8LL);
if ( v3 )
{
v4 = strlen(v2);
hash_put(v3, v2, v4, v2 + 9);
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func2(char *src, char *a2)
{
char *v2; // r12
__int64 v3; // rbp
size_t v4; // rax

v2 = (char *)myalloc(60LL);
strncpy(v2, src, 8uLL);
strncpy(v2 + 9, a2, 0x32uLL);
if ( !list_put(**((_QWORD **)main + 5), v2) )
fail("mime_add: List exhausted");
v3 = *(_QWORD *)(*((_QWORD *)main + 5) + 8LL);
if ( v3 )
{
v4 = strlen(v2);
hash_put(v3, v2, v4, v2 + 9);
}
return v2;
}

original_code:
struct obj_mime *mime_add(const char *key, const char *value)
{
 struct obj_mime *tuple =
     (struct obj_mime *)myalloc(sizeof(struct obj_mime));
 strncpy(tuple->key, key, 8);
 strncpy(tuple->val, value, 50);
 if (list_put(_main->mime->list, tuple) == ((void *)0)) {
  fail("mime_add: List exhausted");
 }
 if (_main->mime->hash != ((void *)0)) {
  hash_put(_main->mime->hash, (UCHAR *) tuple->key,
    strlen(tuple->key), tuple->val);
 }
 return tuple;
}

canonical_original_code:
struct obj_mime *mime_add(char *key, char *value)
{
 struct obj_mime *tuple = (struct obj_mime *)myalloc(sizeof(struct obj_mime));
 strncpy(tuple->key, key, 8);
 strncpy(tuple->val, value, 50);
 if (list_put(_main->mime->list, tuple) == ((void *)0)) {
  fail("mime_add: List exhausted");
 }
 if (_main->mime->hash != ((void *)0)) {
  hash_put(_main->mime->hash, (unsigned char *) tuple->key,
    strlen(tuple->key), tuple->val);
 }
 return tuple;
}

variable_types:
key
char *

variable_types:
value
char *

variable_types: struct obj_mime { char key[-1]; char val[-1]; } *