decompiled_code:
void __fastcall xyz_plugin_destroy(void *ptr)
{
__int64 i; // rbx

if ( ptr )
{
for ( i = *((_QWORD *)ptr + 21); i; i = *((_QWORD *)ptr + 21) )
{
*((_QWORD *)ptr + 21) = *(_QWORD *)(i + 72);
(*(void (**)(void))(i + 64))();
dlclose(*(void **)(i + 40));
free((void *)i);
}
free(ptr);
}
}

original_code:
void xyz_plugin_destroy(struct xyz_plugin_t *plugin)
{
    if(plugin == ((void *)0)) {
        return;
    }
    struct xyz_plugin_node_t *tmp;
    while(plugin->list) {
        tmp = plugin->list;
        plugin->list = plugin->list->next;
        tmp->plugin_destroy();
        dlclose(tmp->handle);
        free(tmp);
    }
    free(plugin);
    return;
}

user_defined_types: struct xyz_plugin_node_t { char name[32]; int state; void *handle; int (*plugin_init)(); int (*plugin_proc)(void *data, void *args); int (*plugin_destroy)(); struct xyz_plugin_node_t *next; }


repo: alannice/learn

decompiled_code:
int __fastcall xyz_plugin_state(__int64 a1)
{
int result; // eax
__int64 i; // rbx

if ( a1 )
{
puts("---xyz_plugin state---");
printf("label: %s\n", (const char *)a1);
printf("path: %s\n", (const char *)(a1 + 36));
result = printf("state: %d\n", *(unsigned int *)(a1 + 32));
for ( i = *(_QWORD *)(a1 + 168); i; i = *(_QWORD *)(i + 72) )
{
printf(" name: %s\n", (const char *)i);
printf(" state: %d\n", *(unsigned int *)(i + 32));
printf(" handle: %p\n", *(const void **)(i + 40));
printf(" plugin_init: %p\n", *(const void **)(i + 48));
printf(" plugin_proc: %p\n", *(const void **)(i + 56));
result = printf(" plugin_destroy: %p\n\n", *(const void **)(i + 64));
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int result; // eax
__int64 i; // rbx

if ( a1 )
{
puts("---xyz_plugin state---");
printf("label: %s\n", (const char *)a1);
printf("path: %s\n", (const char *)(a1 + 36));
result = printf("state: %d\n", *(unsigned int *)(a1 + 32));
for ( i = *(_QWORD *)(a1 + 168); i; i = *(_QWORD *)(i + 72) )
{
printf(" name: %s\n", (const char *)i);
printf(" state: %d\n", *(unsigned int *)(i + 32));
printf(" handle: %p\n", *(const void **)(i + 40));
printf(" plugin_init: %p\n", *(const void **)(i + 48));
printf(" plugin_proc: %p\n", *(const void **)(i + 56));
result = printf(" plugin_destroy: %p\n\n", *(const void **)(i + 64));
}
}
return result;
}

original_code:
void xyz_plugin_state(struct xyz_plugin_t *plugin)
{
    if(plugin == ((void *)0)) {
        return;
    }
    printf("---xyz_plugin state---\n");
    printf("label: %s\n", plugin->label);
    printf("path: %s\n", plugin->path);
    printf("state: %d\n", plugin->state);
    if(plugin->list) {
        struct xyz_plugin_node_t *tmp = plugin->list;
        while(tmp) {
            printf("  name: %s\n", tmp->name);
            printf("  state: %d\n", tmp->state);
            printf("  handle: %p\n", tmp->handle);
            printf("  plugin_init: %p\n", tmp->plugin_init);
            printf("  plugin_proc: %p\n", tmp->plugin_proc);
            printf("  plugin_destroy: %p\n\n", tmp->plugin_destroy);
            tmp = tmp->next;
        }
    }
    return;
}

variable_types: struct xyz_plugin_t { char label[32]; int state; char path[128]; struct xyz_plugin_node_t { char name[32]; int state; void *handle; int (*plugin_init)(); int (*plugin_proc)(void *data, void *args); int (*plugin_destroy)(); struct xyz_plugin_node_t *next; } *list; } *

return_type: void

user_defined_types: struct xyz_plugin_t { char label[32]; int state; char path[128]; struct xyz_plugin_node_t *list; }


decompiled_code:
void xyz_netmodel_sigchld()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( waitpid(-1, stat_loc, 1) )
--g_xyz_netmodel_num;
}

canonical_decompiled_code:
void func0()
{
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

while ( waitpid(-1, stat_loc, 1) )
--g_xyz_netmodel_num;
}

original_code:
void xyz_netmodel_sigchld(int no)
{
    pid_t pid;
    int status;
    while((pid = waitpid(-1, &status, 1)) != 0)
        g_xyz_netmodel_num--;
    return;
}

canonical_original_code:
void xyz_netmodel_sigchld(int no)
{
    int pid;
    int status;
    while((pid = waitpid(-1, &status, 1)) != 0)
        g_xyz_netmodel_num--;
    return;
}

variable_types: no int

variable_types: pid int

variable_types: status int


decompiled_code:
void *__fastcall xyz_netmodel_perthread_func(void *a1)
{
pthread_t v1; // rax

v1 = pthread_self();
pthread_detach(v1);
(*((void (__fastcall **)(_QWORD))a1 + 1))(*(unsigned int *)a1);
close(*(_DWORD *)a1);
return 0LL;
}

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

v1 = pthread_self();
pthread_detach(v1);
(*((void (__fastcall **)(_QWORD))a1 + 1))(*(unsigned int *)a1);
close(*(_DWORD *)a1);
return 0LL;
}

original_code:
void *xyz_netmodel_perthread_func(void *args)
{
    struct xyz_netmodel_thread_args_t *thread_args = args;
    pthread_detach(pthread_self());
    thread_args->func(thread_args->fd);
    close(thread_args->fd);
    return ((void *)0);
}

variable_types:
args
void *

variable_types: struct xyz_netmodel_thread_args_t { int fd; int (*func)(int fd); } *

return_type: void *


decompiled_code:
void __fastcall __noreturn xyz_netmodel_threadpool_func(void *a1)
{
pthread_t v1; // rax
unsigned int v2; // ebp

v1 = pthread_self();
pthread_detach(v1);
while ( 1 )
{
pthread_mutex_lock(&xyz_netmodel_mutex);
pthread_cond_wait(&xyz_netmodel_cond, &xyz_netmodel_mutex);
v2 = xyz_netmodel_connfd;
pthread_mutex_unlock(&xyz_netmodel_mutex);
(*((void (__fastcall **)(_QWORD))a1 + 1))(v2);
close(v2);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
pthread_t v1; // rax
unsigned int v2; // ebp

v1 = pthread_self();
pthread_detach(v1);
while ( 1 )
{
pthread_mutex_lock(&xyz_netmodel_mutex);
pthread_cond_wait(&xyz_netmodel_cond, &xyz_netmodel_mutex);
v2 = xyz_netmodel_connfd;
pthread_mutex_unlock(&xyz_netmodel_mutex);
(*((void (__fastcall **)(_QWORD))a1 + 1))(v2);
close(v2);
}
}

original_code:
void *xyz_netmodel_threadpool_func(void *args)
{
    int connfd;
    struct xyz_netmodel_threadpool_t *threadpool = args;
    pthread_detach(pthread_self());
    while(1) {
        pthread_mutex_lock(&xyz_netmodel_mutex);
        pthread_cond_wait(&xyz_netmodel_cond, &xyz_netmodel_mutex);
        connfd = xyz_netmodel_connfd;
        pthread_mutex_unlock(&xyz_netmodel_mutex);
        threadpool->func(connfd);
        close(connfd);
    }
    return ((void *)0);
}

variable_types: connfd int

variable_types: struct xyz_netmodel_threadpool_t { unsigned long tid; int (*func)(int fd); } *


decompiled_code:
__int64 __fastcall xyz_netmodel_perfork(int fd, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // eax
unsigned int v5; // ebx
__pid_t v6; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

signal(17, (__sighandler_t)xyz_netmodel_sigchld);
do
{
while ( 1 )
{
addr_len = 16;
v4 = accept(fd, &addr, &addr_len);
v5 = v4;
if ( v4 < 0 )
break;
if ( g_xyz_netmodel_num > a2 )
{
close(v4);
}
else
{
v6 = fork();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
if ( !v6 )
{
close(fd);
a3(v5);
close(v5);
exit(0);
}
close(v5);
++g_xyz_netmodel_num;
}
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // eax
unsigned int v5; // ebx
__pid_t v6; // eax
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

signal(17, (__sighandler_t)xyz_netmodel_sigchld);
do
{
while ( 1 )
{
addr_len = 16;
v4 = accept(fd, &addr, &addr_len);
v5 = v4;
if ( v4 < 0 )
break;
if ( g_xyz_netmodel_num > a2 )
{
close(v4);
}
else
{
v6 = fork();
if ( v6 == -1 )
return 0xFFFFFFFFLL;
if ( !v6 )
{
close(fd);
a3(v5);
close(v5);
exit(0);
}
close(v5);
++g_xyz_netmodel_num;
}
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_perfork(int listenfd, int count, xyz_netmodel_func func)
{
    int connfd;
    struct sockaddr addr;
    socklen_t addrlen;
    signal(17, xyz_netmodel_sigchld);
    while(1) {
        addrlen = sizeof(struct sockaddr);
        connfd = accept(listenfd, &addr, &addrlen);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        if(g_xyz_netmodel_num > count) {
            close(connfd);
            continue;
        }
        switch(fork()) {
            case 0:
                close(listenfd);
                func(connfd);
                close(connfd);
                exit(0);
            case -1:
                return -1;
            default:
                close(connfd);
                g_xyz_netmodel_num++;
                break;
        }
    }
    return 0;
}

canonical_original_code:
int xyz_netmodel_perfork(int listenfd, int count, int (*func)(int fd))
{
    int connfd;
    struct sockaddr addr;
    unsigned int addrlen;
    signal(17, xyz_netmodel_sigchld);
    while(1) {
        addrlen = sizeof(struct sockaddr);
        connfd = accept(listenfd, &addr, &addrlen);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        if(g_xyz_netmodel_num > count) {
            close(connfd);
            continue;
        }
        switch(fork()) {
            case 0:
                close(listenfd);
                func(connfd);
                close(connfd);
                exit(0);
            case -1:
                return -1;
            default:
                close(connfd);
                g_xyz_netmodel_num++;
                break;
        }
    }
    return 0;
}

variable_types: listenfd int

variable_types: count int

variable_types:
func
int (*)(int fd)

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

variable_types:
addrlen
unsigned int

return_type: int


decompiled_code:
__int64 xyz_netmodel_tempfd()
{
unsigned int v0; // ebx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

strcpy(v2, "/tmp/xyz_netmode_forkpool.XXXXXX");
v0 = mkstemp(v2);
if ( v0 != -1 )
unlink(v2);
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // ebx
char v2[1032]; // [rsp+0h] [rbp-408h] BYREF

strcpy(v2, "/tmp/xyz_netmode_forkpool.XXXXXX");
v0 = mkstemp(v2);
if ( v0 != -1 )
unlink(v2);
return v0;
}

original_code:
int xyz_netmodel_tempfd()
{
    int lock_fd;
    char lock_file[1024];
    strcpy(lock_file, "/tmp/xyz_netmode_forkpool.XXXXXX");
    lock_fd = mkstemp(lock_file);
    if(lock_fd == -1) {
        return -1;
    }
    unlink(lock_file);
    return lock_fd;
}


decompiled_code:
__int64 __fastcall xyz_netmodel_lockfd(int fd)
{
__int16 vars0[4]; // [rsp+0h] [rbp+0h] BYREF
__int64 vars8; // [rsp+8h] [rbp+8h]
__int64 vars10; // [rsp+10h] [rbp+10h]

vars0[0] = 1;
vars0[1] = 0;
vars8 = 0LL;
vars10 = 0LL;
while ( fcntl(fd, 7, vars0) < 0 )
{
if ( *_errno_location() != 4 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd)
{
__int16 vars0[4]; // [rsp+0h] [rbp+0h] BYREF
__int64 vars8; // [rsp+8h] [rbp+8h]
__int64 vars10; // [rsp+10h] [rbp+10h]

vars0[0] = 1;
vars0[1] = 0;
vars8 = 0LL;
vars10 = 0LL;
while ( fcntl(fd, 7, vars0) < 0 )
{
if ( *_errno_location() != 4 )
return 0xFFFFFFFFLL;
}
return 0LL;
}

original_code:
int xyz_netmodel_lockfd(int fd)
{
    struct flock lock_it;
    lock_it.l_type = 1;
    lock_it.l_whence = 0;
    lock_it.l_start = 0;
    lock_it.l_len = 0;
    int rc;
    while((rc = fcntl(fd, 7, &lock_it)) < 0) {
        if((*__errno_location ()) == 4) {
            continue;
        } else {
            return -1;
        }
    }
    return 0;
}

variable_types: fd int

variable_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }

variable_types: rc int


original_code:
int xyz_netmodel_unlockfd(int fd)
{
    struct flock unlock_it;
    unlock_it.l_type = 2;
    unlock_it.l_whence = 0;
    unlock_it.l_start = 0;
    unlock_it.l_len = 0;
    fcntl(fd, 7, &unlock_it);
    return 0;
}

user_defined_types: struct flock { short l_type; short l_whence; long l_start; long l_len; int l_pid; }


decompiled_code:
__int64 __fastcall xyz_netmodel_forkpool_child(int fd, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

do
{
while ( 1 )
{
do
addr_len = 16;
while ( (unsigned int)xyz_netmodel_lockfd(fd) == -1 );
v4 = accept(a2, &addr, &addr_len);
xyz_netmodel_unlockfd(fd);
if ( v4 < 0 )
break;
a3((unsigned int)v4);
close(v4);
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

do
{
while ( 1 )
{
do
addr_len = 16;
while ( (unsigned int)func5(fd) == -1 );
v4 = accept(a2, &addr, &addr_len);
func6(fd);
if ( v4 < 0 )
break;
a3((unsigned int)v4);
close(v4);
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_forkpool_child(int lock_fd, int listenfd, xyz_netmodel_func func)
{
    int ret;
    int connfd;
    struct sockaddr addr;
    socklen_t addrlen;
    while(1) {
        addrlen = sizeof(addr);
        ret = xyz_netmodel_lockfd(lock_fd);
        if(ret == -1) {
            continue;
        }
        connfd = accept(listenfd, &addr, &addrlen);
        xyz_netmodel_unlockfd(lock_fd);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        func(connfd);
        close(connfd);
    }
    return 0;
}

canonical_original_code:
int xyz_netmodel_forkpool_child(int lock_fd, int listenfd, int (*func)(int fd))
{
    int ret;
    int connfd;
    struct sockaddr addr;
    unsigned int addrlen;
    while(1) {
        addrlen = sizeof(addr);
        ret = xyz_netmodel_lockfd(lock_fd);
        if(ret == -1) {
            continue;
        }
        connfd = accept(listenfd, &addr, &addrlen);
        xyz_netmodel_unlockfd(lock_fd);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        func(connfd);
        close(connfd);
    }
    return 0;
}

variable_types: ret int

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


decompiled_code:
__int64 __fastcall xyz_netmodel_forkpool(int a1, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // eax
int v5; // ebp
__pid_t v6; // eax

signal(17, (__sighandler_t)xyz_netmodel_sigchld);
v4 = xyz_netmodel_tempfd();
if ( v4 != -1 )
{
v5 = v4;
for ( g_xyz_netmodel_num = 0; ; ++g_xyz_netmodel_num )
{
while ( g_xyz_netmodel_num > a2 )
sleep(1u);
v6 = fork();
if ( v6 == -1 )
break;
if ( !v6 )
{
xyz_netmodel_forkpool_child(v5, a1, a3);
exit(0);
}
}
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, int a2, void (__fastcall *a3)(_QWORD))
{
int v4; // eax
int v5; // ebp
__pid_t v6; // eax

signal(17, (__sighandler_t)xyz_netmodel_sigchld);
v4 = func4();
if ( v4 != -1 )
{
v5 = v4;
for ( g_xyz_netmodel_num = 0; ; ++g_xyz_netmodel_num )
{
while ( g_xyz_netmodel_num > a2 )
sleep(1u);
v6 = fork();
if ( v6 == -1 )
break;
if ( !v6 )
{
func7(v5, a1, a3);
exit(0);
}
}
}
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_forkpool(int listenfd, int count, xyz_netmodel_func func)
{
    signal(17, xyz_netmodel_sigchld);
    int lock_fd = xyz_netmodel_tempfd();
    if(lock_fd == -1) {
        return -1;
    }
    g_xyz_netmodel_num = 0;
    while(1) {
        if(g_xyz_netmodel_num <= count) {
            switch(fork()) {
                case 0:
                    xyz_netmodel_forkpool_child(lock_fd, listenfd, func);
                    exit(0);
                case -1:
                    return -1;
                default:
                    g_xyz_netmodel_num++;
                    break;
            }
        } else {
            sleep(1);
        }
    }
    close(lock_fd);
    return 0;
}

canonical_original_code:
int xyz_netmodel_forkpool(int listenfd, int count, int (*func)(int fd))
{
    signal(17, xyz_netmodel_sigchld);
    int lock_fd = xyz_netmodel_tempfd();
    if(lock_fd == -1) {
        return -1;
    }
    g_xyz_netmodel_num = 0;
    while(1) {
        if(g_xyz_netmodel_num <= count) {
            switch(fork()) {
                case 0:
                    xyz_netmodel_forkpool_child(lock_fd, listenfd, func);
                    exit(0);
                case -1:
                    return -1;
                default:
                    g_xyz_netmodel_num++;
                    break;
            }
        } else {
            sleep(1);
        }
    }
    close(lock_fd);
    return 0;
}


decompiled_code:
__int64 __fastcall xyz_netmodel_perthread(int fd, __int64 a2, __int64 a3)
{
int v4; // eax
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
int arg; // [rsp+10h] [rbp-48h] BYREF
__int64 v8; // [rsp+18h] [rbp-40h]
socklen_t addr_len; // [rsp+2Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-28h] BYREF

do
{
while ( 1 )
{
addr_len = 16;
v4 = accept(fd, &addr, &addr_len);
if ( v4 < 0 )
break;
arg = v4;
v8 = a3;
pthread_create(&newthread, 0LL, xyz_netmodel_perthread_func, &arg);
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int fd, __int64 a2, __int64 a3)
{
int v4; // eax
pthread_t newthread; // [rsp+8h] [rbp-50h] BYREF
int arg; // [rsp+10h] [rbp-48h] BYREF
__int64 v8; // [rsp+18h] [rbp-40h]
socklen_t addr_len; // [rsp+2Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-28h] BYREF

do
{
while ( 1 )
{
addr_len = 16;
v4 = accept(fd, &addr, &addr_len);
if ( v4 < 0 )
break;
arg = v4;
v8 = a3;
pthread_create(&newthread, 0LL, xyz_netmodel_perthread_func, &arg);
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_perthread(int listenfd, int count, xyz_netmodel_func func)
{
    struct sockaddr cliaddr;
    socklen_t addrlen;
    struct xyz_netmodel_thread_args_t thread_args;
    int connfd;
    pthread_t tid;
    while(1) {
        addrlen = sizeof(cliaddr);
        connfd = accept(listenfd, &cliaddr, &addrlen);
        if(connfd >= 0) {
            thread_args.fd = connfd;
            thread_args.func = func;
            pthread_create(&tid, ((void *)0), &xyz_netmodel_perthread_func, (void*)&thread_args);
        }
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
    }
    return 0;
}

canonical_original_code:
int xyz_netmodel_perthread(int listenfd, int count, int (*func)(int fd))
{
    struct sockaddr cliaddr;
    unsigned int addrlen;
    struct xyz_netmodel_thread_args_t thread_args;
    int connfd;
    unsigned long tid;
    while(1) {
        addrlen = sizeof(cliaddr);
        connfd = accept(listenfd, &cliaddr, &addrlen);
        if(connfd >= 0) {
            thread_args.fd = connfd;
            thread_args.func = func;
            pthread_create(&tid, ((void *)0), &xyz_netmodel_perthread_func, (void *)&thread_args);
        }
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
    }
    return 0;
}

variable_types: struct xyz_netmodel_thread_args_t { int fd; int (*func)(int fd); }

variable_types:
tid
unsigned long


decompiled_code:
__int64 __fastcall xyz_netmodel_threadpool(int fd, int a2, pthread_t a3)
{
pthread_t *v4; // rax
pthread_t *v5; // rbx
pthread_t *v6; // rbp
int v7; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v4 = (pthread_t *)malloc(16LL * a2);
if ( a2 > 0 )
{
v5 = v4;
v6 = &v4[2 * (unsigned int)a2];
do
{
v5[1] = a3;
pthread_create(v5, 0LL, (void *(*)(void *))xyz_netmodel_threadpool_func, v5);
v5 += 2;
}
while ( v5 != v6 );
}
do
{
while ( 1 )
{
addr_len = 16;
v7 = accept(fd, &addr, &addr_len);
if ( v7 < 0 )
break;
pthread_mutex_lock(&xyz_netmodel_mutex);
xyz_netmodel_connfd = v7;
pthread_cond_signal(&xyz_netmodel_cond);
pthread_mutex_unlock(&xyz_netmodel_mutex);
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(int fd, int a2, pthread_t a3)
{
pthread_t *v4; // rax
pthread_t *v5; // rbx
pthread_t *v6; // rbp
int v7; // ebx
socklen_t addr_len; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

v4 = (pthread_t *)malloc(16LL * a2);
if ( a2 > 0 )
{
v5 = v4;
v6 = &v4[2 * (unsigned int)a2];
do
{
v5[1] = a3;
pthread_create(v5, 0LL, (void *(*)(void *))xyz_netmodel_threadpool_func, v5);
v5 += 2;
}
while ( v5 != v6 );
}
do
{
while ( 1 )
{
addr_len = 16;
v7 = accept(fd, &addr, &addr_len);
if ( v7 < 0 )
break;
pthread_mutex_lock(&xyz_netmodel_mutex);
xyz_netmodel_connfd = v7;
pthread_cond_signal(&xyz_netmodel_cond);
pthread_mutex_unlock(&xyz_netmodel_mutex);
}
}
while ( *_errno_location() == 4 );
return 0xFFFFFFFFLL;
}

original_code:
int xyz_netmodel_threadpool(int listenfd, int count, xyz_netmodel_func func)
{
    int i=0;
    int connfd;
    struct sockaddr addr;
    socklen_t addrlen;
    struct xyz_netmodel_threadpool_t *threadpool = malloc(count*sizeof(struct xyz_netmodel_threadpool_t));
    for(i=0; i<count; i++) {
        threadpool[i].func = func;
        pthread_create(&(threadpool[i].tid), ((void *)0), xyz_netmodel_threadpool_func, (void *)&threadpool[i]);
    }
    while(1) {
        addrlen = sizeof(addr);
        connfd = accept(listenfd, &addr, &addrlen);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        pthread_mutex_lock(&xyz_netmodel_mutex);
        xyz_netmodel_connfd = connfd;
        pthread_cond_signal(&xyz_netmodel_cond);
        pthread_mutex_unlock(&xyz_netmodel_mutex);
    }
    return 0;
}

canonical_original_code:
int xyz_netmodel_threadpool(int listenfd, int count, int (*func)(int fd))
{
    int i = 0;
    int connfd;
    struct sockaddr addr;
    unsigned int addrlen;
    struct xyz_netmodel_threadpool_t *threadpool = malloc(count*sizeof(struct xyz_netmodel_threadpool_t));
    for(i=0; i<count; i++) {
        threadpool[i].func = func;
        pthread_create(&(threadpool[i].tid), ((void *)0), xyz_netmodel_threadpool_func, (void *)&threadpool[i]);
    }
    while(1) {
        addrlen = sizeof(addr);
        connfd = accept(listenfd, &addr, &addrlen);
        if(connfd < 0) {
            if((*__errno_location ()) == 4) {
                continue;
            } else {
                return -1;
            }
        }
        pthread_mutex_lock(&xyz_netmodel_mutex);
        xyz_netmodel_connfd = connfd;
        pthread_cond_signal(&xyz_netmodel_cond);
        pthread_mutex_unlock(&xyz_netmodel_mutex);
    }
    return 0;
}

variable_types: i int

user_defined_types: struct xyz_netmodel_threadpool_t { unsigned long tid; int (*func)(int fd); }


decompiled_code:
char *__fastcall xyz_list_create(char *src)
{
char *v1; // rax
char *v2; // rbx
__int64 v3; // rbp

v1 = (char *)malloc(0x40uLL);
v2 = v1;
if ( v1 )
{
if ( src || *(_BYTE *)xyz_list_create )
strncpy(v1, src, 0x1FuLL);
v3 = xyz_mpool_create(v2, 24LL);
*((_QWORD *)v2 + 4) = v3;
if ( v3 )
{
*((_DWORD *)v2 + 10) = 0;
*((_QWORD *)v2 + 7) = 0LL;
*((_QWORD *)v2 + 6) = 0LL;
}
else
{
free(v2);
v2 = 0LL;
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func0(char *src)
{
char *v1; // rax
char *v2; // rbx
__int64 v3; // rbp

v1 = (char *)malloc(0x40uLL);
v2 = v1;
if ( v1 )
{
if ( src || *(_BYTE *)xyz_list_create )
strncpy(v1, src, 0x1FuLL);
v3 = xyz_mpool_create(v2, 24LL);
*((_QWORD *)v2 + 4) = v3;
if ( v3 )
{
*((_DWORD *)v2 + 10) = 0;
*((_QWORD *)v2 + 7) = 0LL;
*((_QWORD *)v2 + 6) = 0LL;
}
else
{
free(v2);
v2 = 0LL;
}
}
return v2;
}

original_code:
struct xyz_list_t *xyz_list_create(char *label)
{
 struct xyz_list_t *l;
 l = malloc(sizeof(struct xyz_list_t));
 if(l == ((void *)0)) {
  return ((void *)0);
 }
 if(label != ((void *)0) || strlen(label) > 0) {
  strncpy(l->label, label, sizeof(l->label)-1);
 }
 l->mp = xyz_mpool_create(l->label, sizeof(struct xyz_list_node_t));
 if(l->mp == ((void *)0)) {
  free(l);
  return ((void *)0);
 }
 l->count = 0;
 l->head = l->tail = ((void *)0);
 return l;
}

variable_types:
label
char *

variable_types: struct xyz_list_t { char label[32]; struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; } *mp; int count; struct xyz_list_node_t { void *data; struct xyz_list_node_t *prev; } *head; } *

user_defined_types: struct xyz_list_t { char label[32]; struct xyz_mpool_t *mp; int count; struct xyz_list_node_t *head; }


original_code:
void xyz_list_clear(struct xyz_list_t *list)
{
 if(list == ((void *)0)) {
  return;
 }
 struct xyz_list_node_t *ln = list->head;
 while(list->head) {
  ln = list->head;
  list->head = list->head->next;
  xyz_mpool_free(list->mp, ln);
 }
 list->count = 0;
 list->head = list->tail = ((void *)0);
 return;
}

variable_types: struct xyz_list_node_t { void *data; struct xyz_list_node_t *prev; } *

user_defined_types: struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; }


decompiled_code:
void __fastcall xyz_list_destroy(void *ptr)
{
if ( ptr )
{
xyz_list_clear((__int64)ptr);
xyz_mpool_destroy(*((_QWORD *)ptr + 4));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
if ( ptr )
{
func1((__int64)ptr);
xyz_mpool_destroy(*((_QWORD *)ptr + 4));
free(ptr);
}
}

original_code:
void xyz_list_destroy(struct xyz_list_t *list)
{
 if(list == ((void *)0)) {
  return;
 }
 xyz_list_clear(list);
 xyz_mpool_destroy(list->mp);
 free(list);
 return;
}

user_defined_types: struct xyz_list_node_t { void *data; struct xyz_list_node_t *prev; }


original_code:
int xyz_list_puthead(struct xyz_list_t *list, void *data)
{
 if(list == ((void *)0) || data == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *ln = xyz_mpool_malloc(list->mp);
 if(ln == ((void *)0)) {
  return -1;
 }
 ln->data = data;
 if(list->head == ((void *)0) && list->tail == ((void *)0)) {
  list->head = list->tail = ln;
  ln->prev = ln->next = ((void *)0);
 } else {
  ln->next = list->head;
  ln->prev = ((void *)0);
  list->head->prev = ln;
  list->head = ln;
 }
 list->count++;
 return 0;
}

variable_types:
data
void *


original_code:
int xyz_list_puttail(struct xyz_list_t *list, void *data)
{
 if(list == ((void *)0) || data == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *ln = xyz_mpool_malloc(list->mp);
 if(ln == ((void *)0)) {
  return -1;
 }
 ln->data = data;
 if(list->head == ((void *)0) && list->tail == ((void *)0)) {
  list->head = list->tail = ln;
  ln->prev = ln->next = ((void *)0);
 } else {
  ln->prev = list->tail;
  ln->next = ((void *)0);
  list->tail->next = ln;
  list->tail = ln;
 }
 list->count++;
 return 0;
}


original_code:
void *xyz_list_gettail(struct xyz_list_t *list)
{
 if(list == ((void *)0)) {
  return ((void *)0);
 }
 if(list->head == ((void *)0) && list->tail == ((void *)0)) {
  return ((void *)0);
 }
 struct xyz_list_node_t *ln = list->tail;
 if(list->head == list->tail) {
  list->head = list->tail = ((void *)0);
 } else {
  list->tail = list->tail->prev;
  list->tail->next = ((void *)0);
 }
 list->count--;
 void *p = ln->data;
 xyz_mpool_free(list->mp, ln);
 return p;
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall xyz_list_foreach(__int64 a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, _QWORD *a4)
{
_QWORD *v6; // rbx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v6 = *(_QWORD **)(a1 + 48);
if ( !v6 )
return 0LL;
while ( 1 )
{
result = a2(*v6, a3);
if ( (_DWORD)result )
break;
v6 = (_QWORD *)v6[2];
if ( !v6 )
return result;
}
if ( a4 )
*a4 = *v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 (__fastcall *a2)(_QWORD, __int64), __int64 a3, _QWORD *a4)
{
_QWORD *v6; // rbx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a2 )
return 0xFFFFFFFFLL;
v6 = *(_QWORD **)(a1 + 48);
if ( !v6 )
return 0LL;
while ( 1 )
{
result = a2(*v6, a3);
if ( (_DWORD)result )
break;
v6 = (_QWORD *)v6[2];
if ( !v6 )
return result;
}
if ( a4 )
*a4 = *v6;
return result;
}

original_code:
int xyz_list_foreach(struct xyz_list_t *list, xyz_list_foreach_t func, void *arg, void **data)
{
 struct xyz_list_node_t *ln;
 int ret;
 if(list == ((void *)0) || func == ((void *)0)) {
  return -1;
 }
 ln = list->head;
 while(ln) {
  ret = func(ln->data, arg);
  if(ret != 0) {
   if(data != ((void *)0)) {
    *data = ln->data;
   }
   return ret;
  }
  ln = ln->next;
 }
 return 0;
}

canonical_original_code:
int xyz_list_foreach(struct xyz_list_t *list, int (*func)(void *data, void *arg), void *arg, void **data)
{
 struct xyz_list_node_t *ln;
 int ret;
 if(list == ((void *)0) || func == ((void *)0)) {
  return -1;
 }
 ln = list->head;
 while(ln) {
  ret = func(ln->data, arg);
  if(ret != 0) {
   if(data != ((void *)0)) {
    *data = ln->data;
   }
   return ret;
  }
  ln = ln->next;
 }
 return 0;
}

variable_types:
func
int (*)(void *data, void *arg)

variable_types:
arg
void *

variable_types:
data
void **


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

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
result = *(_QWORD *)(a1 + 48);
if ( !result )
return 0LL;
while ( *(_QWORD *)result != a2 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
return 1LL;
}

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

if ( !a1 || !a2 )
return 0xFFFFFFFFLL;
result = *(_QWORD *)(a1 + 48);
if ( !result )
return 0LL;
while ( *(_QWORD *)result != a2 )
{
result = *(_QWORD *)(result + 16);
if ( !result )
return result;
}
return 1LL;
}

original_code:
int xyz_list_find(struct xyz_list_t *list, void *data)
{
 if(list == ((void *)0) || data == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *ln = list->head;
 while(ln) {
  if(ln->data == data)
   return 1;
  ln = ln->next;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall xyz_list_insert(__int64 a1, __int64 a2, __int64 a3)
{
_QWORD *v4; // rbx
__int64 result; // rax
_QWORD *v6; // rdx
__int64 v7; // rax

if ( a3 == 0 || a2 == 0 || !a1 )
return 0xFFFFFFFFLL;
v4 = *(_QWORD **)(a1 + 48);
if ( !v4 )
return 0LL;
while ( *v4 != a2 )
{
v4 = (_QWORD *)v4[2];
if ( !v4 )
return 0LL;
}
v6 = (_QWORD *)xyz_mpool_malloc(*(_QWORD *)(a1 + 32));
result = 0xFFFFFFFFLL;
if ( v6 )
{
*v6 = a3;
v6[1] = v4;
v6[2] = v4[2];
v4[2] = v6;
v7 = v6[2];
if ( v7 )
*(_QWORD *)(v7 + 8) = v6;
else
*(_QWORD *)(a1 + 56) = v6;
++*(_DWORD *)(a1 + 40);
result = 1LL;
}
return result;
}

original_code:
int xyz_list_insert(struct xyz_list_t *list, void *data, void *newdata)
{
 if(list == ((void *)0) || data == ((void *)0) || newdata == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *lntmp = list->head;
 while(lntmp) {
  if(lntmp->data == data) {
   struct xyz_list_node_t *ln = xyz_mpool_malloc(list->mp);
   if(ln == ((void *)0)) {
    return -1;
   }
   ln->data = newdata;
   ln->prev = lntmp;
   ln->next = lntmp->next;
   lntmp->next = ln;
   if(ln->next) {
    ln->next->prev = ln;
   } else {
    list->tail = ln;
   }
   list->count++;
   return 1;
  }
  lntmp = lntmp->next;
 }
 return 0;
}

variable_types:
newdata
void *


original_code:
int xyz_list_delete(struct xyz_list_t *list, void *data)
{
 if(list == ((void *)0) || data == ((void *)0)) {
  return -1;
 }
 struct xyz_list_node_t *ln = list->head;
 while(ln) {
  if(ln->data == data) {
   if(ln == list->head) {
    list->head = list->head->next;
    if(list->head) {
     list->head->prev = ((void *)0);
    } else {
     list->tail = list->head = ((void *)0);
    }
   } else if(ln == list->tail) {
    list->tail = list->tail->prev;
    if(list->tail) {
     list->tail->next = ((void *)0);
    } else {
     list->head = list->tail = ((void *)0);
    }
   } else {
    ln->prev->next = ln->next;
    ln->next->prev = ln->prev;
   }
   xyz_mpool_free(list->mp, ln);
   list->count--;
   return 1;
  }
  ln = ln->next;
 }
 return 0;
}


decompiled_code:
int __fastcall xyz_list_stat(__int64 a1, int a2)
{
int result; // eax
const char **i; // rbx

if ( a1 )
{
puts("------list stat------");
printf("*** %s ***\n", (const char *)a1);
printf("count : %d\n", *(unsigned int *)(a1 + 40));
result = printf("head : %p , tail : %p\n", *(const void **)(a1 + 48), *(const void **)(a1 + 56));
for ( i = *(const char ***)(a1 + 48); i; i = (const char **)i[2] )
result = printf("prev : %p , next : %p , data : %p:%s\n", i[1], i[2], *i, *i);
if ( a2 )
result = xyz_mpool_stat(*(_QWORD *)(a1 + 32), 0LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, int a2)
{
int result; // eax
const char **i; // rbx

if ( a1 )
{
puts("------list stat------");
printf("*** %s ***\n", (const char *)a1);
printf("count : %d\n", *(unsigned int *)(a1 + 40));
result = printf("head : %p , tail : %p\n", *(const void **)(a1 + 48), *(const void **)(a1 + 56));
for ( i = *(const char ***)(a1 + 48); i; i = (const char **)i[2] )
result = printf("prev : %p , next : %p , data : %p:%s\n", i[1], i[2], *i, *i);
if ( a2 )
result = xyz_mpool_stat(*(_QWORD *)(a1 + 32), 0LL);
}
return result;
}

original_code:
void xyz_list_stat(struct xyz_list_t *list, int ex)
{
 if(list == ((void *)0)) {
  return;
 }
 printf("------list stat------\n");
 printf("*** %s ***\n", list->label);
 printf("count : %d\n", list->count);
 printf("head : %p , tail : %p\n", list->head, list->tail);
 struct xyz_list_node_t *ln = list->head;
 while(ln) {
  printf("prev : %p , next : %p , data : %p:%s\n", ln->prev, ln->next, ln->data, (char *)ln->data);
  ln = ln->next;
 }
 if(ex) {
  xyz_mpool_stat(list->mp, 0);
 }
 return;
}

variable_types: ex int


decompiled_code:
int *xyz_event2_create()
{
int *v0; // rbx
void *v1; // rbp

v0 = (int *)malloc(0x20uLL);
if ( v0 )
{
v1 = calloc(0x10000uLL, 0x20uLL);
*((_QWORD *)v0 + 1) = v1;
if ( v1 )
{
*((_QWORD *)v0 + 3) = 0LL;
_xyz_event2_init(v0);
}
else
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

canonical_decompiled_code:
int *func4()
{
int *v0; // rbx
void *v1; // rbp

v0 = (int *)malloc(0x20uLL);
if ( v0 )
{
v1 = calloc(0x10000uLL, 0x20uLL);
*((_QWORD *)v0 + 1) = v1;
if ( v1 )
{
*((_QWORD *)v0 + 3) = 0LL;
func0(v0);
}
else
{
free(v0);
v0 = 0LL;
}
}
return v0;
}

original_code:
struct xyz_event2_t *xyz_event2_create()
{
    struct xyz_event2_t *event2 = malloc(sizeof(struct xyz_event2_t));
    if(event2 == ((void *)0)) {
        return ((void *)0);
    }
    event2->nodes = calloc(65535 +1, sizeof(struct xyz_event2_node_t));
    if(event2->nodes == ((void *)0)) {
        free(event2);
        return ((void *)0);
    }
    event2->call = ((void *)0);
    __xyz_event2_init(event2);
    return event2;
}

variable_types: struct xyz_event2_t { int evfd; struct xyz_event2_node_t { int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *rdarg; void *wtarg; } *nodes; int isstop; int (*call)(); } *

user_defined_types: struct xyz_event2_t { int evfd; struct xyz_event2_node_t *nodes; int isstop; int (*call)(); }


decompiled_code:
void __fastcall xyz_event2_destroy(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
close(*(_DWORD *)ptr);
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
void *v2; // rdi

if ( ptr )
{
close(*(_DWORD *)ptr);
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
free(ptr);
}
}

original_code:
void xyz_event2_destroy(struct xyz_event2_t *ev2)
{
    if(ev2) {
        close(ev2->evfd);
        if(ev2->nodes) {
            free(ev2->nodes);
        }
        free(ev2);
    }
    return;
}

user_defined_types: struct xyz_event2_node_t { int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *rdarg; void *wtarg; }


decompiled_code:
__int64 __fastcall xyz_event2_add(__int64 a1, int a2, int a3, __int64 a4, __int64 a5)
{
__int64 v5; // rax
__int64 v7; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a4 || (unsigned int)a2 > 0xFFFD )
return 0xFFFFFFFFLL;
if ( a3 == 1 )
{
v7 = 32LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v7) = a4;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v7 + 16) = a5;
goto LABEL_7;
}
if ( a3 == 2 )
{
v5 = 32LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5 + 8) = a4;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5 + 24) = a5;
LABEL_7:
_xyz_event2_add(a1, a2, a3);
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2, int a3, __int64 a4, __int64 a5)
{
__int64 v5; // rax
__int64 v7; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
if ( !a4 || (unsigned int)a2 > 0xFFFD )
return 0xFFFFFFFFLL;
if ( a3 == 1 )
{
v7 = 32LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v7) = a4;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v7 + 16) = a5;
goto LABEL_7;
}
if ( a3 == 2 )
{
v5 = 32LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5 + 8) = a4;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5 + 24) = a5;
LABEL_7:
func1(a1, a2, a3);
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int xyz_event2_add(struct xyz_event2_t *ev2, int fd, int type, xyz_ev2_func func, void *arg)
{
    if(ev2 == ((void *)0) || fd < 0 || func == ((void *)0) || fd >= 65535 -1) {
        return -1;
    }
    if(type == 1) {
        ev2->nodes[fd].rdfunc = func;
        ev2->nodes[fd].rdarg = arg;
    } else if(type == 2) {
        ev2->nodes[fd].wtfunc = func;
        ev2->nodes[fd].wtarg = arg;
    } else {
        return -1;
    }
    __xyz_event2_add(ev2, fd, type);
    return 0;
}

canonical_original_code:
int xyz_event2_add(struct xyz_event2_t *ev2, int fd, int type, int (*func)(int fd, void *arg), void *arg)
{
    if(ev2 == ((void *)0) || fd < 0 || func == ((void *)0) || fd >= 65535 -1) {
        return -1;
    }
    if(type == 1) {
        ev2->nodes[fd].rdfunc = func;
        ev2->nodes[fd].rdarg = arg;
    } else if(type == 2) {
        ev2->nodes[fd].wtfunc = func;
        ev2->nodes[fd].wtarg = arg;
    } else {
        return -1;
    }
    __xyz_event2_add(ev2, fd, type);
    return 0;
}

variable_types: fd int

variable_types: type int

variable_types:
func
int (*)(int fd, void *arg)


decompiled_code:
__int64 __fastcall xyz_event2_del(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
__int64 v5; // rax

if ( !a1 || (unsigned int)a2 > 0xFFFE )
return 0xFFFFFFFFLL;
if ( a3 == 1 )
{
v5 = 32LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5) = 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5 + 16) = 0LL;
goto LABEL_6;
}
if ( a3 == 2 )
{
v3 = 32LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v3 + 8) = 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v3 + 24) = 0LL;
LABEL_6:
_xyz_event2_del(a1, a2, a3);
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2, int a3)
{
__int64 v3; // rax
__int64 v5; // rax

if ( !a1 || (unsigned int)a2 > 0xFFFE )
return 0xFFFFFFFFLL;
if ( a3 == 1 )
{
v5 = 32LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5) = 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v5 + 16) = 0LL;
goto LABEL_6;
}
if ( a3 == 2 )
{
v3 = 32LL * a2;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v3 + 8) = 0LL;
*(_QWORD *)(*(_QWORD *)(a1 + 8) + v3 + 24) = 0LL;
LABEL_6:
func2(a1, a2, a3);
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int xyz_event2_del(struct xyz_event2_t *ev2, int fd, int type)
{
    if(ev2 == ((void *)0) || fd < 0 || fd >= 65535) {
        return -1;
    }
    if(type == 1) {
        ev2->nodes[fd].rdfunc = ((void *)0);
        ev2->nodes[fd].rdarg = ((void *)0);
    } else if(type == 2) {
        ev2->nodes[fd].wtfunc = ((void *)0);
        ev2->nodes[fd].wtarg = ((void *)0);
    } else {
        return -1;
    }
    __xyz_event2_del(ev2, fd, type);
    return 0;
}


decompiled_code:
__int64 __fastcall xyz_event2_call(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 + 24) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
if ( a1 )
*(_QWORD *)(a1 + 24) = a2;
return 0LL;
}

original_code:
int xyz_event2_call(struct xyz_event2_t *ev2, xyz_ev2_call call)
{
    if(ev2) {
        ev2->call = call;
    }
    return 0;
}

canonical_original_code:
int xyz_event2_call(struct xyz_event2_t *ev2, int (*call)())
{
    if(ev2) {
        ev2->call = call;
    }
    return 0;
}

variable_types:
call
int (*)()


original_code:
void xyz_event2_loop(struct xyz_event2_t *ev2)
{
    if(ev2 == ((void *)0)) {
        return;
    }
    ev2->isstop = 0;
    while(ev2->isstop == 0) {
        __xyz_event2_run(ev2);
        if(ev2->call) {
            ev2->call();
        }
    }
    return;
}


decompiled_code:
void __fastcall xyz_event2_stop(__int64 a1)
{
if ( a1 )
*(_DWORD *)(a1 + 16) = 1;
}

original_code:
void xyz_event2_stop(struct xyz_event2_t *ev2)
{
    if(ev2) {
        ev2->isstop = 1;
    }
    return;
}


decompiled_code:
int __fastcall xyz_event2_stat(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rbp
const void *v3; // rdx
__int64 v4; // rax
const void *v5; // rdx

if ( a1 )
{
puts("------ event2 stat ------");
printf("isstop : %d\n", *(unsigned int *)(a1 + 16));
printf("call : %p\n", *(const void **)(a1 + 24));
for ( i = 0LL; i != 0xFFFF; ++i )
{
v2 = 32 * i;
v3 = *(const void **)(*(_QWORD *)(a1 + 8) + 32 * i);
if ( v3 )
{
printf("\t[%d] rdfunc : %p\n", (unsigned int)i, v3);
printf("\t[%d] rdarg : %p\n", (unsigned int)i, *(const void **)(*(_QWORD *)(a1 + 8) + v2 + 16));
}
v4 = *(_QWORD *)(a1 + 8);
v5 = *(const void **)(v4 + v2 + 8);
if ( v5 )
{
printf("\t[%d] wtfunc : %p\n", (unsigned int)i, v5);
LODWORD(v4) = printf("\t[%d] wtarg : %p\n", (unsigned int)i, *(const void **)(*(_QWORD *)(a1 + 8) + v2 + 24));
}
}
}
return v4;
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1)
{
__int64 i; // rbx
__int64 v2; // rbp
const void *v3; // rdx
__int64 v4; // rax
const void *v5; // rdx

if ( a1 )
{
puts("------ event2 stat ------");
printf("isstop : %d\n", *(unsigned int *)(a1 + 16));
printf("call : %p\n", *(const void **)(a1 + 24));
for ( i = 0LL; i != 0xFFFF; ++i )
{
v2 = 32 * i;
v3 = *(const void **)(*(_QWORD *)(a1 + 8) + 32 * i);
if ( v3 )
{
printf("\t[%d] rdfunc : %p\n", (unsigned int)i, v3);
printf("\t[%d] rdarg : %p\n", (unsigned int)i, *(const void **)(*(_QWORD *)(a1 + 8) + v2 + 16));
}
v4 = *(_QWORD *)(a1 + 8);
v5 = *(const void **)(v4 + v2 + 8);
if ( v5 )
{
printf("\t[%d] wtfunc : %p\n", (unsigned int)i, v5);
LODWORD(v4) = printf("\t[%d] wtarg : %p\n", (unsigned int)i, *(const void **)(*(_QWORD *)(a1 + 8) + v2 + 24));
}
}
}
return v4;
}

original_code:
void xyz_event2_stat(struct xyz_event2_t *ev2)
{
    int idx;
    if(ev2) {
        printf("------ event2 stat ------\n");
        printf("isstop : %d\n", ev2->isstop);
        printf("call : %p\n", ev2->call);
        for(idx=0; idx<65535; idx++) {
            if(ev2->nodes[idx].rdfunc != ((void *)0)) {
                printf("\t[%d] rdfunc : %p\n", idx, ev2->nodes[idx].rdfunc);
                printf("\t[%d] rdarg : %p\n", idx, ev2->nodes[idx].rdarg);
            }
            if(ev2->nodes[idx].wtfunc != ((void *)0)) {
                printf("\t[%d] wtfunc : %p\n", idx, ev2->nodes[idx].wtfunc);
                printf("\t[%d] wtarg : %p\n", idx, ev2->nodes[idx].wtarg);
            }
        }
    }
    return;
}

variable_types: idx int


decompiled_code:
__int64 __fastcall bkdr_hash(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 & 0x7FFFFFFF;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
int v2; // edx

v1 = *a1;
if ( *a1 )
{
v2 = 0;
do
{
++a1;
v2 = v1 + 131 * v2;
v1 = *a1;
}
while ( *a1 );
}
else
{
v2 = 0;
}
return v2 & 0x7FFFFFFF;
}

original_code:
signed int bkdr_hash(char *str)
{
    unsigned int seed = 131;
    unsigned int hash = 0;
    while (*str)
    {
        hash = hash * seed + (*str++);
    }
    return (hash & 0x7FFFFFFF);
}

variable_types:
str
char *

variable_types:
seed
unsigned int

variable_types:
hash
unsigned int


decompiled_code:
void __fastcall xyz_hash_destroy(void *ptr)
{
__int64 v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = *(_QWORD *)ptr;
if ( v2 )
xyz_mpool_destroy(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v2; // rdi
void *v3; // rdi

if ( ptr )
{
v2 = *(_QWORD *)ptr;
if ( v2 )
xyz_mpool_destroy(v2);
v3 = (void *)*((_QWORD *)ptr + 2);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
void xyz_hash_destroy(struct xyz_hash_t *hash)
{
    if(hash) {
        if(hash->mp) {
            xyz_mpool_destroy(hash->mp);
        }
        if(hash->list) {
            free(hash->list);
        }
        free(hash);
    }
    return;
}

variable_types: struct xyz_hash_t { struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; } *mp; int count; int size; struct xyz_hash_list_t { char key[32]; void *data; struct xyz_hash_list_t *next; } **list; } *

user_defined_types: struct xyz_hash_t { struct xyz_mpool_t *mp; int count; int size; struct xyz_hash_list_t **list; }


decompiled_code:
__int64 __fastcall xyz_hash_get(__int64 a1, char *a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * ((int)bkdr_hash(a2) % *(_DWORD *)(a1 + 12)));
if ( v2 )
{
while ( strcmp(a2, (const char *)v2) )
{
v2 = *(_QWORD *)(v2 + 40);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 32);
}
return v2;
}

original_code:
void *xyz_hash_get(struct xyz_hash_t *hash, char *key)
{
    int nkey = bkdr_hash(key)%hash->size;
    struct xyz_hash_list_t *list = hash->list[nkey];
    if(list == ((void *)0)) {
        return ((void *)0);
    }
    while(list) {
        if(strcmp(key, list->key) == 0) {
            return list->data;
        }
        list = list->next;
    }
    return ((void *)0);
}

variable_types:
key
char *

variable_types: nkey int

variable_types: struct xyz_hash_list_t { char key[32]; void *data; struct xyz_hash_list_t *next; } *


original_code:
int xyz_hash_add(struct xyz_hash_t *hash, char *key, void *data)
{
    int nkey = bkdr_hash(key)%hash->size;
    struct xyz_hash_list_t *list = hash->list[nkey];
    struct xyz_hash_list_t *tmp;
    tmp = xyz_mpool_malloc(hash->mp);
    strncpy(tmp->key, key, sizeof(tmp->key)-1);
    tmp->data = data;
    tmp->next = ((void *)0);
    if(list == ((void *)0)) {
        hash->list[nkey] = tmp;
        hash->count++;
        return 0;
    }
    while(list->next) {
        if(strcmp(list->key, key) == 0) {
            return -1;
        }
        list = list->next;
    }
    list->next = tmp;
    hash->count++;
 return 0;
}

variable_types:
data
void *

user_defined_types: struct xyz_hash_list_t { char key[32]; void *data; struct xyz_hash_list_t *next; }


original_code:
int xyz_hash_del(struct xyz_hash_t *hash, char *key)
{
    int nkey = bkdr_hash(key)%hash->size;
    struct xyz_hash_list_t *list = hash->list[nkey];
    struct xyz_hash_list_t *prov = ((void *)0);
    if(list == ((void *)0)) {
        return 0;
    }
    while(list) {
        if(strcmp(list->key, key) == 0) {
            if(prov) {
                prov->next = list->next;
            } else {
                hash->list[nkey] = ((void *)0);
            }
            xyz_mpool_free(hash->mp, list);
            hash->count--;
            return 0;
        }
        prov = list;
        list = list->next;
    }
 return 0;
}


decompiled_code:
__int64 __fastcall xyz_hash_state(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
puts("---xyz_hash_state---");
printf("hash size : %d\n", *(unsigned int *)(a1 + 12));
printf("hash count : %d\n", *(unsigned int *)(a1 + 8));
printf("hash node :");
if ( *(int *)(a1 + 12) > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v1);
if ( v2 )
{
printf("\n <%d>", (unsigned int)v1);
do
{
printf(" [%s]", (const char *)v2);
v2 = *(_QWORD *)(v2 + 40);
}
while ( v2 );
}
++v1;
}
while ( *(_DWORD *)(a1 + 12) > (int)v1 );
}
puts("\n---the end---");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // r12
__int64 v2; // rbx

if ( !a1 )
return 0xFFFFFFFFLL;
puts("---xyz_hash_state---");
printf("hash size : %d\n", *(unsigned int *)(a1 + 12));
printf("hash count : %d\n", *(unsigned int *)(a1 + 8));
printf("hash node :");
if ( *(int *)(a1 + 12) > 0 )
{
v1 = 0LL;
do
{
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8 * v1);
if ( v2 )
{
printf("\n <%d>", (unsigned int)v1);
do
{
printf(" [%s]", (const char *)v2);
v2 = *(_QWORD *)(v2 + 40);
}
while ( v2 );
}
++v1;
}
while ( *(_DWORD *)(a1 + 12) > (int)v1 );
}
puts("\n---the end---");
return 0LL;
}

original_code:
int xyz_hash_state(struct xyz_hash_t *hash)
{
    struct xyz_hash_list_t *list;
    int i;
    if(hash == ((void *)0)) {
        return -1;
    }
    printf("---xyz_hash_state---\n");
    printf("hash size : %d\n", hash->size);
    printf("hash count : %d\n", hash->count);
    printf("hash node :");
    for(i=0; i<hash->size; i++) {
        list = hash->list[i];
        if(list) {
            printf("\n <%d>", i);
        }
        while(list) {
            printf(" [%s]", list->key);
            list = list->next;
        }
    }
    printf("\n---the end---\n");
 return 0;
}

variable_types: i int


decompiled_code:
char *__fastcall xyz_mpool_create(char *src, int a2)
{
char *v2; // rbx
unsigned int v3; // ebp
char *v4; // rax

v2 = 0LL;
if ( a2 > 2 )
{
v3 = a2;
v4 = (char *)malloc(0x48uLL);
v2 = v4;
if ( v4 )
{
if ( src && *src )
strncpy(v4, src, 0x1FuLL);
if ( (a2 & 7) != 0 )
v3 = (a2 & 0xFFFFFFF8) + 8;
*((_DWORD *)v2 + 8) = v3;
*((_QWORD *)v2 + 5) = 0LL;
*((_DWORD *)v2 + 12) = 0;
*((_QWORD *)v2 + 7) = 0LL;
*((_DWORD *)v2 + 16) = 0;
}
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *src, int a2)
{
char *v2; // rbx
unsigned int v3; // ebp
char *v4; // rax

v2 = 0LL;
if ( a2 > 2 )
{
v3 = a2;
v4 = (char *)malloc(0x48uLL);
v2 = v4;
if ( v4 )
{
if ( src && *src )
strncpy(v4, src, 0x1FuLL);
if ( (a2 & 7) != 0 )
v3 = (a2 & 0xFFFFFFF8) + 8;
*((_DWORD *)v2 + 8) = v3;
*((_QWORD *)v2 + 5) = 0LL;
*((_DWORD *)v2 + 12) = 0;
*((_QWORD *)v2 + 7) = 0LL;
*((_DWORD *)v2 + 16) = 0;
}
}
return v2;
}

original_code:
struct xyz_mpool_t *xyz_mpool_create(char *label, int size)
{
 if(size <= 2) {
  return ((void *)0);
 }
 struct xyz_mpool_t *mp = malloc(sizeof(struct xyz_mpool_t));
 if(mp==((void *)0)) {
  return ((void *)0);
 }
 if(label != ((void *)0) && strlen(label) > 0) {
  strncpy(mp->label, label, sizeof(mp->label)-1);
 }
 mp->data_size = size;
 if(size & 0x7) {
  mp->data_size = ((size>>3)<<3)+8;
 }
 mp->free_list = ((void *)0);
 mp->free_count = 0;
 mp->block_list = ((void *)0);
 mp->block_count = 0;
 return mp;
}

variable_types:
label
char *

variable_types: size int

variable_types: struct xyz_mpool_t { char label[32]; int data_size; char *free_list; int free_count; char *block_list; int block_count; } *


decompiled_code:
void __fastcall xyz_mpool_destroy(void *ptr)
{
_QWORD *i; // rdi

if ( ptr )
{
for ( i = (_QWORD *)*((_QWORD *)ptr + 7); i; i = (_QWORD *)*((_QWORD *)ptr + 7) )
{
*((_QWORD *)ptr + 7) = *i;
free(i);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
_QWORD *i; // rdi

if ( ptr )
{
for ( i = (_QWORD *)*((_QWORD *)ptr + 7); i; i = (_QWORD *)*((_QWORD *)ptr + 7) )
{
*((_QWORD *)ptr + 7) = *i;
free(i);
}
free(ptr);
}
}

original_code:
void xyz_mpool_destroy(struct xyz_mpool_t *mp)
{
 char *p;
 if(mp == ((void *)0)) {
  return;
 }
 while(mp->block_list) {
  p = mp->block_list;
  mp->block_list = *(char **)p;
  free(p);
 }
 free(mp);
 return;
}

variable_types:
p
char *


decompiled_code:
__int64 __fastcall xyz_mpool_free(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
result = *(_QWORD *)(a1 + 40);
*a2 = result;
*(_QWORD *)(a1 + 40) = a2;
++*(_DWORD *)(a1 + 48);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _QWORD *a2)
{
__int64 result; // rax

if ( a1 )
{
if ( a2 )
{
result = *(_QWORD *)(a1 + 40);
*a2 = result;
*(_QWORD *)(a1 + 40) = a2;
++*(_DWORD *)(a1 + 48);
}
}
return result;
}

original_code:
void xyz_mpool_free(struct xyz_mpool_t *mp, void *p)
{
 if(mp == ((void *)0) || p == ((void *)0)) {
  return;
 }
 *(char **)p = mp->free_list;
 mp->free_list = p;
 mp->free_count++;
 return;
}

variable_types:
p
void *


decompiled_code:
int __fastcall xyz_mpool_stat(__int64 a1, int a2)
{
int result; // eax
_QWORD *i; // rbx
_QWORD *j; // rbx

puts("------ mpool stat ------");
printf("*** %s ***\n", (const char *)a1);
printf("data_size:%d\n", *(unsigned int *)(a1 + 32));
printf("free_count:%d\n", *(unsigned int *)(a1 + 48));
printf("block_size:%d\n", 32 * *(_DWORD *)(a1 + 32) + 8LL);
result = printf("block_count:%d\n", *(unsigned int *)(a1 + 64));
if ( a2 )
{
puts("free_list display:");
for ( i = *(_QWORD **)(a1 + 40); i; i = (_QWORD *)*i )
printf(" %p ", i);
putchar(10);
puts("block_list display:");
for ( j = *(_QWORD **)(a1 + 56); j; j = (_QWORD *)*j )
printf(" %p ", j);
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, int a2)
{
int result; // eax
_QWORD *i; // rbx
_QWORD *j; // rbx

puts("------ mpool stat ------");
printf("*** %s ***\n", (const char *)a1);
printf("data_size:%d\n", *(unsigned int *)(a1 + 32));
printf("free_count:%d\n", *(unsigned int *)(a1 + 48));
printf("block_size:%d\n", 32 * *(_DWORD *)(a1 + 32) + 8LL);
result = printf("block_count:%d\n", *(unsigned int *)(a1 + 64));
if ( a2 )
{
puts("free_list display:");
for ( i = *(_QWORD **)(a1 + 40); i; i = (_QWORD *)*i )
printf(" %p ", i);
putchar(10);
puts("block_list display:");
for ( j = *(_QWORD **)(a1 + 56); j; j = (_QWORD *)*j )
printf(" %p ", j);
result = putchar(10);
}
return result;
}

original_code:
void xyz_mpool_stat(struct xyz_mpool_t *mp, int v)
{
 char *p;
 printf("------ mpool stat ------\n");
 printf("*** %s ***\n", mp->label);
 printf("data_size:%d\n", mp->data_size);
 printf("free_count:%d\n", mp->free_count);
 printf("block_size:%d\n", mp->data_size*32 +sizeof(char *));
 printf("block_count:%d\n", mp->block_count);
 if(v) {
  printf("free_list display:\n");
  p = mp->free_list;
  while(p) {
   printf(" %p ", p);
   p = *(char **)p;
  }
  printf("\n");
  printf("block_list display:\n");
  p = mp->block_list;
  while(p) {
   printf(" %p ", p);
   p = *(char **)p;
  }
  printf("\n");
 }
 return;
}

variable_types: v int


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

result = malloc(0x110uLL);
if ( result )
{
*result = 0;
result[1] = 200000;
result[2] = -1;
result[10] = -1;
result[18] = -1;
result[26] = -1;
result[34] = -1;
result[42] = -1;
result[50] = -1;
result[58] = -1;
*((_QWORD *)result + 33) = 0LL;
}
return result;
}

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

result = malloc(0x110uLL);
if ( result )
{
*result = 0;
result[1] = 200000;
result[2] = -1;
result[10] = -1;
result[18] = -1;
result[26] = -1;
result[34] = -1;
result[42] = -1;
result[50] = -1;
result[58] = -1;
*((_QWORD *)result + 33) = 0LL;
}
return result;
}

original_code:
struct xyz_event_t *xyz_event_create()
{
 int i;
 struct xyz_event_t *ev = malloc(sizeof(struct xyz_event_t));
 if(ev == ((void *)0)) {
  return ((void *)0);
 }
 ev->stop = 0;
 ev->usec = 200*1000;
 for(i=0; i<8; i++) {
  ev->array[i].fd = -1;
 }
 ev->call = ((void *)0);
 return ev;
}

variable_types: struct xyz_event_t { int stop; int usec; struct xyz_event_node_t { int fd; int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *arg; } array[8]; int (*call)(); } *

user_defined_types: struct xyz_event_t { int stop; int usec; struct xyz_event_node_t array[8]; int (*call)(); }


decompiled_code:
__int64 __fastcall xyz_event_call(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 264) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_QWORD *)(a1 + 264) = a2;
return 0LL;
}

original_code:
int xyz_event_call(struct xyz_event_t *ev, xyz_ev_call call)
{
    if(ev == ((void *)0)) {
        return -1;
    }
 ev->call = call;
 return 0;
}

canonical_original_code:
int xyz_event_call(struct xyz_event_t *ev, int (*call)())
{
    if(ev == ((void *)0)) {
        return -1;
    }
 ev->call = call;
 return 0;
}

variable_types:
call
int (*)()

user_defined_types: struct xyz_event_node_t { int fd; int (*rdfunc)(int fd, void *arg); int (*wtfunc)(int fd, void *arg); void *arg; }


original_code:
int xyz_event_add(struct xyz_event_t *ev, int fd, int type, xyz_ev_func func, void *arg)
{
 int i;
 if(ev == ((void *)0) || fd < 0 || func == ((void *)0) || fd >= 1024) {
  return -1;
 }
    if(type != 1 && type != 2) {
        return -1;
    }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd == fd) {
   if(type == 1) {
    ev->array[i].rdfunc = func;
   } else if(type == 2) {
    ev->array[i].wtfunc = func;
   } else {
    return -1;
   }
   ev->array[i].arg = arg;
   return 0;
  }
 }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   if(type == 1) {
    ev->array[i].rdfunc = func;
   } else if(type == 2) {
    ev->array[i].wtfunc = func;
   } else {
    return -1;
   }
   ev->array[i].fd = fd;
   ev->array[i].arg = arg;
   return 0;
  }
 }
 return -1;
}

canonical_original_code:
int xyz_event_add(struct xyz_event_t *ev, int fd, int type, int (*func)(int fd, void *arg), void *arg)
{
 int i;
 if(ev == ((void *)0) || fd < 0 || func == ((void *)0) || fd >= 1024) {
  return -1;
 }
    if(type != 1 && type != 2) {
        return -1;
    }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd == fd) {
   if(type == 1) {
    ev->array[i].rdfunc = func;
   } else if(type == 2) {
    ev->array[i].wtfunc = func;
   } else {
    return -1;
   }
   ev->array[i].arg = arg;
   return 0;
  }
 }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   if(type == 1) {
    ev->array[i].rdfunc = func;
   } else if(type == 2) {
    ev->array[i].wtfunc = func;
   } else {
    return -1;
   }
   ev->array[i].fd = fd;
   ev->array[i].arg = arg;
   return 0;
  }
 }
 return -1;
}

variable_types: fd int

variable_types: type int

variable_types:
func
int (*)(int fd, void *arg)

variable_types:
arg
void *


decompiled_code:
__int64 __fastcall xyz_event_del(__int64 a1, unsigned int a2, int a3)
{
_DWORD *v4; // rdx
int v5; // eax
unsigned int v6; // edx
__int64 v8; // rcx
__int64 v9; // rdx

if ( !a1 || a2 > 0x3FF )
return (unsigned int)-1;
if ( (unsigned int)(a3 - 1) > 1 )
return (unsigned int)-1;
v4 = (_DWORD *)(a1 + 8);
v5 = 0;
while ( *v4 != a2 )
{
++v5;
v4 += 8;
if ( v5 == 8 )
return (unsigned int)-1;
}
if ( a3 == 1 )
{
v9 = a1 + 32LL * v5;
*(_QWORD *)(v9 + 16) = 0LL;
if ( *(_QWORD *)(v9 + 24) )
return 0;
goto LABEL_11;
}
v8 = a1 + 32LL * v5;
*(_QWORD *)(v8 + 24) = 0LL;
v6 = 0;
if ( !*(_QWORD *)(v8 + 16) )
{
LABEL_11:
*(_DWORD *)(a1 + 32LL * v5 + 8) = -1;
v6 = 0;
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, int a3)
{
_DWORD *v4; // rdx
int v5; // eax
unsigned int v6; // edx
__int64 v8; // rcx
__int64 v9; // rdx

if ( !a1 || a2 > 0x3FF )
return (unsigned int)-1;
if ( (unsigned int)(a3 - 1) > 1 )
return (unsigned int)-1;
v4 = (_DWORD *)(a1 + 8);
v5 = 0;
while ( *v4 != a2 )
{
++v5;
v4 += 8;
if ( v5 == 8 )
return (unsigned int)-1;
}
if ( a3 == 1 )
{
v9 = a1 + 32LL * v5;
*(_QWORD *)(v9 + 16) = 0LL;
if ( *(_QWORD *)(v9 + 24) )
return 0;
goto LABEL_11;
}
v8 = a1 + 32LL * v5;
*(_QWORD *)(v8 + 24) = 0LL;
v6 = 0;
if ( !*(_QWORD *)(v8 + 16) )
{
LABEL_11:
*(_DWORD *)(a1 + 32LL * v5 + 8) = -1;
v6 = 0;
}
return v6;
}

original_code:
int xyz_event_del(struct xyz_event_t *ev, int fd, int type)
{
 int i;
    if(ev == ((void *)0) || fd < 0 || fd >= 1024) {
        return -1;
    }
    if(type != 1 && type != 2) {
        return -1;
    }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd == fd) {
   if(type == 1) {
    ev->array[i].rdfunc = ((void *)0);
   } else if(type == 2) {
    ev->array[i].wtfunc = ((void *)0);
   } else {
    return -1;
   }
   if(ev->array[i].rdfunc == ((void *)0) && ev->array[i].wtfunc == ((void *)0)) {
    ev->array[i].fd = -1;
   }
   return 0;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall xyz_event_run(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
__int64 v3; // rdx
int v4; // edi
int v5; // eax
int v6; // eax
unsigned int v7; // er13
__int64 v9; // rdi
void (__fastcall *v10)(__int64, _QWORD); // rdx
void (__fastcall *v11)(__int64, _QWORD); // rdx
__int64 v12; // rdi
fd_set v13; // [rsp+0h] [rbp-138h] BYREF
fd_set readfds; // [rsp+80h] [rbp-B8h] BYREF
struct timeval timeout; // [rsp+100h] [rbp-38h] BYREF

if ( !a1 )
return (unsigned int)-1;
timeout.tv_sec = 0LL;
timeout.tv_usec = *(int *)(a1 + 4);
memset(&readfds, 0, sizeof(readfds));
memset(&v13, 0, sizeof(v13));
v1 = (_QWORD *)(a1 + 8);
v2 = (_QWORD *)(a1 + 264);
v3 = a1 + 8;
v4 = 0;
do
{
v5 = *(_DWORD *)v3;
if ( *(int *)v3 >= 0 )
{
if ( *(_QWORD *)(v3 + 8) )
readfds.fds_bits[v5 / 64] |= 1LL << (v5 % 64);
if ( *(_QWORD *)(v3 + 16) )
v13.fds_bits[v5 / 64] |= 1LL << (v5 % 64);
if ( v4 < v5 )
v4 = v5;
}
v3 += 32LL;
}
while ( (_QWORD *)v3 != v2 );
v6 = select(v4 + 1, &readfds, &v13, 0LL, &timeout);
v7 = v6;
if ( v6 )
{
if ( v6 == -1 )
{
v7 = -(*_errno_location() != 4);
}
else
{
do
{
v9 = *(unsigned int *)v1;
if ( (int)v9 >= 0 )
{
v10 = (void (__fastcall *)(__int64, _QWORD))v1[1];
if ( v10 && (readfds.fds_bits[(int)v9 >> 6] & (1LL << ((int)v9 % 64))) != 0 )
v10(v9, v1[3]);
v11 = (void (__fastcall *)(__int64, _QWORD))v1[2];
if ( v11 )
{
v12 = *(unsigned int *)v1;
if ( (v13.fds_bits[(int)v12 / 64] & (1LL << ((int)v12 % 64))) != 0 )
v11(v12, v1[3]);
}
}
v1 += 4;
}
while ( v1 != v2 );
}
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
__int64 v3; // rdx
int v4; // edi
int v5; // eax
int v6; // eax
unsigned int v7; // er13
__int64 v9; // rdi
void (__fastcall *v10)(__int64, _QWORD); // rdx
void (__fastcall *v11)(__int64, _QWORD); // rdx
__int64 v12; // rdi
fd_set v13; // [rsp+0h] [rbp-138h] BYREF
fd_set readfds; // [rsp+80h] [rbp-B8h] BYREF
struct timeval timeout; // [rsp+100h] [rbp-38h] BYREF

if ( !a1 )
return (unsigned int)-1;
timeout.tv_sec = 0LL;
timeout.tv_usec = *(int *)(a1 + 4);
memset(&readfds, 0, sizeof(readfds));
memset(&v13, 0, sizeof(v13));
v1 = (_QWORD *)(a1 + 8);
v2 = (_QWORD *)(a1 + 264);
v3 = a1 + 8;
v4 = 0;
do
{
v5 = *(_DWORD *)v3;
if ( *(int *)v3 >= 0 )
{
if ( *(_QWORD *)(v3 + 8) )
readfds.fds_bits[v5 / 64] |= 1LL << (v5 % 64);
if ( *(_QWORD *)(v3 + 16) )
v13.fds_bits[v5 / 64] |= 1LL << (v5 % 64);
if ( v4 < v5 )
v4 = v5;
}
v3 += 32LL;
}
while ( (_QWORD *)v3 != v2 );
v6 = select(v4 + 1, &readfds, &v13, 0LL, &timeout);
v7 = v6;
if ( v6 )
{
if ( v6 == -1 )
{
v7 = -(*_errno_location() != 4);
}
else
{
do
{
v9 = *(unsigned int *)v1;
if ( (int)v9 >= 0 )
{
v10 = (void (__fastcall *)(__int64, _QWORD))v1[1];
if ( v10 && (readfds.fds_bits[(int)v9 >> 6] & (1LL << ((int)v9 % 64))) != 0 )
v10(v9, v1[3]);
v11 = (void (__fastcall *)(__int64, _QWORD))v1[2];
if ( v11 )
{
v12 = *(unsigned int *)v1;
if ( (v13.fds_bits[(int)v12 / 64] & (1LL << ((int)v12 % 64))) != 0 )
v11(v12, v1[3]);
}
}
v1 += 4;
}
while ( v1 != v2 );
}
}
return v7;
}

original_code:
int xyz_event_run(struct xyz_event_t *ev)
{
 int num, i;
 struct timeval tv;
    fd_set rdset, wtset;
    int maxfd = 0;
    if(ev == ((void *)0)) {
        return -1;
    }
 tv.tv_sec = 0;
 tv.tv_usec = ev->usec;
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdset)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wtset)->__fds_bits)[0]) : "memory"); } while (0);
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  if(ev->array[i].rdfunc != ((void *)0)) {
   ((void) (((&rdset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if(ev->array[i].wtfunc != ((void *)0)) {
   ((void) (((&wtset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if(ev->array[i].fd > maxfd) {
   maxfd = ev->array[i].fd;
  }
 }
 num = select(maxfd+1, &rdset, &wtset, ((void *)0), &tv);
 if(num == 0) {
  return 0;
 } else if(num == -1) {
  if((*__errno_location ()) == 4) {
   return 0;
  } else {
   return -1;
  }
 }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  if(ev->array[i].rdfunc != ((void *)0) && ((((&rdset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ev->array[i].rdfunc(ev->array[i].fd, ev->array[i].arg);
  }
  if(ev->array[i].wtfunc != ((void *)0) && ((((&wtset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ev->array[i].wtfunc(ev->array[i].fd, ev->array[i].arg);
  }
 }
 return num;
}

canonical_original_code:
int xyz_event_run(struct xyz_event_t *ev)
{
 int num; int i;
 struct timeval tv;
    struct fd_set rdset; struct fd_set wtset;
    int maxfd = 0;
    if(ev == ((void *)0)) {
        return -1;
    }
 tv.tv_sec = 0;
 tv.tv_usec = ev->usec;
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rdset)->__fds_bits)[0]) : "memory"); } while (0);
 do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&wtset)->__fds_bits)[0]) : "memory"); } while (0);
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  if(ev->array[i].rdfunc != ((void *)0)) {
   ((void) (((&rdset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if(ev->array[i].wtfunc != ((void *)0)) {
   ((void) (((&wtset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))));
  }
  if(ev->array[i].fd > maxfd) {
   maxfd = ev->array[i].fd;
  }
 }
 num = select(maxfd+1, &rdset, &wtset, ((void *)0), &tv);
 if(num == 0) {
  return 0;
 } else if(num == -1) {
  if((*__errno_location ()) == 4) {
   return 0;
  } else {
   return -1;
  }
 }
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  if(ev->array[i].rdfunc != ((void *)0) && ((((&rdset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ev->array[i].rdfunc(ev->array[i].fd, ev->array[i].arg);
  }
  if(ev->array[i].wtfunc != ((void *)0) && ((((&wtset)->__fds_bits)[((ev->array[i].fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((ev->array[i].fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
            ev->array[i].wtfunc(ev->array[i].fd, ev->array[i].arg);
  }
 }
 return num;
}

variable_types: num int

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

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

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

variable_types: maxfd int


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

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

original_code:
void xyz_event_destroy(struct xyz_event_t *ev)
{
 if(ev) {
  free(ev);
 }
 return;
}


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

if ( a1 )
{
*(_DWORD *)a1 = 0;
do
{
xyz_event_run(a1);
v1 = *(void (**)(void))(a1 + 264);
if ( v1 )
v1();
}
while ( !*(_DWORD *)a1 );
}
}

original_code:
void xyz_event_loop(struct xyz_event_t *ev)
{
    if(ev == ((void *)0)) {
        return;
    }
 ev->stop = 0;
 do {
  xyz_event_run(ev);
  if(ev->call) {
   ev->call();
  }
 } while(! ev->stop);
 return;
}


decompiled_code:
int __fastcall xyz_event_stat(__int64 a1)
{
int result; // eax
unsigned int *v2; // rbx
__int64 v3; // rsi
const void *v4; // rsi
const void *v5; // rsi

if ( a1 )
{
result = puts("------ event stat ------");
v2 = (unsigned int *)(a1 + 8);
do
{
v3 = *v2;
if ( (int)v3 >= 0 )
{
printf("fd:%d ", v3);
v4 = (const void *)*((_QWORD *)v2 + 1);
if ( v4 )
printf("read func : %p ", v4);
v5 = (const void *)*((_QWORD *)v2 + 2);
if ( v5 )
printf("write func : %p", v5);
result = putchar(10);
}
v2 += 8;
}
while ( v2 != (unsigned int *)(a1 + 264) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
int result; // eax
unsigned int *v2; // rbx
__int64 v3; // rsi
const void *v4; // rsi
const void *v5; // rsi

if ( a1 )
{
result = puts("------ event stat ------");
v2 = (unsigned int *)(a1 + 8);
do
{
v3 = *v2;
if ( (int)v3 >= 0 )
{
printf("fd:%d ", v3);
v4 = (const void *)*((_QWORD *)v2 + 1);
if ( v4 )
printf("read func : %p ", v4);
v5 = (const void *)*((_QWORD *)v2 + 2);
if ( v5 )
printf("write func : %p", v5);
result = putchar(10);
}
v2 += 8;
}
while ( v2 != (unsigned int *)(a1 + 264) );
}
return result;
}

original_code:
void xyz_event_stat(struct xyz_event_t *ev)
{
 int i;
    if(ev == ((void *)0)) {
        return;
    }
 printf("------ event stat ------\n");
 for(i=0; i<8; i++) {
  if(ev->array[i].fd < 0) {
   continue;
  }
  printf("fd:%d    ", ev->array[i].fd);
  if(ev->array[i].rdfunc) {
   printf("read func : %p    ", ev->array[i].rdfunc);
  }
  if(ev->array[i].wtfunc) {
   printf("write func : %p", ev->array[i].wtfunc);
  }
  printf("\n");
 }
}

variable_types: i int


decompiled_code:
int __fastcall xyz_log_tag(const char *a1)
{
int result; // eax

if ( a1 )
result = snprintf(g_xyz_log_tag, 0x40uLL, "[%s]", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int result; // eax

if ( a1 )
result = snprintf(g_xyz_log_tag, 0x40uLL, "[%s]", a1);
return result;
}

original_code:
void xyz_log_tag(char *tag)
{
    if(tag) {
        snprintf(g_xyz_log_tag, sizeof(g_xyz_log_tag), "[%s]", tag);
    }
    return;
}

variable_types:
tag
char *


decompiled_code:
void __fastcall xyz_log_open(const char *a1, int a2, int a3)
{
g_xyz_log_level = a3;
openlog(a1, 1, a2);
}

canonical_decompiled_code:
void __fastcall func1(const char *a1, int a2, int a3)
{
g_xyz_log_level = a3;
openlog(a1, 1, a2);
}

original_code:
void xyz_log_open(const char* ident, int facility, int level)
{
 g_xyz_log_level = level;
 openlog(ident, 0x01, facility);
 return;
}

canonical_original_code:
void xyz_log_open(char *ident, int facility, int level)
{
 g_xyz_log_level = level;
 openlog(ident, 0x01, facility);
 return;
}

variable_types:
ident
char *

variable_types: facility int

variable_types: level int


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

if ( g_xyz_log_level >= a1 )
{
va_start(ap, a2);
vsyslog(a1, a2, ap);
}
}

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

if ( g_xyz_log_level >= a1 )
{
va_start(ap, a2);
vsyslog(a1, a2, ap);
}
}

original_code:
void xyz_log_write(int level, const char* format, ...)
{
 if(level > g_xyz_log_level) {
  return;
 }
 va_list args;
 __builtin_va_start(args,format);
 vsyslog(level, format, args);
 __builtin_va_end(args);
 return;
}

canonical_original_code:
void xyz_log_write(int level, char *format, ...)
{
 if(level > g_xyz_log_level) {
  return;
 }
 __builtin_va_list args;
 __builtin_va_start(args,format);
 vsyslog(level, format, args);
 __builtin_va_end(args);
 return;
}

variable_types:
format
char *


decompiled_code:
void xyz_log_close()
{
closelog();
}

canonical_decompiled_code:
void func3()
{
closelog();
}

original_code:
void xyz_log_close(void)
{
 closelog();
 return;
}

canonical_original_code:
void xyz_log_close()
{
 closelog();
 return;
}


getprime

repo: albinoBandicoot/nsieve

decompiled_code:
__int64 __fastcall getprime(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp

v3 = a3;
__gmpz_urandomb();
while ( v3 != __gmpz_sizeinbase() )
__gmpz_urandomb();
return __gmpz_nextprime();
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rbp

v3 = a3;
__gmpz_urandomb();
while ( v3 != __gmpz_sizeinbase() )
__gmpz_urandomb();
return __gmpz_nextprime();
}

original_code:
void getprime (mpz_t res, gmp_randstate_t rand, int bits){
 __gmpz_urandomb (res, rand, bits);
 while (__gmpz_sizeinbase (res, 2) != bits){
  __gmpz_urandomb (res, rand, bits);
 }
 __gmpz_nextprime (res, res);
}

canonical_original_code:
void getprime(struct __mpz_struct res[1], struct __gmp_randstate_struct rand[1], int bits){
 __gmpz_urandomb (res, rand, bits);
 while (__gmpz_sizeinbase (res, 2) != bits){
  __gmpz_urandomb (res, rand, bits);
 }
 __gmpz_nextprime (res, res);
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types: bits int

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int v4; // eax
int result; // eax
__int64 v6; // [rsp+0h] [rbp-58h] BYREF
char v7[16]; // [rsp+20h] [rbp-38h] BYREF

if ( argc == 1 )
{
puts(
"! Error: expecting command line options (list of integers representing bit lengths of the primes to multiply together)");
result = 1;
}
else
{
__gmpz_inits();
__gmpz_set_ui();
__gmp_randinit_default();
if ( argc > 1 )
{
v3 = argv + 1;
do
{
v4 = atoi(*v3);
getprime((__int64)v7, (__int64)&v6, v4);
__gmpz_mul();
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
}
__gmpz_out_str();
putchar(10);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
int v4; // eax
int result; // eax
__int64 v6; // [rsp+0h] [rbp-58h] BYREF
char v7[16]; // [rsp+20h] [rbp-38h] BYREF

if ( argc == 1 )
{
puts(
"! Error: expecting command line options (list of integers representing bit lengths of the primes to multiply together)");
result = 1;
}
else
{
__gmpz_inits();
__gmpz_set_ui();
__gmp_randinit_default();
if ( argc > 1 )
{
v3 = argv + 1;
do
{
v4 = atoi(*v3);
func7((__int64)v7, (__int64)&v6, v4);
__gmpz_mul();
++v3;
}
while ( v3 != &argv[(unsigned int)(argc - 2) + 2] );
}
__gmpz_out_str();
putchar(10);
result = 0;
}
return result;
}

original_code:
int main (int argc, const char *argv[]){
 if (argc == 1){
  printf("! Error: expecting command line options (list of integers representing bit lengths of the primes to multiply together)\n");
  return 1;
 }
 mpz_t res, temp;
 __gmpz_inits (res, temp, ((void *)0));
 __gmpz_set_ui (res, 1);
 gmp_randstate_t rand;
 __gmp_randinit_default (rand);
 int arg =1;
 while (arg < argc){
  getprime (temp, rand, atoi(argv[arg]));
  __gmpz_mul (res, res, temp);
  arg++;
 }
 __gmpz_out_str (stdout, 10, res);
 printf("\n");
}

canonical_original_code:
int main(int argc, char *argv[]){
 if (argc == 1){
  printf("! Error: expecting command line options (list of integers representing bit lengths of the primes to multiply together)\n");
  return 1;
 }
 struct __mpz_struct res[1]; struct __mpz_struct temp[1];
 __gmpz_inits (res, temp, ((void *)0));
 __gmpz_set_ui (res, 1);
 struct __gmp_randstate_struct rand[1];
 __gmp_randinit_default (rand);
 int arg = 1;
 while (arg < argc){
  getprime (temp, rand, atoi(argv[arg]));
  __gmpz_mul (res, res, temp);
  arg++;
 }
 __gmpz_out_str (stdout, 10, res);
 printf("\n");
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct __gmp_randstate_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types: arg int


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

for ( result = *(unsigned int **)(a2 + 16); result; result = (unsigned int *)*((_QWORD *)result + 1) )
++*(_WORD *)(a1 + 2LL * *result);
return result;
}

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

for ( result = *(unsigned int **)(a2 + 16); result; result = (unsigned int *)*((_QWORD *)result + 1) )
++*(_WORD *)(a1 + 2LL * *result);
return result;
}

original_code:
void add_factors_to_table (uint16_t *table, rel_t *rel){
 fl_entry_t *factor = rel->factors;
 while (factor != ((void *)0)){
  table[factor->fac] ++;
  factor = factor->next;
 }
}

canonical_original_code:
void add_factors_to_table(unsigned short *table, struct relation *rel){
 struct flentry *factor = rel->factors;
 while (factor != ((void *)0)){
  table[factor->fac] ++;
  factor = factor->next;
 }
}

variable_types:
table
unsigned short *

variable_types: struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *

user_defined_types: struct relation { struct poly_t *poly; int x; unsigned int cofactor; struct flentry *factors; }

user_defined_types: struct poly_t { struct poly_group_t *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; }

user_defined_types: struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; }


decompiled_code:
__int64 __fastcall construct_rhs(unsigned __int16 *a1, __int64 a2, __int64 a3)
{
unsigned __int16 v4; // dx
__int64 v5; // rbx
__int64 result; // rax
unsigned __int16 v7; // dx
_BYTE v8[56]; // [rsp+0h] [rbp-38h] BYREF

v4 = *a1;
if ( (*a1 & 1) != 0 )
{
printf("Error: table[%d] is not even (=%d)\n", 0LL, v4);
result = 0LL;
}
else
{
if ( (v4 & 2) != 0 )
_gmpz_neg(a2);
_gmpz_init(v8);
if ( (unsigned int)(*(_DWORD *)(a3 + 32) + 1) <= 1 )
{
LABEL_12:
_gmpz_clear(v8);
result = 1LL;
}
else
{
v5 = 1LL;
while ( 1 )
{
v7 = a1[v5];
if ( (v7 & 1) != 0 )
break;
if ( v7 )
{
_gmpz_ui_pow_ui(v8, *(unsigned int *)(*(_QWORD *)(a3 + 48) + 4 * v5 - 4), v7 >> 1);
_gmpz_mul(a2, a2, v8);
_gmpz_mod(a2, a2, a3);
}
if ( *(_DWORD *)(a3 + 32) + 1 <= (unsigned int)++v5 )
goto LABEL_12;
}
printf("Error: table[%d] is not even (=%d)\n", (unsigned int)v5, v7);
_gmpz_clear(v8);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int16 *a1, __int64 a2, __int64 a3)
{
unsigned __int16 v4; // dx
__int64 v5; // rbx
__int64 result; // rax
unsigned __int16 v7; // dx
_BYTE v8[56]; // [rsp+0h] [rbp-38h] BYREF

v4 = *a1;
if ( (*a1 & 1) != 0 )
{
printf("Error: table[%d] is not even (=%d)\n", 0LL, v4);
result = 0LL;
}
else
{
if ( (v4 & 2) != 0 )
_gmpz_neg(a2);
_gmpz_init(v8);
if ( (unsigned int)(*(_DWORD *)(a3 + 32) + 1) <= 1 )
{
LABEL_12:
_gmpz_clear(v8);
result = 1LL;
}
else
{
v5 = 1LL;
while ( 1 )
{
v7 = a1[v5];
if ( (v7 & 1) != 0 )
break;
if ( v7 )
{
_gmpz_ui_pow_ui(v8, *(unsigned int *)(*(_QWORD *)(a3 + 48) + 4 * v5 - 4), v7 >> 1);
_gmpz_mul(a2, a2, v8);
_gmpz_mod(a2, a2, a3);
}
if ( *(_DWORD *)(a3 + 32) + 1 <= (unsigned int)++v5 )
goto LABEL_12;
}
printf("Error: table[%d] is not even (=%d)\n", (unsigned int)v5, v7);
_gmpz_clear(v8);
result = 0LL;
}
}
return result;
}

original_code:
int construct_rhs (uint16_t *table, mpz_t rhs, nsieve_t *ns){
 if (table[0] % 2 != 0){
  printf("Error: table[%d] is not even (=%d)\n", 0, table[0]);
  return 0;
 }
 if ((table[0]/2) % 2 == 1){
  __gmpz_neg (rhs, rhs);
 }
 mpz_t temp;
 __gmpz_init (temp);
 for (int i=1; i < ns->fb_len + 1; i++){
  if (table[i] % 2 != 0){
   printf("Error: table[%d] is not even (=%d)\n", i, table[i]);
   __gmpz_clear (temp);
   return 0;
  }
  if (table[i] > 0){
   __gmpz_ui_pow_ui (temp, ns->fb[i-1], table[i]/2);
   __gmpz_mul (rhs, rhs, temp);
   __gmpz_mod (rhs, rhs, ns->N);
  }
 }
 __gmpz_clear(temp);
 return 1;
}

canonical_original_code:
int construct_rhs(unsigned short *table, struct __mpz_struct rhs[1], struct nsieve_t *ns){
 if (table[0] % 2 != 0){
  printf("Error: table[%d] is not even (=%d)\n", 0, table[0]);
  return 0;
 }
 if ((table[0]/2) % 2 == 1){
  __gmpz_neg (rhs, rhs);
 }
 struct __mpz_struct temp[1];
 __gmpz_init (temp);
 for (int i = 1; i < ns->fb_len + 1; i++){
  if (table[i] % 2 != 0){
   printf("Error: table[%d] is not even (=%d)\n", i, table[i]);
   __gmpz_clear (temp);
   return 0;
  }
  if (table[i] > 0){
   __gmpz_ui_pow_ui (temp, ns->fb[i-1], table[i]/2);
   __gmpz_mul (rhs, rhs, temp);
   __gmpz_mod (rhs, rhs, ns->N);
  }
 }
 __gmpz_clear(temp);
 return 1;
}

variable_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }

user_defined_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t *relns; unsigned int lp_bound; struct hashtable_t partials; int nthreads; unsigned long *threads; union pthread_mutex_t lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t timing; }

user_defined_types: struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry **buckets; }

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

user_defined_types: struct matrel_t { struct relation *r1; struct relation *r2; unsigned long *row; }

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


decompiled_code:
__int64 __fastcall multiply_in_lhs(__int64 a1, int *a2, __int64 a3)
{
__int64 v5; // r13
_BYTE v7[56]; // [rsp+0h] [rbp-38h] BYREF

_gmpz_init(v7);
v5 = *(_QWORD *)(**(_QWORD **)a2 + 80LL);
_gmpz_set_si(v7, *(int *)(v5 + 8));
_gmpz_mul(v7, v7, *(_QWORD *)v5 + 8LL);
_gmpz_add(v7, v7, *(_QWORD *)v5 + 24LL);
_gmpz_mul(a1, a1, v7);
_gmpz_set_si(v7, a2[2]);
_gmpz_mul(v7, v7, *(_QWORD *)a2 + 8LL);
_gmpz_add(v7, v7, *(_QWORD *)a2 + 24LL);
_gmpz_mul(a1, a1, v7);
_gmpz_invert(v7, *(_QWORD *)v5 + 8LL, a3);
_gmpz_mul(a1, a1, v7);
_gmpz_mod(a1, a1, a3);
return _gmpz_clear(v7);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, __int64 a3)
{
__int64 v5; // r13
_BYTE v7[56]; // [rsp+0h] [rbp-38h] BYREF

_gmpz_init(v7);
v5 = *(_QWORD *)(**(_QWORD **)a2 + 80LL);
_gmpz_set_si(v7, *(int *)(v5 + 8));
_gmpz_mul(v7, v7, *(_QWORD *)v5 + 8LL);
_gmpz_add(v7, v7, *(_QWORD *)v5 + 24LL);
_gmpz_mul(a1, a1, v7);
_gmpz_set_si(v7, a2[2]);
_gmpz_mul(v7, v7, *(_QWORD *)a2 + 8LL);
_gmpz_add(v7, v7, *(_QWORD *)a2 + 24LL);
_gmpz_mul(a1, a1, v7);
_gmpz_invert(v7, *(_QWORD *)v5 + 8LL, a3);
_gmpz_mul(a1, a1, v7);
_gmpz_mod(a1, a1, a3);
return _gmpz_clear(v7);
}

original_code:
void multiply_in_lhs (mpz_t lhs, rel_t *rel, nsieve_t *ns) {
 mpz_t temp;
 __gmpz_init (temp);
 rel_t *victim = rel->poly->group->victim;
 __gmpz_set_si (temp, victim->x);
 __gmpz_mul (temp, temp, victim->poly->a);
 __gmpz_add (temp, temp, victim->poly->b);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_set_si (temp, rel->x);
 __gmpz_mul (temp, temp, rel->poly->a);
 __gmpz_add (temp, temp, rel->poly->b);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_invert (temp, victim->poly->a, ns->N);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_mod (lhs, lhs, ns->N);
 __gmpz_clear (temp);
}

canonical_original_code:
void multiply_in_lhs(struct __mpz_struct lhs[1], struct relation *rel, struct nsieve_t *ns) {
 struct __mpz_struct temp[1];
 __gmpz_init (temp);
 struct relation *victim = rel->poly->group->victim;
 __gmpz_set_si (temp, victim->x);
 __gmpz_mul (temp, temp, victim->poly->a);
 __gmpz_add (temp, temp, victim->poly->b);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_set_si (temp, rel->x);
 __gmpz_mul (temp, temp, rel->poly->a);
 __gmpz_add (temp, temp, rel->poly->b);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_invert (temp, victim->poly->a, ns->N);
 __gmpz_mul (lhs, lhs, temp);
 __gmpz_mod (lhs, lhs, ns->N);
 __gmpz_clear (temp);
}

variable_types: struct relation { struct poly_t { struct poly_group_t { struct __mpz_struct a[1]; struct __mpz_struct (*bvals)[1]; unsigned int gvals[12]; unsigned int *ainverses; struct relation *victim; unsigned int nrels; struct relation **relns; } *group; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct c[1]; unsigned int *bmodp; unsigned int M; } *poly; int x; unsigned int cofactor; struct flentry { unsigned int fac; struct flentry *next; } *factors; } *

variable_types: struct nsieve_t { struct __mpz_struct N[1]; unsigned char k; unsigned short bvals; unsigned int M; float T; unsigned int fb_bound; unsigned int fb_len; int extra_rels; unsigned int rels_needed; unsigned int *fb; unsigned char *fb_logs; unsigned int *roots; unsigned int multiplier; unsigned int nfull; unsigned int npartial; unsigned int row_len; struct matrel_t { struct relation *r1; struct relation *r2; unsigned long *row; } *relns; unsigned int lp_bound; struct hashtable_t { unsigned int nbuckets; unsigned int nentries; struct htentry { struct relation *rel; struct htentry *next; } **buckets; } partials; int nthreads; unsigned long *threads; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; int info_npoly; int info_npg; unsigned int tdiv_ct; unsigned long sieve_locs; struct time_data_t { long init_time; long sieve_time; long filter_time; long matsolve_time; long facdeduct_time; long total_time; } timing; } *