decompiled_code:
__int64 __fastcall udp_connect(__int16 a1, const char *a2, unsigned int a3)
{
int v3; // eax
struct addrinfo *v4; // rbx
int v5; // ebp
const char *v6; // rax
int v7; // eax
char v9[32]; // [rsp+0h] [rbp-108h] BYREF
struct sockaddr addr[8]; // [rsp+20h] [rbp-E8h] BYREF
struct addrinfo *pai; // [rsp+A8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+B0h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
snprintf(v9, 0x14uLL, "%d", a3);
v3 = getaddrinfo(a2, v9, &req, &pai);
if ( v3 )
{
v6 = gai_strerror(v3);
fprintf(stderr, "%s\n", v6);
v5 = -1;
}
else
{
v4 = pai;
if ( pai )
{
v5 = -1;
while ( 1 )
{
if ( (v4->ai_family & 0xFFFFFFF7) != 2 )
goto LABEL_10;
v5 = socket(v4->ai_family, 2, v4->ai_protocol);
if ( v5 >= 0 )
break;
perror("udp_connect: socket");
LABEL_10:
v4 = v4->ai_next;
if ( !v4 )
goto LABEL_17;
}
memset(addr, 0, sizeof(addr));
v7 = v4->ai_family;
if ( v7 == 2 )
{
addr[0].sa_family = 2;
*(_WORD *)addr[0].sa_data = _bswap_16(a1);
}
else
{
if ( v7 != 10 )
{
LABEL_9:
close(v5);
v5 = -1;
goto LABEL_10;
}
addr[0].sa_family = 10;
*(_WORD *)addr[0].sa_data = _bswap_16(a1);
}
if ( !bind(v5, addr, v4->ai_addrlen) && !connect(v5, v4->ai_addr, v4->ai_addrlen) )
goto LABEL_17;
goto LABEL_9;
}
v5 = -1;
LABEL_17:
freeaddrinfo(pai);
}
return (unsigned int)v5;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int16 a1, const char *a2, unsigned int a3)
{
int v3; // eax
struct addrinfo *v4; // rbx
int v5; // ebp
const char *v6; // rax
int v7; // eax
char v9[32]; // [rsp+0h] [rbp-108h] BYREF
struct sockaddr addr[8]; // [rsp+20h] [rbp-E8h] BYREF
struct addrinfo *pai; // [rsp+A8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+B0h] [rbp-58h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 2LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
snprintf(v9, 0x14uLL, "%d", a3);
v3 = getaddrinfo(a2, v9, &req, &pai);
if ( v3 )
{
v6 = gai_strerror(v3);
fprintf(stderr, "%s\n", v6);
v5 = -1;
}
else
{
v4 = pai;
if ( pai )
{
v5 = -1;
while ( 1 )
{
if ( (v4->ai_family & 0xFFFFFFF7) != 2 )
goto LABEL_10;
v5 = socket(v4->ai_family, 2, v4->ai_protocol);
if ( v5 >= 0 )
break;
perror("udp_connect: socket");
LABEL_10:
v4 = v4->ai_next;
if ( !v4 )
goto LABEL_17;
}
memset(addr, 0, sizeof(addr));
v7 = v4->ai_family;
if ( v7 == 2 )
{
addr[0].sa_family = 2;
*(_WORD *)addr[0].sa_data = func1(a1);
}
else
{
if ( v7 != 10 )
{
LABEL_9:
close(v5);
v5 = -1;
goto LABEL_10;
}
addr[0].sa_family = 10;
*(_WORD *)addr[0].sa_data = func1(a1);
}
if ( !bind(v5, addr, v4->ai_addrlen) && !connect(v5, v4->ai_addr, v4->ai_addrlen) )
goto LABEL_17;
goto LABEL_9;
}
v5 = -1;
LABEL_17:
freeaddrinfo(pai);
}
return (unsigned int)v5;
}

original_code:
int udp_connect(int local_port,char *remote_host,int remote_port)
{
   struct addrinfo hints,*res,*res0;
   struct sockaddr_storage st;
   int error, sck = -1;
   char port_str[20];
   memset(&hints,0,sizeof(hints));
   hints.ai_family = 0;
   hints.ai_socktype = SOCK_DGRAM;
   snprintf(port_str,sizeof(port_str),"%d",remote_port);
   if ((error = getaddrinfo(remote_host,port_str,&hints,&res0)) != 0) {
      fprintf(stderr,"%s\n",gai_strerror(error));
      return(-1);
   }
   for(res=res0;res;res=res->ai_next)
   {
      if ((res->ai_family != 2) && (res->ai_family != 10))
         continue;
      if ((sck = socket(res->ai_family,SOCK_DGRAM,res->ai_protocol)) < 0) {
         perror("udp_connect: socket");
         continue;
      }
      memset(&st,0,sizeof(st));
      switch(res->ai_family) {
         case 2: {
            struct sockaddr_in *sin = (struct sockaddr_in *)&st;
            sin->sin_family = 2;
            sin->sin_port = htons(local_port);
            break;
         }
         case 10: {
            struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&st;
            sin6->sin6_family = 10;
            sin6->sin6_port = htons(local_port);
            break;
         }
         default:
            close(sck);
            sck = -1;
            continue;
      }
      if (!bind(sck,(struct sockaddr *)&st,res->ai_addrlen) &&
          !connect(sck,res->ai_addr,res->ai_addrlen))
         break;
      close(sck);
      sck = -1;
   }
   freeaddrinfo(res0);
   return(sck);
}

canonical_original_code:
int udp_connect(int local_port, char *remote_host, int remote_port)
{
   struct addrinfo hints; struct addrinfo *res; struct addrinfo *res0;
   struct sockaddr_storage st;
   int error; int sck = -1;
   char port_str[20];
   memset(&hints,0,sizeof(hints));
   hints.ai_family = 0;
   hints.ai_socktype = SOCK_DGRAM;
   snprintf(port_str,sizeof(port_str),"%d",remote_port);
   if ((error = getaddrinfo(remote_host,port_str,&hints,&res0)) != 0) {
      fprintf(stderr,"%s\n",gai_strerror(error));
      return(-1);
   }
   for(res=res0;res;res=res->ai_next)
   {
      if ((res->ai_family != 2) && (res->ai_family != 10))
         continue;
      if ((sck = socket(res->ai_family,SOCK_DGRAM,res->ai_protocol)) < 0) {
         perror("udp_connect: socket");
         continue;
      }
      memset(&st,0,sizeof(st));
      switch(res->ai_family) {
         case 2: {
            struct sockaddr_in *sin = (struct sockaddr_in *)&st;
            sin->sin_family = 2;
            sin->sin_port = htons(local_port);
            break;
         }
         case 10: {
            struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&st;
            sin6->sin6_family = 10;
            sin6->sin6_port = htons(local_port);
            break;
         }
         default:
            close(sck);
            sck = -1;
            continue;
      }
      if (!bind(sck,(struct sockaddr *)&st,res->ai_addrlen) &&
          !connect(sck,res->ai_addr,res->ai_addrlen))
         break;
      close(sck);
      sck = -1;
   }
   freeaddrinfo(res0);
   return(sck);
}

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

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

variable_types: error int

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

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 addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }

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

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


repo: Groundworkstech/dynamips-gdb-mod

decompiled_code:
__int64 __fastcall ip_listen(char *name, unsigned int a2, int a3, int a4, _DWORD *a5)
{
char *v5; // rbx
_DWORD *v8; // r13
_DWORD *v9; // rax
int v10; // eax
int v11; // ebp
struct addrinfo *v12; // rbx
const char *v14; // rax
int *v15; // r15
int v16; // eax
int optval; // [rsp+Ch] [rbp-8Ch] BYREF
char s[24]; // [rsp+10h] [rbp-88h] BYREF
struct addrinfo *pai; // [rsp+28h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-68h] BYREF

v5 = name;
v8 = a5;
optval = 1;
if ( a4 > 0 )
{
v9 = a5;
do
*v9++ = -1;
while ( v9 != &a5[a4 - 1 + 1] );
}
*(_QWORD *)&req.ai_flags = 1LL;
req.ai_protocol = 0;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_socktype = a3;
snprintf(s, 0x14uLL, "%d", a2);
if ( name && !*name )
v5 = 0LL;
v10 = getaddrinfo(v5, s, &req, &pai);
v11 = v10;
if ( v10 )
{
v14 = gai_strerror(v10);
fprintf(stderr, "ip_listen: %s", v14);
v11 = -1;
}
else
{
v12 = pai;
if ( pai && a4 > 0 )
{
do
{
if ( (v12->ai_family & 0xFFFFFFF7) == 2 )
{
v15 = &v8[v11];
v16 = socket(v12->ai_family, v12->ai_socktype, v12->ai_protocol);
*v15 = v16;
if ( v16 >= 0 )
{
setsockopt(v16, 1, 2, &optval, 4u);
if ( bind(*v15, v12->ai_addr, v12->ai_addrlen) < 0 || a3 == 1 && listen(*v15, 5) < 0 )
{
close(*v15);
*v15 = -1;
}
else
{
++v11;
}
}
}
v12 = v12->ai_next;
}
while ( v12 && v11 < a4 );
}
freeaddrinfo(pai);
}
return (unsigned int)v11;
}

canonical_decompiled_code:
__int64 __fastcall func12(char *name, unsigned int a2, int a3, int a4, _DWORD *a5)
{
char *v5; // rbx
_DWORD *v8; // r13
_DWORD *v9; // rax
int v10; // eax
int v11; // ebp
struct addrinfo *v12; // rbx
const char *v14; // rax
int *v15; // r15
int v16; // eax
int optval; // [rsp+Ch] [rbp-8Ch] BYREF
char s[24]; // [rsp+10h] [rbp-88h] BYREF
struct addrinfo *pai; // [rsp+28h] [rbp-70h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-68h] BYREF

v5 = name;
v8 = a5;
optval = 1;
if ( a4 > 0 )
{
v9 = a5;
do
*v9++ = -1;
while ( v9 != &a5[a4 - 1 + 1] );
}
*(_QWORD *)&req.ai_flags = 1LL;
req.ai_protocol = 0;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
req.ai_socktype = a3;
snprintf(s, 0x14uLL, "%d", a2);
if ( name && !*name )
v5 = 0LL;
v10 = getaddrinfo(v5, s, &req, &pai);
v11 = v10;
if ( v10 )
{
v14 = gai_strerror(v10);
fprintf(stderr, "ip_listen: %s", v14);
v11 = -1;
}
else
{
v12 = pai;
if ( pai && a4 > 0 )
{
do
{
if ( (v12->ai_family & 0xFFFFFFF7) == 2 )
{
v15 = &v8[v11];
v16 = socket(v12->ai_family, v12->ai_socktype, v12->ai_protocol);
*v15 = v16;
if ( v16 >= 0 )
{
setsockopt(v16, 1, 2, &optval, 4u);
if ( bind(*v15, v12->ai_addr, v12->ai_addrlen) < 0 || a3 == 1 && listen(*v15, 5) < 0 )
{
close(*v15);
*v15 = -1;
}
else
{
++v11;
}
}
}
v12 = v12->ai_next;
}
while ( v12 && v11 < a4 );
}
freeaddrinfo(pai);
}
return (unsigned int)v11;
}

original_code:
int ip_listen(char *ip_addr,int port,int sock_type,int max_fd,int fd_array[])
{
   struct addrinfo hints,*res,*res0;
   char port_str[20],*addr;
   int nsock,error,i;
   int reuse = 1;
   for(i=0;i<max_fd;i++)
      fd_array[i] = -1;
   memset(&hints,0,sizeof(hints));
   hints.ai_family = 0;
   hints.ai_socktype = sock_type;
   hints.ai_flags = 0x0001;
   snprintf(port_str,sizeof(port_str),"%d",port);
   addr = (ip_addr && strlen(ip_addr)) ? ip_addr : ((void *)0);
   if ((error = getaddrinfo(addr,port_str,&hints,&res0)) != 0) {
      fprintf(stderr,"ip_listen: %s", gai_strerror(error));
      return(-1);
   }
   nsock = 0;
   for(res=res0;(res && (nsock < max_fd));res=res->ai_next)
   {
      if ((res->ai_family != 2) && (res->ai_family != 10))
         continue;
      fd_array[nsock] = socket(res->ai_family,res->ai_socktype,
                               res->ai_protocol);
      if (fd_array[nsock] < 0)
         continue;
      setsockopt(fd_array[nsock],1,2,&reuse,sizeof(reuse));
      if ((bind(fd_array[nsock],res->ai_addr,res->ai_addrlen) < 0) ||
          ((sock_type == SOCK_STREAM) && (listen(fd_array[nsock],5) < 0)))
      {
         close(fd_array[nsock]);
         fd_array[nsock] = -1;
         continue;
      }
      nsock++;
   }
   freeaddrinfo(res0);
   return(nsock);
}

canonical_original_code:
int ip_listen(char *ip_addr, int port, int sock_type, int max_fd, int fd_array[])
{
   struct addrinfo hints; struct addrinfo *res; struct addrinfo *res0;
   char port_str[20]; char *addr;
   int nsock; int error; int i;
   int reuse = 1;
   for(i=0;i<max_fd;i++)
      fd_array[i] = -1;
   memset(&hints,0,sizeof(hints));
   hints.ai_family = 0;
   hints.ai_socktype = sock_type;
   hints.ai_flags = 0x0001;
   snprintf(port_str,sizeof(port_str),"%d",port);
   addr = (ip_addr && strlen(ip_addr)) ? ip_addr : ((void *)0);
   if ((error = getaddrinfo(addr,port_str,&hints,&res0)) != 0) {
      fprintf(stderr,"ip_listen: %s", gai_strerror(error));
      return(-1);
   }
   nsock = 0;
   for(res=res0;(res && (nsock < max_fd));res=res->ai_next)
   {
      if ((res->ai_family != 2) && (res->ai_family != 10))
         continue;
      fd_array[nsock] = socket(res->ai_family,res->ai_socktype,
                               res->ai_protocol);
      if (fd_array[nsock] < 0)
         continue;
      setsockopt(fd_array[nsock],1,2,&reuse,sizeof(reuse));
      if ((bind(fd_array[nsock],res->ai_addr,res->ai_addrlen) < 0) ||
          ((sock_type == SOCK_STREAM) && (listen(fd_array[nsock],5) < 0)))
      {
         close(fd_array[nsock]);
         fd_array[nsock] = -1;
         continue;
      }
      nsock++;
   }
   freeaddrinfo(res0);
   return(nsock);
}

variable_types: port int

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

variable_types:
addr
char *

variable_types: nsock int

variable_types: i int

variable_types: reuse int

return_type: int


decompiled_code:
int __fastcall cisco_isl_rewrite(__int64 a1, unsigned int a2)
{
int result; // eax
int v3; // ecx
unsigned __int64 v4; // rax
_BYTE *v5; // rdx
unsigned int v6; // eax

result = memcmp((const void *)a1, &isl_xaddr_0, 6uLL);
if ( !result )
{
v3 = (unsigned __int16)_bswap_16(*(_WORD *)(a1 + 12));
result = v3 + 10;
if ( v3 + 10 <= a2 )
{
*(_BYTE *)(a1 + 4) = 0;
LODWORD(v4) = -1;
if ( v3 - 16 > 0 )
{
v5 = (_BYTE *)(a1 + 26);
v4 = 0xFFFFFFFFLL;
do
v4 = *((unsigned int *)&crc32_array + (unsigned __int8)(*v5++ ^ v4)) ^ (v4 >> 8);
while ( v5 != (_BYTE *)(a1 + (unsigned int)(v3 - 17) + 27) );
}
v6 = ~(_DWORD)v4;
*(_BYTE *)(a1 + a2 - 4) = v6;
*(_BYTE *)(a1 + a2 - 3) = BYTE1(v6);
*(_BYTE *)(a1 + a2 - 2) = BYTE2(v6);
result = HIBYTE(v6);
*(_BYTE *)(a1 + a2 - 1) = result;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1, unsigned int a2)
{
int result; // eax
int v3; // ecx
unsigned __int64 v4; // rax
_BYTE *v5; // rdx
unsigned int v6; // eax

result = memcmp((const void *)a1, &isl_xaddr_0, 6uLL);
if ( !result )
{
v3 = (unsigned __int16)func1(*(_WORD *)(a1 + 12));
result = v3 + 10;
if ( v3 + 10 <= a2 )
{
*(_BYTE *)(a1 + 4) = 0;
LODWORD(v4) = -1;
if ( v3 - 16 > 0 )
{
v5 = (_BYTE *)(a1 + 26);
v4 = 0xFFFFFFFFLL;
do
v4 = *((unsigned int *)&crc32_array + (unsigned __int8)(*v5++ ^ v4)) ^ (v4 >> 8);
while ( v5 != (_BYTE *)(a1 + (unsigned int)(v3 - 17) + 27) );
}
v6 = ~(_DWORD)v4;
*(_BYTE *)(a1 + a2 - 4) = v6;
*(_BYTE *)(a1 + a2 - 3) = BYTE1(v6);
*(_BYTE *)(a1 + a2 - 2) = BYTE2(v6);
result = HIBYTE(v6);
*(_BYTE *)(a1 + a2 - 1) = result;
}
}
return result;
}

original_code:
void cisco_isl_rewrite(m_uint8_t *pkt,m_uint32_t tot_len)
{
   static m_uint8_t isl_xaddr[6] = { 0x01,0x00,0x0c,0x00,0x10,0x00 };
   u_int real_offset,real_len;
   n_eth_hdr_t *hdr;
   m_uint32_t ifcs;
   hdr = (n_eth_hdr_t *)pkt;
   if (!memcmp(&hdr->daddr,isl_xaddr,6)) {
      real_offset = sizeof(n_eth_hdr_t) + (sizeof(n_eth_llc_hdr_t) + sizeof(n_eth_isl_hdr_t));
      real_len = ntohs(hdr->type);
      real_len -= ((sizeof(n_eth_llc_hdr_t) + sizeof(n_eth_isl_hdr_t)) + 4);
      if ((real_offset+real_len) > tot_len)
         return;
      hdr->daddr.eth_addr_byte[4] = 0x00;
      ifcs = crc32_compute(0xFFFFFFFF,pkt+real_offset,real_len);
      pkt[tot_len-4] = ifcs & 0xff;
      pkt[tot_len-3] = (ifcs >> 8) & 0xff;
      pkt[tot_len-2] = (ifcs >> 16) & 0xff;
      pkt[tot_len-1] = ifcs >> 24;
   }
}

canonical_original_code:
void cisco_isl_rewrite(unsigned char *pkt, unsigned int tot_len)
{
   static unsigned char isl_xaddr[6] = { 0x01,0x00,0x0c,0x00,0x10,0x00 };
   unsigned int real_offset; unsigned int real_len;
   struct n_eth_hdr_t *hdr;
   unsigned int ifcs;
   hdr = (struct n_eth_hdr_t *)pkt;
   if (!memcmp(&hdr->daddr,isl_xaddr,6)) {
      real_offset = sizeof(n_eth_hdr_t) + (sizeof(n_eth_llc_hdr_t) + sizeof(n_eth_isl_hdr_t));
      real_len = ntohs(hdr->type);
      real_len -= ((sizeof(n_eth_llc_hdr_t) + sizeof(n_eth_isl_hdr_t)) + 4);
      if ((real_offset+real_len) > tot_len)
         return;
      hdr->daddr.eth_addr_byte[4] = 0x00;
      ifcs = crc32_compute(0xFFFFFFFF,pkt+real_offset,real_len);
      pkt[tot_len-4] = ifcs & 0xff;
      pkt[tot_len-3] = (ifcs >> 8) & 0xff;
      pkt[tot_len-2] = (ifcs >> 16) & 0xff;
      pkt[tot_len-1] = ifcs >> 24;
   }
}

variable_types:
pkt
unsigned char *

variable_types: struct n_eth_hdr_t { struct n_eth_addr_t { unsigned char eth_addr_byte[6]; } daddr; struct n_eth_addr_t saddr; unsigned short type; } *

variable_types:
ifcs
unsigned int

return_type: void

user_defined_types: struct n_eth_hdr_t { struct n_eth_addr_t daddr; struct n_eth_addr_t saddr; unsigned short type; }


decompiled_code:
__int64 __fastcall netio_bridge_release(__int64 a1)
{
return registry_unref(a1, 2LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return registry_unref(a1, 2LL);
}

original_code:
int netio_bridge_release(char *name)
{
   return(registry_unref(name,OBJ_TYPE_NIO_BRIDGE));
}

variable_types:
name
char *


decompiled_code:
__int64 __fastcall netio_bridge_delete(__int64 a1)
{
return registry_delete_if_unused(a1, 2LL, netio_bridge_free, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
return registry_delete_if_unused(a1, 2LL, netio_bridge_free, 0LL);
}

original_code:
int netio_bridge_delete(char *name)
{
   return(registry_delete_if_unused(name,OBJ_TYPE_NIO_BRIDGE,
                                    netio_bridge_free,((void *)0)));
}


decompiled_code:
__int64 netio_bridge_delete_all()
{
return registry_delete_type(2LL, netio_bridge_free, 0LL);
}

canonical_decompiled_code:
__int64 func15()
{
return registry_delete_type(2LL, netio_bridge_free, 0LL);
}

original_code:
int netio_bridge_delete_all(void)
{
   return(registry_delete_type(OBJ_TYPE_NIO_BRIDGE,netio_bridge_free,((void *)0)));
}

canonical_original_code:
int netio_bridge_delete_all()
{
   return(registry_delete_type(OBJ_TYPE_NIO_BRIDGE,netio_bridge_free,((void *)0)));
}


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

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

original_code:
static inline m_uint32_t m_ntoh32(m_uint8_t *ptr)
{
   m_uint32_t val = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
   return(val);
}

canonical_original_code:
static inline unsigned int m_ntoh32(unsigned char *ptr)
{
   unsigned int val = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | ptr[3];
   return(val);
}

variable_types:
ptr
unsigned char *

variable_types:
val
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall atm_bridge_release(__int64 a1)
{
return registry_unref(a1, 5LL);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return registry_unref(a1, 5LL);
}

original_code:
int atm_bridge_release(char *name)
{
   return(registry_unref(name,OBJ_TYPE_ATM_BRIDGE));
}


decompiled_code:
__int64 __fastcall atm_bridge_delete(__int64 a1)
{
return registry_delete_if_unused(a1, 5LL, atm_bridge_free, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return registry_delete_if_unused(a1, 5LL, atm_bridge_free, 0LL);
}

original_code:
int atm_bridge_delete(char *name)
{
   return(registry_delete_if_unused(name,OBJ_TYPE_ATM_BRIDGE,
                                    atm_bridge_free,((void *)0)));
}


decompiled_code:
__int64 atm_bridge_delete_all()
{
return registry_delete_type(5LL, atm_bridge_free, 0LL);
}

canonical_decompiled_code:
__int64 func11()
{
return registry_delete_type(5LL, atm_bridge_free, 0LL);
}

original_code:
int atm_bridge_delete_all(void)
{
   return(registry_delete_type(OBJ_TYPE_ATM_BRIDGE,atm_bridge_free,((void *)0)));
}

canonical_original_code:
int atm_bridge_delete_all()
{
   return(registry_delete_type(OBJ_TYPE_ATM_BRIDGE,atm_bridge_free,((void *)0)));
}


original_code:
static inline void timer_remove_from_queue(timer_queue_t *queue,
                                           timer_entry_t *timer)
{
   if (timer->prev)
      timer->prev->next = timer->next;
   else
      queue->list = timer->next;
   if (timer->next)
      timer->next->prev = timer->prev;
   timer->next = timer->prev = ((void *)0);
   queue->timer_count--;
   queue->level -= timer->level;
}

canonical_original_code:
static inline void timer_remove_from_queue(struct timer_queue *queue, struct timer_entry *timer)
{
   if (timer->prev)
      timer->prev->next = timer->next;
   else
      queue->list = timer->next;
   if (timer->next)
      timer->next->prev = timer->prev;
   timer->next = timer->prev = ((void *)0);
   queue->timer_count--;
   queue->level -= timer->level;
}

variable_types: struct timer_queue { struct timer_entry { long interval; unsigned long long expire; int (*callback)(void *, struct timer_entry *); void *user_arg; int flags; unsigned long long id; int level; struct timer_queue *queue; struct timer_entry *prev; } *list; 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; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } schedule; unsigned long thread; int running; int timer_count; int level; struct timer_queue *next; } *

variable_types:
timer
struct timer_entry *

user_defined_types: struct timer_queue { struct timer_entry *list; union pthread_mutex_t lock; union pthread_cond_t schedule; unsigned long thread; int running; int timer_count; int level; struct timer_queue *next; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long 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; }


original_code:
static inline int timer_exec(timer_entry_t *timer)
{
   return(timer->callback(timer->user_arg,timer));
}

canonical_original_code:
static inline int timer_exec(struct timer_entry *timer)
{
   return(timer->callback(timer->user_arg,timer));
}

variable_types: struct timer_entry { long interval; unsigned long long expire; int (*callback)(void *, struct timer_entry *); void *user_arg; int flags; unsigned long long id; int level; struct timer_queue { struct timer_entry *list; 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; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } schedule; unsigned long thread; int running; int timer_count; int level; struct timer_queue *next; } *queue; struct timer_entry *prev; } *

user_defined_types: struct timer_entry { long interval; unsigned long long expire; int (*callback)(void *, struct timer_entry *); void *user_arg; int flags; unsigned long long id; int level; struct timer_queue *queue; struct timer_entry *prev; }


decompiled_code:
int __fastcall timer_remove_from_queue_atomic(__int64 a1, __int64 a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
timer_remove_from_queue(a1, a2);
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
pthread_mutex_lock((pthread_mutex_t *)(a1 + 8));
func1(a1, a2);
return pthread_mutex_unlock((pthread_mutex_t *)(a1 + 8));
}

original_code:
static inline void
timer_remove_from_queue_atomic(timer_queue_t *queue,timer_entry_t *timer)
{
   pthread_mutex_lock(&(queue)->lock);
   timer_remove_from_queue(queue,timer);
   pthread_mutex_unlock(&(queue)->lock);
}

canonical_original_code:
static inline void timer_remove_from_queue_atomic(struct timer_queue *queue, struct timer_entry *timer)
{
   pthread_mutex_lock(&(queue)->lock);
   timer_remove_from_queue(queue,timer);
   pthread_mutex_unlock(&(queue)->lock);
}

user_defined_types: struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; }

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


decompiled_code:
__int64 __fastcall timer_find_by_id(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
return hash_table_lookup(timer_id_hash, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
return hash_table_lookup(timer_id_hash, &v2);
}

original_code:
static inline timer_entry_t *timer_find_by_id(timer_id id)
{
   return(hash_table_lookup(timer_id_hash,&id));
}

canonical_original_code:
static inline struct timer_entry *timer_find_by_id(unsigned long long id)
{
   return(hash_table_lookup(timer_id_hash,&id));
}

variable_types:
id
unsigned long long

return_type: struct timer_entry { long interval; unsigned long long expire; int (*callback)(void *, struct timer_entry *); void *user_arg; int flags; unsigned long long id; int level; struct timer_queue { struct timer_entry *list; 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; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } schedule; unsigned long thread; int running; int timer_count; int level; struct timer_queue *next; } *queue; struct timer_entry *prev; } *


decompiled_code:
__int64 timer_alloc_id()
{
while ( hash_table_lookup(timer_id_hash, &timer_next_id) )
++timer_next_id;
return timer_next_id;
}

canonical_decompiled_code:
__int64 func5()
{
while ( hash_table_lookup(timer_id_hash, &timer_next_id) )
++timer_next_id;
return timer_next_id;
}

original_code:
static inline timer_id timer_alloc_id(void)
{
   while(hash_table_lookup(timer_id_hash,&timer_next_id))
      timer_next_id++;
   return(timer_next_id);
}

canonical_original_code:
static inline unsigned long long timer_alloc_id()
{
   while(hash_table_lookup(timer_id_hash,&timer_next_id))
      timer_next_id++;
   return(timer_next_id);
}

return_type: unsigned long long


decompiled_code:
__int64 __fastcall timer_free_id(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
return hash_table_remove(timer_id_hash, &v2);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = a1;
return hash_table_remove(timer_id_hash, &v2);
}

original_code:
static inline void timer_free_id(timer_id id)
{
   hash_table_remove(timer_id_hash,&id);
}

canonical_original_code:
static inline void timer_free_id(unsigned long long id)
{
   hash_table_remove(timer_id_hash,&id);
}


decompiled_code:
unsigned __int64 m_gettime()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 0x3E8uLL;
}

canonical_decompiled_code:
unsigned __int64 func8()
{
struct timeval v1; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v1, 0LL);
return 1000 * v1.tv_sec + v1.tv_usec / 0x3E8uLL;
}

original_code:
static inline m_tmcnt_t m_gettime(void)
{
   struct timeval tvp;
   gettimeofday(&tvp,((void *)0));
   return(((m_tmcnt_t)tvp.tv_sec * 1000) + ((m_tmcnt_t)tvp.tv_usec / 1000));
}

canonical_original_code:
static inline unsigned long long m_gettime()
{
   struct timeval tvp;
   gettimeofday(&tvp,((void *)0));
   return(((unsigned long long)tvp.tv_sec * 1000) + ((unsigned long long)tvp.tv_usec / 1000));
}

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


decompiled_code:
unsigned __int64 m_gettime_adj()
{
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF
struct timeval tv; // [rsp+50h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
timer = tv.tv_sec;
localtime_r(&timer, &tp);
return 1000 * (tv.tv_sec + tp.tm_gmtoff) + tv.tv_usec / 0x3E8uLL;
}

canonical_decompiled_code:
unsigned __int64 func9()
{
time_t timer; // [rsp+8h] [rbp-60h] BYREF
struct tm tp; // [rsp+10h] [rbp-58h] BYREF
struct timeval tv; // [rsp+50h] [rbp-18h] BYREF

gettimeofday(&tv, 0LL);
timer = tv.tv_sec;
localtime_r(&timer, &tp);
return 1000 * (tv.tv_sec + tp.tm_gmtoff) + tv.tv_usec / 0x3E8uLL;
}

original_code:
static inline m_tmcnt_t m_gettime_adj(void)
{
   struct timeval tvp;
   struct tm tmx;
   time_t gmt_adjust;
   time_t ct;
   gettimeofday(&tvp,((void *)0));
   ct = tvp.tv_sec;
   localtime_r(&ct,&tmx);
   gmt_adjust = tmx.tm_gmtoff;
   tvp.tv_sec += gmt_adjust;
   return(((m_tmcnt_t)tvp.tv_sec * 1000) + ((m_tmcnt_t)tvp.tv_usec / 1000));
}

canonical_original_code:
static inline unsigned long long m_gettime_adj()
{
   struct timeval tvp;
   struct tm tmx;
   long gmt_adjust;
   long ct;
   gettimeofday(&tvp,((void *)0));
   ct = tvp.tv_sec;
   localtime_r(&ct,&tmx);
   gmt_adjust = tmx.tm_gmtoff;
   tvp.tv_sec += gmt_adjust;
   return(((unsigned long long)tvp.tv_sec * 1000) + ((unsigned long long)tvp.tv_usec / 1000));
}

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

variable_types: ct long

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


decompiled_code:
void __fastcall __noreturn timer_loop(void *a1)
{
unsigned __int64 v1; // rcx
unsigned __int64 v2; // rax
__int64 v3; // r13
struct timespec v4; // [rsp+0h] [rbp-38h] BYREF

pthread_setcanceltype(1, 0LL);
pthread_setcancelstate(0, 0LL);
m_signal_block(2LL);
m_signal_block(3LL);
m_signal_block(15LL);
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 8));
if ( *(_QWORD *)a1 )
{
v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v4.tv_sec = v1 / 0x3E8;
v4.tv_nsec = 1000000 * (v1 % 0x3E8);
pthread_cond_timedwait((pthread_cond_t *)a1 + 1, (pthread_mutex_t *)((char *)a1 + 8), &v4);
}
else
{
pthread_cond_wait((pthread_cond_t *)a1 + 1, (pthread_mutex_t *)((char *)a1 + 8));
}
if ( !*((_DWORD *)a1 + 26) )
break;
v2 = m_gettime();
v3 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 && *(_QWORD *)(v3 + 8) <= v2 )
{
timer_remove_from_queue((__int64)a1, *(_QWORD *)a1);
*(_DWORD *)(v3 + 40) |= 2u;
if ( (unsigned int)timer_exec(v3) )
timer_schedule_in_queue((__int64)a1, v3);
}
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 8));
}
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 8));
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func11(void *a1)
{
unsigned __int64 v1; // rcx
unsigned __int64 v2; // rax
__int64 v3; // r13
struct timespec v4; // [rsp+0h] [rbp-38h] BYREF

pthread_setcanceltype(1, 0LL);
pthread_setcancelstate(0, 0LL);
m_signal_block(2LL);
m_signal_block(3LL);
m_signal_block(15LL);
while ( 1 )
{
pthread_mutex_lock((pthread_mutex_t *)((char *)a1 + 8));
if ( *(_QWORD *)a1 )
{
v1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
v4.tv_sec = v1 / 0x3E8;
v4.tv_nsec = 1000000 * (v1 % 0x3E8);
pthread_cond_timedwait((pthread_cond_t *)a1 + 1, (pthread_mutex_t *)((char *)a1 + 8), &v4);
}
else
{
pthread_cond_wait((pthread_cond_t *)a1 + 1, (pthread_mutex_t *)((char *)a1 + 8));
}
if ( !*((_DWORD *)a1 + 26) )
break;
v2 = func8();
v3 = *(_QWORD *)a1;
if ( *(_QWORD *)a1 && *(_QWORD *)(v3 + 8) <= v2 )
{
func1((__int64)a1, *(_QWORD *)a1);
*(_DWORD *)(v3 + 40) |= 2u;
if ( (unsigned int)func2(v3) )
func10((__int64)a1, v3);
}
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 8));
}
pthread_mutex_unlock((pthread_mutex_t *)((char *)a1 + 8));
pthread_exit(0LL);
}

original_code:
static void *timer_loop(timer_queue_t *queue)
{
   struct timespec t_spc;
   timer_entry_t *timer;
   m_tmcnt_t c_time;
   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,((void *)0));
   pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,((void *)0));
   m_signal_block(2);
   m_signal_block(3);
   m_signal_block(15);
   for(;;)
   {
      pthread_mutex_lock(&(queue)->lock);
      timer = queue->list;
      if (timer) {
         t_spc.tv_sec = timer->expire / 1000;
         t_spc.tv_nsec = (timer->expire % 1000) * 1000000;
         pthread_cond_timedwait(&queue->schedule,&queue->lock,&t_spc);
      }
      else {
         pthread_cond_wait(&queue->schedule,&queue->lock);
      }
      if (!queue->running) {
         pthread_mutex_unlock(&(queue)->lock);
         break;
      }
      c_time = m_gettime();
      timer = queue->list;
      if ((timer == ((void *)0)) || (timer->expire > c_time)) {
         pthread_mutex_unlock(&(queue)->lock);
         continue;
      }
      timer_remove_from_queue(queue,timer);
      timer->flags |= 2;
      if (timer_exec(timer))
         timer_schedule_in_queue(queue,timer);
      pthread_mutex_unlock(&(queue)->lock);
   }
   pthread_exit(((void *)0));
   return ((void *)0);
}

canonical_original_code:
static void *timer_loop(struct timer_queue *queue)
{
   struct timespec t_spc;
   struct timer_entry *timer;
   unsigned long long c_time;
   pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,((void *)0));
   pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,((void *)0));
   m_signal_block(2);
   m_signal_block(3);
   m_signal_block(15);
   for(;;)
   {
      pthread_mutex_lock(&(queue)->lock);
      timer = queue->list;
      if (timer) {
         t_spc.tv_sec = timer->expire / 1000;
         t_spc.tv_nsec = (timer->expire % 1000) * 1000000;
         pthread_cond_timedwait(&queue->schedule,&queue->lock,&t_spc);
      }
      else {
         pthread_cond_wait(&queue->schedule,&queue->lock);
      }
      if (!queue->running) {
         pthread_mutex_unlock(&(queue)->lock);
         break;
      }
      c_time = m_gettime();
      timer = queue->list;
      if ((timer == ((void *)0)) || (timer->expire > c_time)) {
         pthread_mutex_unlock(&(queue)->lock);
         continue;
      }
      timer_remove_from_queue(queue,timer);
      timer->flags |= 2;
      if (timer_exec(timer))
         timer_schedule_in_queue(queue,timer);
      pthread_mutex_unlock(&(queue)->lock);
   }
   pthread_exit(((void *)0));
   return ((void *)0);
}

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

return_type: void *


decompiled_code:
void *timer_select_queue_from_pool()
{
void *v0; // rsi
int v1; // ecx
__int64 i; // rax

v0 = timer_queue_pool;
v1 = *((_DWORD *)timer_queue_pool + 28);
for ( i = *((_QWORD *)timer_queue_pool + 15); i; i = *(_QWORD *)(i + 120) )
{
if ( *(_DWORD *)(i + 112) < v1 )
{
v1 = *(_DWORD *)(i + 112);
v0 = (void *)i;
}
}
return v0;
}

canonical_decompiled_code:
void *func12()
{
void *v0; // rsi
int v1; // ecx
__int64 i; // rax

v0 = timer_queue_pool;
v1 = *((_DWORD *)timer_queue_pool + 28);
for ( i = *((_QWORD *)timer_queue_pool + 15); i; i = *(_QWORD *)(i + 120) )
{
if ( *(_DWORD *)(i + 112) < v1 )
{
v1 = *(_DWORD *)(i + 112);
v0 = (void *)i;
}
}
return v0;
}

original_code:
timer_queue_t *timer_select_queue_from_pool(void)
{
   timer_queue_t *s_queue,*queue;
   int level;
   s_queue = timer_queue_pool;
   level = s_queue->level;
   for(queue=timer_queue_pool->next;queue;queue=queue->next) {
      if (queue->level < level) {
         level = queue->level;
         s_queue = queue;
      }
   }
   return s_queue;
}

canonical_original_code:
struct timer_queue *timer_select_queue_from_pool()
{
   struct timer_queue *s_queue; struct timer_queue *queue;
   int level;
   s_queue = timer_queue_pool;
   level = s_queue->level;
   for(queue=timer_queue_pool->next;queue;queue=queue->next) {
      if (queue->level < level) {
         level = queue->level;
         s_queue = queue;
      }
   }
   return s_queue;
}

variable_types: level int

return_type: struct timer_queue { struct timer_entry { long interval; unsigned long long expire; int (*callback)(void *, struct timer_entry *); void *user_arg; int flags; unsigned long long id; int level; struct timer_queue *queue; struct timer_entry *prev; } *list; 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; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } schedule; unsigned long thread; int running; int timer_count; int level; struct timer_queue *next; } *


decompiled_code:
__int64 __fastcall timer_schedule(__int64 a1)
{
char *v1; // rax
__int64 v2; // rbx
pthread_mutex_t *v3; // r12
__int64 result; // rax

v1 = (char *)timer_select_queue_from_pool();
if ( v1 )
{
v2 = (__int64)v1;
v3 = (pthread_mutex_t *)(v1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(v1 + 8));
timer_schedule_in_queue(v2, a1);
pthread_mutex_unlock(v3);
result = 0LL;
}
else
{
fprintf(stderr, "timer_schedule: no pool available for timer with ID %llu", *(_QWORD *)(a1 + 48));
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
char *v1; // rax
__int64 v2; // rbx
pthread_mutex_t *v3; // r12
__int64 result; // rax

v1 = (char *)func12();
if ( v1 )
{
v2 = (__int64)v1;
v3 = (pthread_mutex_t *)(v1 + 8);
pthread_mutex_lock((pthread_mutex_t *)(v1 + 8));
func10(v2, a1);
pthread_mutex_unlock(v3);
result = 0LL;
}
else
{
fprintf(stderr, "timer_schedule: no pool available for timer with ID %llu", *(_QWORD *)(a1 + 48));
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
static int timer_schedule(timer_entry_t *timer)
{
   timer_queue_t *queue;
   if (!(queue = timer_select_queue_from_pool())) {
      fprintf(stderr,
              "timer_schedule: no pool available for timer with ID %llu",
              timer->id);
      return(-1);
   }
   pthread_mutex_lock(&(queue)->lock);
   timer_schedule_in_queue(queue,timer);
   pthread_mutex_unlock(&(queue)->lock);
   return(0);
}

canonical_original_code:
static int timer_schedule(struct timer_entry *timer)
{
   struct timer_queue *queue;
   if (!(queue = timer_select_queue_from_pool())) {
      fprintf(stderr,
              "timer_schedule: no pool available for timer with ID %llu",
              timer->id);
      return(-1);
   }
   pthread_mutex_lock(&(queue)->lock);
   timer_schedule_in_queue(queue,timer);
   pthread_mutex_unlock(&(queue)->lock);
   return(0);
}


decompiled_code:
__int64 __fastcall timer_enable(void *ptr)
{
__int64 result; // rax

pthread_mutex_lock(&timer_mutex);
*((_QWORD *)ptr + 6) = timer_alloc_id();
if ( (unsigned int)hash_table_insert(timer_id_hash, (char *)ptr + 48, ptr) == -1 )
{
pthread_mutex_unlock(&timer_mutex);
free(ptr);
result = 0LL;
}
else if ( (unsigned int)timer_schedule((__int64)ptr) == -1 )
{
timer_free(ptr, 0);
pthread_mutex_unlock(&timer_mutex);
result = 0LL;
}
else
{
pthread_mutex_unlock(&timer_mutex);
pthread_cond_signal((pthread_cond_t *)(*((_QWORD *)ptr + 8) + 48LL));
result = *((_QWORD *)ptr + 6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(void *ptr)
{
__int64 result; // rax

pthread_mutex_lock(&timer_mutex);
*((_QWORD *)ptr + 6) = func5();
if ( (unsigned int)hash_table_insert(timer_id_hash, (char *)ptr + 48, ptr) == -1 )
{
pthread_mutex_unlock(&timer_mutex);
free(ptr);
result = 0LL;
}
else if ( (unsigned int)func13((__int64)ptr) == -1 )
{
func7(ptr, 0);
pthread_mutex_unlock(&timer_mutex);
result = 0LL;
}
else
{
pthread_mutex_unlock(&timer_mutex);
pthread_cond_signal((pthread_cond_t *)(*((_QWORD *)ptr + 8) + 48LL));
result = *((_QWORD *)ptr + 6);
}
return result;
}

original_code:
static timer_id timer_enable(timer_entry_t *timer)
{
   pthread_mutex_lock(&timer_mutex);
   timer->id = timer_alloc_id();
   if (hash_table_insert(timer_id_hash,&timer->id,timer) == -1) {
      pthread_mutex_unlock(&timer_mutex);
      free(timer);
      return(0);
   }
   if (timer_schedule(timer) == -1) {
      timer_free(timer,0);
      timer = ((void *)0);
      pthread_mutex_unlock(&timer_mutex);
      return(0);
   }
   pthread_mutex_unlock(&timer_mutex);
   pthread_cond_signal(&timer->queue->schedule);
   return(timer->id);
}

canonical_original_code:
static unsigned long long timer_enable(struct timer_entry *timer)
{
   pthread_mutex_lock(&timer_mutex);
   timer->id = timer_alloc_id();
   if (hash_table_insert(timer_id_hash,&timer->id,timer) == -1) {
      pthread_mutex_unlock(&timer_mutex);
      free(timer);
      return(0);
   }
   if (timer_schedule(timer) == -1) {
      timer_free(timer,0);
      timer = ((void *)0);
      pthread_mutex_unlock(&timer_mutex);
      return(0);
   }
   pthread_mutex_unlock(&timer_mutex);
   pthread_cond_signal(&timer->queue->schedule);
   return(timer->id);
}


decompiled_code:
__int64 __fastcall timer_remove(__int64 a1)
{
__int64 v1; // rax
void *v2; // rbx
pthread_cond_t *v3; // r12
__int64 result; // rax

pthread_mutex_lock(&timer_mutex);
v1 = timer_find_by_id(a1);
if ( v1 )
{
v2 = (void *)v1;
v3 = *(pthread_cond_t **)(v1 + 64);
if ( v3 )
{
timer_remove_from_queue_atomic(*(_QWORD *)(v1 + 64), v1);
timer_free_id(a1);
free(v2);
pthread_mutex_unlock(&timer_mutex);
pthread_cond_signal(v3 + 1);
}
else
{
timer_free_id(a1);
free(v2);
pthread_mutex_unlock(&timer_mutex);
}
result = 0LL;
}
else
{
pthread_mutex_unlock(&timer_mutex);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 v1; // rax
void *v2; // rbx
pthread_cond_t *v3; // r12
__int64 result; // rax

pthread_mutex_lock(&timer_mutex);
v1 = func4(a1);
if ( v1 )
{
v2 = (void *)v1;
v3 = *(pthread_cond_t **)(v1 + 64);
if ( v3 )
{
func3(*(_QWORD *)(v1 + 64), v1);
func6(a1);
free(v2);
pthread_mutex_unlock(&timer_mutex);
pthread_cond_signal(v3 + 1);
}
else
{
func6(a1);
free(v2);
pthread_mutex_unlock(&timer_mutex);
}
result = 0LL;
}
else
{
pthread_mutex_unlock(&timer_mutex);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int timer_remove(timer_id id)
{
   timer_queue_t *queue = ((void *)0);
   timer_entry_t *timer;
   pthread_mutex_lock(&timer_mutex);
   if (!(timer = timer_find_by_id(id))) {
      pthread_mutex_unlock(&timer_mutex);
      return(-1);
   }
   if (timer->queue) {
      queue = timer->queue;
      timer_remove_from_queue_atomic(queue,timer);
   }
   timer_free_id(id);
   free(timer);
   pthread_mutex_unlock(&timer_mutex);
   if (queue)
      pthread_cond_signal(&queue->schedule);
   return(0);
}

canonical_original_code:
int timer_remove(unsigned long long id)
{
   struct timer_queue *queue = ((void *)0);
   struct timer_entry *timer;
   pthread_mutex_lock(&timer_mutex);
   if (!(timer = timer_find_by_id(id))) {
      pthread_mutex_unlock(&timer_mutex);
      return(-1);
   }
   if (timer->queue) {
      queue = timer->queue;
      timer_remove_from_queue_atomic(queue,timer);
   }
   timer_free_id(id);
   free(timer);
   pthread_mutex_unlock(&timer_mutex);
   if (queue)
      pthread_cond_signal(&queue->schedule);
   return(0);
}


decompiled_code:
__int64 __fastcall timer_create_entry(__int64 a1, int a2, int a3, __int64 a4, __int64 a5)
{
_QWORD *v8; // rax
void *v9; // rbx

v8 = malloc(0x58uLL);
if ( !v8 )
return 0LL;
v9 = v8;
*v8 = a1;
v8[2] = 0LL;
v8[3] = a4;
v8[4] = a5;
*((_DWORD *)v8 + 10) = 0;
*((_DWORD *)v8 + 14) = a3;
if ( a2 )
*((_DWORD *)v8 + 10) = 4;
else
v8[1] = m_gettime();
return timer_enable(v9);
}

original_code:
timer_id timer_create_entry(m_tmcnt_t interval,int boundary,int level,
                            timer_proc callback,void *user_arg)
{
   timer_entry_t *timer;
   if (!(timer = malloc(sizeof(*timer))))
      return(0);
   timer->interval = interval;
   timer->offset = 0;
   timer->callback = callback;
   timer->user_arg = user_arg;
   timer->flags = 0;
   timer->level = level;
   if (boundary) {
      timer->flags |= 4;
   } else
      timer->expire = m_gettime();
   return(timer_enable(timer));
}

canonical_original_code:
unsigned long long timer_create_entry(unsigned long long interval, int boundary, int level, int (*callback)(void *, struct timer_entry *), void *user_arg)
{
   struct timer_entry *timer;
   if (!(timer = malloc(sizeof(*timer))))
      return(0);
   timer->interval = interval;
   timer->offset = 0;
   timer->callback = callback;
   timer->user_arg = user_arg;
   timer->flags = 0;
   timer->level = level;
   if (boundary) {
      timer->flags |= 4;
   } else
      timer->expire = m_gettime();
   return(timer_enable(timer));
}

variable_types:
interval
unsigned long long

variable_types: boundary int

variable_types: int (*)(void *, struct timer_entry { long interval; unsigned long long expire; int (*callback)(void *, struct timer_entry *); void *user_arg; int flags; unsigned long long id; int level; struct timer_queue { struct timer_entry *list; 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; } lock; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } schedule; unsigned long thread; int running; int timer_count; int level; struct timer_queue *next; } *queue; struct timer_entry *prev; } *)


decompiled_code:
__int64 __fastcall timer_create_with_offset(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5)
{
_QWORD *v8; // rax

v8 = malloc(0x58uLL);
if ( !v8 )
return 0LL;
*v8 = a1;
v8[2] = 0LL;
v8[3] = a4;
v8[4] = a5;
*((_DWORD *)v8 + 14) = a3;
*((_DWORD *)v8 + 10) = 4;
return timer_enable(v8);
}

original_code:
timer_id timer_create_with_offset(m_tmcnt_t interval,m_tmcnt_t offset,
                                  int level,timer_proc callback,void *user_arg)
{
   timer_entry_t *timer;
   if (!(timer = malloc(sizeof(*timer))))
      return(0);
   timer->interval = interval;
   timer->offset = 0;
   timer->callback = callback;
   timer->user_arg = user_arg;
   timer->flags = 0;
   timer->level = level;
   timer->flags |= 4;
   return(timer_enable(timer));
}

canonical_original_code:
unsigned long long timer_create_with_offset(unsigned long long interval, unsigned long long offset, int level, int (*callback)(void *, struct timer_entry *), void *user_arg)
{
   struct timer_entry *timer;
   if (!(timer = malloc(sizeof(*timer))))
      return(0);
   timer->interval = interval;
   timer->offset = 0;
   timer->callback = callback;
   timer->user_arg = user_arg;
   timer->flags = 0;
   timer->level = level;
   timer->flags |= 4;
   return(timer_enable(timer));
}

variable_types:
offset
unsigned long long


decompiled_code:
__int64 __fastcall timer_set_interval(__int64 a1, __int64 a2)
{
__int64 v2; // rax
_QWORD *v3; // rbx
__int64 v4; // r12
__int64 result; // rax

pthread_mutex_lock(&timer_mutex);
v2 = timer_find_by_id(a1);
if ( v2 )
{
v3 = (_QWORD *)v2;
v4 = *(_QWORD *)(v2 + 64);
pthread_mutex_lock((pthread_mutex_t *)(v4 + 8));
*v3 = a2;
v3[1] = m_gettime() + a2;
timer_remove_from_queue(v4, (__int64)v3);
timer_schedule_in_queue(v4, (__int64)v3);
pthread_mutex_unlock((pthread_mutex_t *)(v4 + 8));
pthread_mutex_unlock(&timer_mutex);
pthread_cond_signal((pthread_cond_t *)(v4 + 48));
result = 0LL;
}
else
{
pthread_mutex_unlock(&timer_mutex);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 a1, __int64 a2)
{
__int64 v2; // rax
_QWORD *v3; // rbx
__int64 v4; // r12
__int64 result; // rax

pthread_mutex_lock(&timer_mutex);
v2 = func4(a1);
if ( v2 )
{
v3 = (_QWORD *)v2;
v4 = *(_QWORD *)(v2 + 64);
pthread_mutex_lock((pthread_mutex_t *)(v4 + 8));
*v3 = a2;
v3[1] = func8() + a2;
func1(v4, (__int64)v3);
func10(v4, (__int64)v3);
pthread_mutex_unlock((pthread_mutex_t *)(v4 + 8));
pthread_mutex_unlock(&timer_mutex);
pthread_cond_signal((pthread_cond_t *)(v4 + 48));
result = 0LL;
}
else
{
pthread_mutex_unlock(&timer_mutex);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int timer_set_interval(timer_id id,long interval)
{
   timer_queue_t *queue;
   timer_entry_t *timer;
   pthread_mutex_lock(&timer_mutex);
   if (!(timer = timer_find_by_id(id))) {
      pthread_mutex_unlock(&timer_mutex);
      return(-1);
   }
   queue = timer->queue;
   pthread_mutex_lock(&(queue)->lock);
   timer->interval = interval;
   timer->expire = m_gettime() + (m_tmcnt_t)interval;
   timer_remove_from_queue(queue,timer);
   timer_schedule_in_queue(queue,timer);
   pthread_mutex_unlock(&(queue)->lock);
   pthread_mutex_unlock(&timer_mutex);
   pthread_cond_signal(&queue->schedule);
   return(0);
}

canonical_original_code:
int timer_set_interval(unsigned long long id, long interval)
{
   struct timer_queue *queue;
   struct timer_entry *timer;
   pthread_mutex_lock(&timer_mutex);
   if (!(timer = timer_find_by_id(id))) {
      pthread_mutex_unlock(&timer_mutex);
      return(-1);
   }
   queue = timer->queue;
   pthread_mutex_lock(&(queue)->lock);
   timer->interval = interval;
   timer->expire = m_gettime() + (unsigned long long)interval;
   timer_remove_from_queue(queue,timer);
   timer_schedule_in_queue(queue,timer);
   pthread_mutex_unlock(&(queue)->lock);
   pthread_mutex_unlock(&timer_mutex);
   pthread_cond_signal(&queue->schedule);
   return(0);
}

variable_types: interval long


decompiled_code:
pthread_cond_t *timer_create_queue()
{
char *v0; // rax
pthread_cond_t *v1; // rbx

v0 = (char *)malloc(0x80uLL);
v1 = (pthread_cond_t *)v0;
if ( v0 )
{
*((_DWORD *)v0 + 26) = 1;
*(_QWORD *)v0 = 0LL;
*((_DWORD *)v0 + 28) = 0;
if ( pthread_mutex_init((pthread_mutex_t *)(v0 + 8), 0LL)
|| pthread_cond_init(v1 + 1, 0LL)
|| pthread_create((pthread_t *)&v1[2], 0LL, (void *(*)(void *))timer_loop, v1) )
{
free(v1);
v1 = 0LL;
}
}
return v1;
}

canonical_decompiled_code:
pthread_cond_t *func19()
{
char *v0; // rax
pthread_cond_t *v1; // rbx

v0 = (char *)malloc(0x80uLL);
v1 = (pthread_cond_t *)v0;
if ( v0 )
{
*((_DWORD *)v0 + 26) = 1;
*(_QWORD *)v0 = 0LL;
*((_DWORD *)v0 + 28) = 0;
if ( pthread_mutex_init((pthread_mutex_t *)(v0 + 8), 0LL)
|| pthread_cond_init(v1 + 1, 0LL)
|| pthread_create((pthread_t *)&v1[2], 0LL, (void *(*)(void *))timer_loop, v1) )
{
free(v1);
v1 = 0LL;
}
}
return v1;
}

original_code:
timer_queue_t *timer_create_queue(void)
{
   timer_queue_t *queue;
   if (!(queue = malloc(sizeof(*queue))))
      return ((void *)0);
   queue->running = 1;
   queue->list = ((void *)0);
   queue->level = 0;
   if (pthread_mutex_init(&queue->lock,((void *)0)))
      goto error;
   if (pthread_cond_init(&queue->schedule,((void *)0)))
      goto error;
   if (pthread_create(&queue->thread,((void *)0),(void *(*)(void *))timer_loop,queue))
      goto error;
   return queue;
 error:
   free(queue);
   return ((void *)0);
}

canonical_original_code:
struct timer_queue *timer_create_queue()
{
   struct timer_queue *queue;
   if (!(queue = malloc(sizeof(*queue))))
      return ((void *)0);
   queue->running = 1;
   queue->list = ((void *)0);
   queue->level = 0;
   if (pthread_mutex_init(&queue->lock,((void *)0)))
      goto error;
   if (pthread_cond_init(&queue->schedule,((void *)0)))
      goto error;
   if (pthread_create(&queue->thread,((void *)0),(void *(*)(void *))timer_loop,queue))
      goto error;
   return queue;
 error:
   free(queue);
   return ((void *)0);
}


decompiled_code:
int timer_flush_queues()
{
char *v0; // r13
pthread_mutex_t *v1; // r14
pthread_cond_t *v2; // r12
pthread_t v3; // r15
__int64 *v4; // rbx
__int64 *v5; // rbp

pthread_mutex_lock(&timer_mutex);
v0 = (char *)timer_queue_pool;
if ( timer_queue_pool )
{
do
{
v1 = (pthread_mutex_t *)(v0 + 8);
pthread_mutex_lock((pthread_mutex_t *)(v0 + 8));
v2 = (pthread_cond_t *)v0;
v0 = (char *)*((_QWORD *)v0 + 15);
v3 = v2[2].__align;
*((_DWORD *)&v2[2].__align + 2) = 0;
v4 = (__int64 *)v2->__align;
if ( v2->__align )
{
do
{
v5 = v4;
v4 = (__int64 *)v4[10];
timer_free_id(v5[6]);
free(v5);
}
while ( v4 );
}
pthread_mutex_unlock(v1);
pthread_cond_signal(v2 + 1);
pthread_join(v3, 0LL);
pthread_cond_destroy(v2 + 1);
pthread_mutex_destroy(v1);
free(v2);
}
while ( v0 );
}
return pthread_mutex_unlock(&timer_mutex);
}

canonical_decompiled_code:
int func20()
{
char *v0; // r13
pthread_mutex_t *v1; // r14
pthread_cond_t *v2; // r12
pthread_t v3; // r15
__int64 *v4; // rbx
__int64 *v5; // rbp

pthread_mutex_lock(&timer_mutex);
v0 = (char *)timer_queue_pool;
if ( timer_queue_pool )
{
do
{
v1 = (pthread_mutex_t *)(v0 + 8);
pthread_mutex_lock((pthread_mutex_t *)(v0 + 8));
v2 = (pthread_cond_t *)v0;
v0 = (char *)*((_QWORD *)v0 + 15);
v3 = v2[2].__align;
*((_DWORD *)&v2[2].__align + 2) = 0;
v4 = (__int64 *)v2->__align;
if ( v2->__align )
{
do
{
v5 = v4;
v4 = (__int64 *)v4[10];
func6(v5[6]);
free(v5);
}
while ( v4 );
}
pthread_mutex_unlock(v1);
pthread_cond_signal(v2 + 1);
pthread_join(v3, 0LL);
pthread_cond_destroy(v2 + 1);
pthread_mutex_destroy(v1);
free(v2);
}
while ( v0 );
}
return pthread_mutex_unlock(&timer_mutex);
}

original_code:
void timer_flush_queues(void)
{
   timer_entry_t *timer,*next_timer;
   timer_queue_t *queue,*next_queue;
   pthread_t thread;
   pthread_mutex_lock(&timer_mutex);
   for(queue=timer_queue_pool;queue;queue=next_queue)
   {
      pthread_mutex_lock(&(queue)->lock);
      next_queue = queue->next;
      thread = queue->thread;
      queue->running = 0;
      for(timer=queue->list;timer;timer=next_timer) {
         next_timer = timer->next;
         timer_free_id(timer->id);
         free(timer);
      }
      pthread_mutex_unlock(&(queue)->lock);
      pthread_cond_signal(&queue->schedule);
      pthread_join(thread,((void *)0));
      pthread_cond_destroy(&queue->schedule);
      pthread_mutex_destroy(&queue->lock);
      free(queue);
   }
   pthread_mutex_unlock(&timer_mutex);
}

canonical_original_code:
void timer_flush_queues()
{
   struct timer_entry *timer; struct timer_entry *next_timer;
   struct timer_queue *queue; struct timer_queue *next_queue;
   unsigned long thread;
   pthread_mutex_lock(&timer_mutex);
   for(queue=timer_queue_pool;queue;queue=next_queue)
   {
      pthread_mutex_lock(&(queue)->lock);
      next_queue = queue->next;
      thread = queue->thread;
      queue->running = 0;
      for(timer=queue->list;timer;timer=next_timer) {
         next_timer = timer->next;
         timer_free_id(timer->id);
         free(timer);
      }
      pthread_mutex_unlock(&(queue)->lock);
      pthread_cond_signal(&queue->schedule);
      pthread_join(thread,((void *)0));
      pthread_cond_destroy(&queue->schedule);
      pthread_mutex_destroy(&queue->lock);
      free(queue);
   }
   pthread_mutex_unlock(&timer_mutex);
}

variable_types:
thread
unsigned long


decompiled_code:
__int64 __fastcall timer_pool_add_queues(int a1)
{
int v1; // ebp
pthread_cond_t *v2; // rbx

if ( a1 <= 0 )
return 0LL;
v1 = 0;
while ( 1 )
{
v2 = timer_create_queue();
if ( !v2 )
break;
pthread_mutex_lock(&timer_mutex);
v2[2].__woken_seq = (unsigned __int64)timer_queue_pool;
timer_queue_pool = v2;
pthread_mutex_unlock(&timer_mutex);
if ( a1 == ++v1 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1)
{
int v1; // ebp
pthread_cond_t *v2; // rbx

if ( a1 <= 0 )
return 0LL;
v1 = 0;
while ( 1 )
{
v2 = func19();
if ( !v2 )
break;
pthread_mutex_lock(&timer_mutex);
v2[2].__woken_seq = (unsigned __int64)timer_queue_pool;
timer_queue_pool = v2;
pthread_mutex_unlock(&timer_mutex);
if ( a1 == ++v1 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int timer_pool_add_queues(int nr_queues)
{
   timer_queue_t *queue;
   int i;
   for(i=0;i<nr_queues;i++)
   {
      if (!(queue = timer_create_queue()))
         return(-1);
      pthread_mutex_lock(&timer_mutex);
      queue->next = timer_queue_pool;
      timer_queue_pool = queue;
      pthread_mutex_unlock(&timer_mutex);
   }
   return(0);
}

canonical_original_code:
int timer_pool_add_queues(int nr_queues)
{
   struct timer_queue *queue;
   int i;
   for(i=0;i<nr_queues;i++)
   {
      if (!(queue = timer_create_queue()))
         return(-1);
      pthread_mutex_lock(&timer_mutex);
      queue->next = timer_queue_pool;
      timer_queue_pool = queue;
      pthread_mutex_unlock(&timer_mutex);
   }
   return(0);
}

variable_types: i int


decompiled_code:
__int64 timer_init()
{
int v0; // edx
__int64 result; // rax

timer_id_hash = hash_table_create(&u64_hash, &u64_equal, 512LL);
if ( timer_id_hash )
{
v0 = timer_pool_add_queues(10);
result = 0LL;
if ( v0 == -1 )
{
fwrite("timer_init: unable to initialize at least one timer queue.", 1uLL, 0x3AuLL, stderr);
result = 0LL;
}
}
else
{
fwrite("timer_init: unable to create hash table.", 1uLL, 0x28uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 func22()
{
int v0; // edx
__int64 result; // rax

timer_id_hash = hash_table_create(&u64_hash, &u64_equal, 512LL);
if ( timer_id_hash )
{
v0 = func21(10);
result = 0LL;
if ( v0 == -1 )
{
fwrite("timer_init: unable to initialize at least one timer queue.", 1uLL, 0x3AuLL, stderr);
result = 0LL;
}
}
else
{
fwrite("timer_init: unable to create hash table.", 1uLL, 0x28uLL, stderr);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int timer_init(void)
{
   if (!(timer_id_hash = hash_table_create(u64_hash,u64_equal,512))) {
      fprintf(stderr,"timer_init: unable to create hash table.");
      return(-1);
   }
   if (timer_pool_add_queues(10) == -1) {
      fprintf(stderr,
              "timer_init: unable to initialize at least one timer queue.");
   }
   return(0);
}

canonical_original_code:
int timer_init()
{
   if (!(timer_id_hash = hash_table_create(u64_hash,u64_equal,512))) {
      fprintf(stderr,"timer_init: unable to create hash table.");
      return(-1);
   }
   if (timer_pool_add_queues(10) == -1) {
      fprintf(stderr,
              "timer_init: unable to initialize at least one timer queue.");
   }
   return(0);
}


decompiled_code:
void *__fastcall plugin_find_symbol(void **a1, const char *a2)
{
void *result; // rax

result = a1;
if ( a1 )
result = dlsym(a1[1], a2);
return result;
}

canonical_decompiled_code:
void *__fastcall func0(void **a1, const char *a2)
{
void *result; // rax

result = a1;
if ( a1 )
result = dlsym(a1[1], a2);
return result;
}

original_code:
void *plugin_find_symbol(struct plugin *plugin,char *symbol)
{
   return((plugin != ((void *)0)) ? dlsym(plugin->dl_handle,symbol) : ((void *)0));
}

canonical_original_code:
void *plugin_find_symbol(struct plugin *plugin, char *symbol)
{
   return((plugin != ((void *)0)) ? dlsym(plugin->dl_handle,symbol) : ((void *)0));
}

variable_types: struct plugin { char *filename; void *dl_handle; struct plugin *next; } *

variable_types:
symbol
char *


decompiled_code:
__int64 __fastcall plugin_init(void **a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = (__int64 (*)(void))plugin_find_symbol(a1, "init");
if ( v1 )
result = v1();
else
result = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(void **a1)
{
__int64 (*v1)(void); // rax
__int64 result; // rax

v1 = (__int64 (*)(void))func0(a1, "init");
if ( v1 )
result = v1();
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static int plugin_init(struct plugin *plugin)
{
   plugin_init_t init;
   if (!(init = plugin_find_symbol(plugin,"init")))
      return(-1);
   return(init());
}

canonical_original_code:
static int plugin_init(struct plugin *plugin)
{
   int (*init)();
   if (!(init = plugin_find_symbol(plugin,"init")))
      return(-1);
   return(init());
}

variable_types:
init
int (*)()

user_defined_types: struct plugin { char *filename; void *dl_handle; struct plugin *next; }


decompiled_code:
__int64 __fastcall plugin_load(char *file)
{
_QWORD *v1; // rax
__int64 v2; // rbx
char *v3; // rax
void *v4; // rax
char *v6; // rax

v1 = malloc(0x18uLL);
v2 = (__int64)v1;
if ( v1 )
{
v1[1] = 0LL;
v1[2] = 0LL;
v3 = strdup(file);
*(_QWORD *)v2 = v3;
if ( v3 )
{
v4 = dlopen(file, 1);
*(_QWORD *)(v2 + 8) = v4;
if ( v4 )
{
if ( (unsigned int)plugin_init((void **)v2) != -1 )
{
*(_QWORD *)(v2 + 16) = plugin_list;
plugin_list = v2;
return v2;
}
dlclose(*(void **)(v2 + 8));
}
else
{
v6 = dlerror();
fprintf(stderr, "plugin_load(\"%s\"): %s\n", file, v6);
}
free(*(void **)v2);
}
free((void *)v2);
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *file)
{
_QWORD *v1; // rax
__int64 v2; // rbx
char *v3; // rax
void *v4; // rax
char *v6; // rax

v1 = malloc(0x18uLL);
v2 = (__int64)v1;
if ( v1 )
{
v1[1] = 0LL;
v1[2] = 0LL;
v3 = strdup(file);
*(_QWORD *)v2 = v3;
if ( v3 )
{
v4 = dlopen(file, 1);
*(_QWORD *)(v2 + 8) = v4;
if ( v4 )
{
if ( (unsigned int)func1((void **)v2) != -1 )
{
*(_QWORD *)(v2 + 16) = plugin_list;
plugin_list = v2;
return v2;
}
dlclose(*(void **)(v2 + 8));
}
else
{
v6 = dlerror();
fprintf(stderr, "plugin_load(\"%s\"): %s\n", file, v6);
}
free(*(void **)v2);
}
free((void *)v2);
v2 = 0LL;
}
return v2;
}

original_code:
struct plugin *plugin_load(char *filename)
{
   struct plugin *p;
   if (!(p = malloc(sizeof(*p))))
      return ((void *)0);
   memset(p,0,sizeof(*p));
   if (!(p->filename = strdup(filename)))
      goto err_strdup;
   if (!(p->dl_handle = dlopen(filename,0x00001))) {
      fprintf(stderr,"plugin_load(\"%s\"): %s\n",filename,dlerror());
      goto err_dlopen;
   }
   if (plugin_init(p) == -1)
      goto err_init;
   p->next = plugin_list;
   plugin_list = p;
   return p;
 err_init:
   dlclose(p->dl_handle);
 err_dlopen:
   free(p->filename);
 err_strdup:
   free(p);
   return ((void *)0);
}

variable_types:
filename
char *

return_type: struct plugin { char *filename; void *dl_handle; struct plugin *next; } *


decompiled_code:
char *dyn_sprintf(char *format, ...)
{
char *v1; // r12
int v2; // ebx
char *v3; // rax
int v4; // eax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

v1 = (char *)malloc(0x200uLL);
if ( v1 )
{
v2 = 512;
while ( 1 )
{
va_start(arg, format);
v4 = vsnprintf(v1, v2, format, arg);
if ( v4 >= 0 && v2 > v4 )
break;
v2 *= 2;
if ( v4 >= 0 )
v2 = v4 + 1;
v3 = (char *)realloc(v1, v2);
if ( !v3 )
{
perror("dyn_sprintf: realloc");
free(v1);
return 0LL;
}
v1 = v3;
}
}
else
{
perror("dyn_sprintf: malloc");
}
return v1;
}

canonical_decompiled_code:
char *func1(char *format, ...)
{
char *v1; // r12
int v2; // ebx
char *v3; // rax
int v4; // eax
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

v1 = (char *)malloc(0x200uLL);
if ( v1 )
{
v2 = 512;
while ( 1 )
{
va_start(arg, format);
v4 = vsnprintf(v1, v2, format, arg);
if ( v4 >= 0 && v2 > v4 )
break;
v2 *= 2;
if ( v4 >= 0 )
v2 = v4 + 1;
v3 = (char *)realloc(v1, v2);
if ( !v3 )
{
perror("dyn_sprintf: realloc");
free(v1);
return 0LL;
}
v1 = v3;
}
}
else
{
perror("dyn_sprintf: malloc");
}
return v1;
}

original_code:
char *dyn_sprintf(const char *fmt,...)
{
   int n,size = 512;
   va_list ap;
   char *p,*p2;
   if ((p = malloc(size)) == ((void *)0)) {
      perror("dyn_sprintf: malloc");
      return ((void *)0);
   }
   for(;;)
   {
      __builtin_va_start(ap,fmt);
      n = vsnprintf(p,size,fmt,ap);
      __builtin_va_end(ap);
      if ((n > -1) && (n < size))
         return p;
      if (n > -1)
         size = n + 1;
      else
         size *= 2;
      if ((p2 = realloc(p,size)) == ((void *)0)) {
         perror("dyn_sprintf: realloc");
         free(p);
         return ((void *)0);
      }
      p = p2;
   }
}

canonical_original_code:
char *dyn_sprintf(char *fmt, ...)
{
   int n; int size = 512;
   __builtin_va_list ap;
   char *p; char *p2;
   if ((p = malloc(size)) == ((void *)0)) {
      perror("dyn_sprintf: malloc");
      return ((void *)0);
   }
   for(;;)
   {
      __builtin_va_start(ap,fmt);
      n = vsnprintf(p,size,fmt,ap);
      __builtin_va_end(ap);
      if ((n > -1) && (n < size))
         return p;
      if (n > -1)
         size = n + 1;
      else
         size *= 2;
      if ((p2 = realloc(p,size)) == ((void *)0)) {
         perror("dyn_sprintf: realloc");
         free(p);
         return ((void *)0);
      }
      p = p2;
   }
}

variable_types:
fmt
char *

variable_types: n int

variable_types: size int

variable_types:
p
char *

return_type: char *


decompiled_code:
__int64 __fastcall m_strsplit(char *s, char a2, void **a3, int a4)
{
void **v5; // r15
void **v6; // rax
__int64 v7; // rdx
__int64 v8; // r12
_BYTE *v9; // rax
_BYTE *v10; // rbp
__int64 result; // rax
char *v12; // rbx
void **v13; // rbx

v5 = a3;
if ( a4 > 0 )
{
v6 = a3;
v7 = (__int64)&a3[(unsigned int)(a4 - 1) + 1];
do
*v6++ = 0LL;
while ( v6 != (void **)v7 );
}
v8 = 1LL;
while ( v8 != (unsigned int)a4 + 1LL )
{
v12 = strchr(s, a2);
if ( !v12 )
v12 = &s[strlen(s)];
v9 = malloc(v12 - s + 1);
v10 = v9;
v5[v8 - 1] = v9;
if ( !v9 )
break;
memcpy(v9, s, v12 - s);
v10[v12 - s] = 0;
s = v12 + 1;
result = (unsigned int)v8++;
if ( !*v12 )
return result;
}
result = 0xFFFFFFFFLL;
if ( a4 > 0 )
{
v13 = v5;
do
free(*v13++);
while ( v13 != &v5[(unsigned int)(a4 - 1) + 1] );
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s, char a2, void **a3, int a4)
{
void **v5; // r15
void **v6; // rax
__int64 v7; // rdx
__int64 v8; // r12
_BYTE *v9; // rax
_BYTE *v10; // rbp
__int64 result; // rax
char *v12; // rbx
void **v13; // rbx

v5 = a3;
if ( a4 > 0 )
{
v6 = a3;
v7 = (__int64)&a3[(unsigned int)(a4 - 1) + 1];
do
*v6++ = 0LL;
while ( v6 != (void **)v7 );
}
v8 = 1LL;
while ( v8 != (unsigned int)a4 + 1LL )
{
v12 = strchr(s, a2);
if ( !v12 )
v12 = &s[strlen(s)];
v9 = malloc(v12 - s + 1);
v10 = v9;
v5[v8 - 1] = v9;
if ( !v9 )
break;
memcpy(v9, s, v12 - s);
v10[v12 - s] = 0;
s = v12 + 1;
result = (unsigned int)v8++;
if ( !*v12 )
return result;
}
result = 0xFFFFFFFFLL;
if ( a4 > 0 )
{
v13 = v5;
do
free(*v13++);
while ( v13 != &v5[(unsigned int)(a4 - 1) + 1] );
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int m_strsplit(char *str,char delim,char **array,int max_count)
{
   int i,pos = 0;
   size_t len;
   char *ptr;
   for(i=0;i<max_count;i++)
      array[i] = ((void *)0);
   do {
      if (pos == max_count)
         goto error;
      ptr = strchr(str,delim);
      if (!ptr)
         ptr = str + strlen(str);
      len = ptr - str;
      if (!(array[pos] = malloc(len+1)))
         goto error;
      memcpy(array[pos],str,len);
      array[pos][len] = 0;
      str = ptr + 1;
      pos++;
   }while(*ptr);
   return(pos);
 error:
   for(i=0;i<max_count;i++)
      free(array[i]);
   return(-1);
}

canonical_original_code:
int m_strsplit(char *str, char delim, char **array, int max_count)
{
   int i; int pos = 0;
   unsigned long len;
   char *ptr;
   for(i=0;i<max_count;i++)
      array[i] = ((void *)0);
   do {
      if (pos == max_count)
         goto error;
      ptr = strchr(str,delim);
      if (!ptr)
         ptr = str + strlen(str);
      len = ptr - str;
      if (!(array[pos] = malloc(len+1)))
         goto error;
      memcpy(array[pos],str,len);
      array[pos][len] = 0;
      str = ptr + 1;
      pos++;
   }while(*ptr);
   return(pos);
 error:
   for(i=0;i<max_count;i++)
      free(array[i]);
   return(-1);
}

variable_types:
str
char *

variable_types: delim char

variable_types:
array
char **

variable_types: pos int

variable_types:
len
unsigned long

variable_types:
ptr
char *


original_code:
int m_strtok(char *str,char delim,char **array,int max_count)
{
   int i,pos = 0;
   size_t len;
   char *ptr;
   for(i=0;i<max_count;i++)
      array[i] = ((void *)0);
   do {
      if (pos == max_count)
         goto error;
      ptr = strchr(str,delim);
      if (!ptr)
         ptr = str + strlen(str);
      len = ptr - str;
      if (!(array[pos] = malloc(len+1)))
         goto error;
      memcpy(array[pos],str,len);
      array[pos][len] = 0;
      while(*ptr == delim)
         ptr++;
      str = ptr;
      pos++;
   }while(*ptr);
   return(pos);
 error:
   for(i=0;i<max_count;i++)
      free(array[i]);
   return(-1);
}

canonical_original_code:
int m_strtok(char *str, char delim, char **array, int max_count)
{
   int i; int pos = 0;
   unsigned long len;
   char *ptr;
   for(i=0;i<max_count;i++)
      array[i] = ((void *)0);
   do {
      if (pos == max_count)
         goto error;
      ptr = strchr(str,delim);
      if (!ptr)
         ptr = str + strlen(str);
      len = ptr - str;
      if (!(array[pos] = malloc(len+1)))
         goto error;
      memcpy(array[pos],str,len);
      array[pos][len] = 0;
      while(*ptr == delim)
         ptr++;
      str = ptr;
      pos++;
   }while(*ptr);
   return(pos);
 error:
   for(i=0;i<max_count;i++)
      free(array[i]);
   return(-1);
}


decompiled_code:
char *__fastcall m_strquote(char *s, size_t maxlen, char *a3)
{
char *v4; // rdx
char *result; // rax

v4 = strpbrk(a3, " \t\"'");
result = a3;
if ( v4 )
{
snprintf(s, maxlen, "\"%s\"", a3);
result = s;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(char *s, size_t maxlen, char *a3)
{
char *v4; // rdx
char *result; // rax

v4 = strpbrk(a3, " \t\"'");
result = a3;
if ( v4 )
{
snprintf(s, maxlen, "\"%s\"", a3);
result = s;
}
return result;
}

original_code:
char *m_strquote(char *buffer,size_t buf_len,char *str)
{
   char *p;
   if (!(p = strpbrk(str," \t\"'")))
      return str;
   snprintf(buffer,buf_len,"\"%s\"",str);
   return buffer;
}

canonical_original_code:
char *m_strquote(char *buffer, unsigned long buf_len, char *str)
{
   char *p;
   if (!(p = strpbrk(str," \t\"'")))
      return str;
   snprintf(buffer,buf_len,"\"%s\"",str);
   return buffer;
}

variable_types:
buffer
char *


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

va_start(va, a2);
return m_flog(log_file, a1, a2, va);
}

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

va_start(va, a2);
return func6(log_file, a1, a2, va);
}

original_code:
void m_log(char *module,char *fmt,...)
{
   va_list ap;
   __builtin_va_start(ap,fmt);
   m_flog(log_file,module,fmt,ap);
   __builtin_va_end(ap);
}

canonical_original_code:
void m_log(char *module, char *fmt, ...)
{
   __builtin_va_list ap;
   __builtin_va_start(ap,fmt);
   m_flog(log_file,module,fmt,ap);
   __builtin_va_end(ap);
}

variable_types:
module
char *


decompiled_code:
void *__fastcall m_memalign(size_t alignment, size_t size)
{
void *result; // rax
void *memptr; // [rsp+8h] [rbp-10h] BYREF

if ( posix_memalign(&memptr, alignment, size) )
return 0LL;
result = memptr;
if ( ((alignment - 1) & (unsigned __int64)memptr) != 0 )
_assert_fail("((m_iptr_t)p & (boundary-1)) == 0", "utils.c", 0x13Au, "m_memalign");
return result;
}

canonical_decompiled_code:
void *__fastcall func10(size_t alignment, size_t size)
{
void *result; // rax
void *memptr; // [rsp+8h] [rbp-10h] BYREF

if ( posix_memalign(&memptr, alignment, size) )
return 0LL;
result = memptr;
if ( ((alignment - 1) & (unsigned __int64)memptr) != 0 )
_assert_fail("((m_iptr_t)p & (boundary-1)) == 0", "utils.c", 0x13Au, "m_memalign");
return result;
}

original_code:
void *m_memalign(size_t boundary,size_t size)
{
   void *p;
   if (posix_memalign((void *)&p,boundary,size))
      return ((void *)0);
   ((void) sizeof ((((m_iptr_t)p & (boundary-1)) == 0) ? 1 : 0), __extension__ ({ if (((m_iptr_t)p & (boundary-1)) == 0) ; else __assert_fail ("((m_iptr_t)p & (boundary-1)) == 0", "utils.c", 314, __extension__ __PRETTY_FUNCTION__); }));
   return p;
}

canonical_original_code:
void *m_memalign(unsigned long boundary, unsigned long size)
{
   void *p;
   if (posix_memalign((void *)&p,boundary,size))
      return ((void *)0);
   ((void) sizeof ((((unsigned long)p & (boundary-1)) == 0) ? 1 : 0), __extension__ ({ if (((unsigned long)p & (boundary-1)) == 0) ; else __assert_fail ("((m_iptr_t)p & (boundary-1)) == 0", "utils.c", 314, __extension__ __PRETTY_FUNCTION__); }));
   return p;
}

variable_types:
boundary
unsigned long

variable_types:
size
unsigned long

variable_types:
p
void *


decompiled_code:
int __fastcall m_signal_block(int signo)
{
sigset_t v2; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v2);
sigaddset(&v2, signo);
return pthread_sigmask(0, &v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func11(int signo)
{
sigset_t v2; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v2);
sigaddset(&v2, signo);
return pthread_sigmask(0, &v2, 0LL);
}

original_code:
int m_signal_block(int sig)
{
   sigset_t sig_mask;
   sigemptyset(&sig_mask);
   sigaddset(&sig_mask,sig);
   return(pthread_sigmask(0,&sig_mask,((void *)0)));
}

canonical_original_code:
int m_signal_block(int sig)
{
   struct __sigset_t sig_mask;
   sigemptyset(&sig_mask);
   sigaddset(&sig_mask,sig);
   return(pthread_sigmask(0,&sig_mask,((void *)0)));
}

variable_types: sig int

variable_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
int __fastcall m_signal_unblock(int signo)
{
sigset_t v2; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v2);
sigaddset(&v2, signo);
return pthread_sigmask(1, &v2, 0LL);
}

canonical_decompiled_code:
int __fastcall func12(int signo)
{
sigset_t v2; // [rsp+0h] [rbp-88h] BYREF

sigemptyset(&v2);
sigaddset(&v2, signo);
return pthread_sigmask(1, &v2, 0LL);
}

original_code:
int m_signal_unblock(int sig)
{
   sigset_t sig_mask;
   sigemptyset(&sig_mask);
   sigaddset(&sig_mask,sig);
   return(pthread_sigmask(1,&sig_mask,((void *)0)));
}

canonical_original_code:
int m_signal_unblock(int sig)
{
   struct __sigset_t sig_mask;
   sigemptyset(&sig_mask);
   sigaddset(&sig_mask,sig);
   return(pthread_sigmask(1,&sig_mask,((void *)0)));
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


decompiled_code:
int __fastcall m_fd_set_non_block(int fd)
{
int v1; // eax

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

canonical_decompiled_code:
int __fastcall func13(int fd)
{
int v1; // eax

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

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

variable_types: fd int

variable_types: flags int


decompiled_code:
void *__fastcall memzone_map_file(int fd, size_t a2)
{
return mmap(0LL, a2, 3, 1, fd, 0LL);
}

canonical_decompiled_code:
void *__fastcall func14(int fd, size_t a2)
{
return mmap(0LL, a2, 3, 1, fd, 0LL);
}

original_code:
u_char *memzone_map_file(int fd,size_t len)
{
   return(mmap(((void *)0),len,0x1|0x2,0x01,fd,(off_t)0));
}

canonical_original_code:
unsigned char *memzone_map_file(int fd, unsigned long len)
{
   return(mmap(((void *)0),len,0x1|0x2,0x01,fd,(long)0));
}

return_type: unsigned char *


decompiled_code:
void *__fastcall memzone_map_cow_file(int fd, size_t a2)
{
return mmap(0LL, a2, 3, 2, fd, 0LL);
}

canonical_decompiled_code:
void *__fastcall func15(int fd, size_t a2)
{
return mmap(0LL, a2, 3, 2, fd, 0LL);
}

original_code:
u_char *memzone_map_cow_file(int fd,size_t len)
{
   return(mmap(((void *)0),len,0x1|0x2,0x02,fd,(off_t)0));
}

canonical_original_code:
unsigned char *memzone_map_cow_file(int fd, unsigned long len)
{
   return(mmap(((void *)0),len,0x1|0x2,0x02,fd,(long)0));
}


decompiled_code:
__int64 __fastcall memzone_create_file(const char *a1, size_t a2, _QWORD *a3)
{
int v4; // eax
unsigned int v5; // ebx
void *v6; // rax

v4 = open(a1, 66, 448LL);
v5 = v4;
if ( v4 == -1 )
{
perror("memzone_create_file: open");
}
else if ( ftruncate(v4, a2) == -1 )
{
perror("memzone_create_file: ftruncate");
close(v5);
v5 = -1;
}
else
{
v6 = memzone_map_file(v5, a2);
*a3 = v6;
if ( !v6 )
{
close(v5);
v5 = -1;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func16(const char *a1, size_t a2, _QWORD *a3)
{
int v4; // eax
unsigned int v5; // ebx
void *v6; // rax

v4 = open(a1, 66, 448LL);
v5 = v4;
if ( v4 == -1 )
{
perror("memzone_create_file: open");
}
else if ( ftruncate(v4, a2) == -1 )
{
perror("memzone_create_file: ftruncate");
close(v5);
v5 = -1;
}
else
{
v6 = func14(v5, a2);
*a3 = v6;
if ( !v6 )
{
close(v5);
v5 = -1;
}
}
return v5;
}

original_code:
int memzone_create_file(char *filename,size_t len,u_char **ptr)
{
   int fd;
   if ((fd = open(filename,0100|02,(0400|0200|0100))) == -1) {
      perror("memzone_create_file: open");
      return(-1);
   }
   if (ftruncate(fd,len) == -1) {
      perror("memzone_create_file: ftruncate");
      close(fd);
      return(-1);
   }
   *ptr = memzone_map_file(fd,len);
   if (!*ptr) {
      close(fd);
      fd = -1;
   }
   return(fd);
}

canonical_original_code:
int memzone_create_file(char *filename, unsigned long len, unsigned char **ptr)
{
   int fd;
   if ((fd = open(filename,0100|02,(0400|0200|0100))) == -1) {
      perror("memzone_create_file: open");
      return(-1);
   }
   if (ftruncate(fd,len) == -1) {
      perror("memzone_create_file: ftruncate");
      close(fd);
      return(-1);
   }
   *ptr = memzone_map_file(fd,len);
   if (!*ptr) {
      close(fd);
      fd = -1;
   }
   return(fd);
}

variable_types:
filename
char *

variable_types:
ptr
unsigned char **


decompiled_code:
__int64 __fastcall memzone_open_cow_file(const char *a1, size_t a2, _QWORD *a3)
{
int v4; // eax
unsigned int v5; // ebx
void *v6; // rax

v4 = open(a1, 2, 448LL);
v5 = v4;
if ( v4 == -1 )
{
perror("memzone_open_file: open");
}
else
{
v6 = memzone_map_cow_file(v4, a2);
*a3 = v6;
if ( !v6 )
{
close(v5);
v5 = -1;
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func17(const char *a1, size_t a2, _QWORD *a3)
{
int v4; // eax
unsigned int v5; // ebx
void *v6; // rax

v4 = open(a1, 2, 448LL);
v5 = v4;
if ( v4 == -1 )
{
perror("memzone_open_file: open");
}
else
{
v6 = func15(v4, a2);
*a3 = v6;
if ( !v6 )
{
close(v5);
v5 = -1;
}
}
return v5;
}

original_code:
int memzone_open_cow_file(char *filename,size_t len,u_char **ptr)
{
   int fd;
   if ((fd = open(filename,02,(0400|0200|0100))) == -1) {
      perror("memzone_open_file: open");
      return(-1);
   }
   *ptr = memzone_map_cow_file(fd,len);
   if (!*ptr) {
      close(fd);
      fd = -1;
   }
   return(fd);
}

canonical_original_code:
int memzone_open_cow_file(char *filename, unsigned long len, unsigned char **ptr)
{
   int fd;
   if ((fd = open(filename,02,(0400|0200|0100))) == -1) {
      perror("memzone_open_file: open");
      return(-1);
   }
   *ptr = memzone_map_cow_file(fd,len);
   if (!*ptr) {
      close(fd);
      fd = -1;
   }
   return(fd);
}


decompiled_code:
__int64 __fastcall memzone_open_file(const char *a1, _QWORD *a2, __off_t *a3)
{
int v5; // eax
unsigned int v6; // ebx
__off_t v7; // rsi
void *v8; // rax
struct stat v10; // [rsp+0h] [rbp-A8h] BYREF

v5 = open(a1, 2, 448LL);
v6 = v5;
if ( v5 != -1 )
{
if ( fstat(v5, &v10) == -1
|| (v7 = v10.st_size, *a3 = v10.st_size, v8 = memzone_map_file(v6, v7), (*a2 = v8) == 0LL) )
{
close(v6);
v6 = -1;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func18(const char *a1, _QWORD *a2, __off_t *a3)
{
int v5; // eax
unsigned int v6; // ebx
__off_t v7; // rsi
void *v8; // rax
struct stat v10; // [rsp+0h] [rbp-A8h] BYREF

v5 = open(a1, 2, 448LL);
v6 = v5;
if ( v5 != -1 )
{
if ( fstat(v5, &v10) == -1
|| (v7 = v10.st_size, *a3 = v10.st_size, v8 = func14(v6, v7), (*a2 = v8) == 0LL) )
{
close(v6);
v6 = -1;
}
}
return v6;
}

original_code:
int memzone_open_file(char *filename,u_char **ptr,off_t *fsize)
{
   struct stat fprop;
   int fd;
   if ((fd = open(filename,02,(0400|0200|0100))) == -1)
      return(-1);
   if (fstat(fd,&fprop) == -1)
      goto err_fstat;
   *fsize = fprop.st_size;
   if (!(*ptr = memzone_map_file(fd,*fsize)))
      goto err_mmap;
   return(fd);
 err_mmap:
 err_fstat:
   close(fd);
   return(-1);
}

canonical_original_code:
int memzone_open_file(char *filename, unsigned char **ptr, long *fsize)
{
   struct stat fprop;
   int fd;
   if ((fd = open(filename,02,(0400|0200|0100))) == -1)
      return(-1);
   if (fstat(fd,&fprop) == -1)
      goto err_fstat;
   *fsize = fprop.st_size;
   if (!(*ptr = memzone_map_file(fd,*fsize)))
      goto err_mmap;
   return(fd);
 err_mmap:
 err_fstat:
   close(fd);
   return(-1);
}

variable_types:
fsize
long *

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

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


decompiled_code:
__int64 __fastcall nvram_cksum(__int16 *a1, unsigned __int64 a2)
{
__int16 *v2; // rbp
__int16 *v3; // r12
unsigned int v4; // ebx
unsigned int i; // edx

v2 = a1;
if ( a2 <= 1 )
{
if ( !a2 )
{
v4 = 0;
return ~v4;
}
v3 = a1;
v4 = 0;
goto LABEL_5;
}
v3 = &a1[((a2 - 2) >> 1) + 1];
v4 = 0;
do
v4 += (unsigned __int16)_bswap_16(*v2++);
while ( v2 != v3 );
if ( (a2 & 1) != 0 )
LABEL_5:
v4 += (unsigned __int16)(_bswap_16(*v3) << 8);
for ( i = HIWORD(v4); HIWORD(v4); i = HIWORD(v4) )
v4 = i + (unsigned __int16)v4;
return ~v4;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int16 *a1, unsigned __int64 a2)
{
__int16 *v2; // rbp
__int16 *v3; // r12
unsigned int v4; // ebx
unsigned int i; // edx

v2 = a1;
if ( a2 <= 1 )
{
if ( !a2 )
{
v4 = 0;
return ~v4;
}
v3 = a1;
v4 = 0;
goto LABEL_5;
}
v3 = &a1[((a2 - 2) >> 1) + 1];
v4 = 0;
do
v4 += (unsigned __int16)func0(*v2++);
while ( v2 != v3 );
if ( (a2 & 1) != 0 )
LABEL_5:
v4 += (unsigned __int16)(func0(*v3) << 8);
for ( i = HIWORD(v4); HIWORD(v4); i = HIWORD(v4) )
v4 = i + (unsigned __int16)v4;
return ~v4;
}

original_code:
m_uint16_t nvram_cksum(m_uint16_t *ptr,size_t count)
{
   m_uint32_t sum = 0;
   while(count > 1) {
      sum = sum + ntohs(*ptr);
      ptr++;
      count -= sizeof(m_uint16_t);
   }
   if (count > 0)
      sum = sum + ((ntohs(*ptr) & 0xFF) << 8);
   while(sum>>16)
      sum = (sum & 0xffff) + (sum >> 16);
   return(~sum);
}

canonical_original_code:
unsigned short nvram_cksum(unsigned short *ptr, unsigned long count)
{
   unsigned int sum = 0;
   while(count > 1) {
      sum = sum + ntohs(*ptr);
      ptr++;
      count -= sizeof(m_uint16_t);
   }
   if (count > 0)
      sum = sum + ((ntohs(*ptr) & 0xFF) << 8);
   while(sum>>16)
      sum = (sum & 0xffff) + (sum >> 16);
   return(~sum);
}

variable_types:
ptr
unsigned short *

variable_types:
count
unsigned long

variable_types:
sum
unsigned int

return_type: unsigned short


decompiled_code:
__int64 __fastcall mem_bswap32(_DWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rsi
_DWORD *v3; // rsi
__int64 result; // rax

v2 = a2 >> 2;
if ( v2 )
{
v3 = &a1[v2];
do
{
result = (*a1 >> 8) & 0xFF00 | (*a1 << 24) | HIBYTE(*a1) | (*a1 << 8) & 0xFF0000u;
*a1++ = result;
}
while ( a1 != v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(_DWORD *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rsi
_DWORD *v3; // rsi
__int64 result; // rax

v2 = a2 >> 2;
if ( v2 )
{
v3 = &a1[v2];
do
{
result = (*a1 >> 8) & 0xFF00 | (*a1 << 24) | HIBYTE(*a1) | (*a1 << 8) & 0xFF0000u;
*a1++ = result;
}
while ( a1 != v3 );
}
return result;
}

original_code:
void mem_bswap32(void *ptr,size_t len)
{
   m_uint32_t *p = ptr;
   size_t count = len >> 2;
   int i;
   for(i=0;i<count;i++,p++)
      *p = swap32(*p);
}

canonical_original_code:
void mem_bswap32(void *ptr, unsigned long len)
{
   unsigned int *p = ptr;
   unsigned long count = len >> 2;
   int i;
   for(i=0;i<count;i++,p++)
      *p = swap32(*p);
}

variable_types:
ptr
void *

variable_types:
len
unsigned long

variable_types:
p
unsigned int *

variable_types: i int


decompiled_code:
__int64 __fastcall m_reverse_u8(int a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

v1 = 0;
v2 = 0;
a1 = (unsigned __int8)a1;
do
{
if ( _bittest(&a1, v1) )
v2 |= 1 << (7 - v1);
++v1;
}
while ( v1 != 8 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1)
{
unsigned int v1; // eax
unsigned int v2; // edx

v1 = 0;
v2 = 0;
a1 = (unsigned __int8)a1;
do
{
if ( _bittest(&a1, v1) )
v2 |= 1 << (7 - v1);
++v1;
}
while ( v1 != 8 );
return v2;
}

original_code:
m_uint8_t m_reverse_u8(m_uint8_t val)
{
   m_uint8_t res = 0;
   int i;
   for(i=0;i<8;i++)
      if (val & (1 << i))
         res |= 1 << (7 - i);
   return(res);
}

canonical_original_code:
unsigned char m_reverse_u8(unsigned char val)
{
   unsigned char res = 0;
   int i;
   for(i=0;i<8;i++)
      if (val & (1 << i))
         res |= 1 << (7 - i);
   return(res);
}

variable_types:
val
unsigned char

variable_types:
res
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall rbtree_min(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = a1 + 88;
do
{
result = a2;
a2 = *(_QWORD *)(a2 + 16);
}
while ( a2 && a2 != v2 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rdi
__int64 result; // rax

v2 = a1 + 88;
do
{
result = a2;
a2 = *(_QWORD *)(a2 + 16);
}
while ( a2 && a2 != v2 );
return result;
}

original_code:
static inline rbtree_node *rbtree_min(rbtree_tree *tree,rbtree_node *x)
{
   while(!(((x->left) == (&(tree)->nil)) || !x->left))
      x = x->left;
   return(x);
}

canonical_original_code:
static inline struct rbtree_node *rbtree_min(struct rbtree_tree *tree, struct rbtree_node *x)
{
   while(!(((x->left) == (&(tree)->nil)) || !x->left))
      x = x->left;
   return(x);
}

variable_types: struct rbtree_tree { int node_count; struct mempool { struct memblock { int tag; unsigned long block_size; struct memblock *next; struct mempool *pool; unsigned long long data[]; } *block_list; 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; } lock; char *name; int flags; int nr_blocks; unsigned long total_size; unsigned long max_size; } mp; struct rbtree_node nil; struct rbtree_node *root; int (*key_cmp)(void *key1, void *key2, void *opt); void *opt_data; } *

variable_types:
x
struct rbtree_node *

return_type: struct rbtree_node { void *key; struct rbtree_node *left; struct rbtree_node *parent; short color; } *

user_defined_types: struct rbtree_tree { int node_count; struct mempool mp; struct rbtree_node nil; struct rbtree_node *root; int (*key_cmp)(void *key1, void *key2, void *opt); void *opt_data; }

user_defined_types: struct mempool { struct memblock *block_list; union pthread_mutex_t lock; char *name; int flags; int nr_blocks; unsigned long total_size; unsigned long max_size; }


original_code:
static inline rbtree_node *rbtree_successor(rbtree_tree *tree,rbtree_node *x)
{
   rbtree_node *y;
   if (!(((x->right) == (&(tree)->nil)) || !x->right))
      return(rbtree_min(tree,x->right));
   y = x->parent;
   while(!(((y) == (&(tree)->nil)) || !y) && (x == y->right)) {
      x = y;
      y = y->parent;
   }
   return(y);
}

canonical_original_code:
static inline struct rbtree_node *rbtree_successor(struct rbtree_tree *tree, struct rbtree_node *x)
{
   struct rbtree_node *y;
   if (!(((x->right) == (&(tree)->nil)) || !x->right))
      return(rbtree_min(tree,x->right));
   y = x->parent;
   while(!(((y) == (&(tree)->nil)) || !y) && (x == y->right)) {
      x = y;
      y = y->parent;
   }
   return(y);
}

variable_types: struct rbtree_node { void *key; struct rbtree_node *left; struct rbtree_node *parent; short color; } *

user_defined_types: struct memblock { int tag; unsigned long block_size; struct memblock *next; struct mempool *pool; unsigned long long data[]; }


original_code:
static inline void rbtree_left_rotate(rbtree_tree *tree,rbtree_node *x)
{
   rbtree_node *y;
   y = x->right;
   x->right = y->left;
   if (!(((x->right) == (&(tree)->nil)) || !x->right))
      x->right->parent = x;
   y->parent = x->parent;
   if ((((x->parent) == (&(tree)->nil)) || !x->parent))
      tree->root = y;
   else {
      if (x == x->parent->left)
         x->parent->left = y;
      else
         x->parent->right = y;
   }
   y->left = x;
   x->parent = y;
}

canonical_original_code:
static inline void rbtree_left_rotate(struct rbtree_tree *tree, struct rbtree_node *x)
{
   struct rbtree_node *y;
   y = x->right;
   x->right = y->left;
   if (!(((x->right) == (&(tree)->nil)) || !x->right))
      x->right->parent = x;
   y->parent = x->parent;
   if ((((x->parent) == (&(tree)->nil)) || !x->parent))
      tree->root = y;
   else {
      if (x == x->parent->left)
         x->parent->left = y;
      else
         x->parent->right = y;
   }
   y->left = x;
   x->parent = y;
}

variable_types: struct rbtree_tree { int node_count; struct mempool { struct memblock { int tag; unsigned long block_size; struct memblock *next; struct mempool *pool; unsigned long long data[]; } *block_list; 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; } lock; char *name; int flags; int nr_blocks; unsigned long total_size; unsigned long max_size; } mp; struct rbtree_node { void *key; struct rbtree_node *left; struct rbtree_node *parent; short color; } nil; struct rbtree_node *root; int (*key_cmp)(void *key1, void *key2, void *opt); void *opt_data; } *


original_code:
static inline void rbtree_right_rotate(rbtree_tree *tree,rbtree_node *y)
{
   rbtree_node *x;
   x = y->left;
   y->left = x->right;
   if (!(((y->left) == (&(tree)->nil)) || !y->left))
      y->left->parent = y;
   x->parent = y->parent;
   if ((((y->parent) == (&(tree)->nil)) || !y->parent))
      tree->root = x;
   else {
      if (y->parent->left == y)
         y->parent->left = x;
      else
         y->parent->right = x;
   }
   x->right = y;
   y->parent = x;
}

canonical_original_code:
static inline void rbtree_right_rotate(struct rbtree_tree *tree, struct rbtree_node *y)
{
   struct rbtree_node *x;
   x = y->left;
   y->left = x->right;
   if (!(((y->left) == (&(tree)->nil)) || !y->left))
      y->left->parent = y;
   x->parent = y->parent;
   if ((((y->parent) == (&(tree)->nil)) || !y->parent))
      tree->root = x;
   else {
      if (y->parent->left == y)
         y->parent->left = x;
      else
         y->parent->right = x;
   }
   x->right = y;
   y->parent = x;
}

variable_types:
y
struct rbtree_node *

user_defined_types: struct rbtree_node { void *key; struct rbtree_node *left; struct rbtree_node *parent; short color; }


original_code:
static void rbtree_removal_fixup(rbtree_tree *tree,rbtree_node *x)
{
   rbtree_node *w;
   while((x != tree->root) && (x->color == RBTREE_BLACK))
   {
      if (x == x->parent->left)
      {
         w = x->parent->right;
         if (w->color == RBTREE_RED) {
            w->color = RBTREE_BLACK;
            x->parent->color = RBTREE_RED;
            rbtree_left_rotate(tree,x->parent);
            w = x->parent->right;
         }
         if ((w->left->color == RBTREE_BLACK) &&
             (w->right->color == RBTREE_BLACK))
         {
            w->color = RBTREE_RED;
            x = x->parent;
         }
         else
         {
            if (w->right->color == RBTREE_BLACK) {
               w->left->color = RBTREE_BLACK;
               w->color = RBTREE_RED;
               rbtree_right_rotate(tree,w);
               w = x->parent->right;
            }
            w->color = x->parent->color;
            x->parent->color = RBTREE_BLACK;
            w->right->color = RBTREE_BLACK;
            rbtree_left_rotate(tree,x->parent);
            x = tree->root;
         }
      }
      else
      {
         w = x->parent->left;
         if (w->color == RBTREE_RED) {
            w->color = RBTREE_BLACK;
            x->parent->color = RBTREE_RED;
            rbtree_right_rotate(tree,x->parent);
            w = x->parent->left;
         }
         if ((w->right->color == RBTREE_BLACK) &&
             (w->left->color == RBTREE_BLACK))
         {
            w->color = RBTREE_RED;
            x = x->parent;
         }
         else
         {
            if (w->left->color == RBTREE_BLACK) {
               w->right->color = RBTREE_BLACK;
               w->color = RBTREE_RED;
               rbtree_left_rotate(tree,w);
               w = x->parent->left;
            }
            w->color = x->parent->color;
            x->parent->color = RBTREE_BLACK;
            w->left->color = RBTREE_BLACK;
            rbtree_right_rotate(tree,x->parent);
            x = tree->root;
         }
      }
   }
   x->color = RBTREE_BLACK;
}

canonical_original_code:
static void rbtree_removal_fixup(struct rbtree_tree *tree, struct rbtree_node *x)
{
   struct rbtree_node *w;
   while((x != tree->root) && (x->color == RBTREE_BLACK))
   {
      if (x == x->parent->left)
      {
         w = x->parent->right;
         if (w->color == RBTREE_RED) {
            w->color = RBTREE_BLACK;
            x->parent->color = RBTREE_RED;
            rbtree_left_rotate(tree,x->parent);
            w = x->parent->right;
         }
         if ((w->left->color == RBTREE_BLACK) &&
             (w->right->color == RBTREE_BLACK))
         {
            w->color = RBTREE_RED;
            x = x->parent;
         }
         else
         {
            if (w->right->color == RBTREE_BLACK) {
               w->left->color = RBTREE_BLACK;
               w->color = RBTREE_RED;
               rbtree_right_rotate(tree,w);
               w = x->parent->right;
            }
            w->color = x->parent->color;
            x->parent->color = RBTREE_BLACK;
            w->right->color = RBTREE_BLACK;
            rbtree_left_rotate(tree,x->parent);
            x = tree->root;
         }
      }
      else
      {
         w = x->parent->left;
         if (w->color == RBTREE_RED) {
            w->color = RBTREE_BLACK;
            x->parent->color = RBTREE_RED;
            rbtree_right_rotate(tree,x->parent);
            w = x->parent->left;
         }
         if ((w->right->color == RBTREE_BLACK) &&
             (w->left->color == RBTREE_BLACK))
         {
            w->color = RBTREE_RED;
            x = x->parent;
         }
         else
         {
            if (w->left->color == RBTREE_BLACK) {
               w->right->color = RBTREE_BLACK;
               w->color = RBTREE_RED;
               rbtree_left_rotate(tree,w);
               w = x->parent->left;
            }
            w->color = x->parent->color;
            x->parent->color = RBTREE_BLACK;
            w->left->color = RBTREE_BLACK;
            rbtree_right_rotate(tree,x->parent);
            x = tree->root;
         }
      }
   }
   x->color = RBTREE_BLACK;
}


decompiled_code:
__int64 __fastcall rbtree_foreach_node(__int64 a1, _QWORD *a2, void (__fastcall *a3)(_QWORD, _QWORD, __int64), __int64 a4)
{
__int64 result; // rax

if ( a2 )
{
result = a1 + 88;
if ( a2 != (_QWORD *)(a1 + 88) )
{
rbtree_foreach_node(a1, a2[2]);
a3(*a2, a2[1], a4);
result = rbtree_foreach_node(a1, a2[3]);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, _QWORD *a2, void (__fastcall *a3)(_QWORD, _QWORD, __int64), __int64 a4)
{
__int64 result; // rax

if ( a2 )
{
result = a1 + 88;
if ( a2 != (_QWORD *)(a1 + 88) )
{
func5(a1, a2[2]);
a3(*a2, a2[1], a4);
result = func5(a1, a2[3]);
}
}
return result;
}

original_code:
static void rbtree_foreach_node(rbtree_tree *tree,rbtree_node *node,
                                tree_fforeach user_fn,void *opt)
{
   if (!(((node) == (&(tree)->nil)) || !node)) {
      rbtree_foreach_node(tree,node->left,user_fn,opt);
      user_fn(node->key,node->value,opt);
      rbtree_foreach_node(tree,node->right,user_fn,opt);
   }
}

canonical_original_code:
static void rbtree_foreach_node(struct rbtree_tree *tree, struct rbtree_node *node, void (*user_fn)(void *key, void *value, void *opt), void *opt)
{
   if (!(((node) == (&(tree)->nil)) || !node)) {
      rbtree_foreach_node(tree,node->left,user_fn,opt);
      user_fn(node->key,node->value,opt);
      rbtree_foreach_node(tree,node->right,user_fn,opt);
   }
}

variable_types:
node
struct rbtree_node *

variable_types: void (*)(void *key, void *value, void *opt)

variable_types:
opt
void *