decompiled_code:
__int64 test_vectors()
{
__int64 i; // rax
__int64 v1; // rbx
unsigned int v2; // er12
__int64 v3; // rsi
__int64 v5; // [rsp+8h] [rbp-70h] BYREF
__int64 v6[2]; // [rsp+10h] [rbp-68h] BYREF
unsigned __int8 v7[88]; // [rsp+20h] [rbp-58h] BYREF

for ( i = 0LL; i != 16; ++i )
*((_BYTE *)v6 + i) = i;
v1 = 0LL;
v2 = 1;
do
{
while ( 1 )
{
v7[v1] = v1;
crypto_auth_isra_0(&v5, v7, v1, v6);
if ( v5 != vectors[v1] )
break;
if ( ++v1 == 64 )
return v2;
}
v3 = (unsigned int)v1++;
printf("test vector failed for %d bytes\n", v3);
v2 = 0;
}
while ( v1 != 64 );
return v2;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 i; // rax
__int64 v1; // rbx
unsigned int v2; // er12
__int64 v3; // rsi
__int64 v5; // [rsp+8h] [rbp-70h] BYREF
__int64 v6[2]; // [rsp+10h] [rbp-68h] BYREF
unsigned __int8 v7[88]; // [rsp+20h] [rbp-58h] BYREF

for ( i = 0LL; i != 16; ++i )
*((_BYTE *)v6 + i) = i;
v1 = 0LL;
v2 = 1;
do
{
while ( 1 )
{
v7[v1] = v1;
func0(&v5, v7, v1, v6);
if ( v5 != vectors[v1] )
break;
if ( ++v1 == 64 )
return v2;
}
v3 = (unsigned int)v1++;
printf("test vector failed for %d bytes\n", v3);
v2 = 0;
}
while ( v1 != 64 );
return v2;
}

original_code:
static int
test_vectors()
{
  u8 in[64], out[8], k[16];
  int i;
  int ok = 1;
  for( i = 0; i < 16; ++i ) k[i] = (u8)i;
  for( i = 0; i < 64; ++i )
  {
    in[i] = (u8)i;
    crypto_auth( out, in, i, k );
    if ( memcmp( out, vectors[i], 8 ) )
    {
      printf( "test vector failed for %d bytes\n", i );
      ok = 0;
    }
  }
  return ok;
}

canonical_original_code:
static int test_vectors()
{
  unsigned char in[64]; unsigned char out[8]; unsigned char k[16];
  int i;
  int ok = 1;
  for( i = 0; i < 16; ++i ) k[i] = (unsigned char)i;
  for( i = 0; i < 64; ++i )
  {
    in[i] = (unsigned char)i;
    crypto_auth( out, in, i, k );
    if ( memcmp( out, vectors[i], 8 ) )
    {
      printf( "test vector failed for %d bytes\n", i );
      ok = 0;
    }
  }
  return ok;
}

variable_types:
in
unsigned char [64]

variable_types:
out
unsigned char [8]

variable_types:
k
unsigned char [16]

variable_types: i int

variable_types: ok int


repo: robertdavidgraham/masscan

decompiled_code:
__int64 __fastcall siphash24(unsigned __int8 *a1, __int64 a2, __int64 *a3)
{
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

crypto_auth_isra_0(&v4, a1, a2, a3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, __int64 a2, __int64 *a3)
{
__int64 v4; // [rsp+8h] [rbp-8h] BYREF

func0(&v4, a1, a2, a3);
return v4;
}

original_code:
uint64_t
siphash24(const void *in, size_t inlen, const uint64_t key[2])
{
    uint64_t result;
    crypto_auth((unsigned char*)&result,
                (const unsigned char *)in,
                inlen,
                (const unsigned char *)&key[0]);
    return result;
}

canonical_original_code:
unsigned long siphash24(void *in, unsigned long inlen, unsigned long key[2])
{
    unsigned long result;
    crypto_auth((unsigned char *)&result,
                (unsigned char *)in,
                inlen,
                (unsigned char *)&key[0]);
    return result;
}

variable_types:
in
void *

variable_types:
inlen
unsigned long

variable_types:
key
unsigned long [2]

variable_types:
result
unsigned long

return_type: unsigned long


decompiled_code:
_BOOL8 siphash24_selftest()
{
return (unsigned int)test_vectors() == 0;
}

canonical_decompiled_code:
_BOOL8 func3()
{
return (unsigned int)func1() == 0;
}

original_code:
int
siphash24_selftest(void)
{
  if (test_vectors())
      return 0;
  else
      return 1;
}

canonical_original_code:
int siphash24_selftest()
{
  if (test_vectors())
      return 0;
  else
      return 1;
}

return_type: int


decompiled_code:
__int64 __fastcall rawsock_get_default_gateway(char *s2, _DWORD *a2)
{
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // eax
int v6; // er14
__int64 *v7; // r13
__int64 v8; // rax
__int64 result; // rax
int *v10; // rbx
int *v11; // rbx
int *v12; // rbx
char s1[16]; // [rsp+0h] [rbp-4048h] BYREF
__int64 v14; // [rsp+10h] [rbp-4038h]
int v15; // [rsp+18h] [rbp-4030h]
__int64 s[2053]; // [rsp+20h] [rbp-4028h] BYREF

*a2 = 0;
v2 = socket(16, 2, 0);
if ( v2 < 0 )
{
v10 = _errno_location();
fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n", "src/rawsock-getroute.c", 357LL, (unsigned int)*v10);
result = (unsigned int)*v10;
}
else
{
v3 = v2;
memset(s, 0, 0x4000uLL);
s[0] = 0x301001A0000001CLL;
HIDWORD(s[1]) = getpid();
if ( send(v3, s, LODWORD(s[0]), 0) < 0 )
{
v12 = _errno_location();
fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n", "src/rawsock-getroute.c", 378LL, (unsigned int)*v12);
result = (unsigned int)*v12;
}
else
{
v4 = getpid();
v5 = read_netlink_constprop_0(v3, s, v4);
v6 = v5;
if ( v5 <= 0 )
{
v11 = _errno_location();
fprintf(stderr, "%s:%d: read_netlink: %d\n", "src/rawsock-getroute.c", 388LL, (unsigned int)*v11);
result = (unsigned int)*v11;
}
else
{
v7 = s;
if ( v5 > 15 )
{
do
{
if ( *(_DWORD *)v7 <= 0xFu || *(_DWORD *)v7 > (unsigned int)v6 )
break;
v14 = 0LL;
v15 = 0;
*(_OWORD *)s1 = 0LL;
if ( !(unsigned int)parseRoutes((__int64)v7, (__int64)s1) && (!s2 || !strcmp(&s1[12], s2)) && !*(_DWORD *)s1 )
*a2 = _bswap_32(*(unsigned int *)&s1[8]);
v8 = (*(_DWORD *)v7 + 3) & 0xFFFFFFFC;
v6 -= v8;
v7 = (__int64 *)((char *)v7 + v8);
}
while ( v6 > 15 );
}
close(v3);
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2, _DWORD *a2)
{
int v2; // eax
int v3; // ebp
int v4; // eax
int v5; // eax
int v6; // er14
__int64 *v7; // r13
__int64 v8; // rax
__int64 result; // rax
int *v10; // rbx
int *v11; // rbx
int *v12; // rbx
char s1[16]; // [rsp+0h] [rbp-4048h] BYREF
__int64 v14; // [rsp+10h] [rbp-4038h]
int v15; // [rsp+18h] [rbp-4030h]
__int64 s[2053]; // [rsp+20h] [rbp-4028h] BYREF

*a2 = 0;
v2 = socket(16, 2, 0);
if ( v2 < 0 )
{
v10 = _errno_location();
fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n", "src/rawsock-getroute.c", 357LL, (unsigned int)*v10);
result = (unsigned int)*v10;
}
else
{
v3 = v2;
memset(s, 0, 0x4000uLL);
s[0] = 0x301001A0000001CLL;
HIDWORD(s[1]) = getpid();
if ( send(v3, s, LODWORD(s[0]), 0) < 0 )
{
v12 = _errno_location();
fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n", "src/rawsock-getroute.c", 378LL, (unsigned int)*v12);
result = (unsigned int)*v12;
}
else
{
v4 = getpid();
v5 = func2(v3, s, v4);
v6 = v5;
if ( v5 <= 0 )
{
v11 = _errno_location();
fprintf(stderr, "%s:%d: read_netlink: %d\n", "src/rawsock-getroute.c", 388LL, (unsigned int)*v11);
result = (unsigned int)*v11;
}
else
{
v7 = s;
if ( v5 > 15 )
{
do
{
if ( *(_DWORD *)v7 <= 0xFu || *(_DWORD *)v7 > (unsigned int)v6 )
break;
v14 = 0LL;
v15 = 0;
*(_OWORD *)s1 = 0LL;
if ( !(unsigned int)func0((__int64)v7, (__int64)s1) && (!s2 || !strcmp(&s1[12], s2)) && !*(_DWORD *)s1 )
*a2 = func1(*(unsigned int *)&s1[8]);
v8 = (*(_DWORD *)v7 + 3) & 0xFFFFFFFC;
v6 -= v8;
v7 = (__int64 *)((char *)v7 + v8);
}
while ( v6 > 15 );
}
close(v3);
result = 0LL;
}
}
}
return result;
}

original_code:
int rawsock_get_default_gateway(const char *ifname, unsigned *ipv4)
{
    int fd;
    struct nlmsghdr *nlMsg;
    char msgBuf[16384];
    int len;
    int msgSeq = 0;
    *ipv4 = 0;
    fd = socket(16, SOCK_DGRAM, 0);
    if (fd < 0) {
        fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n",
            "src/rawsock-getroute.c", 357, (*__errno_location ()));
        return (*__errno_location ());
    }
    memset(msgBuf, 0, sizeof(msgBuf));
    nlMsg = (struct nlmsghdr *)msgBuf;
    nlMsg->nlmsg_len = ((sizeof(struct rtmsg)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )));
    nlMsg->nlmsg_type = RTM_GETROUTE;
    nlMsg->nlmsg_flags = (0x100|0x200) | 0x01;
    nlMsg->nlmsg_seq = msgSeq++;
    nlMsg->nlmsg_pid = getpid();
    if (send(fd, nlMsg, nlMsg->nlmsg_len, 0) < 0) {
        fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n",
            "src/rawsock-getroute.c", 378, (*__errno_location ()));
        return (*__errno_location ());
    }
    len = read_netlink(fd, msgBuf, sizeof(msgBuf), msgSeq, getpid());
    if (len <= 0) {
        fprintf(stderr, "%s:%d: read_netlink: %d\n",
            "src/rawsock-getroute.c", 388, (*__errno_location ()));
        return (*__errno_location ());
    }
    for (; ((len) >= (int)sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len <= (len)); nlMsg = ((len) -= ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) ), (struct nlmsghdr*)(((char*)(nlMsg)) + ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) )))) {
        struct route_info rtInfo[1];
        int err;
        memset(rtInfo, 0, sizeof(struct route_info));
        err = parseRoutes(nlMsg, rtInfo);
        if (err != 0)
            continue;
        if (ifname && strcmp(rtInfo->ifName, ifname) != 0)
            continue;
        if (rtInfo->dstAddr.s_addr != 0)
            continue;
        *ipv4 = ntohl(rtInfo->gateWay.s_addr);
    }
    close(fd);
    return 0;
}

canonical_original_code:
int rawsock_get_default_gateway(char *ifname, unsigned int *ipv4)
{
    int fd;
    struct nlmsghdr *nlMsg;
    char msgBuf[16384];
    int len;
    int msgSeq = 0;
    *ipv4 = 0;
    fd = socket(16, SOCK_DGRAM, 0);
    if (fd < 0) {
        fprintf(stderr, "%s:%d: socket(NETLINK_ROUTE): %d\n",
            "src/rawsock-getroute.c", 357, (*__errno_location ()));
        return (*__errno_location ());
    }
    memset(msgBuf, 0, sizeof(msgBuf));
    nlMsg = (struct nlmsghdr *)msgBuf;
    nlMsg->nlmsg_len = ((sizeof(struct rtmsg)) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )));
    nlMsg->nlmsg_type = RTM_GETROUTE;
    nlMsg->nlmsg_flags = (0x100|0x200) | 0x01;
    nlMsg->nlmsg_seq = msgSeq++;
    nlMsg->nlmsg_pid = getpid();
    if (send(fd, nlMsg, nlMsg->nlmsg_len, 0) < 0) {
        fprintf(stderr, "%s:%d: send(NETLINK_ROUTE): %d\n",
            "src/rawsock-getroute.c", 378, (*__errno_location ()));
        return (*__errno_location ());
    }
    len = read_netlink(fd, msgBuf, sizeof(msgBuf), msgSeq, getpid());
    if (len <= 0) {
        fprintf(stderr, "%s:%d: read_netlink: %d\n",
            "src/rawsock-getroute.c", 388, (*__errno_location ()));
        return (*__errno_location ());
    }
    for (; ((len) >= (int)sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len >= sizeof(struct nlmsghdr) && (nlMsg)->nlmsg_len <= (len)); nlMsg = ((len) -= ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) ), (struct nlmsghdr *)(((char *)(nlMsg)) + ( (((nlMsg)->nlmsg_len)+4U -1) & ~(4U -1) )))) {
        struct route_info rtInfo[1];
        int err;
        memset(rtInfo, 0, sizeof(struct route_info));
        err = parseRoutes(nlMsg, rtInfo);
        if (err != 0)
            continue;
        if (ifname && strcmp(rtInfo->ifName, ifname) != 0)
            continue;
        if (rtInfo->dstAddr.s_addr != 0)
            continue;
        *ipv4 = ntohl(rtInfo->gateWay.s_addr);
    }
    close(fd);
    return 0;
}

variable_types:
ifname
char *

variable_types: fd int

variable_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; } *

variable_types:
msgBuf
char [16384]

variable_types: len int

variable_types: msgSeq int

variable_types: struct route_info { struct in_addr { unsigned int s_addr; } dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; } [1]

variable_types: err int

user_defined_types: struct rtmsg { unsigned char rtm_family; unsigned char rtm_dst_len; unsigned char rtm_src_len; unsigned char rtm_tos; unsigned char rtm_table; unsigned char rtm_protocol; unsigned char rtm_scope; unsigned char rtm_type; unsigned int rtm_flags; }

user_defined_types: struct route_info { struct in_addr dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; }


parseRoutes

original_code:
static int
parseRoutes(struct nlmsghdr *nlHdr, struct route_info *rtInfo)
{
    struct rtmsg *rtMsg;
    struct rtattr *rtAttr;
    int rtLen = 0;
    rtMsg = (struct rtmsg *) ((void*)(((char*)nlHdr) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (rtMsg->rtm_family != 2)
        return 1;
    if (rtMsg->rtm_table != RT_TABLE_MAIN)
        return 1;
    rtAttr = (struct rtattr *)((struct rtattr*)(((char*)(rtMsg)) + ( ((sizeof(struct rtmsg))+4U -1) & ~(4U -1) )));
    rtLen = ((nlHdr)->nlmsg_len - ( (((((sizeof(struct rtmsg))) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
    for (; ((rtLen) >= (int)sizeof(struct rtattr) && (rtAttr)->rta_len >= sizeof(struct rtattr) && (rtAttr)->rta_len <= (rtLen)); rtAttr = ((rtLen) -= ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr*)(((char*)(rtAttr)) + ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) )))) {
        switch (rtAttr->rta_type) {
        case RTA_OIF:
            if_indextoname(*(int *) ((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), rtInfo->ifName);
            break;
        case RTA_GATEWAY:
            rtInfo->gateWay.s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_PREFSRC:
            rtInfo->srcAddr.s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_DST:
            rtInfo->dstAddr .s_addr = *(u_int *)((void*)(((char*)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        }
    }
    return 0;
}

canonical_original_code:
static int parseRoutes(struct nlmsghdr *nlHdr, struct route_info *rtInfo)
{
    struct rtmsg *rtMsg;
    struct rtattr *rtAttr;
    int rtLen = 0;
    rtMsg = (struct rtmsg *) ((void *)(((char *)nlHdr) + ((0) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) )))));
    if (rtMsg->rtm_family != 2)
        return 1;
    if (rtMsg->rtm_table != RT_TABLE_MAIN)
        return 1;
    rtAttr = (struct rtattr *)((struct rtattr *)(((char *)(rtMsg)) + ( ((sizeof(struct rtmsg))+4U -1) & ~(4U -1) )));
    rtLen = ((nlHdr)->nlmsg_len - ( (((((sizeof(struct rtmsg))) + ((int) ( ((sizeof(struct nlmsghdr))+4U -1) & ~(4U -1) ))))+4U -1) & ~(4U -1) ));
    for (; ((rtLen) >= (int)sizeof(struct rtattr) && (rtAttr)->rta_len >= sizeof(struct rtattr) && (rtAttr)->rta_len <= (rtLen)); rtAttr = ((rtLen) -= ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) ), (struct rtattr *)(((char *)(rtAttr)) + ( (((rtAttr)->rta_len)+4U -1) & ~(4U -1) )))) {
        switch (rtAttr->rta_type) {
        case RTA_OIF:
            if_indextoname(*(int *) ((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0)))), rtInfo->ifName);
            break;
        case RTA_GATEWAY:
            rtInfo->gateWay.s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_PREFSRC:
            rtInfo->srcAddr.s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        case RTA_DST:
            rtInfo->dstAddr .s_addr = *(unsigned int *)((void *)(((char *)(rtAttr)) + (( ((sizeof(struct rtattr))+4U -1) & ~(4U -1) ) + (0))));
            break;
        }
    }
    return 0;
}

variable_types: struct route_info { struct in_addr { unsigned int s_addr; } dstAddr; struct in_addr srcAddr; struct in_addr gateWay; char ifName[16]; } *

variable_types: struct rtmsg { unsigned char rtm_family; unsigned char rtm_dst_len; unsigned char rtm_src_len; unsigned char rtm_tos; unsigned char rtm_table; unsigned char rtm_protocol; unsigned char rtm_scope; unsigned char rtm_type; unsigned int rtm_flags; } *

variable_types: struct rtattr { unsigned short rta_len; unsigned short rta_type; } *

variable_types: rtLen int

user_defined_types: struct nlmsghdr { unsigned int nlmsg_len; unsigned short nlmsg_type; unsigned short nlmsg_flags; unsigned int nlmsg_seq; unsigned int nlmsg_pid; }


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

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

original_code:
static int
smtp_selftest(void)
{
    return 0;
}

canonical_original_code:
static int smtp_selftest()
{
    return 0;
}


decompiled_code:
__int64 __fastcall sctp_checksum(_BYTE *a1, unsigned __int64 a2)
{
_BYTE *v2; // rdx
int v3; // eax
unsigned int v4; // ecx
unsigned __int8 v5; // al
unsigned int v6; // ecx
unsigned int v7; // edx
unsigned int v8; // edx
unsigned int v9; // eax
int v10; // eax
unsigned int v11; // ecx
__int64 v12; // rdx
unsigned int v13; // er8
unsigned __int8 v14; // al

v2 = a1;
v3 = -1;
do
{
v4 = v3;
v5 = *v2++ ^ v3;
v6 = crc_c[v5] ^ (v4 >> 8);
v3 = v6;
}
while ( v2 != a1 + 8 );
v7 = crc_c[(unsigned __int8)v6] ^ (v6 >> 8);
v8 = crc_c[(unsigned __int8)v7] ^ (v7 >> 8);
v9 = crc_c[(unsigned __int8)v8] ^ (v8 >> 8);
v10 = crc_c[(unsigned __int8)v9] ^ (v9 >> 8);
if ( a2 > 0xC )
{
v11 = 12;
v12 = 12LL;
do
{
v13 = v10;
v14 = a1[v12] ^ v10;
v12 = ++v11;
v10 = crc_c[v14] ^ (v13 >> 8);
}
while ( v11 < a2 );
}
return _byteswap_ulong(~v10);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1, unsigned __int64 a2)
{
_BYTE *v2; // rdx
int v3; // eax
unsigned int v4; // ecx
unsigned __int8 v5; // al
unsigned int v6; // ecx
unsigned int v7; // edx
unsigned int v8; // edx
unsigned int v9; // eax
int v10; // eax
unsigned int v11; // ecx
__int64 v12; // rdx
unsigned int v13; // er8
unsigned __int8 v14; // al

v2 = a1;
v3 = -1;
do
{
v4 = v3;
v5 = *v2++ ^ v3;
v6 = crc_c[v5] ^ (v4 >> 8);
v3 = v6;
}
while ( v2 != a1 + 8 );
v7 = crc_c[(unsigned __int8)v6] ^ (v6 >> 8);
v8 = crc_c[(unsigned __int8)v7] ^ (v7 >> 8);
v9 = crc_c[(unsigned __int8)v8] ^ (v8 >> 8);
v10 = crc_c[(unsigned __int8)v9] ^ (v9 >> 8);
if ( a2 > 0xC )
{
v11 = 12;
v12 = 12LL;
do
{
v13 = v10;
v14 = a1[v12] ^ v10;
v12 = ++v11;
v10 = crc_c[v14] ^ (v13 >> 8);
}
while ( v11 < a2 );
}
return _byteswap_ulong(~v10);
}

original_code:
unsigned
sctp_checksum(const void *vbuffer, size_t length)
{
    const unsigned char *buffer = (const unsigned char *)vbuffer;
    unsigned i;
    unsigned crc32 = (unsigned)~0;
    unsigned result;
    unsigned char byte0,byte1,byte2,byte3;
    for (i = 0; i < 8; i++) {
        (crc32=(crc32>>8)^crc_c[(crc32^(buffer[i]))&0xFF]);
    }
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    for (i = 12; i < length; i++) {
        (crc32=(crc32>>8)^crc_c[(crc32^(buffer[i]))&0xFF]);
    }
    result = ~crc32;
    byte0 = result & 0xff;
    byte1 = (result>>8) & 0xff;
    byte2 = (result>>16) & 0xff;
    byte3 = (result>>24) & 0xff;
    crc32 = ((byte0 << 24) |
            (byte1 << 16) |
            (byte2 << 8) |
            byte3);
    return ( crc32 );
}

canonical_original_code:
unsigned int sctp_checksum(void *vbuffer, unsigned long length)
{
    unsigned char *buffer = (const unsigned char *)vbuffer;
    unsigned int i;
    unsigned int crc32 = (unsigned)~0;
    unsigned int result;
    unsigned char byte0; unsigned char byte1; unsigned char byte2; unsigned char byte3;
    for (i = 0; i < 8; i++) {
        (crc32=(crc32>>8)^crc_c[(crc32^(buffer[i]))&0xFF]);
    }
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    (crc32=(crc32>>8)^crc_c[(crc32^(0))&0xFF]);
    for (i = 12; i < length; i++) {
        (crc32=(crc32>>8)^crc_c[(crc32^(buffer[i]))&0xFF]);
    }
    result = ~crc32;
    byte0 = result & 0xff;
    byte1 = (result>>8) & 0xff;
    byte2 = (result>>16) & 0xff;
    byte3 = (result>>24) & 0xff;
    crc32 = ((byte0 << 24) |
            (byte1 << 16) |
            (byte2 << 8) |
            byte3);
    return ( crc32 );
}

variable_types:
vbuffer
void *

variable_types:
length
unsigned long

variable_types:
buffer
unsigned char *

variable_types:
i
unsigned int

variable_types:
result
unsigned int

return_type: unsigned int


original_code:
int
sctp_selftest(void)
{
    const char testcase[] =
        "\xd1\x60\x00\x50\x00\x00\x00\x00\x58\xe4\x5d\x36\x01\x00\x00\x14"
        "\x9e\x8d\x52\x25\x00\x00\x80\x00\x00\x0a\x08\x00\x46\x1a\xdf\x3d";
    unsigned xsum;
    xsum = sctp_checksum(testcase, 32);
    if (xsum != 0x58e45d36)
        return 1;
    return 0;
}

canonical_original_code:
int sctp_selftest()
{
    char testcase[] = "\xd1\x60\x00\x50\x00\x00\x00\x00\x58\xe4\x5d\x36\x01\x00\x00\x14"
        "\x9e\x8d\x52\x25\x00\x00\x80\x00\x00\x0a\x08\x00\x46\x1a\xdf\x3d";
    unsigned int xsum;
    xsum = sctp_checksum(testcase, 32);
    if (xsum != 0x58e45d36)
        return 1;
    return 0;
}

variable_types:
testcase
char []

variable_types:
xsum
unsigned int


decompiled_code:
__int16 __fastcall my_htons(__int16 a1)
{
return __ROL2__(a1, 8);
}

canonical_decompiled_code:
__int16 __fastcall func0(__int16 a1)
{
return __ROL2__(a1, 8);
}

original_code:
static unsigned short my_htons(unsigned port)
{
    static const char test[2] = "\x11\x22";
    if (*(unsigned short*)test == 0x1122)
        return (unsigned short)(0xFFFF & port);
    else
        return (unsigned short)((port>>8)&0xFF) | ((port&0xFF)<<8);
}

canonical_original_code:
static unsigned short my_htons(unsigned int port)
{
    static char test[2] = "\x11\x22";
    if (*(unsigned short *)test == 0x1122)
        return (unsigned short)(0xFFFF & port);
    else
        return (unsigned short)((port>>8)&0xFF) | ((port&0xFF)<<8);
}

variable_types:
port
unsigned int

variable_types:
test
char [2]

return_type: unsigned short


decompiled_code:
char *__fastcall tcp_service_name(int a1)
{
char *v1; // rax
unsigned __int16 v2; // ax
int v3; // er8
struct servent *result; // [rsp+8h] [rbp-830h] BYREF
struct servent result_buf; // [rsp+10h] [rbp-828h] BYREF
char buf[2056]; // [rsp+30h] [rbp-808h] BYREF

v1 = (char *)tcp_services[a1];
if ( !v1 )
{
v2 = my_htons(a1);
v3 = getservbyport_r(v2, "tcp", &result_buf, buf, 0x800uLL, &result);
v1 = "unknown";
if ( !v3 )
{
if ( result )
{
v1 = strdup(result_buf.s_name);
tcp_services[a1] = (__int64)v1;
}
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(int a1)
{
char *v1; // rax
unsigned __int16 v2; // ax
int v3; // er8
struct servent *result; // [rsp+8h] [rbp-830h] BYREF
struct servent result_buf; // [rsp+10h] [rbp-828h] BYREF
char buf[2056]; // [rsp+30h] [rbp-808h] BYREF

v1 = (char *)tcp_services[a1];
if ( !v1 )
{
v2 = func0(a1);
v3 = getservbyport_r(v2, "tcp", &result_buf, buf, 0x800uLL, &result);
v1 = "unknown";
if ( !v3 )
{
if ( result )
{
v1 = strdup(result_buf.s_name);
tcp_services[a1] = (__int64)v1;
}
}
}
return v1;
}

original_code:
const char *
tcp_service_name(int port)
{
    if (tcp_services[port])
        return tcp_services[port];
    int r;
    struct servent result_buf;
    struct servent *result;
    char buf[2048];
    r = getservbyport_r(my_htons(port), "tcp", &result_buf,buf, sizeof(buf), &result);
    if (r != 0 || result == ((void *)0))
        return "unknown";
    return tcp_services[port] = strdup(result_buf.s_name);
}

canonical_original_code:
char *tcp_service_name(int port)
{
    if (tcp_services[port])
        return tcp_services[port];
    int r;
    struct servent result_buf;
    struct servent *result;
    char buf[2048];
    r = getservbyport_r(my_htons(port), "tcp", &result_buf,buf, sizeof(buf), &result);
    if (r != 0 || result == ((void *)0))
        return "unknown";
    return tcp_services[port] = strdup(result_buf.s_name);
}

variable_types: port int

variable_types: r int

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; } *

variable_types:
buf
char [2048]

return_type: char *


decompiled_code:
char *__fastcall udp_service_name(int a1)
{
char *v1; // rax
unsigned __int16 v2; // ax
int v3; // er8
struct servent *result; // [rsp+8h] [rbp-830h] BYREF
struct servent result_buf; // [rsp+10h] [rbp-828h] BYREF
char buf[2056]; // [rsp+30h] [rbp-808h] BYREF

v1 = (char *)udp_services[a1];
if ( !v1 )
{
v2 = my_htons(a1);
v3 = getservbyport_r(v2, "udp", &result_buf, buf, 0x800uLL, &result);
v1 = "unknown";
if ( !v3 )
{
if ( result )
{
v1 = strdup(result_buf.s_name);
udp_services[a1] = (__int64)v1;
}
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func2(int a1)
{
char *v1; // rax
unsigned __int16 v2; // ax
int v3; // er8
struct servent *result; // [rsp+8h] [rbp-830h] BYREF
struct servent result_buf; // [rsp+10h] [rbp-828h] BYREF
char buf[2056]; // [rsp+30h] [rbp-808h] BYREF

v1 = (char *)udp_services[a1];
if ( !v1 )
{
v2 = func0(a1);
v3 = getservbyport_r(v2, "udp", &result_buf, buf, 0x800uLL, &result);
v1 = "unknown";
if ( !v3 )
{
if ( result )
{
v1 = strdup(result_buf.s_name);
udp_services[a1] = (__int64)v1;
}
}
}
return v1;
}

original_code:
const char *
udp_service_name(int port)
{
    if (udp_services[port])
        return udp_services[port];
    int r;
    struct servent result_buf;
    struct servent *result;
    char buf[2048];
    r = getservbyport_r(my_htons(port), "udp", &result_buf,buf, sizeof(buf), &result);
    if (r != 0 || result == ((void *)0))
        return "unknown";
    return udp_services[port] = strdup(result_buf.s_name);
}

canonical_original_code:
char *udp_service_name(int port)
{
    if (udp_services[port])
        return udp_services[port];
    int r;
    struct servent result_buf;
    struct servent *result;
    char buf[2048];
    r = getservbyport_r(my_htons(port), "udp", &result_buf,buf, sizeof(buf), &result);
    if (r != 0 || result == ((void *)0))
        return "unknown";
    return udp_services[port] = strdup(result_buf.s_name);
}

variable_types: struct servent { char *s_name; char **s_aliases; int s_port; char *s_proto; }


decompiled_code:
char *__fastcall oproto_service_name(int a1)
{
char *result; // rax
struct protoent *v2; // rdx

result = (char *)oproto_services[a1];
if ( !result )
{
v2 = getprotobynumber(a1);
result = "unknown";
if ( v2 )
{
result = strdup(v2->p_name);
oproto_services[a1] = (__int64)result;
}
}
return result;
}

canonical_decompiled_code:
char *__fastcall func3(int a1)
{
char *result; // rax
struct protoent *v2; // rdx

result = (char *)oproto_services[a1];
if ( !result )
{
v2 = getprotobynumber(a1);
result = "unknown";
if ( v2 )
{
result = strdup(v2->p_name);
oproto_services[a1] = (__int64)result;
}
}
return result;
}

original_code:
const char *
oproto_service_name(int port)
{
    if (oproto_services[port])
        return oproto_services[port];
    {
        struct protoent *result;
        result = getprotobynumber(port);
        if (result == 0)
            return "unknown";
        return oproto_services[port] = strdup(result->p_name);
    }
}

canonical_original_code:
char *oproto_service_name(int port)
{
    if (oproto_services[port])
        return oproto_services[port];
    {
        struct protoent *result;
        result = getprotobynumber(port);
        if (result == 0)
            return "unknown";
        return oproto_services[port] = strdup(result->p_name);
    }
}

variable_types: struct protoent { char *p_name; char **p_aliases; int p_proto; } *


decompiled_code:
_BOOL8 __fastcall rte_ring_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 24) == *(_DWORD *)(a1 + 44);
}

original_code:
static inline int
rte_ring_empty(const struct rte_ring *r)
{
    uint32_t prod_tail = r->prod.tail;
    uint32_t cons_tail = r->cons.tail;
    return !!(cons_tail == prod_tail);
}

canonical_original_code:
static inline int rte_ring_empty(struct rte_ring *r)
{
    unsigned int prod_tail = r->prod.tail;
    unsigned int cons_tail = r->cons.tail;
    return !!(cons_tail == prod_tail);
}

variable_types: struct rte_ring { int flags; struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } prod; struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } cons; void *ring[1]; } *

user_defined_types: struct rte_ring { int flags; struct prod prod; struct cons cons; void *ring[1]; }


decompiled_code:
__int64 __fastcall rte_ring_count(_DWORD *a1)
{
return a1[4] & (unsigned int)(a1[6] - a1[11]);
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
return a1[4] & (unsigned int)(a1[6] - a1[11]);
}

original_code:
static inline unsigned
rte_ring_count(const struct rte_ring *r)
{
    uint32_t prod_tail = r->prod.tail;
    uint32_t cons_tail = r->cons.tail;
    return ((prod_tail - cons_tail) & r->prod.mask);
}

canonical_original_code:
static inline unsigned int rte_ring_count(struct rte_ring *r)
{
    unsigned int prod_tail = r->prod.tail;
    unsigned int cons_tail = r->cons.tail;
    return ((prod_tail - cons_tail) & r->prod.mask);
}

user_defined_types: struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; }

user_defined_types: struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; }


decompiled_code:
__int64 __fastcall rte_ring_free_count(_DWORD *a1)
{
return a1[4] & (unsigned int)(a1[11] - 1 - a1[6]);
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1)
{
return a1[4] & (unsigned int)(a1[11] - 1 - a1[6]);
}

original_code:
static inline unsigned
rte_ring_free_count(const struct rte_ring *r)
{
    uint32_t prod_tail = r->prod.tail;
    uint32_t cons_tail = r->cons.tail;
    return ((cons_tail - prod_tail - 1) & r->prod.mask);
}

canonical_original_code:
static inline unsigned int rte_ring_free_count(struct rte_ring *r)
{
    unsigned int prod_tail = r->prod.tail;
    unsigned int cons_tail = r->cons.tail;
    return ((cons_tail - prod_tail - 1) & r->prod.mask);
}


decompiled_code:
// attributes: thunk
__int64 __fastcall rte_ring_sc_dequeue(_DWORD *a1, _QWORD *a2)
{
return rte_ring_sc_dequeue_bulk_constprop_0(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(_DWORD *a1, _QWORD *a2)
{
return func4(a1, a2);
}

original_code:
static inline int
rte_ring_sc_dequeue(struct rte_ring *r, void **obj_p)
{
    return rte_ring_sc_dequeue_bulk(r, obj_p, 1);
}


decompiled_code:
__int64 __fastcall rte_ring_sp_enqueue(_DWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

v3 = a2;
return rte_ring_sp_enqueue_bulk_constprop_0(a1, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1, __int64 a2)
{
__int64 v3; // [rsp+0h] [rbp-8h] BYREF

v3 = a2;
return func8(a1, &v3);
}

original_code:
static inline int
rte_ring_sp_enqueue(struct rte_ring *r, void *obj)
{
    return rte_ring_sp_enqueue_bulk(r, &obj, 1);
}

variable_types:
obj
void *


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

if ( *(_DWORD *)(a1 + 12) <= a2 )
return 4294967274LL;
if ( !a2 )
a2 = *(_DWORD *)(a1 + 12);
result = 0LL;
*(_DWORD *)(a1 + 4) = a2;
return result;
}

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

if ( *(_DWORD *)(a1 + 12) <= a2 )
return 4294967274LL;
if ( !a2 )
a2 = *(_DWORD *)(a1 + 12);
result = 0LL;
*(_DWORD *)(a1 + 4) = a2;
return result;
}

original_code:
int
rte_ring_set_water_mark(struct rte_ring *r, unsigned count)
{
    if (count >= r->prod.size)
        return -22;
    if (count == 0)
        count = r->prod.size;
    r->prod.watermark = count;
    return 0;
}

canonical_original_code:
int rte_ring_set_water_mark(struct rte_ring *r, unsigned int count)
{
    if (count >= r->prod.size)
        return -22;
    if (count == 0)
        count = r->prod.size;
    r->prod.watermark = count;
    return 0;
}

variable_types:
count
unsigned int


decompiled_code:
int __fastcall rte_ring_dump(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
__int64 v3; // rsi

printf(" flags=%x\n", *a1);
printf(" size=%u\n", a1[3]);
printf(" ct=%u\n", a1[11]);
printf(" ch=%u\n", a1[10]);
printf(" pt=%u\n", a1[6]);
printf(" ph=%u\n", a1[5]);
v1 = rte_ring_count(a1);
printf(" used=%u\n", v1);
v2 = rte_ring_free_count(a1);
printf(" avail=%u\n", v2);
v3 = a1[1];
if ( (_DWORD)v3 == a1[3] )
puts(" watermark=0");
else
printf(" watermark=%u\n", v3);
return puts(" no statistics available");
}

canonical_decompiled_code:
int __fastcall func13(unsigned int *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
__int64 v3; // rsi

printf(" flags=%x\n", *a1);
printf(" size=%u\n", a1[3]);
printf(" ct=%u\n", a1[11]);
printf(" ch=%u\n", a1[10]);
printf(" pt=%u\n", a1[6]);
printf(" ph=%u\n", a1[5]);
v1 = func1(a1);
printf(" used=%u\n", v1);
v2 = func2(a1);
printf(" avail=%u\n", v2);
v3 = a1[1];
if ( (_DWORD)v3 == a1[3] )
puts(" watermark=0");
else
printf(" watermark=%u\n", v3);
return puts(" no statistics available");
}

original_code:
void
rte_ring_dump(const struct rte_ring *r)
{
    printf("  flags=%x\n", r->flags);
    printf("  size=%u\n", r->prod.size);
    printf("  ct=%u\n", r->cons.tail);
    printf("  ch=%u\n", r->cons.head);
    printf("  pt=%u\n", r->prod.tail);
    printf("  ph=%u\n", r->prod.head);
    printf("  used=%u\n", rte_ring_count(r));
    printf("  avail=%u\n", rte_ring_free_count(r));
    if (r->prod.watermark == r->prod.size)
        printf("  watermark=0\n");
    else
        printf("  watermark=%u\n", r->prod.watermark);
    printf("  no statistics available\n");
}

canonical_original_code:
void rte_ring_dump(struct rte_ring *r)
{
    printf("  flags=%x\n", r->flags);
    printf("  size=%u\n", r->prod.size);
    printf("  ct=%u\n", r->cons.tail);
    printf("  ch=%u\n", r->cons.head);
    printf("  pt=%u\n", r->prod.tail);
    printf("  ph=%u\n", r->prod.head);
    printf("  used=%u\n", rte_ring_count(r));
    printf("  avail=%u\n", rte_ring_free_count(r));
    if (r->prod.watermark == r->prod.size)
        printf("  watermark=0\n");
    else
        printf("  watermark=%u\n", r->prod.watermark);
    printf("  no statistics available\n");
}

return_type: void


decompiled_code:
__int64 rte_ring_selftest()
{
int v0; // ebx
__int64 v1; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = 100;
do
{
x_test = (__int64)v3;
v1 = run_test((__int64)v3);
if ( v1 != 500500 )
{
printf("xring: selftest failed with %lu\n", v1);
return 1LL;
}
--v0;
}
while ( v0 );
return 0LL;
}

canonical_decompiled_code:
__int64 func14()
{
int v0; // ebx
__int64 v1; // rax
_BYTE v3[56]; // [rsp+0h] [rbp-38h] BYREF

v0 = 100;
do
{
x_test = (__int64)v3;
v1 = func11((__int64)v3);
if ( v1 != 500500 )
{
printf("xring: selftest failed with %lu\n", v1);
return 1LL;
}
--v0;
}
while ( v0 );
return 0LL;
}

original_code:
int
rte_ring_selftest(void)
{
    unsigned i;
    for (i=0; i<100; i++) {
        uint64_t result;
        struct Test test[1];
        x_test = test;
        result = run_test(test);
        if (result != 500500) {
            printf("xring: selftest failed with %" "l" "u" "\n", result);
            return 1;
        } else
            ;
    }
    return 0;
}

canonical_original_code:
int rte_ring_selftest()
{
    unsigned int i;
    for (i=0; i<100; i++) {
        unsigned long result;
        struct Test test[1];
        x_test = test;
        result = run_test(test);
        if (result != 500500) {
            printf("xring: selftest failed with %" "l" "u" "\n", result);
            return 1;
        } else
            ;
    }
    return 0;
}

variable_types:
result
unsigned long

variable_types: struct Test { struct rte_ring { int flags; struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } prod; struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } cons; void *ring[1]; } *ring; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; unsigned int test_count; } [1]

user_defined_types: struct Test { struct rte_ring *ring; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; unsigned int test_count; }


decompiled_code:
_BOOL8 __fastcall test_consumer_thread(__int64 a1)
{
_DWORD *v2; // rdi
_BOOL8 result; // rax
__int64 v4; // r8
__int64 v5; // r8
__int64 v6; // [rsp+8h] [rbp-8h] BYREF

v2 = *(_DWORD **)a1;
*(_QWORD *)(a1 + 24) = 0LL;
while ( !*(_DWORD *)(a1 + 32) )
{
while ( !(unsigned int)rte_ring_sc_dequeue(v2, &v6) )
{
*(_QWORD *)(a1 + 24) += v6;
if ( *(_DWORD *)(a1 + 32) )
goto LABEL_5;
}
}
LABEL_5:
while ( 1 )
{
result = rte_ring_empty((__int64)v2);
if ( result )
break;
while ( !(unsigned int)rte_ring_sc_dequeue(v2, &v6) )
{
*(_QWORD *)(v5 + 24) += v6;
result = rte_ring_empty((__int64)v2);
if ( result )
goto LABEL_8;
}
}
LABEL_8:
*(_DWORD *)(v4 + 16) = 1;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(__int64 a1)
{
_DWORD *v2; // rdi
_BOOL8 result; // rax
__int64 v4; // r8
__int64 v5; // r8
__int64 v6; // [rsp+8h] [rbp-8h] BYREF

v2 = *(_DWORD **)a1;
*(_QWORD *)(a1 + 24) = 0LL;
while ( !*(_DWORD *)(a1 + 32) )
{
while ( !(unsigned int)func5(v2, &v6) )
{
*(_QWORD *)(a1 + 24) += v6;
if ( *(_DWORD *)(a1 + 32) )
goto LABEL_5;
}
}
LABEL_5:
while ( 1 )
{
result = func0((__int64)v2);
if ( result )
break;
while ( !(unsigned int)func5(v2, &v6) )
{
*(_QWORD *)(v5 + 24) += v6;
result = func0((__int64)v2);
if ( result )
goto LABEL_8;
}
}
LABEL_8:
*(_DWORD *)(v4 + 16) = 1;
return result;
}

original_code:
static void
test_consumer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    struct rte_ring *ring = test->ring;
    int err;
    test->total_count = 0;
    while (!test->not_active) {
        Element e;
        err = rte_ring_sc_dequeue(ring, (void**)&e);
        if (err == 0)
            test->total_count += e;
        else {
            ;
        }
    }
    while (!rte_ring_empty(ring)) {
        Element e;
        err = rte_ring_sc_dequeue(ring, (void**)&e);
        if (err == 0)
            test->total_count += e;
        else {
            ;
        }
    }
    test->consumer_done = 1;
}

canonical_original_code:
static void test_consumer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    struct rte_ring *ring = test->ring;
    int err;
    test->total_count = 0;
    while (!test->not_active) {
        unsigned long e;
        err = rte_ring_sc_dequeue(ring, (void **)&e);
        if (err == 0)
            test->total_count += e;
        else {
            ;
        }
    }
    while (!rte_ring_empty(ring)) {
        unsigned long e;
        err = rte_ring_sc_dequeue(ring, (void **)&e);
        if (err == 0)
            test->total_count += e;
        else {
            ;
        }
    }
    test->consumer_done = 1;
}

variable_types:
v
void *

variable_types: struct Test { struct rte_ring { int flags; struct prod { unsigned int watermark; unsigned int sp_enqueue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } prod; struct cons { unsigned int sc_dequeue; unsigned int size; unsigned int mask; unsigned int head; unsigned int tail; } cons; void *ring[1]; } *ring; unsigned int producer_started; unsigned int producer_done; unsigned int consumer_done; unsigned long long total_count; int not_active; unsigned int test_count; } *

variable_types: err int

variable_types:
e
unsigned long


decompiled_code:
__int64 __fastcall test_producer_thread(__int64 a1)
{
_DWORD *v2; // rdi
__int64 v3; // r10
__int64 result; // rax
__int64 v5; // r11

v2 = *(_DWORD **)a1;
_InterlockedAdd((volatile signed __int32 *)(a1 + 8), 1u);
v3 = 1000LL;
do
{
do
result = rte_ring_sp_enqueue(v2, v3);
while ( (_DWORD)result );
--v3;
}
while ( v3 );
_InterlockedAdd((volatile signed __int32 *)(v5 + 12), 1u);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
_DWORD *v2; // rdi
__int64 v3; // r10
__int64 result; // rax
__int64 v5; // r11

v2 = *(_DWORD **)a1;
_InterlockedAdd((volatile signed __int32 *)(a1 + 8), 1u);
v3 = 1000LL;
do
{
do
result = func9(v2, v3);
while ( (_DWORD)result );
--v3;
}
while ( v3 );
_InterlockedAdd((volatile signed __int32 *)(v5 + 12), 1u);
return result;
}

original_code:
static void
test_producer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    unsigned i = 1000;
    struct rte_ring *ring = test->ring;
    __sync_add_and_fetch((volatile int*)(&test->producer_started), (int)(1));;
    while (i) {
        int err;
        for (;;) {
            err = rte_ring_sp_enqueue(ring, (void*)(size_t)i);
            if (err == 0)
                break;
        }
        i--;
    }
    __sync_add_and_fetch((volatile int*)(&test->producer_done), (int)(1));;
}

canonical_original_code:
static void test_producer_thread(void *v)
{
    struct Test *test = (struct Test *)v;
    unsigned int i = 1000;
    struct rte_ring *ring = test->ring;
    __sync_add_and_fetch((int *)(&test->producer_started), (int)(1));;
    while (i) {
        int err;
        for (;;) {
            err = rte_ring_sp_enqueue(ring, (void *)(unsigned long)i);
            if (err == 0)
                break;
        }
        i--;
    }
    __sync_add_and_fetch((int *)(&test->producer_done), (int)(1));;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall run_test(__int64 a1)
{
int v1; // edx

*(_QWORD *)(a1 + 32) = 0LL;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
*(_QWORD *)a1 = rte_ring_create(0x10u, 3u);
pixie_begin_thread(test_producer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 8) )
pixie_usleep(10LL);
pixie_begin_thread(test_consumer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 12) )
pixie_usleep(10LL);
v1 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 32) = 1;
if ( !v1 )
{
do
pixie_usleep(10LL);
while ( !*(_DWORD *)(a1 + 16) );
}
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
int v1; // edx

*(_QWORD *)(a1 + 32) = 0LL;
*(_OWORD *)a1 = 0LL;
*(_OWORD *)(a1 + 16) = 0LL;
*(_QWORD *)a1 = rte_ring_create(0x10u, 3u);
pixie_begin_thread(test_producer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 8) )
pixie_usleep(10LL);
pixie_begin_thread(test_consumer_thread, 0LL, a1);
while ( !*(_DWORD *)(a1 + 12) )
pixie_usleep(10LL);
v1 = *(_DWORD *)(a1 + 16);
*(_DWORD *)(a1 + 32) = 1;
if ( !v1 )
{
do
pixie_usleep(10LL);
while ( !*(_DWORD *)(a1 + 16) );
}
return *(_QWORD *)(a1 + 24);
}

original_code:
static uint64_t
run_test(struct Test *test)
{
    unsigned i;
    const unsigned THREADS = 1;
    memset(test, 0, sizeof(*test));
    test->ring = rte_ring_create(16, 0x0001|0x0002);
    for (i=0; i<THREADS; i++) {
        pixie_begin_thread(test_producer_thread, 0, test);
    }
    while (test->producer_started < THREADS)
        pixie_usleep(10);
    pixie_begin_thread(test_consumer_thread, 0, test);
    while (test->producer_done < THREADS)
        pixie_usleep(10);
    test->not_active = 1;
    while (!test->consumer_done)
        pixie_usleep(10);
    return test->total_count;
}

canonical_original_code:
static unsigned long run_test(struct Test *test)
{
    unsigned int i;
    unsigned int THREADS = 1;
    memset(test, 0, sizeof(*test));
    test->ring = rte_ring_create(16, 0x0001|0x0002);
    for (i=0; i<THREADS; i++) {
        pixie_begin_thread(test_producer_thread, 0, test);
    }
    while (test->producer_started < THREADS)
        pixie_usleep(10);
    pixie_begin_thread(test_consumer_thread, 0, test);
    while (test->producer_done < THREADS)
        pixie_usleep(10);
    test->not_active = 1;
    while (!test->consumer_done)
        pixie_usleep(10);
    return test->total_count;
}

variable_types:
THREADS
unsigned int


REALLOCARRAY

decompiled_code:
void *__fastcall REALLOCARRAY(void *a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rbx
void *result; // rax

if ( (a3 > 0xFFFFFFFF || a2 > 0xFFFFFFFF) && a3 && 0xFFFFFFFFFFFFFFFFLL / a3 <= a2 )
{
fwrite("[-] alloc too large, aborting\n", 1uLL, 0x1EuLL, stderr);
abort();
}
v3 = a2 * a3;
result = realloc(a1, a2 * a3);
if ( !result )
{
if ( v3 )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(void *a1, unsigned __int64 a2, unsigned __int64 a3)
{
unsigned __int64 v3; // rbx
void *result; // rax

if ( (a3 > 0xFFFFFFFF || a2 > 0xFFFFFFFF) && a3 && 0xFFFFFFFFFFFFFFFFLL / a3 <= a2 )
{
fwrite("[-] alloc too large, aborting\n", 1uLL, 0x1EuLL, stderr);
abort();
}
v3 = a2 * a3;
result = realloc(a1, a2 * a3);
if ( !result )
{
if ( v3 )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
}
return result;
}

original_code:
void *
REALLOCARRAY(void *p, size_t count, size_t size)
{
    if (count >= ((size_t)1 << (sizeof(size_t)*4)) || size >= ((size_t)1 << (sizeof(size_t)*4))) {
        if (size != 0 && count >= (18446744073709551615UL)/size) {
            fprintf(stderr, "[-] alloc too large, aborting\n");
            abort();
        }
    }
    p = realloc(p, count * size);
    if (p == ((void *)0) && count * size != 0) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}

canonical_original_code:
void *REALLOCARRAY(void *p, unsigned long count, unsigned long size)
{
    if (count >= ((unsigned long)1 << (sizeof(unsigned long)*4)) || size >= ((unsigned long)1 << (sizeof(unsigned long)*4))) {
        if (size != 0 && count >= (18446744073709551615UL)/size) {
            fprintf(stderr, "[-] alloc too large, aborting\n");
            abort();
        }
    }
    p = realloc(p, count * size);
    if (p == ((void *)0) && count * size != 0) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}

variable_types:
p
void *

variable_types:
count
unsigned long

variable_types:
size
unsigned long

return_type: void *


CALLOC

decompiled_code:
void *__fastcall CALLOC(size_t nmemb, size_t size)
{
void *result; // rax

if ( (size > 0xFFFFFFFF || nmemb > 0xFFFFFFFF) && size && 0xFFFFFFFFFFFFFFFFLL / size <= nmemb )
{
fwrite("[-] alloc too large, aborting\n", 1uLL, 0x1EuLL, stderr);
abort();
}
result = calloc(nmemb, size);
if ( !result )
{
if ( nmemb * size )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t nmemb, size_t size)
{
void *result; // rax

if ( (size > 0xFFFFFFFF || nmemb > 0xFFFFFFFF) && size && 0xFFFFFFFFFFFFFFFFLL / size <= nmemb )
{
fwrite("[-] alloc too large, aborting\n", 1uLL, 0x1EuLL, stderr);
abort();
}
result = calloc(nmemb, size);
if ( !result )
{
if ( nmemb * size )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
}
return result;
}

original_code:
void *
CALLOC(size_t count, size_t size)
{
    void *p;
    if (count >= ((size_t)1 << (sizeof(size_t)*4)) || size >= ((size_t)1 << (sizeof(size_t)*4))) {
        if (size != 0 && count >= (18446744073709551615UL)/size) {
            fprintf(stderr, "[-] alloc too large, aborting\n");
            abort();
        }
    }
    p = calloc(count, size);
    if (p == ((void *)0) && count * size != 0) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}

canonical_original_code:
void *CALLOC(unsigned long count, unsigned long size)
{
    void *p;
    if (count >= ((unsigned long)1 << (sizeof(unsigned long)*4)) || size >= ((unsigned long)1 << (sizeof(unsigned long)*4))) {
        if (size != 0 && count >= (18446744073709551615UL)/size) {
            fprintf(stderr, "[-] alloc too large, aborting\n");
            abort();
        }
    }
    p = calloc(count, size);
    if (p == ((void *)0) && count * size != 0) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}


MALLOC

decompiled_code:
void *__fastcall MALLOC(size_t a1)
{
void *result; // rax

if ( !a1 )
a1 = 1LL;
result = malloc(a1);
if ( !result )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func2(size_t a1)
{
void *result; // rax

if ( !a1 )
a1 = 1LL;
result = malloc(a1);
if ( !result )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
return result;
}

original_code:
void *
MALLOC(size_t size)
{
    void *p;
    if (size == 0)
        size = 1;
    p = malloc(size);
    if (p == ((void *)0)) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}

canonical_original_code:
void *MALLOC(unsigned long size)
{
    void *p;
    if (size == 0)
        size = 1;
    p = malloc(size);
    if (p == ((void *)0)) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}


REALLOC

decompiled_code:
void *__fastcall REALLOC(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
return result;
}

original_code:
void *
REALLOC(void *p, size_t size)
{
    p = realloc(p, size);
    if (p == ((void *)0)) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}

canonical_original_code:
void *REALLOC(void *p, unsigned long size)
{
    p = realloc(p, size);
    if (p == ((void *)0)) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}


STRDUP

decompiled_code:
char *__fastcall STRDUP(const char *a1)
{
char *result; // rax

result = strdup(a1);
if ( !result )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
return result;
}

canonical_decompiled_code:
char *__fastcall func4(const char *a1)
{
char *result; // rax

result = strdup(a1);
if ( !result )
{
fwrite("[-] out of memory, aborting\n", 1uLL, 0x1CuLL, stderr);
abort();
}
return result;
}

original_code:
char *
STRDUP(const char *str)
{
    char *p = strdup(str);
    if (p == ((void *)0) && str != ((void *)0)) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}

canonical_original_code:
char *STRDUP(char *str)
{
    char *p = strdup(str);
    if (p == ((void *)0) && str != ((void *)0)) {
        fprintf(stderr, "[-] out of memory, aborting\n");
        abort();
    }
    return p;
}

variable_types:
str
char *

variable_types:
p
char *


READ

decompiled_code:
unsigned __int64 __fastcall READ(char a1, __int64 a2, __int64 a3)
{
char v3; // cl
__int64 v4; // rsi

v3 = a3 ^ a1;
v4 = __ROL8__(a3, a1) ^ a2;
return ((unsigned __int64)(((unsigned __int8)sbox[(unsigned __int8)(v3 ^ HIBYTE(v4))] << 24) | ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE6(v4))] << 16)) << 33) ^ ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ v4)] | ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE1(v4))] << 8)) ^ ((__int64)((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE4(v4))] | ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE5(v4))] << 8)) << 23) ^ (((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE3(v4))] << 24) | ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE2(v4))] << 16));
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(char a1, __int64 a2, __int64 a3)
{
char v3; // cl
__int64 v4; // rsi

v3 = a3 ^ a1;
v4 = __ROL8__(a3, a1) ^ a2;
return ((unsigned __int64)(((unsigned __int8)sbox[(unsigned __int8)(v3 ^ HIBYTE(v4))] << 24) | ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE6(v4))] << 16)) << 33) ^ ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ v4)] | ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE1(v4))] << 8)) ^ ((__int64)((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE4(v4))] | ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE5(v4))] << 8)) << 23) ^ (((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE3(v4))] << 24) | ((unsigned __int8)sbox[(unsigned __int8)(v3 ^ BYTE2(v4))] << 16));
}

canonical_original_code:
static inline unsigned long READ(unsigned long r, unsigned long R, unsigned long seed)
{
    unsigned long r0; unsigned long r1; unsigned long r2; unsigned long r3;
    R ^= (seed << r) ^ (seed >> (64 - r));
    r0 = sbox[((((R)>>(0*8))^seed^r)&0xFF)]<< 0 | sbox[((((R)>>(1*8))^seed^r)&0xFF)]<< 8;
    r1 = (sbox[((((R)>>(2*8))^seed^r)&0xFF)]<<16UL | sbox[((((R)>>(3*8))^seed^r)&0xFF)]<<24UL)&0x0ffffFFFFUL;
    r2 = sbox[((((R)>>(4*8))^seed^r)&0xFF)]<< 0 | sbox[((((R)>>(5*8))^seed^r)&0xFF)]<< 8;
    r3 = (sbox[((((R)>>(6*8))^seed^r)&0xFF)]<<16UL | sbox[((((R)>>(7*8))^seed^r)&0xFF)]<<24UL)&0x0ffffFFFFUL;
    R = r0 ^ r1 ^ r2<<23UL ^ r3<<33UL;
    return R;
}

variable_types:
r
unsigned long

variable_types:
R
unsigned long

variable_types:
seed
unsigned long


UNENCRYPT

original_code:
static inline uint64_t
UNENCRYPT(unsigned r, uint64_t a, uint64_t b, uint64_t m, uint64_t seed)
{
    uint64_t L, R;
    unsigned j;
    uint64_t tmp;
    if (r & 1) {
        R = m % a;
        L = m / a;
    } else {
        L = m % a;
        R = m / a;
    }
    for (j=r; j>=1; j--) {
        if (j & 1) {
            tmp = READ(j, L, seed);
            if (tmp > R) {
                tmp = (tmp - R);
                tmp = a - (tmp%a);
                if (tmp == a)
                    tmp = 0;
            } else {
                tmp = (R - tmp);
                tmp %= a;
            }
        } else {
            tmp = READ(j, L, seed);
            if (tmp > R) {
                tmp = (tmp - R);
                tmp = b - (tmp%b);
                if (tmp == b)
                    tmp = 0;
            } else {
                tmp = (R - tmp);
                tmp %= b;
            }
        }
        R = L;
        L = tmp;
    }
    return a * R + L;
}

canonical_original_code:
static inline unsigned long UNENCRYPT(unsigned int r, unsigned long a, unsigned long b, unsigned long m, unsigned long seed)
{
    unsigned long L; unsigned long R;
    unsigned int j;
    unsigned long tmp;
    if (r & 1) {
        R = m % a;
        L = m / a;
    } else {
        L = m % a;
        R = m / a;
    }
    for (j=r; j>=1; j--) {
        if (j & 1) {
            tmp = READ(j, L, seed);
            if (tmp > R) {
                tmp = (tmp - R);
                tmp = a - (tmp%a);
                if (tmp == a)
                    tmp = 0;
            } else {
                tmp = (R - tmp);
                tmp %= a;
            }
        } else {
            tmp = READ(j, L, seed);
            if (tmp > R) {
                tmp = (tmp - R);
                tmp = b - (tmp%b);
                if (tmp == b)
                    tmp = 0;
            } else {
                tmp = (R - tmp);
                tmp %= b;
            }
        }
        R = L;
        L = tmp;
    }
    return a * R + L;
}

variable_types:
r
unsigned int

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
m
unsigned long

variable_types:
L
unsigned long

variable_types:
j
unsigned int

variable_types:
tmp
unsigned long


original_code:
void
blackrock_init(struct BlackRock *br, uint64_t range, uint64_t seed, unsigned rounds)
{
    double foo = sqrt(range * 1.0);
    switch (range) {
        case 0:
            br->a = 0;
            br->b = 0;
            break;
        case 1:
            br->a = 1;
            br->b = 1;
            break;
        case 2:
            br->a = 1;
            br->b = 2;
            break;
        case 3:
            br->a = 2;
            br->b = 2;
            break;
        case 4:
        case 5:
        case 6:
            br->a = 2;
            br->b = 3;
            break;
        case 7:
        case 8:
            br->a = 3;
            br->b = 3;
            break;
        default:
            br->range = range;
            br->a = (uint64_t)(foo - 2);
            br->b = (uint64_t)(foo + 3);
            break;
    }
    while (br->a * br->b <= range)
        br->b++;
    br->rounds = rounds;
    br->seed = seed;
    br->range = range;
}

canonical_original_code:
void blackrock_init(struct BlackRock *br, unsigned long range, unsigned long seed, unsigned int rounds)
{
    double foo = sqrt(range * 1.0);
    switch (range) {
        case 0:
            br->a = 0;
            br->b = 0;
            break;
        case 1:
            br->a = 1;
            br->b = 1;
            break;
        case 2:
            br->a = 1;
            br->b = 2;
            break;
        case 3:
            br->a = 2;
            br->b = 2;
            break;
        case 4:
        case 5:
        case 6:
            br->a = 2;
            br->b = 3;
            break;
        case 7:
        case 8:
            br->a = 3;
            br->b = 3;
            break;
        default:
            br->range = range;
            br->a = (unsigned long)(foo - 2);
            br->b = (unsigned long)(foo + 3);
            break;
    }
    while (br->a * br->b <= range)
        br->b++;
    br->rounds = rounds;
    br->seed = seed;
    br->range = range;
}

variable_types: struct BlackRock { unsigned long range; unsigned long a; unsigned long b; unsigned long seed; unsigned int rounds; unsigned long a_bits; unsigned long a_mask; unsigned long b_bits; unsigned long b_mask; } *

variable_types:
range
unsigned long

variable_types:
rounds
unsigned int

variable_types: foo double


decompiled_code:
unsigned __int64 __fastcall blackrock_shuffle(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r13
unsigned __int64 v3; // r12
unsigned int v4; // ebp
__int64 v5; // rax
__int64 v6; // r8
unsigned __int64 v7; // rbx
unsigned __int64 i; // rcx

v2 = *(_QWORD *)(a1 + 16);
v3 = *(_QWORD *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 32);
v5 = ENCRYPT(v4, v3, v2, a2, *(_QWORD *)(a1 + 24));
v7 = *(_QWORD *)a1;
for ( i = v5; i >= v7; i = ENCRYPT(v4, v3, v2, i, v6) )
;
return i;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r13
unsigned __int64 v3; // r12
unsigned int v4; // ebp
__int64 v5; // rax
__int64 v6; // r8
unsigned __int64 v7; // rbx
unsigned __int64 i; // rcx

v2 = *(_QWORD *)(a1 + 16);
v3 = *(_QWORD *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 32);
v5 = func1(v4, v3, v2, a2, *(_QWORD *)(a1 + 24));
v7 = *(_QWORD *)a1;
for ( i = v5; i >= v7; i = func1(v4, v3, v2, i, v6) )
;
return i;
}

original_code:
uint64_t
blackrock_shuffle(const struct BlackRock *br, uint64_t m)
{
    uint64_t c;
    c = ENCRYPT(br->rounds, br->a, br->b, m, br->seed);
    while (c >= br->range)
        c = ENCRYPT(br->rounds, br->a, br->b, c, br->seed);
    return c;
}

canonical_original_code:
unsigned long blackrock_shuffle(struct BlackRock *br, unsigned long m)
{
    unsigned long c;
    c = ENCRYPT(br->rounds, br->a, br->b, m, br->seed);
    while (c >= br->range)
        c = ENCRYPT(br->rounds, br->a, br->b, c, br->seed);
    return c;
}

variable_types:
c
unsigned long

user_defined_types: struct BlackRock { unsigned long range; unsigned long a; unsigned long b; unsigned long seed; unsigned int rounds; unsigned long a_bits; unsigned long a_mask; unsigned long b_bits; unsigned long b_mask; }


decompiled_code:
__int64 __fastcall blackrock_verify(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // r13
_BYTE *v4; // rbp
unsigned __int64 i; // r15
unsigned __int64 v6; // rax
_BYTE *v7; // rax
_BYTE *v8; // r12
unsigned int v9; // er13

v2 = a2;
v3 = *a1;
if ( *a1 <= a2 )
v2 = *a1;
v4 = (_BYTE *)CALLOC(1LL, v2);
if ( !v3 )
goto LABEL_14;
for ( i = 0LL; i != v3; ++i )
{
v6 = blackrock_shuffle((__int64)a1, i);
if ( a2 > v6 )
++v4[v6];
}
if ( v2 )
{
v7 = v4;
v8 = &v4[v2];
v9 = 1;
do
{
if ( *v7 != 1 )
v9 = 0;
++v7;
}
while ( v7 != v8 );
}
else
{
LABEL_14:
v9 = 1;
}
free(v4);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1, unsigned __int64 a2)
{
unsigned __int64 v2; // r12
unsigned __int64 v3; // r13
_BYTE *v4; // rbp
unsigned __int64 i; // r15
unsigned __int64 v6; // rax
_BYTE *v7; // rax
_BYTE *v8; // r12
unsigned int v9; // er13

v2 = a2;
v3 = *a1;
if ( *a1 <= a2 )
v2 = *a1;
v4 = (_BYTE *)CALLOC(1LL, v2);
if ( !v3 )
goto LABEL_14;
for ( i = 0LL; i != v3; ++i )
{
v6 = func4((__int64)a1, i);
if ( a2 > v6 )
++v4[v6];
}
if ( v2 )
{
v7 = v4;
v8 = &v4[v2];
v9 = 1;
do
{
if ( *v7 != 1 )
v9 = 0;
++v7;
}
while ( v7 != v8 );
}
else
{
LABEL_14:
v9 = 1;
}
free(v4);
return v9;
}

original_code:
static unsigned
blackrock_verify(struct BlackRock *br, uint64_t max)
{
    unsigned char *list;
    uint64_t i;
    unsigned is_success = 1;
    uint64_t range = br->range;
    list = CALLOC(1, (size_t)((range<max)?range:max));
    for (i=0; i<range; i++) {
        uint64_t x = blackrock_shuffle(br, i);
        if (x < max)
            list[x]++;
    }
    for (i=0; i<max && i<range; i++) {
        if (list[i] != 1)
            is_success = 0;
    }
    free(list);
    return is_success;
}

canonical_original_code:
static unsigned int blackrock_verify(struct BlackRock *br, unsigned long max)
{
    unsigned char *list;
    unsigned long i;
    unsigned int is_success = 1;
    unsigned long range = br->range;
    list = CALLOC(1, (unsigned long)((range<max)?range:max));
    for (i=0; i<range; i++) {
        unsigned long x = blackrock_shuffle(br, i);
        if (x < max)
            list[x]++;
    }
    for (i=0; i<max && i<range; i++) {
        if (list[i] != 1)
            is_success = 0;
    }
    free(list);
    return is_success;
}

variable_types:
max
unsigned long

variable_types:
list
unsigned char *

variable_types:
i
unsigned long

variable_types:
x
unsigned long


decompiled_code:
unsigned __int64 __fastcall blackrock_unshuffle(__int64 a1, unsigned __int64 a2)
{
__int64 v2; // r13
unsigned __int64 v3; // r12
int v4; // ebp
__int64 v5; // rax
__int64 v6; // r8
unsigned __int64 v7; // rbx
unsigned __int64 i; // rcx

v2 = *(_QWORD *)(a1 + 16);
v3 = *(_QWORD *)(a1 + 8);
v4 = *(_DWORD *)(a1 + 32);
v5 = UNENCRYPT(v4, v3, v2, a2, *(_QWORD *)(a1 + 24));
v7 = *(_QWORD *)a1;
for ( i = v5; i >= v7; i = UNENCRYPT(v4, v3, v2, i, v6) )
;
return i;
}

original_code:
uint64_t
blackrock_unshuffle(const struct BlackRock *br, uint64_t m)
{
    uint64_t c;
    c = UNENCRYPT(br->rounds, br->a, br->b, m, br->seed);
    while (c >= br->range)
        c = UNENCRYPT(br->rounds, br->a, br->b, c, br->seed);
    return c;
}

canonical_original_code:
unsigned long blackrock_unshuffle(struct BlackRock *br, unsigned long m)
{
    unsigned long c;
    c = UNENCRYPT(br->rounds, br->a, br->b, m, br->seed);
    while (c >= br->range)
        c = UNENCRYPT(br->rounds, br->a, br->b, c, br->seed);
    return c;
}


decompiled_code:
int __fastcall blackrock_benchmark(unsigned int a1)
{
__int64 v1; // rbp
unsigned __int64 v2; // rbx
__int64 v3; // r12
unsigned __int64 v4; // rsi
__int64 v5; // rax
__int64 v7; // rax
double v8; // xmm1_8
_BYTE v9[104]; // [rsp+0h] [rbp-68h] BYREF

v1 = 0LL;
v2 = 0LL;
puts("-- blackrock-1 -- ");
printf("rounds = %u\n", a1);
blackrock_init((__int64)v9, 0x12356789123uLL, 1LL, a1);
v3 = pixie_nanotime();
do
{
v4 = v2++;
v1 += blackrock_shuffle((__int64)v9, v4);
}
while ( v2 != 5000000 );
v5 = pixie_nanotime();
if ( v1 )
{
v7 = v5 - v3;
if ( v7 < 0 )
v8 = (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1)) + (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1));
else
v8 = (double)(int)v7;
printf("iterations/second = %5.3f-million\n", 5000000.0 / (v8 / 1000000000.0) / 1000000.0);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
__int64 v1; // rbp
unsigned __int64 v2; // rbx
__int64 v3; // r12
unsigned __int64 v4; // rsi
__int64 v5; // rax
__int64 v7; // rax
double v8; // xmm1_8
_BYTE v9[104]; // [rsp+0h] [rbp-68h] BYREF

v1 = 0LL;
v2 = 0LL;
puts("-- blackrock-1 -- ");
printf("rounds = %u\n", a1);
func3((__int64)v9, 0x12356789123uLL, 1LL, a1);
v3 = pixie_nanotime();
do
{
v4 = v2++;
v1 += func4((__int64)v9, v4);
}
while ( v2 != 5000000 );
v5 = pixie_nanotime();
if ( v1 )
{
v7 = v5 - v3;
if ( v7 < 0 )
v8 = (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1)) + (double)(int)(v7 & 1 | ((unsigned __int64)v7 >> 1));
else
v8 = (double)(int)v7;
printf("iterations/second = %5.3f-million\n", 5000000.0 / (v8 / 1000000000.0) / 1000000.0);
}
return putchar(10);
}

original_code:
void
blackrock_benchmark(unsigned rounds)
{
    struct BlackRock br;
    uint64_t range = 0x012356789123ULL;
    uint64_t i;
    uint64_t result = 0;
    uint64_t start, stop;
    static const uint64_t ITERATIONS = 5000000ULL;
    printf("-- blackrock-1 -- \n");
    printf("rounds = %u\n", rounds);
    blackrock_init(&br, range, 1, rounds);
    start = pixie_nanotime();
    for (i=0; i<ITERATIONS; i++) {
        result += blackrock_shuffle(&br, i);
    }
    stop = pixie_nanotime();
    if (result) {
        double elapsed = ((double)(stop - start))/(1000000000.0);
        double rate = ITERATIONS/elapsed;
        rate /= 1000000.0;
        printf("iterations/second = %5.3f-million\n", rate);
    }
    printf("\n");
}

canonical_original_code:
void blackrock_benchmark(unsigned int rounds)
{
    struct BlackRock br;
    unsigned long range = 0x012356789123ULL;
    unsigned long i;
    unsigned long result = 0;
    unsigned long start; unsigned long stop;
    static unsigned long ITERATIONS = 5000000ULL;
    printf("-- blackrock-1 -- \n");
    printf("rounds = %u\n", rounds);
    blackrock_init(&br, range, 1, rounds);
    start = pixie_nanotime();
    for (i=0; i<ITERATIONS; i++) {
        result += blackrock_shuffle(&br, i);
    }
    stop = pixie_nanotime();
    if (result) {
        double elapsed = ((double)(stop - start))/(1000000000.0);
        double rate = ITERATIONS/elapsed;
        rate /= 1000000.0;
        printf("iterations/second = %5.3f-million\n", rate);
    }
    printf("\n");
}

variable_types: struct BlackRock { unsigned long range; unsigned long a; unsigned long b; unsigned long seed; unsigned int rounds; unsigned long a_bits; unsigned long a_mask; unsigned long b_bits; unsigned long b_mask; }

variable_types:
result
unsigned long

variable_types:
start
unsigned long

variable_types:
stop
unsigned long

variable_types:
ITERATIONS
unsigned long

variable_types: elapsed double

variable_types: rate double


decompiled_code:
__int64 blackrock_selftest()
{
unsigned __int64 v0; // rbx
unsigned __int64 v1; // rax
unsigned __int64 v2; // rbp
__int64 v3; // rax
unsigned __int64 v5[13]; // [rsp+0h] [rbp-68h] BYREF

v0 = 0LL;
blackrock_init((__int64)v5, 0x3E8uLL, 0LL, 4);
while ( 1 )
{
v1 = blackrock_shuffle((__int64)v5, v0);
if ( blackrock_unshuffle((__int64)v5, v1) != v0 )
break;
if ( ++v0 == 10 )
{
v2 = 9045LL;
while ( 1 )
{
v3 = time(0LL);
v2 = 2 * (v0 + v2);
blackrock_init((__int64)v5, v2, v3, 4);
if ( !(unsigned int)blackrock_verify(v5, v2) )
break;
if ( ++v0 == 15 )
return 0LL;
}
fwrite("BLACKROCK: randomization failed\n", 1uLL, 0x20uLL, stderr);
return 1LL;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned __int64 v0; // rbx
unsigned __int64 v1; // rax
unsigned __int64 v2; // rbp
__int64 v3; // rax
unsigned __int64 v5[13]; // [rsp+0h] [rbp-68h] BYREF

v0 = 0LL;
func3((__int64)v5, 0x3E8uLL, 0LL, 4);
while ( 1 )
{
v1 = func4((__int64)v5, v0);
if ( func6((__int64)v5, v1) != v0 )
break;
if ( ++v0 == 10 )
{
v2 = 9045LL;
while ( 1 )
{
v3 = time(0LL);
v2 = 2 * (v0 + v2);
func3((__int64)v5, v2, v3, 4);
if ( !(unsigned int)func5(v5, v2) )
break;
if ( ++v0 == 15 )
return 0LL;
}
fwrite("BLACKROCK: randomization failed\n", 1uLL, 0x20uLL, stderr);
return 1LL;
}
}
return 1LL;
}

original_code:
int
blackrock_selftest(void)
{
    uint64_t i;
    uint64_t range;
    {
        struct BlackRock br;
        blackrock_init(&br, 1000, 0, 4);
        for (i=0; i<10; i++) {
            uint64_t result, result2;
            result = blackrock_shuffle(&br, i);
            result2 = blackrock_unshuffle(&br, result);
            if (i != result2)
                return 1;
        }
    }
    range = 3015 * 3;
    for (i=0; i<5; i++) {
        struct BlackRock br;
        int is_success;
        range += 10 + i;
        range *= 2;
        blackrock_init(&br, range, time(0), 4);
        is_success = blackrock_verify(&br, range);
        if (!is_success) {
            fprintf(stderr, "BLACKROCK: randomization failed\n");
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int blackrock_selftest()
{
    unsigned long i;
    unsigned long range;
    {
        struct BlackRock br;
        blackrock_init(&br, 1000, 0, 4);
        for (i=0; i<10; i++) {
            unsigned long result; unsigned long result2;
            result = blackrock_shuffle(&br, i);
            result2 = blackrock_unshuffle(&br, result);
            if (i != result2)
                return 1;
        }
    }
    range = 3015 * 3;
    for (i=0; i<5; i++) {
        struct BlackRock br;
        int is_success;
        range += 10 + i;
        range *= 2;
        blackrock_init(&br, range, time(0), 4);
        is_success = blackrock_verify(&br, range);
        if (!is_success) {
            fprintf(stderr, "BLACKROCK: randomization failed\n");
            return 1;
        }
    }
    return 0;
}


ENCRYPT

decompiled_code:
__int64 __fastcall ENCRYPT(unsigned int a1, unsigned __int64 a2, unsigned __int64 a3, unsigned __int64 a4, __int64 a5)
{
__int64 v7; // r10
unsigned __int64 v8; // r12
unsigned int v9; // er9
unsigned __int64 v10; // rax
unsigned __int64 v11; // r10
int v12; // er9
unsigned __int64 v13; // rax
__int64 v14; // rdx
unsigned __int64 v15; // rax
int v16; // er9
unsigned __int64 v17; // rax

v7 = a4 / a2;
if ( !a1 )
{
v14 = a4 / a2;
v11 = a4 % a2;
return a2 * v14 + v11;
}
v8 = a4 % a2;
LOBYTE(v9) = 1;
while ( (v9 & 1) != 0 )
{
v10 = READ(v9, v7, a5);
v9 = v12 + 1;
v13 = v8 + v10;
v8 = v11;
v14 = v13 % a2;
if ( a1 < v9 )
goto LABEL_7;
LABEL_4:
v7 = v14;
}
v15 = READ(v9, v7, a5);
v9 = v16 + 1;
v17 = v8 + v15;
v8 = v11;
v14 = v17 % a3;
if ( a1 >= v9 )
goto LABEL_4;
LABEL_7:
if ( (a1 & 1) != 0 )
return a2 * v11 + v14;
return a2 * v14 + v11;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned __int64 a2, unsigned __int64 a3, unsigned __int64 a4, __int64 a5)
{
__int64 v7; // r10
unsigned __int64 v8; // r12
unsigned int v9; // er9
unsigned __int64 v10; // rax
unsigned __int64 v11; // r10
int v12; // er9
unsigned __int64 v13; // rax
__int64 v14; // rdx
unsigned __int64 v15; // rax
int v16; // er9
unsigned __int64 v17; // rax

v7 = a4 / a2;
if ( !a1 )
{
v14 = a4 / a2;
v11 = a4 % a2;
return a2 * v14 + v11;
}
v8 = a4 % a2;
LOBYTE(v9) = 1;
while ( (v9 & 1) != 0 )
{
v10 = func0(v9, v7, a5);
v9 = v12 + 1;
v13 = v8 + v10;
v8 = v11;
v14 = v13 % a2;
if ( a1 < v9 )
goto LABEL_7;
LABEL_4:
v7 = v14;
}
v15 = func0(v9, v7, a5);
v9 = v16 + 1;
v17 = v8 + v15;
v8 = v11;
v14 = v17 % a3;
if ( a1 >= v9 )
goto LABEL_4;
LABEL_7:
if ( (a1 & 1) != 0 )
return a2 * v11 + v14;
return a2 * v14 + v11;
}

original_code:
static inline uint64_t
ENCRYPT(unsigned r, uint64_t a, uint64_t b, uint64_t m, uint64_t seed)
{
    uint64_t L, R;
    unsigned j;
    uint64_t tmp;
    L = m % a;
    R = m / a;
    for (j=1; j<=r; j++) {
        if (j & 1) {
            tmp = (L + READ(j, R, seed)) % a;
        } else {
            tmp = (L + READ(j, R, seed)) % b;
        }
        L = R;
        R = tmp;
    }
    if (r & 1) {
        return a * L + R;
    } else {
        return a * R + L;
    }
}

canonical_original_code:
static inline unsigned long ENCRYPT(unsigned int r, unsigned long a, unsigned long b, unsigned long m, unsigned long seed)
{
    unsigned long L; unsigned long R;
    unsigned int j;
    unsigned long tmp;
    L = m % a;
    R = m / a;
    for (j=1; j<=r; j++) {
        if (j & 1) {
            tmp = (L + READ(j, R, seed)) % a;
        } else {
            tmp = (L + READ(j, R, seed)) % b;
        }
        L = R;
        R = tmp;
    }
    if (r & 1) {
        return a * L + R;
    } else {
        return a * R + L;
    }
}

variable_types:
r
unsigned int

variable_types:
a
unsigned long

variable_types:
b
unsigned long

variable_types:
m
unsigned long

variable_types:
seed
unsigned long

variable_types:
L
unsigned long

variable_types:
R
unsigned long

variable_types:
j
unsigned int

variable_types:
tmp
unsigned long


decompiled_code:
__int64 __fastcall r_rand(unsigned int *a1)
{
unsigned int v1; // eax

v1 = 214013 * *a1 + 2531011;
*a1 = v1;
return HIWORD(v1) & 0x7FFF;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
unsigned int v1; // eax

v1 = 214013 * *a1 + 2531011;
*a1 = v1;
return HIWORD(v1) & 0x7FFF;
}

original_code:
static unsigned
r_rand(unsigned *seed)
{
    static const unsigned a = 214013;
    static const unsigned c = 2531011;
    *seed = (*seed) * a + c;
    return (*seed)>>16 & 0x7fff;
}

canonical_original_code:
static unsigned int r_rand(unsigned int *seed)
{
    static unsigned int a = 214013;
    static unsigned int c = 2531011;
    *seed = (*seed) * a + c;
    return (*seed)>>16 & 0x7fff;
}

variable_types:
seed
unsigned int *

variable_types:
a
unsigned int

variable_types:
c
unsigned int


original_code:
size_t
base64_encode(void *vdst, size_t sizeof_dst,
              const void *vsrc, size_t sizeof_src)
{
    static const char *b64 =
        "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz"
        "0123456789"
        "+/";
    size_t i = 0;
    size_t d = 0;
    unsigned char *dst = (unsigned char *)vdst;
    const unsigned char *src = (const unsigned char *)vsrc;
    while (i + 3 <= sizeof_src) {
        unsigned n;
        if (d + 4 > sizeof_dst)
            return d;
        n = src[i]<<16 | src[i+1]<<8 | src[i+2];
        dst[d+0] = b64[ (n>>18) & 0x3F ];
        dst[d+1] = b64[ (n>>12) & 0x3F ];
        dst[d+2] = b64[ (n>> 6) & 0x3F ];
        dst[d+3] = b64[ (n>> 0) & 0x3F ];
        i += 3;
        d += 4;
    }
    if (i + 2 <= sizeof_src && d + 4 <= sizeof_dst) {
        unsigned n = src[i]<<16 | src[i+1]<<8;
        dst[d+0] = b64[ (n>>18) & 0x3F ];
        dst[d+1] = b64[ (n>>12) & 0x3F ];
        dst[d+2] = b64[ (n>> 6) & 0x3F ];
        dst[d+3] = '=';
        d += 4;
    } else if (i + 1 <= sizeof_src && d + 4 <= sizeof_dst) {
        unsigned n = src[i]<<16;
        dst[d+0] = b64[ (n>>18) & 0x3F ];
        dst[d+1] = b64[ (n>>12) & 0x3F ];
        dst[d+2] = '=';
        dst[d+3] = '=';
        d += 4;
    }
    return d;
}

canonical_original_code:
unsigned long base64_encode(void *vdst, unsigned long sizeof_dst, void *vsrc, unsigned long sizeof_src)
{
    static char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        "abcdefghijklmnopqrstuvwxyz"
        "0123456789"
        "+/";
    unsigned long i = 0;
    unsigned long d = 0;
    unsigned char *dst = (unsigned char *)vdst;
    unsigned char *src = (const unsigned char *)vsrc;
    while (i + 3 <= sizeof_src) {
        unsigned int n;
        if (d + 4 > sizeof_dst)
            return d;
        n = src[i]<<16 | src[i+1]<<8 | src[i+2];
        dst[d+0] = b64[ (n>>18) & 0x3F ];
        dst[d+1] = b64[ (n>>12) & 0x3F ];
        dst[d+2] = b64[ (n>> 6) & 0x3F ];
        dst[d+3] = b64[ (n>> 0) & 0x3F ];
        i += 3;
        d += 4;
    }
    if (i + 2 <= sizeof_src && d + 4 <= sizeof_dst) {
        unsigned int n = src[i]<<16 | src[i+1]<<8;
        dst[d+0] = b64[ (n>>18) & 0x3F ];
        dst[d+1] = b64[ (n>>12) & 0x3F ];
        dst[d+2] = b64[ (n>> 6) & 0x3F ];
        dst[d+3] = '=';
        d += 4;
    } else if (i + 1 <= sizeof_src && d + 4 <= sizeof_dst) {
        unsigned int n = src[i]<<16;
        dst[d+0] = b64[ (n>>18) & 0x3F ];
        dst[d+1] = b64[ (n>>12) & 0x3F ];
        dst[d+2] = '=';
        dst[d+3] = '=';
        d += 4;
    }
    return d;
}

variable_types:
vdst
void *

variable_types:
vsrc
void *

variable_types:
i
unsigned long

variable_types:
d
unsigned long

variable_types:
dst
unsigned char *

variable_types:
src
unsigned char *

variable_types:
n
unsigned int


original_code:
size_t
base64_decode(void *vdst, size_t sizeof_dst,
              const void *vsrc, size_t sizeof_src)
{
 static const unsigned char rstr[] = {
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 62, 0xFF, 0xFF, 0xFF, 63,
  52, 53, 54, 55, 56, 57, 58, 59,
        60, 61, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0, 1, 2, 3, 4, 5, 6,
        7, 8, 9, 10, 11, 12, 13, 14,
  15, 16, 17, 18, 19, 20, 21, 22,
        23, 24, 25, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 26, 27, 28, 29, 30, 31, 32,
        33, 34, 35, 36, 37, 38, 39, 40,
  41, 42, 43, 44, 45, 46, 47, 48,
        49, 50, 51, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
 };
    size_t i = 0;
    size_t d = 0;
    unsigned char *dst = (unsigned char *)vdst;
    const unsigned char *src = (const unsigned char *)vsrc;
 while (i < sizeof_src) {
        unsigned b;
  unsigned c=0;
  while (i<sizeof_src && (c = rstr[src[i]]) > 64)
   i++;
  if (src[i] == '=' || i++ >= sizeof_src)
   break;
  b = (c << 2) & 0xfc;
  while (i<sizeof_src && (c = rstr[src[i]]) > 64)
   i++;
  if (src[i] == '=' || i++ >= sizeof_src)
   break;
  b |= (c>>4) & 0x03;
  if (d<sizeof_dst)
   dst[d++] = (unsigned char)b;
  if (i>=sizeof_src)
   break;
  b = (c<<4) & 0xF0;
  while (i<sizeof_src && src[i] != '=' && (c = rstr[src[i]]) > 64)
   ;
  if (src[i] == '=' || i++ >= sizeof_src)
   break;
  b |= (c>>2) & 0x0F;
  if (d<sizeof_dst)
   dst[d++] = (unsigned char)b;
  if (i>=sizeof_src)
   break;
  b = (c<<6) & 0xC0;
  while (i<sizeof_src && src[i] != '=' && (c = rstr[src[i]]) > 64)
   ;
  if (src[i] == '=' || i++ >= sizeof_src)
   break;
  b |= c;
  if (d<sizeof_dst)
   dst[d++] = (unsigned char)b;
  if (i>=sizeof_src)
   break;
 }
 if (d<sizeof_dst)
  dst[d] = '\0';
 return d;
}

canonical_original_code:
unsigned long base64_decode(void *vdst, unsigned long sizeof_dst, void *vsrc, unsigned long sizeof_src)
{
 static unsigned char rstr[] = {
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 62, 0xFF, 0xFF, 0xFF, 63,
  52, 53, 54, 55, 56, 57, 58, 59,
        60, 61, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0, 1, 2, 3, 4, 5, 6,
        7, 8, 9, 10, 11, 12, 13, 14,
  15, 16, 17, 18, 19, 20, 21, 22,
        23, 24, 25, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 26, 27, 28, 29, 30, 31, 32,
        33, 34, 35, 36, 37, 38, 39, 40,
  41, 42, 43, 44, 45, 46, 47, 48,
        49, 50, 51, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
        0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
 };
    unsigned long i = 0;
    unsigned long d = 0;
    unsigned char *dst = (unsigned char *)vdst;
    unsigned char *src = (const unsigned char *)vsrc;
 while (i < sizeof_src) {
        unsigned int b;
  unsigned int c = 0;
  while (i<sizeof_src && (c = rstr[src[i]]) > 64)
   i++;
  if (src[i] == '=' || i++ >= sizeof_src)
   break;
  b = (c << 2) & 0xfc;
  while (i<sizeof_src && (c = rstr[src[i]]) > 64)
   i++;
  if (src[i] == '=' || i++ >= sizeof_src)
   break;
  b |= (c>>4) & 0x03;
  if (d<sizeof_dst)
   dst[d++] = (unsigned char)b;
  if (i>=sizeof_src)
   break;
  b = (c<<4) & 0xF0;
  while (i<sizeof_src && src[i] != '=' && (c = rstr[src[i]]) > 64)
   ;
  if (src[i] == '=' || i++ >= sizeof_src)
   break;
  b |= (c>>2) & 0x0F;
  if (d<sizeof_dst)
   dst[d++] = (unsigned char)b;
  if (i>=sizeof_src)
   break;
  b = (c<<6) & 0xC0;
  while (i<sizeof_src && src[i] != '=' && (c = rstr[src[i]]) > 64)
   ;
  if (src[i] == '=' || i++ >= sizeof_src)
   break;
  b |= c;
  if (d<sizeof_dst)
   dst[d++] = (unsigned char)b;
  if (i>=sizeof_src)
   break;
 }
 if (d<sizeof_dst)
  dst[d] = '\0';
 return d;
}

variable_types:
rstr
unsigned char []

variable_types:
b
unsigned int


decompiled_code:
__int64 base64_selftest()
{
__int64 v0; // rax
__int64 result; // rax
int v2; // ebx
unsigned int v3; // eax
unsigned __int64 v4; // r12
char v5; // al
__int64 v6; // rdx
__int64 v7; // rcx
__int64 v8; // rax
__int64 v9; // rax
unsigned int v10; // [rsp+Ch] [rbp-16Ch] BYREF
char s2; // [rsp+10h] [rbp-168h] BYREF
int v12; // [rsp+80h] [rbp-F8h] BYREF
char v13; // [rsp+84h] [rbp-F4h]
char s1[136]; // [rsp+F0h] [rbp-88h] BYREF

v10 = time(0LL);
v0 = base64_encode((__int64)&s2, 0x64uLL, (__int64)"hello", 5uLL);
if ( base64_decode(&v12, 0x64uLL, (__int64)&s2, v0) == 5 || v12 == 1819043176 && v13 == 111 )
{
v2 = 100;
do
{
v3 = (unsigned int)r_rand(&v10) % 0x32;
v4 = v3;
if ( v3 )
{
do
{
v5 = r_rand(&v10);
*(_BYTE *)(v6 - 1) = v5;
}
while ( v6 != v7 );
v8 = base64_encode((__int64)&v12, 0x64uLL, (__int64)&s2, v4);
if ( v4 != base64_decode(s1, 0x64uLL, (__int64)&v12, v8) && memcmp(s1, &s2, v4) )
goto LABEL_3;
}
else
{
v9 = base64_encode((__int64)&v12, 0x64uLL, (__int64)&s2, 0LL);
base64_decode(s1, 0x64uLL, (__int64)&v12, v9);
}
--v2;
}
while ( v2 );
result = 0LL;
}
else
{
LABEL_3:
fwrite("base64: selftest failed\n", 1uLL, 0x18uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int
base64_selftest(void)
{
    char buf[100];
    char buf2[100];
    char buf3[100];
    size_t buf_len;
    size_t buf2_len;
    unsigned i;
    unsigned seed = (unsigned)time(0);
    buf_len = base64_encode(buf, sizeof(buf), "hello", 5);
    buf2_len = base64_decode(buf2, sizeof(buf2), buf, buf_len);
    if (buf2_len != 5 && memcmp(buf2, "hello", 5) != 0) {
        fprintf(stderr, "base64: selftest failed\n");
        return 1;
    }
    for (i=0; i<100; i++) {
        unsigned j;
        size_t buf3_len;
        buf_len = r_rand(&seed) % 50;
        for (j=0; j<buf_len; j++) {
            buf[j] = (char)r_rand(&seed);
        }
        buf2_len = base64_encode(buf2, sizeof(buf2), buf, buf_len);
        buf3_len = base64_decode(buf3, sizeof(buf3), buf2, buf2_len);
        if (buf3_len != buf_len && memcmp(buf3, buf, buf_len) != 0) {
            fprintf(stderr, "base64: selftest failed\n");
            return 1;
        }
    }
    return 0;
}

canonical_original_code:
int base64_selftest()
{
    char buf[100];
    char buf2[100];
    char buf3[100];
    unsigned long buf_len;
    unsigned long buf2_len;
    unsigned int i;
    unsigned int seed = (unsigned)time(0);
    buf_len = base64_encode(buf, sizeof(buf), "hello", 5);
    buf2_len = base64_decode(buf2, sizeof(buf2), buf, buf_len);
    if (buf2_len != 5 && memcmp(buf2, "hello", 5) != 0) {
        fprintf(stderr, "base64: selftest failed\n");
        return 1;
    }
    for (i=0; i<100; i++) {
        unsigned int j;
        unsigned long buf3_len;
        buf_len = r_rand(&seed) % 50;
        for (j=0; j<buf_len; j++) {
            buf[j] = (char)r_rand(&seed);
        }
        buf2_len = base64_encode(buf2, sizeof(buf2), buf, buf_len);
        buf3_len = base64_decode(buf3, sizeof(buf3), buf2, buf2_len);
        if (buf3_len != buf_len && memcmp(buf3, buf, buf_len) != 0) {
            fprintf(stderr, "base64: selftest failed\n");
            return 1;
        }
    }
    return 0;
}

variable_types:
buf
char [100]

variable_types:
i
unsigned int

variable_types:
seed
unsigned int


decompiled_code:
__int64 __fastcall tcp_transmit_alloc(__int64 a1, __int64 a2)
{
return MALLOC(a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return MALLOC(a2);
}

original_code:
unsigned char *
tcp_transmit_alloc(struct InteractiveData *more, size_t length)
{
    (void) more;
    return MALLOC(length);
}

canonical_original_code:
unsigned char *tcp_transmit_alloc(struct InteractiveData *more, unsigned long length)
{
    (void) more;
    return MALLOC(length);
}

variable_types: struct InteractiveData { void *m_payload; unsigned int m_length; unsigned int is_payload_dynamic; unsigned int is_closing; } *

variable_types:
length
unsigned long

return_type: unsigned char *


decompiled_code:
void __fastcall tcp_close(__int64 a1)
{
if ( a1 )
*(_BYTE *)(a1 + 12) |= 2u;
}

original_code:
void
tcp_close(struct InteractiveData *more)
{
    if (more == ((void *)0))
        return;
    more->is_closing = 1;
}

user_defined_types: struct InteractiveData { void *m_payload; unsigned int m_length; unsigned int is_payload_dynamic; unsigned int is_closing; }


original_code:
void
tcp_transmit(struct InteractiveData *more, const void *payload, size_t length, unsigned flags)
{
    more->m_payload = payload;
    more->m_length = (unsigned)length;
    if (flags & TCPTRAN_DYNAMIC)
        more->is_payload_dynamic = 1;
}

canonical_original_code:
void tcp_transmit(struct InteractiveData *more, void *payload, unsigned long length, unsigned int flags)
{
    more->m_payload = payload;
    more->m_length = (unsigned int)length;
    if (flags & TCPTRAN_DYNAMIC)
        more->is_payload_dynamic = 1;
}

variable_types:
payload
void *

variable_types:
flags
unsigned int


memcasecmp

decompiled_code:
__int64 __fastcall memcasecmp(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rdi
const __int32_t *v5; // rdx
__int64 i; // rax

if ( a3 <= 0 )
return 0LL;
v4 = a3;
v5 = *_ctype_tolower_loc();
for ( i = 0LL; i != v4; ++i )
{
if ( v5[*(char *)(a2 + i)] != v5[*(char *)(a1 + i)] )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rdi
const __int32_t *v5; // rdx
__int64 i; // rax

if ( a3 <= 0 )
return 0LL;
v4 = a3;
v5 = *_ctype_tolower_loc();
for ( i = 0LL; i != v4; ++i )
{
if ( v5[*(char *)(a2 + i)] != v5[*(char *)(a1 + i)] )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int
memcasecmp(const void *lhs, const void *rhs, int length)
{
    int i;
    for (i=0; i<length; i++) {
        if (tolower(((char*)lhs)[i]) != tolower(((char*)rhs)[i]))
            return -1;
    }
    return 0;
}

canonical_original_code:
int memcasecmp(void *lhs, void *rhs, int length)
{
    int i;
    for (i=0; i<length; i++) {
        if (tolower(((char *)lhs)[i]) != tolower(((char *)rhs)[i]))
            return -1;
    }
    return 0;
}

variable_types:
lhs
void *

variable_types:
rhs
void *

variable_types: length int

variable_types: i int


decompiled_code:
__int64 __fastcall strcpy_s(_BYTE *a1, unsigned __int64 a2, char *a3)
{
__int64 result; // rax
char v5; // dl
unsigned __int64 v6; // rax

result = 34LL;
if ( a2 )
{
if ( a1 )
{
if ( a3 )
{
v5 = *a3;
v6 = 0LL;
if ( v5 )
{
while ( 1 )
{
a1[v6++] = v5;
v5 = a3[v6];
if ( !v5 )
break;
if ( a2 == v6 )
goto LABEL_13;
}
if ( a2 > v6 )
{
a1 += v6;
goto LABEL_10;
}
LABEL_13:
*a1 = 0;
result = 34LL;
}
else
{
LABEL_10:
*a1 = 0;
result = 0LL;
}
}
else
{
*a1 = 0;
result = 22LL;
}
}
else
{
result = 22LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_BYTE *a1, unsigned __int64 a2, char *a3)
{
__int64 result; // rax
char v5; // dl
unsigned __int64 v6; // rax

result = 34LL;
if ( a2 )
{
if ( a1 )
{
if ( a3 )
{
v5 = *a3;
v6 = 0LL;
if ( v5 )
{
while ( 1 )
{
a1[v6++] = v5;
v5 = a3[v6];
if ( !v5 )
break;
if ( a2 == v6 )
goto LABEL_13;
}
if ( a2 > v6 )
{
a1 += v6;
goto LABEL_10;
}
LABEL_13:
*a1 = 0;
result = 34LL;
}
else
{
LABEL_10:
*a1 = 0;
result = 0LL;
}
}
else
{
*a1 = 0;
result = 22LL;
}
}
else
{
result = 22LL;
}
}
return result;
}

original_code:
errno_t strcpy_s(char *dst, size_t sizeof_dst, const char *src)
{
    size_t i;
    if (sizeof_dst == 0)
        return 34;
    if (dst == ((void *)0))
        return 22;
    if (src == ((void *)0)) {
        dst[0] = 0;
        return 22;
    }
    for (i=0; src[i]; i++) {
        if (i >= sizeof_dst) {
            dst[0] = 0;
            return 34;
        } else
            dst[i] = src[i];
    }
    if (i >= sizeof_dst) {
        dst[0] = 0;
        return 34;
    } else
        dst[i] = src[i];
    return 0;
}

canonical_original_code:
int strcpy_s(char *dst, unsigned long sizeof_dst, char *src)
{
    unsigned long i;
    if (sizeof_dst == 0)
        return 34;
    if (dst == ((void *)0))
        return 22;
    if (src == ((void *)0)) {
        dst[0] = 0;
        return 22;
    }
    for (i=0; src[i]; i++) {
        if (i >= sizeof_dst) {
            dst[0] = 0;
            return 34;
        } else
            dst[i] = src[i];
    }
    if (i >= sizeof_dst) {
        dst[0] = 0;
        return 34;
    } else
        dst[i] = src[i];
    return 0;
}

variable_types:
dst
char *

variable_types:
src
char *

variable_types:
i
unsigned long


original_code:
errno_t localtime_s(struct tm* _tm, const time_t *time)
{
    struct tm *x;
    x = localtime(time);
    if (x == ((void *)0)) {
        memset(_tm, 0, sizeof(*_tm));
        return -1;
    }
    memcpy(_tm, x, sizeof(*_tm));
    return 0;
}

canonical_original_code:
int localtime_s(struct tm *_tm, long *time)
{
    struct tm *x;
    x = localtime(time);
    if (x == ((void *)0)) {
        memset(_tm, 0, sizeof(*_tm));
        return -1;
    }
    memcpy(_tm, x, sizeof(*_tm));
    return 0;
}

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:
time
long *


original_code:
errno_t gmtime_s(struct tm* _tm, const time_t *time)
{
    struct tm *x;
    x = gmtime(time);
    if (x == ((void *)0)) {
        memset(_tm, 0, sizeof(*_tm));
        return -1;
    }
    memcpy(_tm, x, sizeof(*_tm));
    return 0;
}

canonical_original_code:
int gmtime_s(struct tm *_tm, long *time)
{
    struct tm *x;
    x = gmtime(time);
    if (x == ((void *)0)) {
        memset(_tm, 0, sizeof(*_tm));
        return -1;
    }
    memcpy(_tm, x, sizeof(*_tm));
    return 0;
}

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


decompiled_code:
// attributes: thunk
char *strerror_x(int errnum)
{
return strerror(errnum);
}

canonical_decompiled_code:
char *func5(int errnum)
{
return strerror(errnum);
}

original_code:
const char *strerror_x(int x)
{
    return strerror(x);
}

variable_types: x int