anetSetSendBuffer

decompiled_code:
__int64 __fastcall anetSetSendBuffer(char *a1, int a2, int a3)
{
unsigned int v3; // er12
int *v5; // rax
char *v6; // rax
int optval[5]; // [rsp+Ch] [rbp-14h] BYREF

optval[0] = a3;
v3 = setsockopt(a2, 1, 7, optval, 4u);
if ( v3 != -1 )
return 0;
v5 = _errno_location();
v6 = strerror(*v5);
anetSetError(a1, "setsockopt SO_SNDBUF: %s\n", v6);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *a1, int a2, int a3)
{
unsigned int v3; // er12
int *v5; // rax
char *v6; // rax
int optval[5]; // [rsp+Ch] [rbp-14h] BYREF

optval[0] = a3;
v3 = setsockopt(a2, 1, 7, optval, 4u);
if ( v3 != -1 )
return 0;
v5 = _errno_location();
v6 = strerror(*v5);
func0(a1, "setsockopt SO_SNDBUF: %s\n", v6);
return v3;
}

original_code:
int anetSetSendBuffer(char *err, int fd, int buffsize)
{
    if (setsockopt(fd, 1, 7, &buffsize, sizeof(buffsize)) == -1)
    {
        anetSetError(err, "setsockopt SO_SNDBUF: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: buffsize int


anetTcpKeepAlive

repo: mengguang/mg-common-utils

decompiled_code:
__int64 __fastcall anetTcpKeepAlive(char *a1, int a2)
{
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int optval[5]; // [rsp+Ch] [rbp-14h] BYREF

optval[0] = 1;
v2 = setsockopt(a2, 1, 9, optval, 4u);
if ( v2 != -1 )
return 0;
v4 = _errno_location();
v5 = strerror(*v4);
anetSetError(a1, "setsockopt SO_KEEPALIVE: %s\n", v5);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, int a2)
{
unsigned int v2; // er12
int *v4; // rax
char *v5; // rax
int optval[5]; // [rsp+Ch] [rbp-14h] BYREF

optval[0] = 1;
v2 = setsockopt(a2, 1, 9, optval, 4u);
if ( v2 != -1 )
return 0;
v4 = _errno_location();
v5 = strerror(*v4);
func0(a1, "setsockopt SO_KEEPALIVE: %s\n", v5);
return v2;
}

original_code:
int anetTcpKeepAlive(char *err, int fd)
{
    int yes = 1;
    if (setsockopt(fd, 1, 9, &yes, sizeof(yes)) == -1) {
        anetSetError(err, "setsockopt SO_KEEPALIVE: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types:
err
char *

variable_types: fd int

variable_types: yes int

return_type: int


anetResolve

decompiled_code:
__int64 __fastcall anetResolve(char *a1, const char *a2, char *a3)
{
struct hostent *v4; // rax
char *v5; // rax
struct in_addr inp; // [rsp+4h] [rbp-2Ch] BYREF

if ( inet_aton(a2, &inp) )
goto LABEL_4;
v4 = gethostbyname(a2);
if ( v4 )
{
inp.s_addr = **(_DWORD **)v4->h_addr_list;
LABEL_4:
v5 = inet_ntoa(inp);
strcpy(a3, v5);
return 0LL;
}
anetSetError(a1, "can't resolve: %s\n", a2);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, const char *a2, char *a3)
{
struct hostent *v4; // rax
char *v5; // rax
struct in_addr inp; // [rsp+4h] [rbp-2Ch] BYREF

if ( inet_aton(a2, &inp) )
goto LABEL_4;
v4 = gethostbyname(a2);
if ( v4 )
{
inp.s_addr = **(_DWORD **)v4->h_addr_list;
LABEL_4:
v5 = inet_ntoa(inp);
strcpy(a3, v5);
return 0LL;
}
func0(a1, "can't resolve: %s\n", a2);
return 0xFFFFFFFFLL;
}

original_code:
int anetResolve(char *err, char *host, char *ipbuf)
{
    struct sockaddr_in sa;
    sa.sin_family = 2;
    if (inet_aton(host, &sa.sin_addr) == 0) {
        struct hostent *he;
        he = gethostbyname(host);
        if (he == ((void *)0)) {
            anetSetError(err, "can't resolve: %s\n", host);
            return -1;
        }
        memcpy(&sa.sin_addr, he->h_addr_list[0], sizeof(struct in_addr));
    }
    strcpy(ipbuf,inet_ntoa(sa.sin_addr));
    return 0;
}

variable_types:
host
char *

variable_types:
ipbuf
char *

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 hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

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


anetTcpConnect

decompiled_code:
__int64 __fastcall anetTcpConnect(char *a1, const char *a2, __int16 a3)
{
return anetTcpGenericConnect(a1, a2, a3, 0);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, const char *a2, __int16 a3)
{
return func4(a1, a2, a3, 0);
}

original_code:
int anetTcpConnect(char *err, char *addr, int port)
{
    return anetTcpGenericConnect(err,addr,port,0);
}

variable_types:
addr
char *

variable_types: port int


anetTcpNonBlockConnect

decompiled_code:
__int64 __fastcall anetTcpNonBlockConnect(char *a1, const char *a2, __int16 a3)
{
return anetTcpGenericConnect(a1, a2, a3, 1);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *a1, const char *a2, __int16 a3)
{
return func4(a1, a2, a3, 1);
}

original_code:
int anetTcpNonBlockConnect(char *err, char *addr, int port)
{
    return anetTcpGenericConnect(err,addr,port,1);
}


anetRead

decompiled_code:
__int64 __fastcall anetRead(int fd, void *buf, int a3)
{
unsigned int v3; // er13
int v6; // eax

v3 = 0;
if ( a3 )
{
do
{
v6 = read(fd, buf, (int)(a3 - v3));
if ( !v6 )
break;
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v3 += v6;
buf = (char *)buf + v6;
}
while ( a3 != v3 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, void *buf, int a3)
{
unsigned int v3; // er13
int v6; // eax

v3 = 0;
if ( a3 )
{
do
{
v6 = read(fd, buf, (int)(a3 - v3));
if ( !v6 )
break;
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v3 += v6;
buf = (char *)buf + v6;
}
while ( a3 != v3 );
}
return v3;
}

original_code:
int anetRead(int fd, char *buf, int count)
{
    int nread, totlen = 0;
    while(totlen != count) {
        nread = read(fd,buf,count-totlen);
        if (nread == 0) return totlen;
        if (nread == -1) return -1;
        totlen += nread;
        buf += nread;
    }
    return totlen;
}

canonical_original_code:
int anetRead(int fd, char *buf, int count)
{
    int nread; int totlen = 0;
    while(totlen != count) {
        nread = read(fd,buf,count-totlen);
        if (nread == 0) return totlen;
        if (nread == -1) return -1;
        totlen += nread;
        buf += nread;
    }
    return totlen;
}

variable_types:
buf
char *

variable_types: count int

variable_types: nread int

variable_types: totlen int


anetWrite

decompiled_code:
__int64 __fastcall anetWrite(int fd, void *buf, int a3)
{
unsigned int v3; // er13
int v6; // eax

v3 = 0;
if ( a3 )
{
do
{
v6 = write(fd, buf, (int)(a3 - v3));
if ( !v6 )
break;
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v3 += v6;
buf = (char *)buf + v6;
}
while ( a3 != v3 );
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func12(int fd, void *buf, int a3)
{
unsigned int v3; // er13
int v6; // eax

v3 = 0;
if ( a3 )
{
do
{
v6 = write(fd, buf, (int)(a3 - v3));
if ( !v6 )
break;
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v3 += v6;
buf = (char *)buf + v6;
}
while ( a3 != v3 );
}
return v3;
}

original_code:
int anetWrite(int fd, char *buf, int count)
{
    int nwritten, totlen = 0;
    while(totlen != count) {
        nwritten = write(fd,buf,count-totlen);
        if (nwritten == 0) return totlen;
        if (nwritten == -1) return -1;
        totlen += nwritten;
        buf += nwritten;
    }
    return totlen;
}

canonical_original_code:
int anetWrite(int fd, char *buf, int count)
{
    int nwritten; int totlen = 0;
    while(totlen != count) {
        nwritten = write(fd,buf,count-totlen);
        if (nwritten == 0) return totlen;
        if (nwritten == -1) return -1;
        totlen += nwritten;
        buf += nwritten;
    }
    return totlen;
}

variable_types: nwritten int


anetTcpServer

decompiled_code:
__int64 __fastcall anetTcpServer(char *a1, __int16 a2, const char *a3)
{
int v4; // eax
unsigned int v5; // er12
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rdx
int v11; // edi
int *v12; // rax
char *v13; // rdx
int v14; // edi
int *v15; // rax
char *v16; // rdx
int optval; // [rsp+Ch] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-30h] BYREF

optval = 1;
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
anetSetError(a1, "socket: %s\n", v8);
return v5;
}
if ( setsockopt(v4, 1, 2, &optval, 4u) == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
anetSetError(a1, "setsockopt SO_REUSEADDR: %s\n", v10);
LABEL_10:
v11 = v5;
v5 = -1;
close(v11);
return v5;
}
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(a2);
*(_DWORD *)&addr.sa_data[2] = _bswap_32_constprop_0();
if ( a3 && !inet_aton(a3, (struct in_addr *)&addr.sa_data[2]) )
{
anetSetError(a1, "Invalid bind address\n");
v14 = v5;
v5 = -1;
close(v14);
return v5;
}
if ( bind(v5, &addr, 0x10u) == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
anetSetError(a1, "bind: %s\n", v13);
goto LABEL_10;
}
if ( listen(v5, 511) == -1 )
{
v15 = _errno_location();
v16 = strerror(*v15);
anetSetError(a1, "listen: %s\n", v16);
goto LABEL_10;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func13(char *a1, __int16 a2, const char *a3)
{
int v4; // eax
unsigned int v5; // er12
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rdx
int v11; // edi
int *v12; // rax
char *v13; // rdx
int v14; // edi
int *v15; // rax
char *v16; // rdx
int optval; // [rsp+Ch] [rbp-34h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-30h] BYREF

optval = 1;
v4 = socket(2, 1, 0);
v5 = v4;
if ( v4 == -1 )
{
v7 = _errno_location();
v8 = strerror(*v7);
func0(a1, "socket: %s\n", v8);
return v5;
}
if ( setsockopt(v4, 1, 2, &optval, 4u) == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
func0(a1, "setsockopt SO_REUSEADDR: %s\n", v10);
LABEL_10:
v11 = v5;
v5 = -1;
close(v11);
return v5;
}
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func1(a2);
*(_DWORD *)&addr.sa_data[2] = func2();
if ( a3 && !inet_aton(a3, (struct in_addr *)&addr.sa_data[2]) )
{
func0(a1, "Invalid bind address\n");
v14 = v5;
v5 = -1;
close(v14);
return v5;
}
if ( bind(v5, &addr, 0x10u) == -1 )
{
v12 = _errno_location();
v13 = strerror(*v12);
func0(a1, "bind: %s\n", v13);
goto LABEL_10;
}
if ( listen(v5, 511) == -1 )
{
v15 = _errno_location();
v16 = strerror(*v15);
func0(a1, "listen: %s\n", v16);
goto LABEL_10;
}
return v5;
}

original_code:
int anetTcpServer(char *err, int port, char *bindaddr)
{
    int s, on = 1;
    struct sockaddr_in sa;
    if ((s = socket(2, SOCK_STREAM, 0)) == -1) {
        anetSetError(err, "socket: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    if (setsockopt(s, 1, 2, &on, sizeof(on)) == -1) {
        anetSetError(err, "setsockopt SO_REUSEADDR: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    memset(&sa,0,sizeof(sa));
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    sa.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    if (bindaddr) {
        if (inet_aton(bindaddr, &sa.sin_addr) == 0) {
            anetSetError(err, "Invalid bind address\n");
            close(s);
            return -1;
        }
    }
    if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) == -1) {
        anetSetError(err, "bind: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    if (listen(s, 511) == -1) {
        anetSetError(err, "listen: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    return s;
}

canonical_original_code:
int anetTcpServer(char *err, int port, char *bindaddr)
{
    int s; int on = 1;
    struct sockaddr_in sa;
    if ((s = socket(2, SOCK_STREAM, 0)) == -1) {
        anetSetError(err, "socket: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    if (setsockopt(s, 1, 2, &on, sizeof(on)) == -1) {
        anetSetError(err, "setsockopt SO_REUSEADDR: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    memset(&sa,0,sizeof(sa));
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    sa.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    if (bindaddr) {
        if (inet_aton(bindaddr, &sa.sin_addr) == 0) {
            anetSetError(err, "Invalid bind address\n");
            close(s);
            return -1;
        }
    }
    if (bind(s, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
        anetSetError(err, "bind: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    if (listen(s, 511) == -1) {
        anetSetError(err, "listen: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    return s;
}

variable_types:
bindaddr
char *

variable_types: s int

variable_types: on int

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


anetAccept

decompiled_code:
__int64 __fastcall anetAccept(char *a1, int a2, char *a3, _DWORD *a4)
{
int v7; // edi
unsigned int v8; // er12
char *v9; // rax
char *v11; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-40h] BYREF

while ( 1 )
{
addr_len = 16;
v8 = accept(a2, &addr, &addr_len);
if ( v8 != -1 )
break;
v7 = *_errno_location();
if ( v7 != 4 )
{
v11 = strerror(v7);
anetSetError(a1, "accept: %s\n", v11);
return v8;
}
}
if ( a3 )
{
v9 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
strcpy(a3, v9);
}
if ( a4 )
*a4 = (unsigned __int16)_bswap_16(*(__int16 *)addr.sa_data);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func14(char *a1, int a2, char *a3, _DWORD *a4)
{
int v7; // edi
unsigned int v8; // er12
char *v9; // rax
char *v11; // rax
socklen_t addr_len; // [rsp+Ch] [rbp-44h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-40h] BYREF

while ( 1 )
{
addr_len = 16;
v8 = accept(a2, &addr, &addr_len);
if ( v8 != -1 )
break;
v7 = *_errno_location();
if ( v7 != 4 )
{
v11 = strerror(v7);
func0(a1, "accept: %s\n", v11);
return v8;
}
}
if ( a3 )
{
v9 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
strcpy(a3, v9);
}
if ( a4 )
*a4 = (unsigned __int16)func1(*(__int16 *)addr.sa_data);
return v8;
}

original_code:
int anetAccept(char *err, int serversock, char *ip, int *port)
{
    int fd;
    struct sockaddr_in sa;
    unsigned int saLen;
    while(1) {
        saLen = sizeof(sa);
        fd = accept(serversock, (struct sockaddr*)&sa, &saLen);
        if (fd == -1) {
            if ((*__errno_location ()) == 4)
                continue;
            else {
                anetSetError(err, "accept: %s\n", strerror((*__errno_location ())));
                return -1;
            }
        }
        break;
    }
    if (ip) strcpy(ip,inet_ntoa(sa.sin_addr));
    if (port) *port = ntohs(sa.sin_port);
    return fd;
}

canonical_original_code:
int anetAccept(char *err, int serversock, char *ip, int *port)
{
    int fd;
    struct sockaddr_in sa;
    unsigned int saLen;
    while(1) {
        saLen = sizeof(sa);
        fd = accept(serversock, (struct sockaddr *)&sa, &saLen);
        if (fd == -1) {
            if ((*__errno_location ()) == 4)
                continue;
            else {
                anetSetError(err, "accept: %s\n", strerror((*__errno_location ())));
                return -1;
            }
        }
        break;
    }
    if (ip) strcpy(ip,inet_ntoa(sa.sin_addr));
    if (port) *port = ntohs(sa.sin_port);
    return fd;
}

variable_types:
err
char *

variable_types: serversock int

variable_types:
ip
char *

variable_types:
port
int *

variable_types:
saLen
unsigned int


decompiled_code:
int __fastcall g_hash_table_print_gstring(const char **a1, const char **a2)
{
return printf("%s => %s\n", *a1, *a2);
}

canonical_decompiled_code:
int __fastcall func7(const char **a1, const char **a2)
{
return printf("%s => %s\n", *a1, *a2);
}

original_code:
void g_hash_table_print_gstring(gpointer key,gpointer val,gpointer user_data) {
    GString *skey=(GString *)key;
    GString *sval=(GString *)val;
    printf("%s => %s\n",skey->str,sval->str);
    return;
}

canonical_original_code:
void g_hash_table_print_gstring(void *key, void *val, void *user_data) {
    struct _GString *skey = (GString *)key;
    struct _GString *sval = (GString *)val;
    printf("%s => %s\n",skey->str,sval->str);
    return;
}

variable_types:
key
void *

variable_types:
val
void *

variable_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; } *

return_type: void


decompiled_code:
__int64 __fastcall my_free(const char **a1)
{
printf("freeing: %s\n", *a1);
return g_string_free();
}

canonical_decompiled_code:
__int64 __fastcall func8(const char **a1)
{
printf("freeing: %s\n", *a1);
return g_string_free();
}

original_code:
void my_free(gpointer data) {
    GString *s=(GString *)data;
    printf("freeing: %s\n",s->str);
    g_string_free(s,(!(0)));
    return;
}

canonical_original_code:
void my_free(void *data) {
    struct _GString *s = (GString *)data;
    printf("freeing: %s\n",s->str);
    g_string_free(s,(!(0)));
    return;
}

variable_types:
data
void *

user_defined_types: struct _GString { char *str; unsigned long len; unsigned long allocated_len; }


decompiled_code:
// attributes: thunk
__int64 my_hash()
{
return g_string_hash();
}

canonical_decompiled_code:
__int64 func9()
{
return g_string_hash();
}

original_code:
guint my_hash(gconstpointer key){
    return g_string_hash((GString *)key);
}

canonical_original_code:
unsigned int my_hash(void *key){
    return g_string_hash((struct _GString *)key);
}

return_type: unsigned int


decompiled_code:
// attributes: thunk
__int64 my_equal()
{
return g_string_equal();
}

canonical_decompiled_code:
__int64 func10()
{
return g_string_equal();
}

original_code:
gboolean my_equal(gconstpointer a, gconstpointer b) {
    return g_string_equal((GString *)a,(GString *)b);
}

canonical_original_code:
int my_equal(void *a, void *b) {
    return g_string_equal((struct _GString *)a,(struct _GString *)b);
}

variable_types:
a
void *

variable_types:
b
void *


decompiled_code:
void loop_func()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

variable_types: k long

variable_types: i int


setupSigSegvAction

decompiled_code:
int setupSigSegvAction()
{
struct sigaction v1; // [rsp+0h] [rbp-A0h] BYREF

sigemptyset(&v1.sa_mask);
v1.sa_flags = -939524092;
v1.sa_handler = (__sighandler_t)segvHandler;
sigaction(11, &v1, 0LL);
sigaction(7, &v1, 0LL);
sigaction(8, &v1, 0LL);
sigaction(4, &v1, 0LL);
sigaction(7, &v1, 0LL);
v1.sa_flags = -939524096;
v1.sa_handler = (__sighandler_t)sigtermHandler;
return sigaction(15, &v1, 0LL);
}

canonical_decompiled_code:
int func5()
{
struct sigaction v1; // [rsp+0h] [rbp-A0h] BYREF

sigemptyset(&v1.sa_mask);
v1.sa_flags = -939524092;
v1.sa_handler = (__sighandler_t)segvHandler;
sigaction(11, &v1, 0LL);
sigaction(7, &v1, 0LL);
sigaction(8, &v1, 0LL);
sigaction(4, &v1, 0LL);
sigaction(7, &v1, 0LL);
v1.sa_flags = -939524096;
v1.sa_handler = (__sighandler_t)sigtermHandler;
return sigaction(15, &v1, 0LL);
}

original_code:
static void setupSigSegvAction(void) {
    struct sigaction act;
    sigemptyset (&act.sa_mask);
    act.sa_flags = 0x40000000 | 0x08000000 | 0x80000000 | 4;
    act.__sigaction_handler.sa_sigaction = segvHandler;
    sigaction (11, &act, ((void *)0));
    sigaction (7, &act, ((void *)0));
    sigaction (8, &act, ((void *)0));
    sigaction (4, &act, ((void *)0));
    sigaction (7, &act, ((void *)0));
    act.sa_flags = 0x40000000 | 0x08000000 | 0x80000000;
    act.__sigaction_handler.sa_handler = sigtermHandler;
    sigaction (15, &act, ((void *)0));
    return;
}

canonical_original_code:
static void setupSigSegvAction() {
    struct sigaction act;
    sigemptyset (&act.sa_mask);
    act.sa_flags = 0x40000000 | 0x08000000 | 0x80000000 | 4;
    act.__sigaction_handler.sa_sigaction = segvHandler;
    sigaction (11, &act, ((void *)0));
    sigaction (7, &act, ((void *)0));
    sigaction (8, &act, ((void *)0));
    sigaction (4, &act, ((void *)0));
    sigaction (7, &act, ((void *)0));
    act.sa_flags = 0x40000000 | 0x08000000 | 0x80000000;
    act.__sigaction_handler.sa_handler = sigtermHandler;
    sigaction (15, &act, ((void *)0));
    return;
}

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

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

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


decompiled_code:
__int64 get_uuid()
{
time_t v0; // rax

v0 = time(0LL);
return (v0 << 32) + (mid << 24) + (++sid & 0xFFFFFF);
}

canonical_decompiled_code:
__int64 func13()
{
time_t v0; // rax

v0 = time(0LL);
return (v0 << 32) + (mid << 24) + (++sid & 0xFFFFFF);
}

original_code:
unsigned long long get_uuid() {
    unsigned long long uuid = (unsigned long long)time(((void *)0));
    uuid <<= 32;
    uuid += mid << 24;
    sid++;
    uuid += sid % (1 << 24);
    return uuid;
}

variable_types:
uuid
unsigned long long

return_type: unsigned long long


original_code:
unsigned long long get_uuid_52bit() {
    unsigned long long uuid= (unsigned long long)time(((void *)0));
    uuid-=515483463;
    uuid <<= 22;
    uuid += mid << 18;
    ++sid;
    uuid+=sid % ( 1 << 18);
    return uuid;
}

canonical_original_code:
unsigned long long get_uuid_52bit() {
    unsigned long long uuid = (unsigned long long)time(((void *)0));
    uuid-=515483463;
    uuid <<= 22;
    uuid += mid << 18;
    ++sid;
    uuid+=sid % ( 1 << 18);
    return uuid;
}


anetSetError

decompiled_code:
int anetSetError(char *a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+18h] [rbp-C8h] BYREF
__int64 v8; // [rsp+40h] [rbp-A0h]
__int64 v9; // [rsp+48h] [rbp-98h]
__int64 v10; // [rsp+50h] [rbp-90h]
__int64 v11; // [rsp+58h] [rbp-88h]

v8 = a3;
v9 = a4;
v10 = a5;
v11 = a6;
if ( a1 )
{
arg[0].gp_offset = 16;
va_start(arg, a6);
result = vsnprintf(a1, 0x100uLL, a2, arg);
}
return result;
}

canonical_decompiled_code:
int func0(char *a1, const char *a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+18h] [rbp-C8h] BYREF
__int64 v8; // [rsp+40h] [rbp-A0h]
__int64 v9; // [rsp+48h] [rbp-98h]
__int64 v10; // [rsp+50h] [rbp-90h]
__int64 v11; // [rsp+58h] [rbp-88h]

v8 = a3;
v9 = a4;
v10 = a5;
v11 = a6;
if ( a1 )
{
arg[0].gp_offset = 16;
va_start(arg, a6);
result = vsnprintf(a1, 0x100uLL, a2, arg);
}
return result;
}

original_code:
static void anetSetError(char *err, const char *fmt, ...)
{
    va_list ap;
    if (!err) return;
    __builtin_va_start(ap,fmt);
    vsnprintf(err, 256, fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
static void anetSetError(char *err, char *fmt, ...)
{
    __builtin_va_list ap;
    if (!err) return;
    __builtin_va_start(ap,fmt);
    vsnprintf(err, 256, fmt, ap);
    __builtin_va_end(ap);
}

variable_types:
fmt
char *


anetNonBlock

decompiled_code:
__int64 __fastcall anetNonBlock(char *a1, unsigned int a2)
{
int *v2; // rax
char *v3; // rax
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__int64 result; // rax
int *v8; // rax
char *v9; // rax
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9

if ( (unsigned int)fcntl64(a2, 3LL) == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
anetSetError(a1, "fcntl(F_GETFL): %s", (__int64)v3, v4, v5, v6);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)fcntl64(a2, 4LL) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
anetSetError(a1, "fcntl(F_SETFL,O_NONBLOCK): %s", (__int64)v9, v10, v11, v12);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, unsigned int a2)
{
int *v2; // rax
char *v3; // rax
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
__int64 result; // rax
int *v8; // rax
char *v9; // rax
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9

if ( (unsigned int)fcntl64(a2, 3LL) == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
func0(a1, "fcntl(F_GETFL): %s", (__int64)v3, v4, v5, v6);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)fcntl64(a2, 4LL) == -1 )
{
v8 = _errno_location();
v9 = strerror(*v8);
func0(a1, "fcntl(F_SETFL,O_NONBLOCK): %s", (__int64)v9, v10, v11, v12);
result = 0xFFFFFFFFLL;
}
else
{
result = 0LL;
}
return result;
}

original_code:
int anetNonBlock(char *err, int fd)
{
    int flags;
    if ((flags = fcntl(fd, 3)) == -1) {
        anetSetError(err, "fcntl(F_GETFL): %s\n", strerror((*__errno_location ())));
        return -1;
    }
    if (fcntl(fd, 4, flags | 04000) == -1) {
        anetSetError(err, "fcntl(F_SETFL,O_NONBLOCK): %s\n", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: fd int

variable_types: flags int


anetTcpNoDelay

decompiled_code:
__int64 __fastcall anetTcpNoDelay(char *a1, int a2)
{
int *v2; // rax
char *v3; // rax
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
int optval; // [rsp+1Ch] [rbp-4h] BYREF

optval = 1;
if ( setsockopt(a2, 6, 1, &optval, 4u) != -1 )
return 0LL;
v2 = _errno_location();
v3 = strerror(*v2);
anetSetError(a1, "setsockopt TCP_NODELAY: %s", (__int64)v3, v4, v5, v6);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
int *v2; // rax
char *v3; // rax
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
int optval; // [rsp+1Ch] [rbp-4h] BYREF

optval = 1;
if ( setsockopt(a2, 6, 1, &optval, 4u) != -1 )
return 0LL;
v2 = _errno_location();
v3 = strerror(*v2);
func0(a1, "setsockopt TCP_NODELAY: %s", (__int64)v3, v4, v5, v6);
return 0xFFFFFFFFLL;
}

original_code:
int anetTcpNoDelay(char *err, int fd)
{
    int yes = 1;
    if (setsockopt(fd, IPPROTO_TCP, 1, &yes, sizeof(yes)) == -1)
    {
        anetSetError(err, "setsockopt TCP_NODELAY: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types:
err
char *

variable_types: yes int


anetSetSendBuffer

decompiled_code:
__int64 __fastcall anetSetSendBuffer(char *a1, int a2, int a3)
{
int *v3; // rax
char *v4; // rax
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
int optval[2]; // [rsp+0h] [rbp-10h] BYREF
char *v10; // [rsp+8h] [rbp-8h]

v10 = a1;
optval[1] = a2;
optval[0] = a3;
if ( setsockopt(a2, 1, 7, optval, 4u) != -1 )
return 0LL;
v3 = _errno_location();
v4 = strerror(*v3);
anetSetError(v10, "setsockopt SO_SNDBUF: %s", (__int64)v4, v5, v6, v7);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *a1, int a2, int a3)
{
int *v3; // rax
char *v4; // rax
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
int optval[2]; // [rsp+0h] [rbp-10h] BYREF
char *v10; // [rsp+8h] [rbp-8h]

v10 = a1;
optval[1] = a2;
optval[0] = a3;
if ( setsockopt(a2, 1, 7, optval, 4u) != -1 )
return 0LL;
v3 = _errno_location();
v4 = strerror(*v3);
func0(v10, "setsockopt SO_SNDBUF: %s", (__int64)v4, v5, v6, v7);
return 0xFFFFFFFFLL;
}

original_code:
int anetSetSendBuffer(char *err, int fd, int buffsize)
{
    if (setsockopt(fd, 1, 7, &buffsize, sizeof(buffsize)) == -1)
    {
        anetSetError(err, "setsockopt SO_SNDBUF: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}

variable_types: buffsize int


anetTcpKeepAlive

decompiled_code:
__int64 __fastcall anetTcpKeepAlive(char *a1, int a2)
{
int *v2; // rax
char *v3; // rax
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
int optval; // [rsp+1Ch] [rbp-4h] BYREF

optval = 1;
if ( setsockopt(a2, 1, 9, &optval, 4u) != -1 )
return 0LL;
v2 = _errno_location();
v3 = strerror(*v2);
anetSetError(a1, "setsockopt SO_KEEPALIVE: %s", (__int64)v3, v4, v5, v6);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, int a2)
{
int *v2; // rax
char *v3; // rax
__int64 v4; // rcx
__int64 v5; // r8
__int64 v6; // r9
int optval; // [rsp+1Ch] [rbp-4h] BYREF

optval = 1;
if ( setsockopt(a2, 1, 9, &optval, 4u) != -1 )
return 0LL;
v2 = _errno_location();
v3 = strerror(*v2);
func0(a1, "setsockopt SO_KEEPALIVE: %s", (__int64)v3, v4, v5, v6);
return 0xFFFFFFFFLL;
}

original_code:
int anetTcpKeepAlive(char *err, int fd)
{
    int yes = 1;
    if (setsockopt(fd, 1, 9, &yes, sizeof(yes)) == -1) {
        anetSetError(err, "setsockopt SO_KEEPALIVE: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    return 0;
}


anetResolve

decompiled_code:
__int64 __fastcall anetResolve(char *a1, char *a2, char *a3)
{
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
char *v7; // rax
struct in_addr in; // [rsp+24h] [rbp-1Ch] BYREF
struct hostent *v10; // [rsp+38h] [rbp-8h]

if ( !inet_aton(a2, &in) )
{
v10 = gethostbyname(a2);
if ( !v10 )
{
anetSetError(a1, "can't resolve: %s", (__int64)a2, v3, v4, v5);
return 0xFFFFFFFFLL;
}
in.s_addr = **(_DWORD **)v10->h_addr_list;
}
v7 = inet_ntoa(in);
strcpy(a3, v7);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, char *a2, char *a3)
{
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
char *v7; // rax
struct in_addr in; // [rsp+24h] [rbp-1Ch] BYREF
struct hostent *v10; // [rsp+38h] [rbp-8h]

if ( !inet_aton(a2, &in) )
{
v10 = gethostbyname(a2);
if ( !v10 )
{
func0(a1, "can't resolve: %s", (__int64)a2, v3, v4, v5);
return 0xFFFFFFFFLL;
}
in.s_addr = **(_DWORD **)v10->h_addr_list;
}
v7 = inet_ntoa(in);
strcpy(a3, v7);
return 0LL;
}

original_code:
int anetResolve(char *err, char *host, char *ipbuf)
{
    struct sockaddr_in sa;
    sa.sin_family = 2;
    if (inet_aton(host, &sa.sin_addr) == 0) {
        struct hostent *he;
        he = gethostbyname(host);
        if (he == ((void *)0)) {
            anetSetError(err, "can't resolve: %s\n", host);
            return -1;
        }
        memcpy(&sa.sin_addr, he->h_addr_list[0], sizeof(struct in_addr));
    }
    strcpy(ipbuf,inet_ntoa(sa.sin_addr));
    return 0;
}

variable_types:
host
char *

variable_types:
ipbuf
char *

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 hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


anetTcpGenericConnect

decompiled_code:
__int64 __fastcall anetTcpGenericConnect(char *a1, char *a2, uint16_t a3, char a4)
{
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
int *v8; // rax
char *v9; // rax
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
struct sockaddr addr; // [rsp+20h] [rbp-20h] BYREF
struct hostent *v16; // [rsp+30h] [rbp-10h]
int fd; // [rsp+3Ch] [rbp-4h]

fd = anetCreateSocket(a1, 2);
if ( fd == -1 )
return 0xFFFFFFFFLL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = htons(a3);
if ( !inet_aton(a2, (struct in_addr *)&addr.sa_data[2]) )
{
v16 = gethostbyname(a2);
if ( !v16 )
{
anetSetError(a1, "can't resolve: %s", (__int64)a2, v5, v6, v7);
close(fd);
return 0xFFFFFFFFLL;
}
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v16->h_addr_list;
}
if ( (a4 & 1) != 0 && (unsigned int)anetNonBlock(a1, fd) )
return 0xFFFFFFFFLL;
if ( connect(fd, &addr, 0x10u) != -1 )
return (unsigned int)fd;
if ( *_errno_location() == 115 && (a4 & 1) != 0 )
return (unsigned int)fd;
v8 = _errno_location();
v9 = strerror(*v8);
anetSetError(a1, "connect: %s", (__int64)v9, v10, v11, v12);
close(fd);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, char *a2, uint16_t a3, char a4)
{
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
int *v8; // rax
char *v9; // rax
__int64 v10; // rcx
__int64 v11; // r8
__int64 v12; // r9
struct sockaddr addr; // [rsp+20h] [rbp-20h] BYREF
struct hostent *v16; // [rsp+30h] [rbp-10h]
int fd; // [rsp+3Ch] [rbp-4h]

fd = func6(a1, 2);
if ( fd == -1 )
return 0xFFFFFFFFLL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = htons(a3);
if ( !inet_aton(a2, (struct in_addr *)&addr.sa_data[2]) )
{
v16 = gethostbyname(a2);
if ( !v16 )
{
func0(a1, "can't resolve: %s", (__int64)a2, v5, v6, v7);
close(fd);
return 0xFFFFFFFFLL;
}
*(_DWORD *)&addr.sa_data[2] = **(_DWORD **)v16->h_addr_list;
}
if ( (a4 & 1) != 0 && (unsigned int)func1(a1, fd) )
return 0xFFFFFFFFLL;
if ( connect(fd, &addr, 0x10u) != -1 )
return (unsigned int)fd;
if ( *_errno_location() == 115 && (a4 & 1) != 0 )
return (unsigned int)fd;
v8 = _errno_location();
v9 = strerror(*v8);
func0(a1, "connect: %s", (__int64)v9, v10, v11, v12);
close(fd);
return 0xFFFFFFFFLL;
}

original_code:
static int anetTcpGenericConnect(char *err, char *addr, int port, int flags)
{
    int s, on = 1;
    struct sockaddr_in sa;
    if ((s = socket(2, SOCK_STREAM, 0)) == -1) {
        anetSetError(err, "creating socket: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    setsockopt(s, 1, 2, &on, sizeof(on));
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    if (inet_aton(addr, &sa.sin_addr) == 0) {
        struct hostent *he;
        he = gethostbyname(addr);
        if (he == ((void *)0)) {
            anetSetError(err, "can't resolve: %s\n", addr);
            close(s);
            return -1;
        }
        memcpy(&sa.sin_addr, he->h_addr_list[0], sizeof(struct in_addr));
    }
    if (flags & 1) {
        if (anetNonBlock(err,s) != 0)
            return -1;
    }
    if (connect(s, (struct sockaddr*)&sa, sizeof(sa)) == -1) {
        if ((*__errno_location ()) == 115 &&
            flags & 1)
            return s;
        anetSetError(err, "connect: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    return s;
}

canonical_original_code:
static int anetTcpGenericConnect(char *err, char *addr, int port, int flags)
{
    int s; int on = 1;
    struct sockaddr_in sa;
    if ((s = socket(2, SOCK_STREAM, 0)) == -1) {
        anetSetError(err, "creating socket: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    setsockopt(s, 1, 2, &on, sizeof(on));
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    if (inet_aton(addr, &sa.sin_addr) == 0) {
        struct hostent *he;
        he = gethostbyname(addr);
        if (he == ((void *)0)) {
            anetSetError(err, "can't resolve: %s\n", addr);
            close(s);
            return -1;
        }
        memcpy(&sa.sin_addr, he->h_addr_list[0], sizeof(struct in_addr));
    }
    if (flags & 1) {
        if (anetNonBlock(err,s) != 0)
            return -1;
    }
    if (connect(s, (struct sockaddr *)&sa, sizeof(sa)) == -1) {
        if ((*__errno_location ()) == 115 &&
            flags & 1)
            return s;
        anetSetError(err, "connect: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    return s;
}

variable_types:
addr
char *

variable_types: port int

variable_types: s int

variable_types: on int

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


anetTcpConnect

decompiled_code:
__int64 __fastcall anetTcpConnect(char *a1, char *a2, uint16_t a3)
{
return anetTcpGenericConnect(a1, a2, a3, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, char *a2, uint16_t a3)
{
return func7(a1, a2, a3, 0);
}

original_code:
int anetTcpConnect(char *err, char *addr, int port)
{
    return anetTcpGenericConnect(err,addr,port,0);
}


anetTcpNonBlockConnect

decompiled_code:
__int64 __fastcall anetTcpNonBlockConnect(char *a1, char *a2, uint16_t a3)
{
return anetTcpGenericConnect(a1, a2, a3, 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(char *a1, char *a2, uint16_t a3)
{
return func7(a1, a2, a3, 1);
}

original_code:
int anetTcpNonBlockConnect(char *err, char *addr, int port)
{
    return anetTcpGenericConnect(err,addr,port,1);
}


anetRead

decompiled_code:
__int64 __fastcall anetRead(int a1, char *a2, int a3)
{
int v6; // [rsp+18h] [rbp-8h]
unsigned int v7; // [rsp+1Ch] [rbp-4h]

v7 = 0;
while ( v7 != a3 )
{
v6 = read(a1, a2, (int)(a3 - v7));
if ( !v6 )
return v7;
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v7 += v6;
a2 += v6;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func13(int a1, char *a2, int a3)
{
int v6; // [rsp+18h] [rbp-8h]
unsigned int v7; // [rsp+1Ch] [rbp-4h]

v7 = 0;
while ( v7 != a3 )
{
v6 = read(a1, a2, (int)(a3 - v7));
if ( !v6 )
return v7;
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v7 += v6;
a2 += v6;
}
return v7;
}

original_code:
int anetRead(int fd, char *buf, int count)
{
    int nread, totlen = 0;
    while(totlen != count) {
        nread = read(fd,buf,count-totlen);
        if (nread == 0) return totlen;
        if (nread == -1) return -1;
        totlen += nread;
        buf += nread;
    }
    return totlen;
}

variable_types:
buf
char *

variable_types: count int

variable_types: nread int

variable_types: totlen int


anetWrite

decompiled_code:
__int64 __fastcall anetWrite(int a1, char *a2, int a3)
{
int v6; // [rsp+18h] [rbp-8h]
unsigned int v7; // [rsp+1Ch] [rbp-4h]

v7 = 0;
while ( v7 != a3 )
{
v6 = write(a1, a2, (int)(a3 - v7));
if ( !v6 )
return v7;
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v7 += v6;
a2 += v6;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func14(int a1, char *a2, int a3)
{
int v6; // [rsp+18h] [rbp-8h]
unsigned int v7; // [rsp+1Ch] [rbp-4h]

v7 = 0;
while ( v7 != a3 )
{
v6 = write(a1, a2, (int)(a3 - v7));
if ( !v6 )
return v7;
if ( v6 == -1 )
return 0xFFFFFFFFLL;
v7 += v6;
a2 += v6;
}
return v7;
}

original_code:
int anetWrite(int fd, char *buf, int count)
{
    int nwritten, totlen = 0;
    while(totlen != count) {
        nwritten = write(fd,buf,count-totlen);
        if (nwritten == 0) return totlen;
        if (nwritten == -1) return -1;
        totlen += nwritten;
        buf += nwritten;
    }
    return totlen;
}

variable_types: fd int

variable_types: nwritten int


anetTcpServer

decompiled_code:
__int64 __fastcall anetTcpServer(char *a1, uint16_t a2, char *a3)
{
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
sockaddr s; // [rsp+20h] [rbp-20h] BYREF
int fd; // [rsp+3Ch] [rbp-4h]

fd = anetCreateSocket(a1, 2);
if ( fd == -1 )
return 0xFFFFFFFFLL;
memset(&s, 0, sizeof(s));
s.sa_family = 2;
*(_WORD *)s.sa_data = htons(a2);
*(_DWORD *)&s.sa_data[2] = htonl(0);
if ( a3 && !inet_aton(a3, (struct in_addr *)&s.sa_data[2]) )
{
anetSetError(a1, "invalid bind address", v4, v5, v6, v7);
close(fd);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)anetListen(a1, fd, &s, 0x10u) == -1 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)fd;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(char *a1, uint16_t a2, char *a3)
{
__int64 result; // rax
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
sockaddr s; // [rsp+20h] [rbp-20h] BYREF
int fd; // [rsp+3Ch] [rbp-4h]

fd = func6(a1, 2);
if ( fd == -1 )
return 0xFFFFFFFFLL;
memset(&s, 0, sizeof(s));
s.sa_family = 2;
*(_WORD *)s.sa_data = htons(a2);
*(_DWORD *)&s.sa_data[2] = htonl(0);
if ( a3 && !inet_aton(a3, (struct in_addr *)&s.sa_data[2]) )
{
func0(a1, "invalid bind address", v4, v5, v6, v7);
close(fd);
result = 0xFFFFFFFFLL;
}
else if ( (unsigned int)func15(a1, fd, &s, 0x10u) == -1 )
{
result = 0xFFFFFFFFLL;
}
else
{
result = (unsigned int)fd;
}
return result;
}

original_code:
int anetTcpServer(char *err, int port, char *bindaddr)
{
    int s, on = 1;
    struct sockaddr_in sa;
    if ((s = socket(2, SOCK_STREAM, 0)) == -1) {
        anetSetError(err, "socket: %s\n", strerror((*__errno_location ())));
        return -1;
    }
    if (setsockopt(s, 1, 2, &on, sizeof(on)) == -1) {
        anetSetError(err, "setsockopt SO_REUSEADDR: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    memset(&sa,0,sizeof(sa));
    sa.sin_family = 2;
    sa.sin_port = htons(port);
    sa.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    if (bindaddr) {
        if (inet_aton(bindaddr, &sa.sin_addr) == 0) {
            anetSetError(err, "Invalid bind address\n");
            close(s);
            return -1;
        }
    }
    if (bind(s, (struct sockaddr*)&sa, sizeof(sa)) == -1) {
        anetSetError(err, "bind: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    if (listen(s, 511) == -1) {
        anetSetError(err, "listen: %s\n", strerror((*__errno_location ())));
        close(s);
        return -1;
    }
    return s;
}

variable_types:
err
char *

variable_types:
bindaddr
char *


setupSigSegvAction

canonical_decompiled_code:
int func6()
{
struct sigaction v1; // [rsp+0h] [rbp-A0h] BYREF

sigemptyset(&v1.sa_mask);
v1.sa_flags = -939524092;
v1.sa_handler = (__sighandler_t)segvHandler;
sigaction(11, &v1, 0LL);
sigaction(7, &v1, 0LL);
sigaction(8, &v1, 0LL);
sigaction(4, &v1, 0LL);
sigaction(7, &v1, 0LL);
v1.sa_flags = -939524096;
v1.sa_handler = (__sighandler_t)sigtermHandler;
return sigaction(15, &v1, 0LL);
}

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


canonical_decompiled_code:
__int64 func14()
{
time_t v0; // rax

v0 = time(0LL);
return (v0 << 32) + (mid << 24) + (++sid & 0xFFFFFF);
}

canonical_original_code:
unsigned long long get_uuid() {
    unsigned long long uuid = (unsigned long long)time(((void *)0));
    uuid <<= 32;
    uuid += mid << 24;
    sid++;
    uuid += sid % (1 << 24);
    return uuid;
}

variable_types:
uuid
unsigned long long


Quit

repo: mengning/ase

decompiled_code:
void __noreturn Quit()
{
exit(0);
}

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

original_code:
int Quit()
{
    exit(0);
}

canonical_original_code:
int Quit()
{
    exit(0);
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
MenuConfig("version", "XXX V1.0(Menu program v1.0 inside)", 0LL);
MenuConfig("quit", "Quit from XXX", Quit);
ExecuteMenu();
return 0;
}

original_code:
int main()
{
    MenuConfig("version","XXX V1.0(Menu program v1.0 inside)",((void *)0));
    MenuConfig("quit","Quit from XXX",Quit);
    ExecuteMenu();
}


search

decompiled_code:
int __fastcall search(unsigned int a1)
{
__int64 i; // rax

for ( i = pHead; *(_DWORD *)i != a1; i = *(_QWORD *)(i + 8) )
;
return printf("find student %d\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int a1)
{
__int64 i; // rax

for ( i = pHead; *(_DWORD *)i != a1; i = *(_QWORD *)(i + 8) )
;
return printf("find student %d\n", a1);
}

original_code:
tStudent* search(int id)
{
    tStudent * pStudent = ((void *)0);
    pStudent = pHead;
    while(pStudent->id != id)
    {
        pStudent = pStudent->next;
    }
    printf("find student %d\n",pStudent->id);
}

canonical_original_code:
struct Student *search(int id)
{
    struct Student *pStudent = ((void *)0);
    pStudent = pHead;
    while(pStudent->id != id)
    {
        pStudent = pStudent->next;
    }
    printf("find student %d\n",pStudent->id);
}

variable_types: id int

variable_types: struct Student { int id; int name; struct Student *next; } *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
void *v4; // rbp
int i; // ebx
_DWORD *v6; // rax
__int64 v7; // rax
unsigned int *v8; // r12

v3 = CreateLinkTable(argc, argv, envp);
if ( !v3 )
__assert_fail("pLinkTable != NULL", "testlinktable.c", 0x2Bu, "main");
v4 = (void *)v3;
for ( i = 0; i != 10; ++i )
{
v6 = malloc(0x10uLL);
v6[2] = i;
AddLinkTableNode(v4, v6);
}
v7 = SearchLinkTableNode(v4, SearchConditon);
printf("%d\n", *(unsigned int *)(v7 + 8));
v8 = (unsigned int *)Search(v4);
printf("%d\n", v8[2]);
DelLinkTableNode(v4, v8);
free(v8);
DeleteLinkTable(v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
void *v4; // rbp
int i; // ebx
_DWORD *v6; // rax
__int64 v7; // rax
unsigned int *v8; // r12

v3 = func7(argc, argv, envp);
if ( !v3 )
__assert_fail("pLinkTable != NULL", "testlinktable.c", 0x2Bu, "main");
v4 = (void *)v3;
for ( i = 0; i != 10; ++i )
{
v6 = malloc(0x10uLL);
v6[2] = i;
func9(v4, v6);
}
v7 = SearchLinkTableNode(v4, SearchConditon);
printf("%d\n", *(unsigned int *)(v7 + 8));
v8 = (unsigned int *)Search(v4);
printf("%d\n", v8[2]);
func10(v4, v8);
free(v8);
func8(v4);
return 0;
}

original_code:
int main()
{
    int i;
    tLinkTable * pLinkTable = CreateLinkTable();
    if(pLinkTable != ((void *)0))
    {
        printf("UserCase 001:Pass\n");
    }
    for(i = 0; i < 10; i++)
    {
        tNode* pNode = (tNode*)malloc(sizeof(tNode));
        pNode->data = 5;
        ("AddLinkTableNode\n");
        AddLinkTableNode(pLinkTable,(tLinkTableNode *)pNode);
    }
    ("SearchLinkTableNode\n");
    tNode* pTempNode = (tNode*)SearchLinkTableNode(pLinkTable,SearchConditon);
    printf("%d\n",pTempNode->data);
    pTempNode = Search(pLinkTable);
    printf("%d\n",pTempNode->data);
    ("DelLinkTableNode\n");
    DelLinkTableNode(pLinkTable,(tLinkTableNode *)pTempNode);
    free(pTempNode);
    DeleteLinkTable(pLinkTable);
    return;
}

canonical_original_code:
int main()
{
    int i;
    struct LinkTable *pLinkTable = CreateLinkTable();
    if(pLinkTable != ((void *)0))
    {
        printf("UserCase 001:Pass\n");
    }
    for(i = 0; i < 10; i++)
    {
        struct Node *pNode = (tNode*)malloc(sizeof(tNode));
        pNode->data = 5;
        ("AddLinkTableNode\n");
        AddLinkTableNode(pLinkTable,(struct LinkTableNode *)pNode);
    }
    ("SearchLinkTableNode\n");
    struct Node *pTempNode = (tNode*)SearchLinkTableNode(pLinkTable,SearchConditon);
    printf("%d\n",pTempNode->data);
    pTempNode = Search(pLinkTable);
    printf("%d\n",pTempNode->data);
    ("DelLinkTableNode\n");
    DelLinkTableNode(pLinkTable,(struct LinkTableNode *)pTempNode);
    free(pTempNode);
    DeleteLinkTable(pLinkTable);
    return;
}

variable_types: i int

variable_types: struct LinkTable { struct LinkTableNode { struct LinkTableNode *pNext; } *pHead; struct LinkTableNode *pTail; int SumOfNode; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; } *

variable_types: struct Node { struct LinkTableNode { struct LinkTableNode *pNext; } *pNext; int data; } *

user_defined_types: struct LinkTable { struct LinkTableNode *pHead; struct LinkTableNode *pTail; int SumOfNode; union pthread_mutex_t mutex; }

user_defined_types: struct Node { struct LinkTableNode *pNext; int data; }

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

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


SearchConditon

decompiled_code:
__int64 __fastcall SearchConditon(__int64 a1)
{
return (unsigned int)-(*(_DWORD *)(a1 + 8) != 6);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
return (unsigned int)-(*(_DWORD *)(a1 + 8) != 6);
}

original_code:
int SearchConditon(tLinkTableNode * pLinkTableNode)
{
    tNode * pNode = (tNode *)pLinkTableNode;
    if(pNode->data == 5)
    {
        return 0;
    }
    return (-1);
}

canonical_original_code:
int SearchConditon(struct LinkTableNode *pLinkTableNode)
{
    struct Node *pNode = (tNode *)pLinkTableNode;
    if(pNode->data == 5)
    {
        return 0;
    }
    return (-1);
}

variable_types: struct LinkTableNode { struct LinkTableNode *pNext; } *


main

repo: mengxipeng/extramng

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 2 || argc == 2 )
return dumptree((char *)argv[1]);
puts("\nUsage: mngtree <file.mng>\n");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( argc > 2 || argc == 2 )
return func13((char *)argv[1]);
puts("\nUsage: mngtree <file.mng>\n");
return 0;
}

original_code:
int main(int argc, char *argv[])
{
  char* fileprefix = "pngs/_";
  if(argc >2)
  {
    fileprefix = argv[2];
  }
  if (argc > 1)
    return dumptree (argv[1], fileprefix);
  else
    printf ("\nUsage: mngtree <file.mng>\n\n");
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  char *fileprefix = "pngs/_";
  if(argc >2)
  {
    fileprefix = argv[2];
  }
  if (argc > 1)
    return dumptree (argv[1], fileprefix);
  else
    printf ("\nUsage: mngtree <file.mng>\n\n");
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
fileprefix
char *


myalloc

decompiled_code:
void *__fastcall myalloc(size_t size)
{
return calloc(1uLL, size);
}

canonical_decompiled_code:
void *__fastcall func9(size_t size)
{
return calloc(1uLL, size);
}

original_code:
mng_ptr myalloc (mng_size_t iSize)
{
  return (mng_ptr)calloc (1, iSize);
}

canonical_original_code:
void *myalloc(unsigned long iSize)
{
  return (void *)calloc (1, iSize);
}

variable_types:
iSize
unsigned long

return_type: void *


myfree

decompiled_code:
// attributes: thunk
void myfree(void *ptr)
{
free(ptr);
}

canonical_decompiled_code:
void func10(void *ptr)
{
free(ptr);
}

original_code:
void myfree (mng_ptr pPtr, mng_size_t iSize)
{
  free (pPtr);
  return;
}

canonical_original_code:
void myfree(void *pPtr, unsigned long iSize)
{
  free (pPtr);
  return;
}

variable_types:
pPtr
void *


repo: mer-tools/sp-stress

decompiled_code:
int open_oom_adj()
{
return open("/proc/self/oom_adj", 2);
}

canonical_decompiled_code:
int func7()
{
return open("/proc/self/oom_adj", 2);
}

original_code:
static int open_oom_adj(void)
{
  return open("/proc/self/oom_adj", 02);
}

canonical_original_code:
static int open_oom_adj()
{
  return open("/proc/self/oom_adj", 02);
}


decompiled_code:
__int64 get_oom_adj()
{
unsigned int v0; // er12
int v1; // eax
int v3; // ebp
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = 0;
v1 = open_oom_adj();
if ( v1 >= 0 )
{
v3 = v1;
if ( read(v1, v4, 0x40uLL) > 0 )
v0 = atoi(v4);
close(v3);
}
return v0;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // er12
int v1; // eax
int v3; // ebp
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = 0;
v1 = func7();
if ( v1 >= 0 )
{
v3 = v1;
if ( read(v1, v4, 0x40uLL) > 0 )
v0 = atoi(v4);
close(v3);
}
return v0;
}

original_code:
static int get_oom_adj(void)
{
  int val = 0;
  int fd = open_oom_adj();
  if (fd >= 0)
  {
    char buf[64];
    if (read(fd, buf, sizeof(buf)) > 0)
      val = atoi(buf);
    close(fd);
  }
  return val;
}

canonical_original_code:
static int get_oom_adj()
{
  int val = 0;
  int fd = open_oom_adj();
  if (fd >= 0)
  {
    char buf[64];
    if (read(fd, buf, sizeof(buf)) > 0)
      val = atoi(buf);
    close(fd);
  }
  return val;
}

variable_types: val int

variable_types: fd int

variable_types:
buf
char [64]


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
printf("\nUsage: %s [ -e ] [-f fast|rand] [-j <oom_adj>|inherit] [ -l ] <megabytes>\n", a1);
puts("\nOptions:");
puts(" -e\t\texit after consuming/dirtying the allocated memory.");
puts(" -l\t\tthe given amount of RAM is left free instead of consumed.");
puts(" -f\t\tfilling memory using 'rand' or 'fast' method.");
puts(" -j\t\tset oom_adj to specified value (default = 0) or inherit it.");
puts("\nExample:");
printf(" %s -e 20\n", a1);
printf(" %s -f fast -j inherit 20\n", a1);
printf(" %s -f fast -j -17 -l 20\n", a1);
putchar(10);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(const char *a1)
{
printf("\nUsage: %s [ -e ] [-f fast|rand] [-j <oom_adj>|inherit] [ -l ] <megabytes>\n", a1);
puts("\nOptions:");
puts(" -e\t\texit after consuming/dirtying the allocated memory.");
puts(" -l\t\tthe given amount of RAM is left free instead of consumed.");
puts(" -f\t\tfilling memory using 'rand' or 'fast' method.");
puts(" -j\t\tset oom_adj to specified value (default = 0) or inherit it.");
puts("\nExample:");
printf(" %s -e 20\n", a1);
printf(" %s -f fast -j inherit 20\n", a1);
printf(" %s -f fast -j -17 -l 20\n", a1);
putchar(10);
return 1LL;
}

original_code:
static int usage(const char *progname)
{
  printf ("\nUsage: %s [ -e ] [-f fast|rand] [-j <oom_adj>|inherit] [ -l ] <megabytes>\n", progname);
  printf ("\nOptions:\n");
  printf ("  -e\t\texit after consuming/dirtying the allocated memory.\n");
  printf ("  -l\t\tthe given amount of RAM is left free instead of consumed.\n");
  printf ("  -f\t\tfilling memory using 'rand' or 'fast' method.\n");
  printf ("  -j\t\tset oom_adj to specified value (default = 0) or inherit it.\n");
  printf ("\nExample:\n");
  printf ("  %s -e 20\n", progname);
  printf ("  %s -f fast -j inherit 20\n", progname);
  printf ("  %s -f fast -j -17 -l 20\n", progname);
  printf ("\n");
  return 1;
}

canonical_original_code:
static int usage(char *progname)
{
  printf ("\nUsage: %s [ -e ] [-f fast|rand] [-j <oom_adj>|inherit] [ -l ] <megabytes>\n", progname);
  printf ("\nOptions:\n");
  printf ("  -e\t\texit after consuming/dirtying the allocated memory.\n");
  printf ("  -l\t\tthe given amount of RAM is left free instead of consumed.\n");
  printf ("  -f\t\tfilling memory using 'rand' or 'fast' method.\n");
  printf ("  -j\t\tset oom_adj to specified value (default = 0) or inherit it.\n");
  printf ("\nExample:\n");
  printf ("  %s -e 20\n", progname);
  printf ("  %s -f fast -j inherit 20\n", progname);
  printf ("  %s -f fast -j -17 -l 20\n", progname);
  printf ("\n");
  return 1;
}

variable_types:
progname
char *


decompiled_code:
_BOOL8 __fastcall set_oom_adj(unsigned int a1)
{
int v1; // ebx
int v2; // eax
int v3; // ebp
int v4; // eax
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = 0;
v2 = open_oom_adj();
if ( v2 >= 0 )
{
v3 = v2;
v4 = snprintf(v6, 0x40uLL, "%d", a1);
v1 = write(v3, v6, v4);
close(v3);
}
return v1 > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(unsigned int a1)
{
int v1; // ebx
int v2; // eax
int v3; // ebp
int v4; // eax
char v6[88]; // [rsp+0h] [rbp-58h] BYREF

v1 = 0;
v2 = func7();
if ( v2 >= 0 )
{
v3 = v2;
v4 = snprintf(v6, 0x40uLL, "%d", a1);
v1 = write(v3, v6, v4);
close(v3);
}
return v1 > 0;
}

original_code:
static int set_oom_adj(int oom_adj)
{
  int fd = open_oom_adj();
  int len= 0;
  if (fd >= 0)
  {
    char buf[64];
    len = snprintf(buf, sizeof(buf), "%d", oom_adj);
    len = write(fd, buf, len);
    close(fd);
  }
  return (len > 0);
}

canonical_original_code:
static int set_oom_adj(int oom_adj)
{
  int fd = open_oom_adj();
  int len = 0;
  if (fd >= 0)
  {
    char buf[64];
    len = snprintf(buf, sizeof(buf), "%d", oom_adj);
    len = write(fd, buf, len);
    close(fd);
  }
  return (len > 0);
}

variable_types: len int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // eax
unsigned int v5; // er13
unsigned int v6; // er14
int v7; // er15
unsigned int v8; // er12
int v9; // eax
int v10; // eax
unsigned int v11; // er12
const char *v13; // rdi
int v14; // eax
const char *v15; // rdx
char *v16; // rbx
char *v17; // rbp
void *v18; // rdi
_BOOL4 v19; // [rsp+4h] [rbp-44h]

opterr = 0;
v4 = get_oom_adj(argc, argv, envp);
if ( argc <= 1 )
return usage(*argv);
v5 = v4;
v6 = 0;
v7 = 0;
v8 = 0;
v19 = 1;
while ( 1 )
{
v9 = getopt(argc, (char *const *)argv, "el:f:j:");
if ( v9 == -1 )
break;
if ( v9 == 106 )
{
v13 = optarg;
if ( !optarg || (v6 = v5, v13 = optarg, strcmp(optarg, "inherit")) )
v6 = atoi(v13);
}
else if ( v9 > 106 )
{
if ( v9 != 108 )
return usage(*argv);
v10 = strtoul(optarg, 0LL, 0);
v11 = v10 << 20;
printf("Should leave %u MB free\n", v10 & 0xFFF);
v8 = (unsigned int)calc_allocsize(v11) << 20;
if ( !v8 )
{
puts("Can't do this (too much memory already in use?)");
return 1;
}
}
else if ( v9 == 101 )
{
v7 = 1;
}
else
{
if ( v9 != 102 )
return usage(*argv);
v19 = strcmp(optarg, "fast") != 0;
}
}
if ( !v8 )
{
if ( optind >= argc )
return usage(*argv);
v8 = atoi(argv[optind]) << 20;
if ( !v8 )
return usage(*argv);
}
printf("current oom_adj is set to %d\n", v5);
if ( v6 != v5 )
{
v14 = set_oom_adj(v6);
v15 = "AJDUSTED";
if ( !v14 )
v15 = "FAILED";
printf("updating oom_adj to %d: %s\n", v6, v15);
}
if ( v19 )
{
printf("preparing data using %s filling method\n", "RAND");
v16 = (char *)malloc(v8);
if ( v16 )
{
v17 = &v16[8 * (v8 >> 3)];
while ( v16 != v17 )
{
v16 += 8;
*((_QWORD *)v16 - 1) = random();
}
goto LABEL_29;
}
LABEL_34:
printf("jammed with %u MB\n", v8 >> 20);
return 0;
}
printf("preparing data using %s filling method\n", "FAST");
v18 = malloc(v8);
if ( !v18 )
goto LABEL_34;
memset(v18, v8, v8 | 0x55);
LABEL_29:
printf("%u MB eat\n", v8 >> 20);
if ( !v7 )
{
while ( 1 )
sleep(0x3Cu);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4; // eax
unsigned int v5; // er13
unsigned int v6; // er14
int v7; // er15
unsigned int v8; // er12
int v9; // eax
int v10; // eax
unsigned int v11; // er12
const char *v13; // rdi
int v14; // eax
const char *v15; // rdx
char *v16; // rbx
char *v17; // rbp
void *v18; // rdi
_BOOL4 v19; // [rsp+4h] [rbp-44h]

opterr = 0;
v4 = func8(argc, argv, envp);
if ( argc <= 1 )
return func10(*argv);
v5 = v4;
v6 = 0;
v7 = 0;
v8 = 0;
v19 = 1;
while ( 1 )
{
v9 = getopt(argc, (char *const *)argv, "el:f:j:");
if ( v9 == -1 )
break;
if ( v9 == 106 )
{
v13 = optarg;
if ( !optarg || (v6 = v5, v13 = optarg, strcmp(optarg, "inherit")) )
v6 = atoi(v13);
}
else if ( v9 > 106 )
{
if ( v9 != 108 )
return func10(*argv);
v10 = strtoul(optarg, 0LL, 0);
v11 = v10 << 20;
printf("Should leave %u MB free\n", v10 & 0xFFF);
v8 = (unsigned int)func9(v11) << 20;
if ( !v8 )
{
puts("Can't do this (too much memory already in use?)");
return 1;
}
}
else if ( v9 == 101 )
{
v7 = 1;
}
else
{
if ( v9 != 102 )
return func10(*argv);
v19 = strcmp(optarg, "fast") != 0;
}
}
if ( !v8 )
{
if ( optind >= argc )
return func10(*argv);
v8 = atoi(argv[optind]) << 20;
if ( !v8 )
return func10(*argv);
}
printf("current oom_adj is set to %d\n", v5);
if ( v6 != v5 )
{
v14 = func11(v6);
v15 = "AJDUSTED";
if ( !v14 )
v15 = "FAILED";
printf("updating oom_adj to %d: %s\n", v6, v15);
}
if ( v19 )
{
printf("preparing data using %s filling method\n", "RAND");
v16 = (char *)malloc(v8);
if ( v16 )
{
v17 = &v16[8 * (v8 >> 3)];
while ( v16 != v17 )
{
v16 += 8;
*((_QWORD *)v16 - 1) = random();
}
goto LABEL_29;
}
LABEL_34:
printf("jammed with %u MB\n", v8 >> 20);
return 0;
}
printf("preparing data using %s filling method\n", "FAST");
v18 = malloc(v8);
if ( !v18 )
goto LABEL_34;
memset(v18, v8, v8 | 0x55);
LABEL_29:
printf("%u MB eat\n", v8 >> 20);
if ( !v7 )
{
while ( 1 )
sleep(0x3Cu);
}
return 0;
}

original_code:
int main(int argc, char * const argv[])
{
   int c;
   opterr = 0;
   unsigned size = 0;
   unsigned leave_free;
   int exit_when_done = 0;
   int cur_oom = get_oom_adj();
   int new_oom = 0;
   void* data;
   enum FILL fill = FILL_RAND;
   if (argc < 2)
     return usage(argv[0]);
   while ((c = getopt(argc, argv, "el:f:j:")) != -1)
   {
     switch(c)
     {
       case 'e':
          exit_when_done = 1;
          break;
       case 'l':
         leave_free = strtoul(optarg, ((void *)0), 0) << 20;
         printf ("Should leave %u MB free\n", leave_free >> 20 );
         size = calc_allocsize(leave_free) << 20;
         if (size == 0)
         {
            printf("Can't do this (too much memory already in use?)\n");
            return 1;
         }
         break;
       case 'f':
          fill = (0 == strcmp(optarg, "fast") ? FILL_FAST : FILL_RAND);
          break;
       case 'j':
          new_oom = (optarg && 0 == strcmp(optarg, "inherit") ? cur_oom : atoi(optarg));
          break;
       default:
         return usage(argv[0]);
     }
   }
  if (!size)
  {
    if (optind >= argc)
      return usage(argv[0]);
    size = atoi(argv[optind]) << 20;
    if (size <= 0)
      return usage(argv[0]);
  }
  printf ("current oom_adj is set to %d\n", cur_oom);
  if (cur_oom != new_oom)
  {
    printf ("updating oom_adj to %d: %s\n", new_oom, (set_oom_adj(new_oom) ? "AJDUSTED" : "FAILED"));
  }
  printf ("preparing data using %s filling method\n", (FILL_FAST == fill ? "FAST" : "RAND"));
  data = malloc(size);
  if ( data )
  {
    if (FILL_FAST == fill)
    {
      memset(data, size, size | 0x55);
    }
    else
    {
      long int* r = (long int*)data;
      unsigned s = size / sizeof(*r);
      while (s-- > 0)
      {
        *r++ = random();
      }
    }
    printf ("%u MB eat\n", size >> 20);
    if (exit_when_done)
      return 0;
    while (1)
      sleep(60);
  }
  else
  {
    printf ("jammed with %u MB\n", size >> 20);
  }
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   int c;
   opterr = 0;
   unsigned int size = 0;
   unsigned int leave_free;
   int exit_when_done = 0;
   int cur_oom = get_oom_adj();
   int new_oom = 0;
   void *data;
   enum FILL fill = FILL_RAND;
   if (argc < 2)
     return usage(argv[0]);
   while ((c = getopt(argc, argv, "el:f:j:")) != -1)
   {
     switch(c)
     {
       case 'e':
          exit_when_done = 1;
          break;
       case 'l':
         leave_free = strtoul(optarg, ((void *)0), 0) << 20;
         printf ("Should leave %u MB free\n", leave_free >> 20 );
         size = calc_allocsize(leave_free) << 20;
         if (size == 0)
         {
            printf("Can't do this (too much memory already in use?)\n");
            return 1;
         }
         break;
       case 'f':
          fill = (0 == strcmp(optarg, "fast") ? FILL_FAST : FILL_RAND);
          break;
       case 'j':
          new_oom = (optarg && 0 == strcmp(optarg, "inherit") ? cur_oom : atoi(optarg));
          break;
       default:
         return usage(argv[0]);
     }
   }
  if (!size)
  {
    if (optind >= argc)
      return usage(argv[0]);
    size = atoi(argv[optind]) << 20;
    if (size <= 0)
      return usage(argv[0]);
  }
  printf ("current oom_adj is set to %d\n", cur_oom);
  if (cur_oom != new_oom)
  {
    printf ("updating oom_adj to %d: %s\n", new_oom, (set_oom_adj(new_oom) ? "AJDUSTED" : "FAILED"));
  }
  printf ("preparing data using %s filling method\n", (FILL_FAST == fill ? "FAST" : "RAND"));
  data = malloc(size);
  if ( data )
  {
    if (FILL_FAST == fill)
    {
      memset(data, size, size | 0x55);
    }
    else
    {
      long *r = (long int*)data;
      unsigned int s = size / sizeof(*r);
      while (s-- > 0)
      {
        *r++ = random();
      }
    }
    printf ("%u MB eat\n", size >> 20);
    if (exit_when_done)
      return 0;
    while (1)
      sleep(60);
  }
  else
  {
    printf ("jammed with %u MB\n", size >> 20);
  }
  return 0;
}

variable_types: c int

variable_types:
size
unsigned int

variable_types:
data
void *

variable_types:
fill
enum FILL { FILL_FAST=0, FILL_RAND=1 }

variable_types:
r
long *

variable_types:
s
unsigned int


decompiled_code:
double cpu_load_slice()
{
double result; // xmm0_8

for ( result = 1.0; *(double *)&s_slice > result; result = result + 1.0 )
;
return result;
}

canonical_decompiled_code:
double func7()
{
double result; // xmm0_8

for ( result = 1.0; *(double *)&s_slice > result; result = result + 1.0 )
;
return result;
}

original_code:
static void cpu_load_slice(void)
{
   double load = 1.0;
   while (load < s_slice)
      load += 1.0;
}

canonical_original_code:
static void cpu_load_slice()
{
   double load = 1.0;
   while (load < s_slice)
      load += 1.0;
}

variable_types: load double


decompiled_code:
__int64 __fastcall set_nice(int inc)
{
int *v1; // rax
int *v2; // rbx

v1 = __errno_location();
*v1 = 0;
v2 = v1;
if ( nice(inc) < 0 && *v2 )
perror("\nWARNING: setting priority failed: operating with default.\nReason");
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int inc)
{
int *v1; // rax
int *v2; // rbx

v1 = __errno_location();
*v1 = 0;
v2 = v1;
if ( nice(inc) < 0 && *v2 )
perror("\nWARNING: setting priority failed: operating with default.\nReason");
return 1LL;
}

original_code:
static int set_nice(int change)
{
   (*__errno_location ()) = 0;
   if (nice(change) < 0 && (*__errno_location ()) != 0)
     perror ("\nWARNING: setting priority failed: operating with default.\nReason");
   return 1;
}

variable_types: change int


decompiled_code:
__int64 __fastcall set_sched(int policy, int a2)
{
int v2; // er8
__int64 result; // rax
struct sched_param param; // [rsp+1Ch] [rbp-Ch] BYREF

if ( (unsigned int)(policy - 1) > 1 || a2 && a2 <= 90 )
{
param.__sched_priority = sched_get_priority_max(policy);
v2 = sched_setscheduler(0, policy, &param);
result = 1LL;
if ( v2 < 0 )
{
perror("\nWARNING: setting scheduler failed failed: operating with default.\nReason");
result = 1LL;
}
}
else
{
fprintf(
stderr,
"\nERROR: unsuitable %d load (random or >90) selected for real-time scheduling.\n",
(unsigned int)a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int policy, int a2)
{
int v2; // er8
__int64 result; // rax
struct sched_param param; // [rsp+1Ch] [rbp-Ch] BYREF

if ( (unsigned int)(policy - 1) > 1 || a2 && a2 <= 90 )
{
param.__sched_priority = sched_get_priority_max(policy);
v2 = sched_setscheduler(0, policy, &param);
result = 1LL;
if ( v2 < 0 )
{
perror("\nWARNING: setting scheduler failed failed: operating with default.\nReason");
result = 1LL;
}
}
else
{
fprintf(
stderr,
"\nERROR: unsuitable %d load (random or >90) selected for real-time scheduling.\n",
(unsigned int)a2);
result = 0LL;
}
return result;
}

original_code:
static int set_sched(int policy, int load)
{
   struct sched_param param;
   if ((policy == 2 || policy == 1)
       && (load == 0 || load > 90))
   {
      fprintf(stderr, "\nERROR: unsuitable %d load (random or >90) selected for real-time scheduling.\n", load);
      return 0;
   }
   memset(&param, 0, sizeof(param));
   param.sched_priority = sched_get_priority_max(policy);
   if (sched_setscheduler(0, policy, &param) < 0)
     perror("\nWARNING: setting scheduler failed failed: operating with default.\nReason");
   return 1;
}

variable_types: policy int

variable_types: load int

variable_types: struct sched_param { int sched_priority; }


decompiled_code:
__int64 __fastcall parse_args(int a1, __int64 a2, unsigned int *a3)
{
__int64 result; // rax
int *v6; // rax
int *v7; // r13
const char **v8; // r15
unsigned int v9; // eax
int v10; // er14
__int64 v11; // rdi
char *v12; // rax
char v13; // bl
char *endptr; // [rsp+0h] [rbp-40h] BYREF

if ( (unsigned int)(a1 - 2) > 2 )
return 0LL;
v6 = __errno_location();
*v6 = 0;
v7 = v6;
v8 = (const char **)(a2 + 8LL * a1 - 8);
v9 = strtoul(*v8, &endptr, 0);
*a3 = v9;
v10 = v9;
if ( *v8 == endptr || *v7 || v9 > 0x64 )
{
puts("\nIllegal load value given.");
return 0LL;
}
if ( a1 == 2 )
return 1LL;
v11 = *(_QWORD *)(a2 + 8);
if ( a1 == 3 )
{
if ( !strncmp((const char *)v11, "-p", 2uLL) )
return set_nice(-19);
return 0LL;
}
if ( *(_BYTE *)v11 != 45 )
return 0LL;
if ( *(_BYTE *)(v11 + 1) != 115 )
return 0LL;
v12 = *(char **)(a2 + 16);
v13 = *v12;
if ( *(_BYTE *)(v11 + 2) || !v13 || v12[1] )
return 0LL;
switch ( (*__ctype_tolower_loc())[v13] )
{
case 'b':
result = set_sched(3, v10);
break;
case 'f':
result = set_sched(1, v10);
break;
case 'h':
return set_nice(-19);
case 'l':
result = set_nice(19);
break;
case 'o':
result = set_sched(0, v10);
break;
case 'r':
result = set_sched(2, v10);
break;
default:
fprintf(stderr, "\nERROR: Unknown scheduling policy / priority '%c'.\n", (unsigned int)v13);
result = 0LL;
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int a1, __int64 a2, unsigned int *a3)
{
__int64 result; // rax
int *v6; // rax
int *v7; // r13
const char **v8; // r15
unsigned int v9; // eax
int v10; // er14
__int64 v11; // rdi
char *v12; // rax
char v13; // bl
char *endptr; // [rsp+0h] [rbp-40h] BYREF

if ( (unsigned int)(a1 - 2) > 2 )
return 0LL;
v6 = __errno_location();
*v6 = 0;
v7 = v6;
v8 = (const char **)(a2 + 8LL * a1 - 8);
v9 = strtoul(*v8, &endptr, 0);
*a3 = v9;
v10 = v9;
if ( *v8 == endptr || *v7 || v9 > 0x64 )
{
puts("\nIllegal load value given.");
return 0LL;
}
if ( a1 == 2 )
return 1LL;
v11 = *(_QWORD *)(a2 + 8);
if ( a1 == 3 )
{
if ( !strncmp((const char *)v11, "-p", 2uLL) )
return func8(-19);
return 0LL;
}
if ( *(_BYTE *)v11 != 45 )
return 0LL;
if ( *(_BYTE *)(v11 + 1) != 115 )
return 0LL;
v12 = *(char **)(a2 + 16);
v13 = *v12;
if ( *(_BYTE *)(v11 + 2) || !v13 || v12[1] )
return 0LL;
switch ( (*__ctype_tolower_loc())[v13] )
{
case 'b':
result = func9(3, v10);
break;
case 'f':
result = func9(1, v10);
break;
case 'h':
return func8(-19);
case 'l':
result = func8(19);
break;
case 'o':
result = func9(0, v10);
break;
case 'r':
result = func9(2, v10);
break;
default:
fprintf(stderr, "\nERROR: Unknown scheduling policy / priority '%c'.\n", (unsigned int)v13);
result = 0LL;
break;
}
return result;
}

original_code:
static int parse_args(int argc, const char* argv[], unsigned *load)
{
   char sched_pol;
   char *endptr;
   if (argc < 2 || argc > 4)
     return 0;
   (*__errno_location ()) = 0;
   *load = strtoul(argv[argc-1], &endptr, 0);
   if (argv[argc-1] == endptr || (*__errno_location ()) != 0 || *load > 100)
   {
      printf ("\nIllegal load value given.\n");
      return 0;
   }
   if (argc == 2)
     return 1;
   if (argc == 3)
   {
      if (!strncmp(argv[1], "-p", 2))
 return set_nice(-19);
      return 0;
   }
   sched_pol = argv[2][0];
   if (argv[1][0] != '-' || argv[1][1] != 's' || argv[1][2]
       || !sched_pol || argv[2][1])
     return 0;
   switch(tolower(sched_pol))
   {
   case 'l':
      return set_nice(19);
   case 'h':
      return set_nice(-19);
   case 'b':
      return set_sched(3, *load);
   case 'f':
      return set_sched(1, *load);
   case 'r':
      return set_sched(2, *load);
   case 'o':
      return set_sched(0, *load);
   default:
      fprintf(stderr, "\nERROR: Unknown scheduling policy / priority '%c'.\n", sched_pol);
      return 0;
   }
}

canonical_original_code:
static int parse_args(int argc, char *argv[], unsigned int *load)
{
   char sched_pol;
   char *endptr;
   if (argc < 2 || argc > 4)
     return 0;
   (*__errno_location ()) = 0;
   *load = strtoul(argv[argc-1], &endptr, 0);
   if (argv[argc-1] == endptr || (*__errno_location ()) != 0 || *load > 100)
   {
      printf ("\nIllegal load value given.\n");
      return 0;
   }
   if (argc == 2)
     return 1;
   if (argc == 3)
   {
      if (!strncmp(argv[1], "-p", 2))
 return set_nice(-19);
      return 0;
   }
   sched_pol = argv[2][0];
   if (argv[1][0] != '-' || argv[1][1] != 's' || argv[1][2]
       || !sched_pol || argv[2][1])
     return 0;
   switch(tolower(sched_pol))
   {
   case 'l':
      return set_nice(19);
   case 'h':
      return set_nice(-19);
   case 'b':
      return set_sched(3, *load);
   case 'f':
      return set_sched(1, *load);
   case 'r':
      return set_sched(2, *load);
   case 'o':
      return set_sched(0, *load);
   default:
      fprintf(stderr, "\nERROR: Unknown scheduling policy / priority '%c'.\n", sched_pol);
      return 0;
   }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
load
unsigned int *

variable_types:
endptr
char *


decompiled_code:
int calibrate_cpu()
{
unsigned __int64 v0; // rbx
time_t v1; // rbp
__int64 v2; // rdx
__int64 v3; // rax

printf("calibrating cpu speed:");
fflush(stdout);
LABEL_2:
v0 = 1000000LL;
while ( 1 )
{
v1 = time(0LL);
do
cpu_load_slice();
while ( v2 + 1 < v0 );
v3 = time(0LL) - v1;
if ( v3 > 4 )
break;
if ( v3 )
v0 *= 5 / v3 + 1;
else
v0 *= 10LL;
if ( !v0 )
{
*(double *)&s_slice = 10.0 * *(double *)&s_slice;
goto LABEL_2;
}
}
s_loops = v0 / v3;
return printf(" %llu loops per second\n", v0 / v3);
}

canonical_decompiled_code:
int func11()
{
unsigned __int64 v0; // rbx
time_t v1; // rbp
__int64 v2; // rdx
__int64 v3; // rax

printf("calibrating cpu speed:");
fflush(stdout);
LABEL_2:
v0 = 1000000LL;
while ( 1 )
{
v1 = time(0LL);
do
func7();
while ( v2 + 1 < v0 );
v3 = time(0LL) - v1;
if ( v3 > 4 )
break;
if ( v3 )
v0 *= 5 / v3 + 1;
else
v0 *= 10LL;
if ( !v0 )
{
*(double *)&s_slice = 10.0 * *(double *)&s_slice;
goto LABEL_2;
}
}
s_loops = v0 / v3;
return printf(" %llu loops per second\n", v0 / v3);
}

original_code:
static void calibrate_cpu(void)
{
   LOOPS loops;
   time_t period;
   printf ("calibrating cpu speed:");
   fflush(stdout);
   do
   {
      loops = 1000 * 1000;
      while (loops)
      {
         LOOPS loop = 0;
         period = time(((void *)0));
         while (loop < loops)
         {
            cpu_load_slice();
            loop++;
         }
         period = time(((void *)0)) - period;
         if (period >= 5)
            break;
         else if ( 0 == period )
            loops *= 10;
         else
            loops *= 1 + 5 / period;
      }
      if ( loops )
         break;
      else
         s_slice *= 10.0;
   } while ( 1 );
   s_loops = loops / period;
   printf (" %llu loops per second\n", s_loops);
}

canonical_original_code:
static void calibrate_cpu()
{
   unsigned long long loops;
   long period;
   printf ("calibrating cpu speed:");
   fflush(stdout);
   do
   {
      loops = 1000 * 1000;
      while (loops)
      {
         unsigned long long loop = 0;
         period = time(((void *)0));
         while (loop < loops)
         {
            cpu_load_slice();
            loop++;
         }
         period = time(((void *)0)) - period;
         if (period >= 5)
            break;
         else if ( 0 == period )
            loops *= 10;
         else
            loops *= 1 + 5 / period;
      }
      if ( loops )
         break;
      else
         s_slice *= 10.0;
   } while ( 1 );
   s_loops = loops / period;
   printf (" %llu loops per second\n", s_loops);
}

variable_types:
loops
unsigned long long

variable_types: period long

variable_types:
loop
unsigned long long


decompiled_code:
void __fastcall __noreturn generate_load(unsigned int a1)
{
char v1; // r13
int v2; // er12
unsigned __int64 v3; // r15
int v4; // ebx
int v5; // ebp
__int64 v6; // r13
__int64 v7; // rax
__int64 v8; // rax
unsigned __int64 v9; // [rsp+8h] [rbp-40h]

v1 = 45;
v2 = 0;
v9 = s_loops;
v3 = s_loops / 0x64uLL;
printf("generate %u%c cpu load\n", a1, 37LL);
while ( 1 )
{
if ( a1 )
{
v4 = a1;
v5 = 100 - a1;
}
else
{
v7 = random() & 1;
v5 = -(int)v7 & 0x32;
v4 = v7 == 0 ? 100 : 50;
}
printf("\r%c", (unsigned int)v1);
v6 = (unsigned int)++v2;
fflush(stdout);
if ( !show_0[v2] )
{
v2 = 0;
v6 = 0LL;
}
if ( !v4 )
break;
while ( 1 )
{
if ( v9 > 0x63 )
{
do
LABEL_13:
cpu_load_slice();
while ( v3 > v8 + 1 );
}
--v4;
if ( !v5 )
break;
LABEL_10:
--v5;
usleep(0x2710u);
if ( !(v4 | v5) )
goto LABEL_7;
if ( !v4 )
goto LABEL_6;
}
while ( v4 )
{
if ( v9 > 0x63 )
goto LABEL_13;
--v4;
}
LABEL_7:
v1 = show_0[v6];
}
LABEL_6:
if ( !v5 )
goto LABEL_7;
goto LABEL_10;
}

canonical_decompiled_code:
void __fastcall __noreturn func12(unsigned int a1)
{
char v1; // r13
int v2; // er12
unsigned __int64 v3; // r15
int v4; // ebx
int v5; // ebp
__int64 v6; // r13
__int64 v7; // rax
__int64 v8; // rax
unsigned __int64 v9; // [rsp+8h] [rbp-40h]

v1 = 45;
v2 = 0;
v9 = s_loops;
v3 = s_loops / 0x64uLL;
printf("generate %u%c cpu load\n", a1, 37LL);
while ( 1 )
{
if ( a1 )
{
v4 = a1;
v5 = 100 - a1;
}
else
{
v7 = random() & 1;
v5 = -(int)v7 & 0x32;
v4 = v7 == 0 ? 100 : 50;
}
printf("\r%c", (unsigned int)v1);
v6 = (unsigned int)++v2;
fflush(stdout);
if ( !show_0[v2] )
{
v2 = 0;
v6 = 0LL;
}
if ( !v4 )
break;
while ( 1 )
{
if ( v9 > 0x63 )
{
do
LABEL_13:
func7();
while ( v3 > v8 + 1 );
}
--v4;
if ( !v5 )
break;
LABEL_10:
--v5;
usleep(0x2710u);
if ( !(v4 | v5) )
goto LABEL_7;
if ( !v4 )
goto LABEL_6;
}
while ( v4 )
{
if ( v9 > 0x63 )
goto LABEL_13;
--v4;
}
LABEL_7:
v1 = show_0[v6];
}
LABEL_6:
if ( !v5 )
goto LABEL_7;
goto LABEL_10;
}

original_code:
static void generate_load(unsigned load)
{
   const LOOPS slice = s_loops / 100;
   static const char show[] = "-\\|/";
   unsigned stage = 0;
   printf ("generate %u%c cpu load\n", load, '%');
   while (1)
   {
      unsigned busy = (load ? load : (0 == (random() & 1) ? 100 : 50));
      unsigned idle = 100 - busy;
      printf("\r%c", show[stage]);
      fflush(stdout);
      if ( !show[++stage] )
         stage = 0;
      while (busy || idle)
      {
         if ( busy )
         {
            LOOPS loop = 0;
            while (loop < slice)
            {
               cpu_load_slice();
               loop++;
            }
            busy--;
         }
         if ( idle )
         {
            usleep(10 * 1000);
            idle--;
         }
      }
   }
}

canonical_original_code:
static void generate_load(unsigned int load)
{
   unsigned long long slice = s_loops / 100;
   static char show[] = "-\\|/";
   unsigned int stage = 0;
   printf ("generate %u%c cpu load\n", load, '%');
   while (1)
   {
      unsigned int busy = (load ? load : (0 == (random() & 1) ? 100 : 50));
      unsigned int idle = 100 - busy;
      printf("\r%c", show[stage]);
      fflush(stdout);
      if ( !show[++stage] )
         stage = 0;
      while (busy || idle)
      {
         if ( busy )
         {
            unsigned long long loop = 0;
            while (loop < slice)
            {
               cpu_load_slice();
               loop++;
            }
            busy--;
         }
         if ( idle )
         {
            usleep(10 * 1000);
            idle--;
         }
      }
   }
}

variable_types:
load
unsigned int

variable_types:
slice
unsigned long long

variable_types:
show
char []

variable_types:
stage
unsigned int

variable_types:
busy
unsigned int

variable_types:
idle
unsigned int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char *v4; // rax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
puts("\nCPU load generator");
puts("Copyright (C) 2006,2008 Nokia Corporation.");
if ( (unsigned int)parse_args((unsigned int)argc, argv, v6) )
{
calibrate_cpu();
generate_load(v6[0]);
}
v3 = *argv;
v4 = strrchr(*argv, 47);
if ( v4 )
v3 = v4 + 1;
printf("\nUsage: %s [-s <id>] <highest CPU load>\n\nExample: %s -s h 50\n\n", v3, v3);
puts(
"CPU load of 0 means random load, anything else is percentage (1-100).\n"
"\n"
"The value given to '-s' can be used to set the scheduling priority/policy:\n"
"\tl -- lowest nice() priority\n"
"\th -- highest nice() priority\n"
"\tb -- use SCHED_BATCH scheduler\n"
"\tf -- use SCHED_FIFO scheduler (real time)\n"
"\tr -- use SCHED_RR scheduler (real time)\n"
"\to -- use SCHED_OTHER (default) scheduler\n"
"\n"
"See \"man sched_setscheduler\" and \"man 2 nice\".");
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
char *v4; // rax
unsigned int v6[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v6[0] = 0;
puts("\nCPU load generator");
puts("Copyright (C) 2006,2008 Nokia Corporation.");
if ( (unsigned int)func10((unsigned int)argc, argv, v6) )
{
func11();
func12(v6[0]);
}
v3 = *argv;
v4 = strrchr(*argv, 47);
if ( v4 )
v3 = v4 + 1;
printf("\nUsage: %s [-s <id>] <highest CPU load>\n\nExample: %s -s h 50\n\n", v3, v3);
puts(
"CPU load of 0 means random load, anything else is percentage (1-100).\n"
"\n"
"The value given to '-s' can be used to set the scheduling priority/policy:\n"
"\tl -- lowest nice() priority\n"
"\th -- highest nice() priority\n"
"\tb -- use SCHED_BATCH scheduler\n"
"\tf -- use SCHED_FIFO scheduler (real time)\n"
"\tr -- use SCHED_RR scheduler (real time)\n"
"\to -- use SCHED_OTHER (default) scheduler\n"
"\n"
"See \"man sched_setscheduler\" and \"man 2 nice\".");
return 1;
}

original_code:
int main(int argc, const char* argv[])
{
   const char *name;
   unsigned int load = 0;
   printf ("\nCPU load generator\n");
   printf ("Copyright (C) 2006,2008 Nokia Corporation.\n");
   if (parse_args(argc, argv, &load))
   {
      calibrate_cpu();
      generate_load(load);
      return 0;
   }
   name = strrchr(argv[0], '/');
   if (name)
     name++;
   else
     name = argv[0];
   printf("\nUsage: %s [-s <id>] <highest CPU load>\n"
   "\nExample: %s -s h 50\n\n", name, name);
   printf("CPU load of 0 means random load, anything else is percentage (1-100).\n"
   "\nThe value given to '-s' can be used to set the scheduling priority/policy:\n"
   "\tl -- lowest nice() priority\n"
   "\th -- highest nice() priority\n"
   "\tb -- use SCHED_BATCH scheduler\n"
   "\tf -- use SCHED_FIFO scheduler (real time)\n"
   "\tr -- use SCHED_RR scheduler (real time)\n"
   "\to -- use SCHED_OTHER (default) scheduler\n"
   "\nSee \"man sched_setscheduler\" and \"man 2 nice\".\n");
   return 1;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   char *name;
   unsigned int load = 0;
   printf ("\nCPU load generator\n");
   printf ("Copyright (C) 2006,2008 Nokia Corporation.\n");
   if (parse_args(argc, argv, &load))
   {
      calibrate_cpu();
      generate_load(load);
      return 0;
   }
   name = strrchr(argv[0], '/');
   if (name)
     name++;
   else
     name = argv[0];
   printf("\nUsage: %s [-s <id>] <highest CPU load>\n"
   "\nExample: %s -s h 50\n\n", name, name);
   printf("CPU load of 0 means random load, anything else is percentage (1-100).\n"
   "\nThe value given to '-s' can be used to set the scheduling priority/policy:\n"
   "\tl -- lowest nice() priority\n"
   "\th -- highest nice() priority\n"
   "\tb -- use SCHED_BATCH scheduler\n"
   "\tf -- use SCHED_FIFO scheduler (real time)\n"
   "\tr -- use SCHED_RR scheduler (real time)\n"
   "\to -- use SCHED_OTHER (default) scheduler\n"
   "\nSee \"man sched_setscheduler\" and \"man 2 nice\".\n");
   return 1;
}

variable_types:
name
char *


xshmCleanup

repo: mer-tools/swaplogger

decompiled_code:
int xshmCleanup()
{
return dlclose(xextLibrary);
}

canonical_decompiled_code:
int func1()
{
return dlclose(xextLibrary);
}

original_code:
void xshmCleanup(void)
{
    dlclose(xextLibrary);
}

canonical_original_code:
void xshmCleanup()
{
    dlclose(xextLibrary);
}


decompiled_code:
__int64 __fastcall eglSwapBuffersRegion2(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
if ( count_eglSwapBuffers )
registerSwap(&LC0, a3, a4);
return real_eglSwapBuffersRegion2(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, unsigned int a3, __int64 a4)
{
if ( count_eglSwapBuffers )
registerSwap(&LC0, a3, a4);
return real_eglSwapBuffersRegion2(a1, a2, a3);
}

original_code:
__attribute__((visibility("default"))) EGLBoolean eglSwapBuffersRegion2(EGLDisplay dpy, EGLSurface surface,
                                                    EGLint count, const EGLint* rects)
{
    if (count_eglSwapBuffers)
    {
        registerSwap("EGL", count, (const struct Rect*)rects);
    }
    return real_eglSwapBuffersRegion2(dpy, surface, count, rects);
}

canonical_original_code:
unsigned int eglSwapBuffersRegion2(void *dpy, void *surface, int count, int *rects)
{
    if (count_eglSwapBuffers)
    {
        registerSwap("EGL", count, (struct Rect *)rects);
    }
    return real_eglSwapBuffersRegion2(dpy, surface, count, rects);
}

variable_types:
dpy
void *

variable_types:
surface
void *

variable_types: count int

variable_types:
rects
int *


eglCleanup

decompiled_code:
int eglCleanup()
{
return dlclose(eglLibrary);
}

canonical_decompiled_code:
int func2()
{
return dlclose(eglLibrary);
}

original_code:
void eglCleanup(void)
{
    dlclose(eglLibrary);
}

canonical_original_code:
void eglCleanup()
{
    dlclose(eglLibrary);
}


eglSwapBuffers

decompiled_code:
__int64 __fastcall eglSwapBuffers(__int64 a1, __int64 a2)
{
_OWORD v3[2]; // [rsp+0h] [rbp-28h] BYREF

if ( !real_eglSwapBuffers )
initSwapLogger();
if ( count_eglSwapBuffers )
{
v3[0] = 0LL;
eglQuerySurface(a1, a2, 12375LL, (char *)v3 + 8);
eglQuerySurface(a1, a2, 12374LL, (char *)v3 + 12);
registerSwap(&LC0, 1LL, v3);
}
return real_eglSwapBuffers(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
_OWORD v3[2]; // [rsp+0h] [rbp-28h] BYREF

if ( !real_eglSwapBuffers )
initSwapLogger();
if ( count_eglSwapBuffers )
{
v3[0] = 0LL;
eglQuerySurface(a1, a2, 12375LL, (char *)v3 + 8);
eglQuerySurface(a1, a2, 12374LL, (char *)v3 + 12);
registerSwap(&LC0, 1LL, v3);
}
return real_eglSwapBuffers(a1, a2);
}

original_code:
__attribute__((visibility("default"))) EGLBoolean eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
{
    if (!real_eglSwapBuffers)
    {
        initSwapLogger();
    }
    if (count_eglSwapBuffers)
    {
        struct Rect rect = {.x = 0, .y = 0};
        eglQuerySurface(dpy, surface, 0x3057, &rect.w);
        eglQuerySurface(dpy, surface, 0x3056, &rect.h);
        registerSwap("EGL", 1, &rect);
    }
    return real_eglSwapBuffers(dpy, surface);
}

canonical_original_code:
unsigned int eglSwapBuffers(void *dpy, void *surface)
{
    if (!real_eglSwapBuffers)
    {
        initSwapLogger();
    }
    if (count_eglSwapBuffers)
    {
        struct Rect rect = {.x = 0, .y = 0};
        eglQuerySurface(dpy, surface, 0x3057, &rect.w);
        eglQuerySurface(dpy, surface, 0x3056, &rect.h);
        registerSwap("EGL", 1, &rect);
    }
    return real_eglSwapBuffers(dpy, surface);
}

variable_types:
rect
struct Rect { int x; }


damageCleanup

decompiled_code:
int damageCleanup()
{
pthread_t v0; // rdi
int result; // eax

v0 = *((_QWORD *)&damage + 3);
*((_DWORD *)&damage + 5) = 1;
result = pthread_join(v0, 0LL);
if ( *((_QWORD *)&damage + 1) )
result = XDamageDestroy(damage);
if ( damage )
result = XCloseDisplay(damage);
return result;
}

canonical_decompiled_code:
int func1()
{
pthread_t v0; // rdi
int result; // eax

v0 = *((_QWORD *)&damage + 3);
*((_DWORD *)&damage + 5) = 1;
result = pthread_join(v0, 0LL);
if ( *((_QWORD *)&damage + 1) )
result = XDamageDestroy(damage);
if ( damage )
result = XCloseDisplay(damage);
return result;
}

original_code:
void damageCleanup(void)
{
    damage.done = 1;
    pthread_join(damage.eventThread, ((void *)0));
    if (damage.damage)
    {
        XDamageDestroy(damage.dpy, damage.damage);
    }
    if (damage.dpy)
    {
        XCloseDisplay(damage.dpy);
    }
}

canonical_original_code:
void damageCleanup()
{
    damage.done = 1;
    pthread_join(damage.eventThread, ((void *)0));
    if (damage.damage)
    {
        XDamageDestroy(damage.dpy, damage.damage);
    }
    if (damage.dpy)
    {
        XCloseDisplay(damage.dpy);
    }
}


damageInit

decompiled_code:
__int64 damageInit()
{
Display *v0; // rax
Window v1; // rax
__int64 v2; // rax
char v4[12]; // [rsp+0h] [rbp-Ch] BYREF

damage = 0LL;
*((_OWORD *)&damage + 1) = 0LL;
v0 = XOpenDisplay(0LL);
damage = v0;
if ( v0 )
{
if ( (unsigned int)XDamageQueryExtension(v0, (char *)&damage + 16, v4) )
{
v1 = XDefaultRootWindow(damage);
v2 = XDamageCreate(damage, v1, 3LL);
*((_QWORD *)&damage + 1) = v2;
if ( v2 )
{
pthread_create((pthread_t *)&damage + 3, 0LL, eventThread, 0LL);
return 1LL;
}
puts("Unable to create damage handle");
}
else
{
puts("Damage extension not supported");
}
}
else
{
puts("Unable to open display");
}
damageCleanup();
return 0LL;
}

canonical_decompiled_code:
__int64 func2()
{
Display *v0; // rax
Window v1; // rax
__int64 v2; // rax
char v4[12]; // [rsp+0h] [rbp-Ch] BYREF

damage = 0LL;
*((_OWORD *)&damage + 1) = 0LL;
v0 = XOpenDisplay(0LL);
damage = v0;
if ( v0 )
{
if ( (unsigned int)XDamageQueryExtension(v0, (char *)&damage + 16, v4) )
{
v1 = XDefaultRootWindow(damage);
v2 = XDamageCreate(damage, v1, 3LL);
*((_QWORD *)&damage + 1) = v2;
if ( v2 )
{
pthread_create((pthread_t *)&damage + 3, 0LL, eventThread, 0LL);
return 1LL;
}
puts("Unable to create damage handle");
}
else
{
puts("Damage extension not supported");
}
}
else
{
puts("Unable to open display");
}
func1();
return 0LL;
}

original_code:
int damageInit(void)
{
    int errBase;
    memset(&damage, 0, sizeof(damage));
    damage.dpy = XOpenDisplay(((void *)0));
    if (!damage.dpy)
    {
        printf("Unable to open display\n");
        goto out;
    }
    if (!XDamageQueryExtension(damage.dpy, &damage.eventBase, &errBase))
    {
        printf("Damage extension not supported\n");
        goto out;
    }
    damage.damage = XDamageCreate(damage.dpy, XDefaultRootWindow(damage.dpy),
                                  3);
    if (!damage.damage)
    {
        printf("Unable to create damage handle\n");
        goto out;
    }
    pthread_create(&damage.eventThread, ((void *)0), eventThread, ((void *)0));
    return 1;
out:
    damageCleanup();
    return 0;
}

canonical_original_code:
int damageInit()
{
    int errBase;
    memset(&damage, 0, sizeof(damage));
    damage.dpy = XOpenDisplay(((void *)0));
    if (!damage.dpy)
    {
        printf("Unable to open display\n");
        goto out;
    }
    if (!XDamageQueryExtension(damage.dpy, &damage.eventBase, &errBase))
    {
        printf("Damage extension not supported\n");
        goto out;
    }
    damage.damage = XDamageCreate(damage.dpy, XDefaultRootWindow(damage.dpy),
                                  3);
    if (!damage.damage)
    {
        printf("Unable to create damage handle\n");
        goto out;
    }
    pthread_create(&damage.eventThread, ((void *)0), eventThread, ((void *)0));
    return 1;
out:
    damageCleanup();
    return 0;
}

variable_types: errBase int


repo: meridion/microsynth

decompiled_code:
__int64 __fastcall msynth_parse_args(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax

*(&config + 1) = 0xFFFFFFFFLL;
*(&config + 3) = -1LL;
*(&config + 2) = (__int64)"default";
config = 0LL;
while ( 2 )
{
v2 = getopt(argc, argv, "s:rvb:p:d:h");
if ( v2 == -1 )
{
result = *((unsigned int *)&config + 3);
if ( (_DWORD)result )
{
result = 0LL;
if ( *((_DWORD *)&config + 2) == -1 )
{
puts("When enabling software resampling, you are required to\nalso specify a samplerate using -s.");
LABEL_7:
LODWORD(config) = 1;
result = 1LL;
}
}
}
else
{
switch ( v2 )
{
case 'b':
*((_DWORD *)&config + 6) = atoi(optarg);
continue;
case 'd':
*(&config + 2) = (__int64)optarg;
continue;
case 'h':
printf(
"Usage %s:\n"
" -s Set samplerate (usually 48000 or 44100)\n"
" -r Enable software resampling\n"
" -b Set buffer time in microseconds\n"
" This is used to determine the amount of memory\n"
" used to buffer samples to. (e.g. 500000)\n"
" -p Set period time in microseconds.\n"
" The period is the amount of samples written at\n"
" once to the soundcard. Is usually less than half\n"
" the buffer time. (e.g. 250000)\n",
*argv);
puts(
"\n"
" By default the buffer time will be minimized to\n"
" to reduce latency, and the period time will be\n"
" maximized to reduce synthesis overhead.\n"
"\n"
" -d Set ALSA device name (usually default or hw:0,0)\n"
" -h Show this help.");
result = 1LL;
break;
case 'p':
*((_DWORD *)&config + 7) = atoi(optarg);
continue;
case 'r':
*((_DWORD *)&config + 3) = 1;
continue;
case 's':
*((_DWORD *)&config + 2) = atoi(optarg);
continue;
case 'v':
HIDWORD(config) = 1;
continue;
default:
goto LABEL_7;
}
}
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax

*(&config + 1) = 0xFFFFFFFFLL;
*(&config + 3) = -1LL;
*(&config + 2) = (__int64)"default";
config = 0LL;
while ( 2 )
{
v2 = getopt(argc, argv, "s:rvb:p:d:h");
if ( v2 == -1 )
{
result = *((unsigned int *)&config + 3);
if ( (_DWORD)result )
{
result = 0LL;
if ( *((_DWORD *)&config + 2) == -1 )
{
puts("When enabling software resampling, you are required to\nalso specify a samplerate using -s.");
LABEL_7:
LODWORD(config) = 1;
result = 1LL;
}
}
}
else
{
switch ( v2 )
{
case 'b':
*((_DWORD *)&config + 6) = atoi(optarg);
continue;
case 'd':
*(&config + 2) = (__int64)optarg;
continue;
case 'h':
printf(
"Usage %s:\n"
" -s Set samplerate (usually 48000 or 44100)\n"
" -r Enable software resampling\n"
" -b Set buffer time in microseconds\n"
" This is used to determine the amount of memory\n"
" used to buffer samples to. (e.g. 500000)\n"
" -p Set period time in microseconds.\n"
" The period is the amount of samples written at\n"
" once to the soundcard. Is usually less than half\n"
" the buffer time. (e.g. 250000)\n",
*argv);
puts(
"\n"
" By default the buffer time will be minimized to\n"
" to reduce latency, and the period time will be\n"
" maximized to reduce synthesis overhead.\n"
"\n"
" -d Set ALSA device name (usually default or hw:0,0)\n"
" -h Show this help.");
result = 1LL;
break;
case 'p':
*((_DWORD *)&config + 7) = atoi(optarg);
continue;
case 'r':
*((_DWORD *)&config + 3) = 1;
continue;
case 's':
*((_DWORD *)&config + 2) = atoi(optarg);
continue;
case 'v':
HIDWORD(config) = 1;
continue;
default:
goto LABEL_7;
}
}
return result;
}
}

original_code:
static int msynth_parse_args(int argc, char *argv[])
{
    int arg;
    config.exit_code = 0;
    config.srate = -1;
    config.resample = 0;
    config.buffer_time = config.period_time = -1;
    config.device_name = "default";
    config.verbose = 0;
    while ((arg = getopt(argc, argv, "s:rvb:p:d:h")) != -1) {
        switch (arg) {
            case 's':
                config.srate = atoi(optarg);
                break;
            case 'r':
                config.resample = 1;
                break;
            case 'v':
                config.verbose = 1;
                break;
            case 'b':
                config.buffer_time = atoi(optarg);
                break;
            case 'p':
                config.period_time = atoi(optarg);
                break;
            case 'd':
                config.device_name = optarg;
                break;
            case 'h':
                printf("Usage %s:\n"
                    "    -s Set samplerate (usually 48000 or 44100)\n"
                    "    -r Enable software resampling\n"
                    "    -b Set buffer time in microseconds\n"
                    "       This is used to determine the amount of memory\n"
                    "       used to buffer samples to. (e.g. 500000)\n"
                    "    -p Set period time in microseconds.\n"
                    "       The period is the amount of samples written at\n"
                    "       once to the soundcard. Is usually less than"
                    " half\n"
                    "       the buffer time. (e.g. 250000)\n", argv[0]);
                printf(
                    "\n"
                    "    By default the buffer time will be minimized to\n"
                    "    to reduce latency, and the period time will be\n"
                    "    maximized to reduce synthesis overhead.\n"
                    "\n"
                    "    -d Set ALSA device name (usually default or hw:0,0)\n"
                    "    -h Show this help.\n");
                return 1;
            case '?':
            default:
                config.exit_code = 1;
                return 1;
        }
    }
    if (config.resample && config.srate == -1) {
        printf("When enabling software resampling, you are required to\n"
            "also specify a samplerate using -s.\n");
        config.exit_code = 1;
        return 1;
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: arg int