main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rax
char *v5; // rbx
const char *v6; // rsi
const char *v7; // rdi
int v8; // eax
struct addrinfo *v9; // rax
int *v10; // rbx
int v11; // eax
const char *v12; // rdi
int v13; // er12
const char *v15; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-70h] BYREF
__int64 arg[4]; // [rsp+10h] [rbp-68h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-48h] BYREF

v4 = (char *)calloc(1uLL, 0x58uLL);
server_socket = (__int64)v4;
if ( !v4 )
{
print_error("memory allocation error");
exit(1);
}
v5 = v4;
pthread_mutex_init((pthread_mutex_t *)(v4 + 8), 0LL);
pthread_mutex_init((pthread_mutex_t *)(v5 + 48), 0LL);
if ( argc <= 3 )
{
print_error("Wrong number of args - server IP, port and login name needed.");
exit(1);
}
if ( argc != 4 && !strcmp(argv[4], "-f") )
g_fail = 1;
v6 = argv[2];
v7 = argv[1];
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v8 = getaddrinfo(v7, v6, &req, &pai);
if ( v8 )
{
v13 = 1;
v15 = gai_strerror(v8);
fprintf(stderr, "%sgetaddrinfo failed: %s\n", "error: ", v15);
return v13;
}
v9 = pai;
if ( !pai )
goto LABEL_22;
while ( 1 )
{
v10 = (int *)server_socket;
v11 = socket(v9->ai_family, v9->ai_socktype, v9->ai_protocol);
*v10 = v11;
if ( v11 != -1 )
break;
print_error("create socket");
LABEL_21:
v9 = pai->ai_next;
pai = v9;
if ( !v9 )
goto LABEL_22;
}
if ( connect(v11, pai->ai_addr, pai->ai_addrlen) == -1 )
{
close(*(_DWORD *)server_socket);
print_error("connect socket");
goto LABEL_21;
}
if ( !pai )
{
LABEL_22:
v13 = 1;
fprintf(stderr, "%sfailed to connect\n", "error: ");
return v13;
}
printf("Connected to server: %s\n", argv[1]);
if ( signal(2, signal_handler) == (__sighandler_t)-1LL )
print_error("cannot catch SIGINT signal");
if ( signal(15, signal_handler) == (__sighandler_t)-1LL )
print_error("cannot catch SIGTERM signal");
pthread_mutex_init(&mesg_mutex, 0LL);
arg[1] = (__int64)&mesg_list;
arg[0] = server_socket;
arg[2] = (__int64)&terminal_thread;
v12 = "pthread_create (send)";
if ( pthread_create(&send_thread, 0LL, (void *(*)(void *))&send_thread_worker, arg) )
{
LABEL_26:
print_error(v12);
clean();
exit(1);
}
if ( pthread_create(&terminal_thread, 0LL, (void *(*)(void *))&terminal_thread_worker, arg) )
{
v12 = "pthread_create (terminal)";
goto LABEL_26;
}
v12 = "pthread_create (receive)";
v13 = pthread_create(&recv_thread, 0LL, (void *(*)(void *))&recv_thread_worker, arg);
if ( v13 )
goto LABEL_26;
login((__int64)&mesg_list, argv[3]);
pthread_join(terminal_thread, 0LL);
clean();
return v13;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v4; // rax
char *v5; // rbx
const char *v6; // rsi
const char *v7; // rdi
int v8; // eax
struct addrinfo *v9; // rax
int *v10; // rbx
int v11; // eax
const char *v12; // rdi
int v13; // er12
const char *v15; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-70h] BYREF
__int64 arg[4]; // [rsp+10h] [rbp-68h] BYREF
struct addrinfo req; // [rsp+30h] [rbp-48h] BYREF

v4 = (char *)calloc(1uLL, 0x58uLL);
server_socket = (__int64)v4;
if ( !v4 )
{
print_error("memory allocation error");
exit(1);
}
v5 = v4;
pthread_mutex_init((pthread_mutex_t *)(v4 + 8), 0LL);
pthread_mutex_init((pthread_mutex_t *)(v5 + 48), 0LL);
if ( argc <= 3 )
{
print_error("Wrong number of args - server IP, port and login name needed.");
exit(1);
}
if ( argc != 4 && !strcmp(argv[4], "-f") )
g_fail = 1;
v6 = argv[2];
v7 = argv[1];
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v8 = getaddrinfo(v7, v6, &req, &pai);
if ( v8 )
{
v13 = 1;
v15 = gai_strerror(v8);
fprintf(stderr, "%sgetaddrinfo failed: %s\n", "error: ", v15);
return v13;
}
v9 = pai;
if ( !pai )
goto LABEL_22;
while ( 1 )
{
v10 = (int *)server_socket;
v11 = socket(v9->ai_family, v9->ai_socktype, v9->ai_protocol);
*v10 = v11;
if ( v11 != -1 )
break;
print_error("create socket");
LABEL_21:
v9 = pai->ai_next;
pai = v9;
if ( !v9 )
goto LABEL_22;
}
if ( connect(v11, pai->ai_addr, pai->ai_addrlen) == -1 )
{
close(*(_DWORD *)server_socket);
print_error("connect socket");
goto LABEL_21;
}
if ( !pai )
{
LABEL_22:
v13 = 1;
fprintf(stderr, "%sfailed to connect\n", "error: ");
return v13;
}
printf("Connected to server: %s\n", argv[1]);
if ( signal(2, signal_handler) == (__sighandler_t)-1LL )
print_error("cannot catch SIGINT signal");
if ( signal(15, signal_handler) == (__sighandler_t)-1LL )
print_error("cannot catch SIGTERM signal");
pthread_mutex_init(&mesg_mutex, 0LL);
arg[1] = (__int64)&mesg_list;
arg[0] = server_socket;
arg[2] = (__int64)&terminal_thread;
v12 = "pthread_create (send)";
if ( pthread_create(&send_thread, 0LL, (void *(*)(void *))&send_thread_worker, arg) )
{
LABEL_26:
print_error(v12);
func1();
exit(1);
}
if ( pthread_create(&terminal_thread, 0LL, (void *(*)(void *))&terminal_thread_worker, arg) )
{
v12 = "pthread_create (terminal)";
goto LABEL_26;
}
v12 = "pthread_create (receive)";
v13 = pthread_create(&recv_thread, 0LL, (void *(*)(void *))&recv_thread_worker, arg);
if ( v13 )
goto LABEL_26;
func0((__int64)&mesg_list, argv[3]);
pthread_join(terminal_thread, 0LL);
func1();
return v13;
}

original_code:
int main(int argc, const char *argv[])
{
 if ((server_socket = (server_socket_t *) calloc(1, sizeof(server_socket_t))) == ((void *)0)) {
  print_error("memory allocation error");
  exit(1);
 }
 pthread_mutex_init(&(server_socket->sock_w_lock), ((void *)0));
 pthread_mutex_init(&(server_socket->sock_r_lock), ((void *)0));
 if (argc < 4) {
  print_error("Wrong number of args - server IP, port and login name needed.");
  exit(1);
 }
 if (argc > 4) {
  if (strcmp(argv[4], "-f") == 0) {
   g_fail = 1;
  }
 }
 struct addrinfo hints;
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 int status;
 struct addrinfo *res;
 if ((status = getaddrinfo(argv[1], argv[2], &hints, &res)) != 0) {
  fprintf(stderr, "%sgetaddrinfo failed: %s\n", "error: ", gai_strerror(status));
  return 1;
 }
 for (; res != ((void *)0); res = res->ai_next) {
  if ((server_socket->socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
   print_error("create socket");
   continue;
  }
  if (connect(server_socket->socket, res->ai_addr, res->ai_addrlen) == -1) {
   close(server_socket->socket);
   print_error("connect socket");
   continue;
  }
  break;
 }
 if (res == ((void *)0)) {
  fprintf(stderr, "%sfailed to connect\n", "error: ");
  return 1;
 }
 printf("Connected to server: %s\n", argv[1]);
 if (signal(2, signal_handler) == ((__sighandler_t) -1)) {
  print_error("cannot catch SIGINT signal");
 }
 if (signal(15, signal_handler) == ((__sighandler_t) -1)) {
  print_error("cannot catch SIGTERM signal");
 }
 pthread_mutex_init(&mesg_mutex, ((void *)0));
 thread_args_t args;
 args.server_socket = server_socket;
 args.mesg_list = &mesg_list;
 args.terminal_thread = &terminal_thread;
 if (pthread_create(&send_thread, ((void *)0), send_thread_worker, &args) != 0) {
  print_error("pthread_create (send)");
  clean();
  exit(1);
    }
 if (pthread_create(&terminal_thread, ((void *)0), terminal_thread_worker, &args) != 0) {
  print_error("pthread_create (terminal)");
  clean();
  exit(1);
 }
 if (pthread_create(&recv_thread, ((void *)0), recv_thread_worker, &args) != 0) {
  print_error("pthread_create (receive)");
  clean();
  exit(1);
 }
 login(&mesg_list, argv[3]);
 pthread_join(terminal_thread, ((void *)0));
 clean();
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 if ((server_socket = (struct __server_socket_s *) calloc(1, sizeof(server_socket_t))) == ((void *)0)) {
  print_error("memory allocation error");
  exit(1);
 }
 pthread_mutex_init(&(server_socket->sock_w_lock), ((void *)0));
 pthread_mutex_init(&(server_socket->sock_r_lock), ((void *)0));
 if (argc < 4) {
  print_error("Wrong number of args - server IP, port and login name needed.");
  exit(1);
 }
 if (argc > 4) {
  if (strcmp(argv[4], "-f") == 0) {
   g_fail = 1;
  }
 }
 struct addrinfo hints;
 memset(&hints, 0, sizeof(hints));
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 int status;
 struct addrinfo *res;
 if ((status = getaddrinfo(argv[1], argv[2], &hints, &res)) != 0) {
  fprintf(stderr, "%sgetaddrinfo failed: %s\n", "error: ", gai_strerror(status));
  return 1;
 }
 for (; res != ((void *)0); res = res->ai_next) {
  if ((server_socket->socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
   print_error("create socket");
   continue;
  }
  if (connect(server_socket->socket, res->ai_addr, res->ai_addrlen) == -1) {
   close(server_socket->socket);
   print_error("connect socket");
   continue;
  }
  break;
 }
 if (res == ((void *)0)) {
  fprintf(stderr, "%sfailed to connect\n", "error: ");
  return 1;
 }
 printf("Connected to server: %s\n", argv[1]);
 if (signal(2, signal_handler) == ((__sighandler_t) -1)) {
  print_error("cannot catch SIGINT signal");
 }
 if (signal(15, signal_handler) == ((__sighandler_t) -1)) {
  print_error("cannot catch SIGTERM signal");
 }
 pthread_mutex_init(&mesg_mutex, ((void *)0));
 struct __thread_args_s args;
 args.server_socket = server_socket;
 args.mesg_list = &mesg_list;
 args.terminal_thread = &terminal_thread;
 if (pthread_create(&send_thread, ((void *)0), send_thread_worker, &args) != 0) {
  print_error("pthread_create (send)");
  clean();
  exit(1);
    }
 if (pthread_create(&terminal_thread, ((void *)0), terminal_thread_worker, &args) != 0) {
  print_error("pthread_create (terminal)");
  clean();
  exit(1);
 }
 if (pthread_create(&recv_thread, ((void *)0), recv_thread_worker, &args) != 0) {
  print_error("pthread_create (receive)");
  clean();
  exit(1);
 }
 login(&mesg_list, argv[3]);
 pthread_join(terminal_thread, ((void *)0));
 clean();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: status int

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

variable_types: struct __thread_args_s { struct __server_socket_s { int socket; 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; } sock_w_lock; union pthread_mutex_t sock_r_lock; } *server_socket; struct __mesg_list_s { struct __mesg_item_s { struct __message_s { unsigned char type; unsigned int id; char *text; unsigned long text_len; } *mesg; struct __mesg_item_s *next; } *start; struct __mesg_item_s *end; union pthread_mutex_t *mesg_mutex; } *mesg_list; unsigned long *terminal_thread; }

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
fprintf(stdout, "usage: %s -h\n\t%s <portno> [-f]\n\n", a1, a1);
return fwrite(
" \t-h\t\tShow this help\n"
" \t<portno>\tNumber of port on which the server listens\n"
" \t-f\t\tSending message will fail with defined probability\n",
1uLL,
0x93uLL,
stdout);
}

canonical_decompiled_code:
size_t __fastcall func2(const char *a1)
{
fprintf(stdout, "usage: %s -h\n\t%s <portno> [-f]\n\n", a1, a1);
return fwrite(
" \t-h\t\tShow this help\n"
" \t<portno>\tNumber of port on which the server listens\n"
" \t-f\t\tSending message will fail with defined probability\n",
1uLL,
0x93uLL,
stdout);
}

original_code:
void usage(const char *argv0) {
  fprintf(stdout, "usage:  %s -h\n\t%s <portno> [-f]\n\n", argv0, argv0);
  fprintf(stdout, "      \t-h\t\tShow this help\n      \t<portno>\tNumber of port on which the server listens\n      \t-f\t\tSending message will fail with defined probability\n");
}

canonical_original_code:
void usage(char *argv0) {
  fprintf(stdout, "usage:  %s -h\n\t%s <portno> [-f]\n\n", argv0, argv0);
  fprintf(stdout, "      \t-h\t\tShow this help\n      \t<portno>\tNumber of port on which the server listens\n      \t-f\t\tSending message will fail with defined probability\n");
}

return_type: void


clean

decompiled_code:
int clean()
{
pthread_t *v0; // rbx
pthread_t *v1; // rdi

v0 = (pthread_t *)g_clients;
if ( g_clients )
{
do
{
pthread_cancel(v0[12]);
pthread_cancel(v0[13]);
v1 = v0;
v0 = (pthread_t *)v0[27];
disconnect_client(v1, &g_clients);
}
while ( v0 );
}
return close(g_server_socket);
}

canonical_decompiled_code:
int func0()
{
pthread_t *v0; // rbx
pthread_t *v1; // rdi

v0 = (pthread_t *)g_clients;
if ( g_clients )
{
do
{
pthread_cancel(v0[12]);
pthread_cancel(v0[13]);
v1 = v0;
v0 = (pthread_t *)v0[27];
disconnect_client(v1, &g_clients);
}
while ( v0 );
}
return close(g_server_socket);
}

original_code:
void clean() {
  client_item_t *p = g_clients.start, *tmp;
  while (p != ((void *)0)) {
    pthread_cancel(p->recv_thread);
    pthread_cancel(p->send_thread);
    tmp = p->next;
    disconnect_client(p, &g_clients);
    p = tmp;
  }
  close(g_server_socket);
}

canonical_original_code:
void clean() {
  struct __client_item_s *p = g_clients.start; struct __client_item_s *tmp;
  while (p != ((void *)0)) {
    pthread_cancel(p->recv_thread);
    pthread_cancel(p->send_thread);
    tmp = p->next;
    disconnect_client(p, &g_clients);
    p = tmp;
  }
  close(g_server_socket);
}

variable_types: struct __client_item_s { char *name; int socket; 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; } sock_w_lock; union pthread_mutex_t sock_r_lock; unsigned long recv_thread; unsigned long send_thread; struct __client_queue_s { struct __queue_item_s { struct __message_s { unsigned char type; unsigned int id; char *text; unsigned long text_len; } *msg; struct __client_item_s *sender; struct __queue_item_s *next; } *start; struct __queue_item_s *end; union pthread_mutex_t queue_mx; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } queue_cond; } queue; struct __client_item_s *next; } *

user_defined_types: struct __client_item_s { char *name; int socket; union pthread_mutex_t sock_w_lock; union pthread_mutex_t sock_r_lock; unsigned long recv_thread; unsigned long send_thread; struct __client_queue_s queue; struct __client_item_s *next; }

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

user_defined_types: struct __client_queue_s { struct __queue_item_s *start; struct __queue_item_s *end; union pthread_mutex_t queue_mx; union pthread_cond_t queue_cond; }

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

user_defined_types: union pthread_cond_t { struct __pthread_cond_s __data; char __size[48]; long long __align; }

user_defined_types: struct __queue_item_s { struct __message_s *msg; struct __client_item_s *sender; struct __queue_item_s *next; }


decompiled_code:
void __fastcall signal_handler(int a1)
{
if ( a1 == 2 || a1 == 15 )
{
puts("signal received");
clean();
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
if ( a1 == 2 || a1 == 15 )
{
puts("signal received");
func0();
}
}

original_code:
void signal_handler(int signum) {
  if (signum == 2 || signum == 15) {
    printf("signal received\n");
    clean();
  }
}

variable_types: signum int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // er12
struct addrinfo *v6; // rax
__int64 v7; // rsi
int v8; // eax
__int64 v9; // rdx
int v10; // ebp
__int64 v11; // rdx
sockaddr *v12; // rsi
__int64 v13; // rdx
__int64 v14; // rdx
__int64 v15; // rdx
__int64 v16; // rdx
int v17; // ebx
const void *v18; // rax
pthread_t *v19; // rax
__int64 v20; // rdx
pthread_t *v21; // rbp
__int64 v22; // rdx
const char *v24; // rax
int optval; // [rsp+10h] [rbp-108h] BYREF
socklen_t addr_len; // [rsp+14h] [rbp-104h] BYREF
struct addrinfo *pai; // [rsp+18h] [rbp-100h] BYREF
char buf[48]; // [rsp+20h] [rbp-F8h] BYREF
struct addrinfo req; // [rsp+50h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+80h] [rbp-98h] BYREF

if ( argc <= 1 )
{
print_error("port number is missing", argv, envp);
usage(*argv);
exit(1);
}
v3 = argv[1];
if ( *(_WORD *)v3 == 26669 && !v3[2] )
{
usage(*argv);
exit(0);
}
if ( argc != 2 && !strcmp(argv[2], "-f") )
g_fail = 1;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v4 = getaddrinfo(0LL, v3, &req, &pai);
v5 = v4;
if ( v4 )
{
v5 = 1;
v24 = gai_strerror(v4);
fprintf(stderr, "%sgetaddrinfo failed: %s\n", "error: ", v24);
return v5;
}
v6 = pai;
optval = 1;
if ( !pai )
goto LABEL_29;
while ( 1 )
{
v7 = (unsigned int)v6->ai_socktype;
v8 = socket(v6->ai_family, v7, v6->ai_protocol);
g_server_socket = v8;
v10 = v8;
if ( v8 != -1 )
break;
print_error("create socket", v7, v9);
LABEL_28:
v6 = pai->ai_next;
pai = v6;
if ( !v6 )
goto LABEL_29;
}
if ( setsockopt(v8, 1, 2, &optval, 4u) == -1 )
{
print_error("setsockopt", 1LL, v11);
exit(1);
}
v12 = pai->ai_addr;
if ( bind(v10, v12, pai->ai_addrlen) == -1 )
{
print_error("bind socket", v12, v13);
goto LABEL_28;
}
if ( !pai )
{
LABEL_29:
v5 = 1;
fprintf(stderr, "%sfailed to bind socket\n", "error: ");
return v5;
}
freeaddrinfo(pai);
if ( listen(v10, 10) == -1 )
{
v5 = 1;
print_error("listen", 10LL, v14);
}
else
{
if ( signal(2, signal_handler) == (__sighandler_t)-1LL )
print_error("cannot catch SIGINT signal", signal_handler, v15);
if ( signal(15, signal_handler) == (__sighandler_t)-1LL )
print_error("cannot catch SIGTERM signal", signal_handler, v16);
pthread_mutex_init(&g_client_list_mx, 0LL);
addr_len = 128;
file_init();
while ( 1 )
{
v17 = accept(g_server_socket, &addr, &addr_len);
if ( v17 == -1 )
break;
v18 = (const void *)get_in_addr(&addr);
inet_ntop(addr.sa_family, v18, buf, 0x2Eu);
printf("new client connected: %s\n", buf);
v19 = (pthread_t *)malloc(0x18uLL);
v21 = v19;
if ( !v19 )
{
print_error("memory allocation error", buf, v20);
clean();
exit(1);
}
*(_DWORD *)v19 = v17;
v19[2] = (pthread_t)&g_clients;
if ( pthread_create(v19 + 1, 0LL, (void *(*)(void *))&client_thread_worker, v19) )
{
print_error("pthread_create", 0LL, v22);
free(v21);
}
addr_len = 128;
}
clean();
}
return v5;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // eax
int v5; // er12
struct addrinfo *v6; // rax
__int64 v7; // rsi
int v8; // eax
__int64 v9; // rdx
int v10; // ebp
__int64 v11; // rdx
sockaddr *v12; // rsi
__int64 v13; // rdx
__int64 v14; // rdx
__int64 v15; // rdx
__int64 v16; // rdx
int v17; // ebx
const void *v18; // rax
pthread_t *v19; // rax
__int64 v20; // rdx
pthread_t *v21; // rbp
__int64 v22; // rdx
const char *v24; // rax
int optval; // [rsp+10h] [rbp-108h] BYREF
socklen_t addr_len; // [rsp+14h] [rbp-104h] BYREF
struct addrinfo *pai; // [rsp+18h] [rbp-100h] BYREF
char buf[48]; // [rsp+20h] [rbp-F8h] BYREF
struct addrinfo req; // [rsp+50h] [rbp-C8h] BYREF
struct sockaddr addr; // [rsp+80h] [rbp-98h] BYREF

if ( argc <= 1 )
{
print_error("port number is missing", argv, envp);
func2(*argv);
exit(1);
}
v3 = argv[1];
if ( *(_WORD *)v3 == 26669 && !v3[2] )
{
func2(*argv);
exit(0);
}
if ( argc != 2 && !strcmp(argv[2], "-f") )
g_fail = 1;
*(_OWORD *)&req.ai_flags = 0LL;
*(_OWORD *)&req.ai_addrlen = 0LL;
req.ai_socktype = 1;
req.ai_flags = 1;
*(_OWORD *)&req.ai_canonname = 0LL;
v4 = getaddrinfo(0LL, v3, &req, &pai);
v5 = v4;
if ( v4 )
{
v5 = 1;
v24 = gai_strerror(v4);
fprintf(stderr, "%sgetaddrinfo failed: %s\n", "error: ", v24);
return v5;
}
v6 = pai;
optval = 1;
if ( !pai )
goto LABEL_29;
while ( 1 )
{
v7 = (unsigned int)v6->ai_socktype;
v8 = socket(v6->ai_family, v7, v6->ai_protocol);
g_server_socket = v8;
v10 = v8;
if ( v8 != -1 )
break;
print_error("create socket", v7, v9);
LABEL_28:
v6 = pai->ai_next;
pai = v6;
if ( !v6 )
goto LABEL_29;
}
if ( setsockopt(v8, 1, 2, &optval, 4u) == -1 )
{
print_error("setsockopt", 1LL, v11);
exit(1);
}
v12 = pai->ai_addr;
if ( bind(v10, v12, pai->ai_addrlen) == -1 )
{
print_error("bind socket", v12, v13);
goto LABEL_28;
}
if ( !pai )
{
LABEL_29:
v5 = 1;
fprintf(stderr, "%sfailed to bind socket\n", "error: ");
return v5;
}
freeaddrinfo(pai);
if ( listen(v10, 10) == -1 )
{
v5 = 1;
print_error("listen", 10LL, v14);
}
else
{
if ( signal(2, signal_handler) == (__sighandler_t)-1LL )
print_error("cannot catch SIGINT signal", signal_handler, v15);
if ( signal(15, signal_handler) == (__sighandler_t)-1LL )
print_error("cannot catch SIGTERM signal", signal_handler, v16);
pthread_mutex_init(&g_client_list_mx, 0LL);
addr_len = 128;
file_init();
while ( 1 )
{
v17 = accept(g_server_socket, &addr, &addr_len);
if ( v17 == -1 )
break;
v18 = (const void *)get_in_addr(&addr);
inet_ntop(addr.sa_family, v18, buf, 0x2Eu);
printf("new client connected: %s\n", buf);
v19 = (pthread_t *)malloc(0x18uLL);
v21 = v19;
if ( !v19 )
{
print_error("memory allocation error", buf, v20);
func0();
exit(1);
}
*(_DWORD *)v19 = v17;
v19[2] = (pthread_t)&g_clients;
if ( pthread_create(v19 + 1, 0LL, (void *(*)(void *))&client_thread_worker, v19) )
{
print_error("pthread_create", 0LL, v22);
free(v21);
}
addr_len = 128;
}
func0();
}
return v5;
}

original_code:
int main(int argc, const char *argv[])
{
  struct addrinfo hints;
  struct addrinfo *res;
  int status;
  if (argc < 2) {
    print_error("port number is missing");
    usage(argv[0]);
    exit(1);
  } else if (strcmp(argv[1], "-h") == 0) {
    usage(argv[0]);
    exit(0);
  }
  if (argc > 2) {
    if (strcmp(argv[2], "-f") == 0) {
      g_fail = 1;
    }
  }
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0x0001;
  if ((status = getaddrinfo(((void *)0), argv[1], &hints, &res)) != 0) {
    fprintf(stderr, "%sgetaddrinfo failed: %s\n", "error: ", gai_strerror(status));
    return 1;
  }
  int yes = 1;
  for (; res != ((void *)0); res = res->ai_next) {
    if ((g_server_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
      print_error("create socket");
      continue;
    }
    if (setsockopt(g_server_socket, 1, 2, &yes,
          sizeof(int)) == -1) {
      print_error("setsockopt");
      exit(1);
    }
    if (bind(g_server_socket, res->ai_addr, res->ai_addrlen) == -1) {
      print_error("bind socket");
      continue;
    }
    break;
  }
  if (res == ((void *)0)) {
    fprintf(stderr, "%sfailed to bind socket\n", "error: ");
    return 1;
  }
  freeaddrinfo(res);
  if (listen(g_server_socket, 10) == -1) {
    print_error("listen");
    return 1;
  }
  if (signal(2, signal_handler) == ((__sighandler_t) -1)) {
    print_error("cannot catch SIGINT signal");
  }
  if (signal(15, signal_handler) == ((__sighandler_t) -1)) {
    print_error("cannot catch SIGTERM signal");
  }
  pthread_mutex_init(&g_client_list_mx, ((void *)0));
  int client_socket;
  struct sockaddr_storage client_addr;
  socklen_t addr_size = sizeof(client_addr);
  char ip[46];
  file_init();
  while ((client_socket = accept(g_server_socket, (struct sockaddr *)&client_addr, &addr_size)) != -1) {
    inet_ntop(client_addr.ss_family,
        get_in_addr((struct sockaddr *)&client_addr),
        ip, sizeof(ip));
    printf("new client connected: %s\n", ip);
    client_thread_param_t *pm;
    if ((pm = (client_thread_param_t *) malloc(sizeof(client_thread_param_t))) == ((void *)0)) {
      print_error("memory allocation error");
      clean();
      exit(1);
    }
    pm->socket = client_socket;
    pm->clients = &g_clients;
    if (pthread_create(&(pm->thread), ((void *)0), client_thread_worker, pm) != 0) {
      print_error("pthread_create");
      free(pm);
    }
    addr_size = sizeof(client_addr);
  }
  clean();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
  struct addrinfo hints;
  struct addrinfo *res;
  int status;
  if (argc < 2) {
    print_error("port number is missing");
    usage(argv[0]);
    exit(1);
  } else if (strcmp(argv[1], "-h") == 0) {
    usage(argv[0]);
    exit(0);
  }
  if (argc > 2) {
    if (strcmp(argv[2], "-f") == 0) {
      g_fail = 1;
    }
  }
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = 0x0001;
  if ((status = getaddrinfo(((void *)0), argv[1], &hints, &res)) != 0) {
    fprintf(stderr, "%sgetaddrinfo failed: %s\n", "error: ", gai_strerror(status));
    return 1;
  }
  int yes = 1;
  for (; res != ((void *)0); res = res->ai_next) {
    if ((g_server_socket = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) == -1) {
      print_error("create socket");
      continue;
    }
    if (setsockopt(g_server_socket, 1, 2, &yes,
          sizeof(int)) == -1) {
      print_error("setsockopt");
      exit(1);
    }
    if (bind(g_server_socket, res->ai_addr, res->ai_addrlen) == -1) {
      print_error("bind socket");
      continue;
    }
    break;
  }
  if (res == ((void *)0)) {
    fprintf(stderr, "%sfailed to bind socket\n", "error: ");
    return 1;
  }
  freeaddrinfo(res);
  if (listen(g_server_socket, 10) == -1) {
    print_error("listen");
    return 1;
  }
  if (signal(2, signal_handler) == ((__sighandler_t) -1)) {
    print_error("cannot catch SIGINT signal");
  }
  if (signal(15, signal_handler) == ((__sighandler_t) -1)) {
    print_error("cannot catch SIGTERM signal");
  }
  pthread_mutex_init(&g_client_list_mx, ((void *)0));
  int client_socket;
  struct sockaddr_storage client_addr;
  unsigned int addr_size = sizeof(client_addr);
  char ip[46];
  file_init();
  while ((client_socket = accept(g_server_socket, (struct sockaddr *)&client_addr, &addr_size)) != -1) {
    inet_ntop(client_addr.ss_family,
        get_in_addr((struct sockaddr *)&client_addr),
        ip, sizeof(ip));
    printf("new client connected: %s\n", ip);
    struct __client_thread_param_s *pm;
    if ((pm = (struct __client_thread_param_s *) malloc(sizeof(client_thread_param_t))) == ((void *)0)) {
      print_error("memory allocation error");
      clean();
      exit(1);
    }
    pm->socket = client_socket;
    pm->clients = &g_clients;
    if (pthread_create(&(pm->thread), ((void *)0), client_thread_worker, pm) != 0) {
      print_error("pthread_create");
      free(pm);
    }
    addr_size = sizeof(client_addr);
  }
  clean();
  return 0;
}

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

variable_types: yes int

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

variable_types:
ip
char [46]

variable_types: struct __client_thread_param_s { int socket; unsigned long thread; struct __client_list_s { struct __client_item_s { char *name; int socket; 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; } sock_w_lock; union pthread_mutex_t sock_r_lock; unsigned long recv_thread; unsigned long send_thread; struct __client_queue_s { struct __queue_item_s { struct __message_s { unsigned char type; unsigned int id; char *text; unsigned long text_len; } *msg; struct __client_item_s *sender; struct __queue_item_s *next; } *start; struct __queue_item_s *end; union pthread_mutex_t queue_mx; union pthread_cond_t { struct __pthread_cond_s { union { unsigned long long __wseq; struct { unsigned int __low; unsigned int __high; } __wseq32; }; union { unsigned long long __g1_start; struct { unsigned int __low; unsigned int __high; } __g1_start32; }; unsigned int __g_refs[2]; unsigned int __g_size[2]; unsigned int __g1_orig_size; unsigned int __wrefs; unsigned int __g_signals[2]; } __data; char __size[48]; long long __align; } queue_cond; } queue; struct __client_item_s *next; } *start; struct __client_item_s *end; } *clients; } *

return_type: int

user_defined_types: struct __client_thread_param_s { int socket; unsigned long thread; struct __client_list_s *clients; }

user_defined_types: struct __client_list_s { struct __client_item_s *start; struct __client_item_s *end; }


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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *(_BYTE *)ptr != 1 )
free(v2);
}
free(ptr);
}
}

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

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
{
if ( *(_BYTE *)ptr != 1 )
free(v2);
}
free(ptr);
}
}

original_code:
void free_message(message_t *msg) {
  if (msg != ((void *)0)) {
    if (msg->text != ((void *)0) && msg->type != 1) {
      free(msg->text);
    }
    free(msg);
  }
}

canonical_original_code:
void free_message(struct __message_s *msg) {
  if (msg != ((void *)0)) {
    if (msg->text != ((void *)0) && msg->type != 1) {
      free(msg->text);
    }
    free(msg);
  }
}

variable_types: struct __message_s { unsigned char type; unsigned int id; char *text; unsigned long text_len; } *


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

if ( a1 )
result = printf(
"Msg id(%d): type = '%d', text = \"%s\"\n",
*((unsigned int *)a1 + 1),
*(unsigned __int8 *)a1,
a1[1]);
return result;
}

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

if ( a1 )
result = printf(
"Msg id(%d): type = '%d', text = \"%s\"\n",
*((unsigned int *)a1 + 1),
*(unsigned __int8 *)a1,
a1[1]);
return result;
}

original_code:
void print_message(message_t *msg) {
  if (msg != ((void *)0)) {
    printf("Msg id(%d): type = '%d', text = \"%s\"\n", msg->id, msg->type, msg->text);
  }
}

canonical_original_code:
void print_message(struct __message_s *msg) {
  if (msg != ((void *)0)) {
    printf("Msg id(%d): type = '%d', text = \"%s\"\n", msg->id, msg->type, msg->text);
  }
}

user_defined_types: struct __message_s { unsigned char type; unsigned int id; char *text; unsigned long text_len; }


decompiled_code:
__int64 __fastcall terminal_thread_worker(__int64 a1)
{
__int64 i; // r13
char *v2; // rax
int v3; // er12
int v4; // edx
__int64 v5; // r15
unsigned __int64 v6; // rcx
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rcx
_QWORD *v10; // r14
char *v11; // rax
char *v12; // rsi
int v13; // eax
char *src; // [rsp+0h] [rbp-38h] BYREF
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

for ( i = *(_QWORD *)(a1 + 8); ; mesg_add(i, v10) )
{
do
{
while ( 1 )
{
getline(&src, n, stdin);
if ( *src )
break;
*(src - 1) = 0;
}
v2 = src;
v3 = 0;
do
{
++v2;
v4 = v3++;
}
while ( *v2 );
v5 = v4;
src[v4] = 0;
}
while ( v4 <= 1 );
if ( (v4 & 0xFFFFFFFD) == 4 )
{
v6 = 5LL;
if ( (unsigned __int64)v4 <= 5 )
v6 = v4;
if ( !memcmp(src, "exit", v6) )
break;
v8 = 5LL;
if ( (unsigned __int64)v4 <= 5 )
v8 = v4;
if ( !memcmp(src, "quit", v8) )
break;
v9 = 7LL;
if ( (unsigned __int64)v4 <= 7 )
v9 = v4;
if ( !memcmp(src, "logout", v9) )
break;
}
v10 = calloc(1uLL, 0x18uLL);
if ( !v10 )
{
print_error("memory allocation error");
return 0LL;
}
v11 = (char *)malloc(v3);
v12 = src;
v10[1] = v11;
strncpy(v11, v12, v3);
*(_BYTE *)v10 = 3;
v13 = counter;
v10[2] = v5;
*((_DWORD *)v10 + 1) = v13;
counter = v13 + 1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 i; // r13
char *v2; // rax
int v3; // er12
int v4; // edx
__int64 v5; // r15
unsigned __int64 v6; // rcx
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rcx
_QWORD *v10; // r14
char *v11; // rax
char *v12; // rsi
int v13; // eax
char *src; // [rsp+0h] [rbp-38h] BYREF
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

for ( i = *(_QWORD *)(a1 + 8); ; mesg_add(i, v10) )
{
do
{
while ( 1 )
{
getline(&src, n, stdin);
if ( *src )
break;
*(src - 1) = 0;
}
v2 = src;
v3 = 0;
do
{
++v2;
v4 = v3++;
}
while ( *v2 );
v5 = v4;
src[v4] = 0;
}
while ( v4 <= 1 );
if ( (v4 & 0xFFFFFFFD) == 4 )
{
v6 = 5LL;
if ( (unsigned __int64)v4 <= 5 )
v6 = v4;
if ( !memcmp(src, "exit", v6) )
break;
v8 = 5LL;
if ( (unsigned __int64)v4 <= 5 )
v8 = v4;
if ( !memcmp(src, "quit", v8) )
break;
v9 = 7LL;
if ( (unsigned __int64)v4 <= 7 )
v9 = v4;
if ( !memcmp(src, "logout", v9) )
break;
}
v10 = calloc(1uLL, 0x18uLL);
if ( !v10 )
{
print_error("memory allocation error");
return 0LL;
}
v11 = (char *)malloc(v3);
v12 = src;
v10[1] = v11;
strncpy(v11, v12, v3);
*(_BYTE *)v10 = 3;
v13 = counter;
v10[2] = v5;
*((_DWORD *)v10 + 1) = v13;
counter = v13 + 1;
}
return 0LL;
}

original_code:
void* terminal_thread_worker(void *data) {
 thread_args_t *args = (thread_args_t *) data;
 mesg_list_t *mesg_list = args->mesg_list;
  char *input;
 while(1) {
  size_t l;
  getline(&input, &l, stdin);
  int len = 0;
  char *c = input;
    char *msg_text = ((void *)0);
  while (*c != 0) {
   c++;
   len++;
  }
  input[--len]=(char)0;
  if(len <= 1) {
   continue;
  }
  if(len == 4 || len == 6) {
   int result = strncmp(input, "exit", len);
   if(result != 0) {
    result = strncmp(input, "quit", len);
   }
   if(result != 0) {
    result = strncmp(input, "logout", len);
   }
   if(result == 0) {
    break;
   }
  }
  message_t* new_msg;
  if ((new_msg = (message_t *) calloc(1, sizeof(message_t))) == ((void *)0)) {
   print_error("memory allocation error");
   break;
  }
    new_msg->text = (char *) malloc((len+1)*sizeof(char));
    strncpy(new_msg->text, input, len+1);
  new_msg->type = 3;
  new_msg->id = counter++;
  new_msg->text_len = len;
  mesg_add(mesg_list, new_msg);
 }
 return ((void *)0);
}

canonical_original_code:
void *terminal_thread_worker(void *data) {
 struct __thread_args_s *args = (thread_args_t *) data;
 struct __mesg_list_s *mesg_list = args->mesg_list;
  char *input;
 while(1) {
  unsigned long l;
  getline(&input, &l, stdin);
  int len = 0;
  char *c = input;
    char *msg_text = ((void *)0);
  while (*c != 0) {
   c++;
   len++;
  }
  input[--len]=(char)0;
  if(len <= 1) {
   continue;
  }
  if(len == 4 || len == 6) {
   int result = strncmp(input, "exit", len);
   if(result != 0) {
    result = strncmp(input, "quit", len);
   }
   if(result != 0) {
    result = strncmp(input, "logout", len);
   }
   if(result == 0) {
    break;
   }
  }
  struct __message_s *new_msg;
  if ((new_msg = (struct __message_s *) calloc(1, sizeof(message_t))) == ((void *)0)) {
   print_error("memory allocation error");
   break;
  }
    new_msg->text = (char *) malloc((len+1)*sizeof(char));
    strncpy(new_msg->text, input, len+1);
  new_msg->type = 3;
  new_msg->id = counter++;
  new_msg->text_len = len;
  mesg_add(mesg_list, new_msg);
 }
 return ((void *)0);
}

variable_types:
data
void *

variable_types: struct __thread_args_s { struct __server_socket_s { int socket; 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; } sock_w_lock; union pthread_mutex_t sock_r_lock; } *server_socket; struct __mesg_list_s { struct __mesg_item_s { struct __message_s { unsigned char type; unsigned int id; char *text; unsigned long text_len; } *mesg; struct __mesg_item_s *next; } *start; struct __mesg_item_s *end; union pthread_mutex_t *mesg_mutex; } *mesg_list; unsigned long *terminal_thread; } *

variable_types: struct __mesg_list_s { struct __mesg_item_s { struct __message_s { unsigned char type; unsigned int id; char *text; unsigned long text_len; } *mesg; struct __mesg_item_s *next; } *start; struct __mesg_item_s *end; 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; } *mesg_mutex; } *

variable_types:
input
char *

variable_types:
l
unsigned long

variable_types: len int

variable_types:
c
char *

variable_types: result int

return_type: void *

user_defined_types: struct __thread_args_s { struct __server_socket_s *server_socket; struct __mesg_list_s *mesg_list; unsigned long *terminal_thread; }

user_defined_types: struct __mesg_list_s { struct __mesg_item_s *start; struct __mesg_item_s *end; union pthread_mutex_t *mesg_mutex; }

user_defined_types: struct __server_socket_s { int socket; union pthread_mutex_t sock_w_lock; union pthread_mutex_t sock_r_lock; }

user_defined_types: struct __mesg_item_s { struct __message_s *mesg; struct __mesg_item_s *next; }


decompiled_code:
void __fastcall print_error(char *s)
{
void *v1; // rsp
char v2[16]; // [rsp+0h] [rbp-10h] BYREF

if ( *_errno_location() <= 0 )
{
fprintf(stderr, "%s%s\n", "error: ", s);
}
else
{
v1 = alloca(strlen(s) + 8);
sprintf(v2, "%s%s", "error: ", s);
perror(v2);
}
}

canonical_decompiled_code:
void __fastcall func0(char *s)
{
void *v1; // rsp
char v2[16]; // [rsp+0h] [rbp-10h] BYREF

if ( *_errno_location() <= 0 )
{
fprintf(stderr, "%s%s\n", "error: ", s);
}
else
{
v1 = alloca(strlen(s) + 8);
sprintf(v2, "%s%s", "error: ", s);
perror(v2);
}
}

original_code:
void print_error(const char *message) {
  if ((*__errno_location ()) > 0) {
    char error_string[strlen("error: ")+strlen(message)+1];
    sprintf(error_string, "%s%s", "error: ", message);
    perror(error_string);
  } else {
    fprintf(stderr, "%s%s\n", "error: ", message);
  }
}

canonical_original_code:
void print_error(char *message) {
  if ((*__errno_location ()) > 0) {
    char error_string[-1];
    sprintf(error_string, "%s%s", "error: ", message);
    perror(error_string);
  } else {
    fprintf(stderr, "%s%s\n", "error: ", message);
  }
}

variable_types:
message
char *


decompiled_code:
int file_init()
{
char *v0; // rax
size_t v1; // rax
int result; // eax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v0 = getenv("HOME");
strncpy(DIR_PATH, v0, 0xFEuLL);
v1 = strlen(DIR_PATH);
*(_DWORD *)&DIR_PATH[v1] = 1936944943;
*(__int16 *)((char *)&word_464 + v1) = 13156;
byte_466[v1] = 0;
memset(&v3, 0, sizeof(v3));
result = stat(DIR_PATH, &v3);
if ( result == -1 )
result = mkdir(DIR_PATH, 0x1EDu);
return result;
}

canonical_decompiled_code:
int func0()
{
char *v0; // rax
size_t v1; // rax
int result; // eax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v0 = getenv("HOME");
strncpy(DIR_PATH, v0, 0xFEuLL);
v1 = strlen(DIR_PATH);
*(_DWORD *)&DIR_PATH[v1] = 1936944943;
*(__int16 *)((char *)&word_464 + v1) = 13156;
byte_466[v1] = 0;
memset(&v3, 0, sizeof(v3));
result = stat(DIR_PATH, &v3);
if ( result == -1 )
result = mkdir(DIR_PATH, 0x1EDu);
return result;
}

original_code:
void file_init() {
  strncpy(DIR_PATH, getenv("HOME"), sizeof(DIR_PATH)-1);
  strncat(DIR_PATH, "/""ossd3", sizeof(DIR_PATH)-1);
  struct stat st = {0};
  if (stat(DIR_PATH, &st) == -1) {
    mkdir(DIR_PATH, 0755);
  }
}

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

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


decompiled_code:
unsigned __int64 __fastcall hash_long(__int64 a1, char a2)
{
return (unsigned __int64)(2654404609LL * a1) >> (32 - a2);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func7(__int64 a1, char a2)
{
return (unsigned __int64)(2654404609LL * a1) >> (32 - a2);
}

original_code:
static inline unsigned long hash_long(unsigned long val, unsigned int bits)
{
 unsigned long hash = val;
 hash *= 0x9e370001UL;
 return hash >> (32 - bits);
}

variable_types:
val
unsigned long

variable_types:
bits
unsigned int

variable_types:
hash
unsigned long

return_type: unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int *v4; // rax
unsigned int *v5; // rax
int v7; // [rsp+8h] [rbp-10h] BYREF
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)hash_init(argc, argv, envp) )
{
v3 = -1;
puts("initial hash failed");
}
else
{
v3 = 0;
v7 = 23;
if ( (unsigned int)hash_add(0LL, &v7, 4LL) )
puts("add data into hash failed!");
v8[0] = 230;
if ( (unsigned int)hash_add(2LL, v8, 4LL) )
puts("add data into hash failed!");
hash_print();
v4 = (unsigned int *)hash_find(1LL);
if ( v4 )
printf("find it, key: %d, data: %d\n", *v4, **((unsigned int **)v4 + 1));
else
puts("not find it");
v5 = (unsigned int *)hash_deep_find(0LL, &v7, 4LL);
if ( v5 )
printf("find it, key: %d, data: %d\n", *v5, **((unsigned int **)v5 + 1));
else
puts("not find it");
}
return v3;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
unsigned int *v4; // rax
unsigned int *v5; // rax
int v7; // [rsp+8h] [rbp-10h] BYREF
int v8[3]; // [rsp+Ch] [rbp-Ch] BYREF

if ( (unsigned int)func9(argc, argv, envp) )
{
v3 = -1;
puts("initial hash failed");
}
else
{
v3 = 0;
v7 = 23;
if ( (unsigned int)func11(0LL, &v7, 4LL) )
puts("add data into hash failed!");
v8[0] = 230;
if ( (unsigned int)func11(2LL, v8, 4LL) )
puts("add data into hash failed!");
func14();
v4 = (unsigned int *)func12(1LL);
if ( v4 )
printf("find it, key: %d, data: %d\n", *v4, **((unsigned int **)v4 + 1));
else
puts("not find it");
v5 = (unsigned int *)func13(0LL, &v7, 4LL);
if ( v5 )
printf("find it, key: %d, data: %d\n", *v5, **((unsigned int **)v5 + 1));
else
puts("not find it");
}
return v3;
}

original_code:
int main(void)
{
 if(hash_init() != 0)
 {
  printf("initial hash failed\n");
  return -1;
 }
 int val = 23;
 if(hash_add(0, &val, sizeof(int)) != 0)
  printf("add data into hash failed!\n");
 int value = 230;
 if(hash_add(2, &value, sizeof(int)) != 0)
  printf("add data into hash failed!\n");
 hash_print();
 data_hash_t *p = ((void *)0);
 if((p = hash_find(1)) != ((void *)0))
 {
  printf("find it, key: %d, data: %d\n", p->key, *(int *)p->data);
 }
 else
 {
  printf("not find it\n");
 }
 if((p = hash_deep_find(0, &val, sizeof(int))) != ((void *)0))
 {
  printf("find it, key: %d, data: %d\n", p->key, *(int *)p->data);
 }
 else
 {
  printf("not find it\n");
 }
 return 0;
}

canonical_original_code:
int main()
{
 if(hash_init() != 0)
 {
  printf("initial hash failed\n");
  return -1;
 }
 int val = 23;
 if(hash_add(0, &val, sizeof(int)) != 0)
  printf("add data into hash failed!\n");
 int value = 230;
 if(hash_add(2, &value, sizeof(int)) != 0)
  printf("add data into hash failed!\n");
 hash_print();
 struct _data_hash_t *p = ((void *)0);
 if((p = hash_find(1)) != ((void *)0))
 {
  printf("find it, key: %d, data: %d\n", p->key, *(int *)p->data);
 }
 else
 {
  printf("not find it\n");
 }
 if((p = hash_deep_find(0, &val, sizeof(int))) != ((void *)0))
 {
  printf("find it, key: %d, data: %d\n", p->key, *(int *)p->data);
 }
 else
 {
  printf("not find it\n");
 }
 return 0;
}

variable_types: val int

variable_types: value int

variable_types: struct _data_hash_t { unsigned int key; void *data; struct _data_hash_t *next; } *


decompiled_code:
_BOOL8 __fastcall xdr__rpc2_data_t(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x100u, 1u, (xdrproc_t)&xdr_char) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(XDR *a1, char *a2)
{
return xdr_vector(a1, a2, 0x100u, 1u, (xdrproc_t)&xdr_char) != 0;
}

original_code:
bool_t
xdr__rpc2_data_t (XDR *xdrs, _rpc2_data_t *objp)
{
 register int32_t *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->data, 256,
  sizeof (char), (xdrproc_t) xdr_char))
   return (0);
 return (1);
}

canonical_original_code:
int xdr__rpc2_data_t(struct XDR *xdrs, struct _rpc2_data_t *objp)
{
 register int *buf;
 int i;
  if (!xdr_vector (xdrs, (char *)objp->data, 256,
  sizeof (char), (int (*)(struct XDR *, void *, ...)) xdr_char))
   return (0);
 return (1);
}

variable_types: struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *

variable_types: struct _rpc2_data_t { char data[256]; } *

variable_types:
buf
int *

variable_types: i int

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }


decompiled_code:
_BOOL8 __fastcall xdr_rpc2_data_t(XDR *a1, char *a2)
{
return xdr__rpc2_data_t(a1, a2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(XDR *a1, char *a2)
{
return func0(a1, a2);
}

original_code:
bool_t
xdr_rpc2_data_t (XDR *xdrs, rpc2_data_t *objp)
{
 register int32_t *buf;
  if (!xdr__rpc2_data_t (xdrs, objp))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_rpc2_data_t(struct XDR *xdrs, struct _rpc2_data_t *objp)
{
 register int *buf;
  if (!xdr__rpc2_data_t (xdrs, objp))
   return (0);
 return (1);
}

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


decompiled_code:
void __noreturn rpc1_server()
{
SVCXPRT *v0; // rax
SVCXPRT *v1; // rdi

pmap_unset(0x38000023uLL, 1uLL);
v0 = svcudp_create(-1);
if ( v0 )
{
if ( svc_register(v0, 0x38000023uLL, 1uLL, rpc1_rpc_prog_1, 0x11uLL) )
{
v1 = svctcp_create(-1, 0, 0);
if ( v1 )
{
if ( !svc_register(v1, 0x38000023uLL, 1uLL, rpc1_rpc_prog_1, 6uLL) )
{
fwrite("unable to register (RPC1_RPC_PROG, RPC1_RPC_VERS1, tcp).", 1uLL, 0x38uLL, stderr);
exit(1);
}
svc_run();
fwrite("svc_run returned", 1uLL, 0x10uLL, stderr);
exit(1);
}
fwrite("cannot create tcp service.", 1uLL, 0x1AuLL, stderr);
exit(1);
}
fwrite("unable to register (RPC1_RPC_PROG, RPC1_RPC_VERS1, udp).", 1uLL, 0x38uLL, stderr);
exit(1);
}
fwrite("cannot create udp service.", 1uLL, 0x1AuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
SVCXPRT *v0; // rax
SVCXPRT *v1; // rdi

pmap_unset(0x38000023uLL, 1uLL);
v0 = svcudp_create(-1);
if ( v0 )
{
if ( svc_register(v0, 0x38000023uLL, 1uLL, rpc1_rpc_prog_1, 0x11uLL) )
{
v1 = svctcp_create(-1, 0, 0);
if ( v1 )
{
if ( !svc_register(v1, 0x38000023uLL, 1uLL, rpc1_rpc_prog_1, 6uLL) )
{
fwrite("unable to register (RPC1_RPC_PROG, RPC1_RPC_VERS1, tcp).", 1uLL, 0x38uLL, stderr);
exit(1);
}
svc_run();
fwrite("svc_run returned", 1uLL, 0x10uLL, stderr);
exit(1);
}
fwrite("cannot create tcp service.", 1uLL, 0x1AuLL, stderr);
exit(1);
}
fwrite("unable to register (RPC1_RPC_PROG, RPC1_RPC_VERS1, udp).", 1uLL, 0x38uLL, stderr);
exit(1);
}
fwrite("cannot create udp service.", 1uLL, 0x1AuLL, stderr);
exit(1);
}

original_code:
void *
rpc1_server()
{
 register SVCXPRT *transp;
 pmap_unset (0x38000023, 1);
 transp = svcudp_create(-1);
 if (transp == ((void *)0)) {
  fprintf (stderr, "%s", "cannot create udp service.");
  exit(1);
 }
 if (!svc_register(transp, 0x38000023, 1, rpc1_rpc_prog_1, IPPROTO_UDP)) {
  fprintf (stderr, "%s", "unable to register (RPC1_RPC_PROG, RPC1_RPC_VERS1, udp).");
  exit(1);
 }
 transp = svctcp_create(-1, 0, 0);
 if (transp == ((void *)0)) {
  fprintf (stderr, "%s", "cannot create tcp service.");
  exit(1);
 }
 if (!svc_register(transp, 0x38000023, 1, rpc1_rpc_prog_1, IPPROTO_TCP)) {
  fprintf (stderr, "%s", "unable to register (RPC1_RPC_PROG, RPC1_RPC_VERS1, tcp).");
  exit(1);
 }
 svc_run ();
 fprintf (stderr, "%s", "svc_run returned");
 exit (1);
}

canonical_original_code:
void *rpc1_server()
{
 register struct SVCXPRT *transp;
 pmap_unset (0x38000023, 1);
 transp = svcudp_create(-1);
 if (transp == ((void *)0)) {
  fprintf (stderr, "%s", "cannot create udp service.");
  exit(1);
 }
 if (!svc_register(transp, 0x38000023, 1, rpc1_rpc_prog_1, IPPROTO_UDP)) {
  fprintf (stderr, "%s", "unable to register (RPC1_RPC_PROG, RPC1_RPC_VERS1, udp).");
  exit(1);
 }
 transp = svctcp_create(-1, 0, 0);
 if (transp == ((void *)0)) {
  fprintf (stderr, "%s", "cannot create tcp service.");
  exit(1);
 }
 if (!svc_register(transp, 0x38000023, 1, rpc1_rpc_prog_1, IPPROTO_TCP)) {
  fprintf (stderr, "%s", "unable to register (RPC1_RPC_PROG, RPC1_RPC_VERS1, tcp).");
  exit(1);
 }
 svc_run ();
 fprintf (stderr, "%s", "svc_run returned");
 exit (1);
}

variable_types: struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops { int (*xp_recv)(struct SVCXPRT *__xprt, struct rpc_msg { unsigned long rm_xid; enum msg_type { CALL=0, REPLY=1 } rm_direction; union { struct call_body { unsigned long cb_rpcvers; unsigned long cb_prog; unsigned long cb_vers; unsigned long cb_proc; struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; } cb_cred; struct opaque_auth cb_verf; } RM_cmb; struct reply_body { enum reply_stat { MSG_ACCEPTED=0, MSG_DENIED=1 } rp_stat; union { struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat { SUCCESS=0, PROG_UNAVAIL=1, PROG_MISMATCH=2, PROC_UNAVAIL=3, GARBAGE_ARGS=4, SYSTEM_ERR=5 } ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char *where; int (*proc)(struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *, void *, ...); } AR_results; } ru; } RP_ar; struct rejected_reply { enum reject_stat { RPC_MISMATCH=0, AUTH_ERROR=1 } rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 } RJ_why; } ru; } RP_dr; } ru; } RM_rmb; } ru; } *__msg); enum xprt_stat { XPRT_DIED=0, XPRT_MOREREQS=1, XPRT_IDLE=2 } (*xp_stat)(struct SVCXPRT *__xprt); int (*xp_getargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); int (*xp_reply)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); int (*xp_freeargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); void (*xp_destroy)(struct SVCXPRT *__xprt); } *xp_ops; int xp_addrlen; 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]; } xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; } *

user_defined_types: struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops *xp_ops; int xp_addrlen; struct sockaddr_in xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; }

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

user_defined_types: struct xp_ops { int (*xp_recv)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); enum xprt_stat (*xp_stat)(struct SVCXPRT *__xprt); int (*xp_getargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); int (*xp_reply)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); int (*xp_freeargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); void (*xp_destroy)(struct SVCXPRT *__xprt); }

user_defined_types: struct rpc_msg { unsigned long rm_xid; enum msg_type rm_direction; union { struct call_body RM_cmb; struct reply_body RM_rmb; } ru; }

user_defined_types: struct call_body { unsigned long cb_rpcvers; unsigned long cb_prog; unsigned long cb_vers; unsigned long cb_proc; struct opaque_auth cb_cred; struct opaque_auth cb_verf; }

user_defined_types: struct reply_body { enum reply_stat rp_stat; union { struct accepted_reply RP_ar; struct rejected_reply RP_dr; } ru; }

user_defined_types: struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char *where; int (*proc)(struct XDR *, void *, ...); } AR_results; } ru; }

user_defined_types: struct rejected_reply { enum reject_stat rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat RJ_why; } ru; }


original_code:
int *
rpc1_rpcc_1_svc(rpc1_data_t *argp, struct svc_req *rqstp)
{
 static int result;
 char buff[256] = {0};
 if(argp->type == 1)
 {
  result = 0;
  char timebuff[256] = {0};
  getSysTime_r(timebuff);
  sprintf((char *)buff, "type %d: current time: %s", argp->type, timebuff);
 }
 else if(argp->type == 2)
 {
  result = 0;
  sprintf((char *)buff, "type %d: pid number %d", argp->type, getpid());
 }
 else
 {
  printf("%s(): Error param...type %d\n", __FUNCTION__, argp->type);
  result = -1;
  return &result;
 }
 struct sockaddr_in *sin = (&(rqstp->rq_xprt)->xp_raddr);
 int ip = sin->sin_addr.s_addr;
 struct in_addr in;
 in.s_addr = ip;
 char *phost = inet_ntoa(in);
 printf("ip address: %s\n", phost);
 rpc2_rpc_prog_1(phost, buff);
 return &result;
}

canonical_original_code:
int *rpc1_rpcc_1_svc(struct _rpc1_data_t *argp, struct svc_req *rqstp)
{
 static int result;
 char buff[256] = {0};
 if(argp->type == 1)
 {
  result = 0;
  char timebuff[256] = {0};
  getSysTime_r(timebuff);
  sprintf((char *)buff, "type %d: current time: %s", argp->type, timebuff);
 }
 else if(argp->type == 2)
 {
  result = 0;
  sprintf((char *)buff, "type %d: pid number %d", argp->type, getpid());
 }
 else
 {
  printf("%s(): Error param...type %d\n", __FUNCTION__, argp->type);
  result = -1;
  return &result;
 }
 struct sockaddr_in *sin = (&(rqstp->rq_xprt)->xp_raddr);
 int ip = sin->sin_addr.s_addr;
 struct in_addr in;
 in.s_addr = ip;
 char *phost = inet_ntoa(in);
 printf("ip address: %s\n", phost);
 rpc2_rpc_prog_1(phost, buff);
 return &result;
}

variable_types: struct _rpc1_data_t { int type; char data[]; } *

variable_types: struct svc_req { unsigned long rq_prog; unsigned long rq_vers; unsigned long rq_proc; struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; } rq_cred; char *rq_clntcred; struct SVCXPRT { int xp_sock; unsigned short xp_port; struct xp_ops { int (*xp_recv)(struct SVCXPRT *__xprt, struct rpc_msg { unsigned long rm_xid; enum msg_type { CALL=0, REPLY=1 } rm_direction; union { struct call_body { unsigned long cb_rpcvers; unsigned long cb_prog; unsigned long cb_vers; unsigned long cb_proc; struct opaque_auth cb_cred; struct opaque_auth cb_verf; } RM_cmb; struct reply_body { enum reply_stat { MSG_ACCEPTED=0, MSG_DENIED=1 } rp_stat; union { struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat { SUCCESS=0, PROG_UNAVAIL=1, PROG_MISMATCH=2, PROC_UNAVAIL=3, GARBAGE_ARGS=4, SYSTEM_ERR=5 } ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char *where; int (*proc)(struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *, void *, ...); } AR_results; } ru; } RP_ar; struct rejected_reply { enum reject_stat { RPC_MISMATCH=0, AUTH_ERROR=1 } rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 } RJ_why; } ru; } RP_dr; } ru; } RM_rmb; } ru; } *__msg); enum xprt_stat { XPRT_DIED=0, XPRT_MOREREQS=1, XPRT_IDLE=2 } (*xp_stat)(struct SVCXPRT *__xprt); int (*xp_getargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); int (*xp_reply)(struct SVCXPRT *__xprt, struct rpc_msg *__msg); int (*xp_freeargs)(struct SVCXPRT *__xprt, int (*__xdr_args)(struct XDR *, void *, ...), char *__args_ptr); void (*xp_destroy)(struct SVCXPRT *__xprt); } *xp_ops; int xp_addrlen; 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]; } xp_raddr; struct opaque_auth xp_verf; char *xp_p1; char *xp_p2; char xp_pad[256]; } *rq_xprt; } *

variable_types:
buff
char [256]

variable_types:
timebuff
char [256]

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: ip int

variable_types:
in
struct in_addr { unsigned int s_addr; }

variable_types:
phost
char *

return_type: int *

user_defined_types: struct svc_req { unsigned long rq_prog; unsigned long rq_vers; unsigned long rq_proc; struct opaque_auth rq_cred; char *rq_clntcred; struct SVCXPRT *rq_xprt; }


decompiled_code:
char *__fastcall getSysTime_tv(__int64 a1, char *a2)
{
struct tm *v2; // rax

if ( !a2 )
return 0LL;
v2 = localtime((const time_t *)a1);
if ( !v2 )
return 0LL;
sprintf(
a2,
"%04d-%02d-%02d,%02d:%02d:%02d.%04ld",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday,
(unsigned int)v2->tm_hour,
(unsigned int)v2->tm_min,
(unsigned int)v2->tm_sec,
*(_QWORD *)(a1 + 8) / 100LL);
return a2;
}

canonical_decompiled_code:
char *__fastcall func0(__int64 a1, char *a2)
{
struct tm *v2; // rax

if ( !a2 )
return 0LL;
v2 = localtime((const time_t *)a1);
if ( !v2 )
return 0LL;
sprintf(
a2,
"%04d-%02d-%02d,%02d:%02d:%02d.%04ld",
(unsigned int)(v2->tm_year + 1900),
(unsigned int)(v2->tm_mon + 1),
(unsigned int)v2->tm_mday,
(unsigned int)v2->tm_hour,
(unsigned int)v2->tm_min,
(unsigned int)v2->tm_sec,
*(_QWORD *)(a1 + 8) / 100LL);
return a2;
}

original_code:
char * getSysTime_tv(struct timeval *tv, char *timestamp)
{
 if (!timestamp)
 {
  return ((void *)0);
 }
 struct tm *datetime;
 if ((datetime = localtime(&tv->tv_sec)) == ((void *)0))
 {
  return ((void *)0);
 }
 sprintf(timestamp, "%04d-%02d-%02d,%02d:%02d:%02d.%04ld",
  datetime->tm_year + 1900, datetime->tm_mon + 1, datetime->tm_mday,
  datetime->tm_hour, datetime->tm_min, datetime->tm_sec, tv->tv_usec/100);
 return timestamp;
}

canonical_original_code:
char *getSysTime_tv(struct timeval *tv, char *timestamp)
{
 if (!timestamp)
 {
  return ((void *)0);
 }
 struct tm *datetime;
 if ((datetime = localtime(&tv->tv_sec)) == ((void *)0))
 {
  return ((void *)0);
 }
 sprintf(timestamp, "%04d-%02d-%02d,%02d:%02d:%02d.%04ld",
  datetime->tm_year + 1900, datetime->tm_mon + 1, datetime->tm_mday,
  datetime->tm_hour, datetime->tm_min, datetime->tm_sec, tv->tv_usec/100);
 return timestamp;
}

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

variable_types:
timestamp
char *

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

return_type: char *


decompiled_code:
char *__fastcall getSysTime_r(char *a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
return getSysTime_tv((__int64)&v2, a1);
}

canonical_decompiled_code:
char *__fastcall func1(char *a1)
{
struct timeval v2; // [rsp+0h] [rbp-18h] BYREF

gettimeofday(&v2, 0LL);
return func0((__int64)&v2, a1);
}

original_code:
char * getSysTime_r(char *timestamp)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 getSysTime_tv(&tv, timestamp);
}

canonical_original_code:
char *getSysTime_r(char *timestamp)
{
 struct timeval tv;
 gettimeofday(&tv, ((void *)0));
 getSysTime_tv(&tv, timestamp);
}

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


getSysTimeV

decompiled_code:
char *__fastcall getSysTimeV(__int64 a1)
{
return getSysTime_tv(a1, buff_1);
}

canonical_decompiled_code:
char *__fastcall func2(__int64 a1)
{
return func0(a1, buff_1);
}

original_code:
char * getSysTimeV(struct timeval *tv)
{
 static char buff[64] = {0};
 return getSysTime_tv(tv, buff);
}

canonical_original_code:
char *getSysTimeV(struct timeval *tv)
{
 static char buff[64] = {0};
 return getSysTime_tv(tv, buff);
}

variable_types:
buff
char [64]

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


getSysTime

decompiled_code:
char *getSysTime()
{
return getSysTime_r(buff_0);
}

canonical_decompiled_code:
char *func3()
{
return func1(buff_0);
}

original_code:
char * getSysTime()
{
 static char buff[32] = {0};
 return getSysTime_r(buff);
}

canonical_original_code:
char *getSysTime()
{
 static char buff[32] = {0};
 return getSysTime_r(buff);
}

variable_types:
buff
char [32]


decompiled_code:
int *__fastcall rpc2_rpcc_1(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, void *, __int64, bool_t (**)(XDR *, int *), int *, __int64, _QWORD); // rax
bool v3; // zf
int *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, __int64, void *, __int64, bool_t (**)(XDR *, int *), int *, __int64, _QWORD))(a2 + 8);
clnt_res_0 = 0;
v3 = (*v2)(a2, 1LL, &xdr_rpc2_data_t, a1, &xdr_int, &clnt_res_0, TIMEOUT, 0LL) == 0;
result = &clnt_res_0;
if ( !v3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
int *__fastcall func0(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, void *, __int64, bool_t (**)(XDR *, int *), int *, __int64, _QWORD); // rax
bool v3; // zf
int *result; // rax

v2 = *(unsigned int (__fastcall ***)(__int64, __int64, void *, __int64, bool_t (**)(XDR *, int *), int *, __int64, _QWORD))(a2 + 8);
clnt_res_0 = 0;
v3 = (*v2)(a2, 1LL, &xdr_rpc2_data_t, a1, &xdr_int, &clnt_res_0, TIMEOUT, 0LL) == 0;
result = &clnt_res_0;
if ( !v3 )
result = 0LL;
return result;
}

original_code:
int *
rpc2_rpcc_1(rpc2_data_t *argp, CLIENT *clnt)
{
 static int clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 1, (xdrproc_t) xdr_rpc2_data_t, (caddr_t) argp, (xdrproc_t) xdr_int, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return (&clnt_res);
}

canonical_original_code:
int *rpc2_rpcc_1(struct _rpc2_data_t *argp, struct CLIENT *clnt)
{
 static int clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 1, (int (*)(struct XDR *, void *, ...)) xdr_rpc2_data_t, (char *) argp, (int (*)(struct XDR *, void *, ...)) xdr_int, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return (&clnt_res);
}

variable_types: struct _rpc2_data_t { char data[256]; } *

variable_types: struct CLIENT { struct AUTH { struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; } ah_cred; struct opaque_auth ah_verf; union des_block { struct { unsigned int high; unsigned int low; } key; char c[8]; } ah_key; struct auth_ops { void (*ah_nextverf)(struct AUTH *); int (*ah_marshal)(struct AUTH *, struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *); int (*ah_validate)(struct AUTH *, struct opaque_auth *); int (*ah_refresh)(struct AUTH *); void (*ah_destroy)(struct AUTH *); } *ah_ops; char *ah_private; } *cl_auth; struct clnt_ops { enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 } (*cl_call)(struct CLIENT *, unsigned long, int (*)(struct XDR *, void *, ...), char *, int (*)(struct XDR *, void *, ...), char *, struct timeval { long tv_sec; long tv_usec; }); void (*cl_abort)(); void (*cl_geterr)(struct CLIENT *, struct rpc_err { enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 } re_status; union { int RE_errno; enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 } RE_why; struct { unsigned long low; unsigned long high; } RE_vers; struct { long s1; long s2; } RE_lb; } ru; } *); int (*cl_freeres)(struct CLIENT *, int (*)(struct XDR *, void *, ...), char *); void (*cl_destroy)(struct CLIENT *); int (*cl_control)(struct CLIENT *, int, char *); } *cl_ops; char *cl_private; } *

user_defined_types: struct CLIENT { struct AUTH *cl_auth; struct clnt_ops *cl_ops; char *cl_private; }

user_defined_types: struct AUTH { struct opaque_auth ah_cred; struct opaque_auth ah_verf; union des_block ah_key; struct auth_ops *ah_ops; char *ah_private; }

user_defined_types: struct clnt_ops { enum clnt_stat (*cl_call)(struct CLIENT *, unsigned long, int (*)(struct XDR *, void *, ...), char *, int (*)(struct XDR *, void *, ...), char *, struct timeval); void (*cl_abort)(); void (*cl_geterr)(struct CLIENT *, struct rpc_err *); int (*cl_freeres)(struct CLIENT *, int (*)(struct XDR *, void *, ...), char *); void (*cl_destroy)(struct CLIENT *); int (*cl_control)(struct CLIENT *, int, char *); }

user_defined_types: struct auth_ops { void (*ah_nextverf)(struct AUTH *); int (*ah_marshal)(struct AUTH *, struct XDR *); int (*ah_validate)(struct AUTH *, struct opaque_auth *); int (*ah_refresh)(struct AUTH *); void (*ah_destroy)(struct AUTH *); }

user_defined_types: struct rpc_err { enum clnt_stat re_status; union { int RE_errno; enum auth_stat RE_why; struct { unsigned long low; unsigned long high; } RE_vers; struct { long s1; long s2; } RE_lb; } ru; }


original_code:
void
rpc2_rpc_prog_1(char *host, char *pbuf)
{
  printf("host: %s, result: %s\n", host, pbuf);
 CLIENT *clnt;
 int *result_1;
 rpc2_data_t rpc2_rpcc_1_arg;
 memcpy(rpc2_rpcc_1_arg.data, pbuf, sizeof(rpc2_data_t));
 clnt = clnt_create (host, 0x38000024, 1, "udp");
 if (clnt == ((void *)0)) {
  printf("%s(): clnet_create failed...\n", __FUNCTION__);
  clnt_pcreateerror (host);
  exit (1);
 }
 result_1 = rpc2_rpcc_1(&rpc2_rpcc_1_arg, clnt);
 if (result_1 == (int *) ((void *)0)) {
  printf("%s(): rpc2_rpcc_1 failed...\n", __FUNCTION__);
  clnt_perror (clnt, "call failed");
 }
 ((*(clnt)->cl_ops->cl_destroy)(clnt));
}

canonical_original_code:
void rpc2_rpc_prog_1(char *host, char *pbuf)
{
  printf("host: %s, result: %s\n", host, pbuf);
 struct CLIENT *clnt;
 int *result_1;
 struct _rpc2_data_t rpc2_rpcc_1_arg;
 memcpy(rpc2_rpcc_1_arg.data, pbuf, sizeof(rpc2_data_t));
 clnt = clnt_create (host, 0x38000024, 1, "udp");
 if (clnt == ((void *)0)) {
  printf("%s(): clnet_create failed...\n", __FUNCTION__);
  clnt_pcreateerror (host);
  exit (1);
 }
 result_1 = rpc2_rpcc_1(&rpc2_rpcc_1_arg, clnt);
 if (result_1 == (int *) ((void *)0)) {
  printf("%s(): rpc2_rpcc_1 failed...\n", __FUNCTION__);
  clnt_perror (clnt, "call failed");
 }
 ((*(clnt)->cl_ops->cl_destroy)(clnt));
}

variable_types:
host
char *

variable_types:
pbuf
char *

user_defined_types: struct opaque_auth { int oa_flavor; char *oa_base; unsigned int oa_length; }

user_defined_types: union des_block { struct { unsigned int high; unsigned int low; } key; char c[8]; }

user_defined_types: enum clnt_stat { RPC_SUCCESS=0, RPC_CANTENCODEARGS=1, RPC_CANTDECODERES=2, RPC_CANTSEND=3, RPC_CANTRECV=4, RPC_TIMEDOUT=5, RPC_VERSMISMATCH=6, RPC_AUTHERROR=7, RPC_PROGUNAVAIL=8, RPC_PROGVERSMISMATCH=9, RPC_PROCUNAVAIL=10, RPC_CANTDECODEARGS=11, RPC_SYSTEMERROR=12, RPC_NOBROADCAST=21, RPC_UNKNOWNHOST=13, RPC_UNKNOWNPROTO=17, RPC_UNKNOWNADDR=19, RPC_RPCBFAILURE=14, RPC_PROGNOTREGISTERED=15, RPC_N2AXLATEFAILURE=22, RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, RPC_INPROGRESS=24, RPC_STALERACHANDLE=25 }

user_defined_types: struct XDR { enum xdr_op x_op; struct xdr_ops *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; }

user_defined_types: enum auth_stat { AUTH_OK=0, AUTH_BADCRED=1, AUTH_REJECTEDCRED=2, AUTH_BADVERF=3, AUTH_REJECTEDVERF=4, AUTH_TOOWEAK=5, AUTH_INVALIDRESP=6, AUTH_FAILED=7 }

user_defined_types: enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 }


decompiled_code:
bool_t __fastcall xdr__rpc1_data_t(XDR *xdrs, __int64 a2)
{
bool_t result; // eax

result = xdr_int(xdrs, (int *)a2);
if ( result )
result = xdr_vector(xdrs, (char *)(a2 + 4), 0, 1u, (xdrproc_t)&xdr_char) != 0;
return result;
}

canonical_decompiled_code:
bool_t __fastcall func0(XDR *xdrs, __int64 a2)
{
bool_t result; // eax

result = xdr_int(xdrs, (int *)a2);
if ( result )
result = xdr_vector(xdrs, (char *)(a2 + 4), 0, 1u, (xdrproc_t)&xdr_char) != 0;
return result;
}

original_code:
bool_t
xdr__rpc1_data_t (XDR *xdrs, _rpc1_data_t *objp)
{
 register int32_t *buf;
 int i;
  if (!xdr_int (xdrs, &objp->type))
   return (0);
  if (!xdr_vector (xdrs, (char *)objp->data, 0,
  sizeof (char), (xdrproc_t) xdr_char))
   return (0);
 return (1);
}

canonical_original_code:
int xdr__rpc1_data_t(struct XDR *xdrs, struct _rpc1_data_t *objp)
{
 register int *buf;
 int i;
  if (!xdr_int (xdrs, &objp->type))
   return (0);
  if (!xdr_vector (xdrs, (char *)objp->data, 0,
  sizeof (char), (int (*)(struct XDR *, void *, ...)) xdr_char))
   return (0);
 return (1);
}

variable_types: struct XDR { enum xdr_op { XDR_ENCODE=0, XDR_DECODE=1, XDR_FREE=2 } x_op; struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); } *x_ops; char *x_public; char *x_private; char *x_base; unsigned int x_handy; } *

variable_types: struct _rpc1_data_t { int type; char data[]; } *

variable_types:
buf
int *

variable_types: i int


decompiled_code:
_BOOL8 __fastcall xdr_rpc1_data_t(XDR *a1, __int64 a2)
{
return xdr__rpc1_data_t(a1, a2) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(XDR *a1, __int64 a2)
{
return func0(a1, a2) != 0;
}

original_code:
bool_t
xdr_rpc1_data_t (XDR *xdrs, rpc1_data_t *objp)
{
 register int32_t *buf;
  if (!xdr__rpc1_data_t (xdrs, objp))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_rpc1_data_t(struct XDR *xdrs, struct _rpc1_data_t *objp)
{
 register int *buf;
  if (!xdr__rpc1_data_t (xdrs, objp))
   return (0);
 return (1);
}

user_defined_types: struct _rpc1_data_t { int type; char data[]; }

user_defined_types: struct xdr_ops { int (*x_getlong)(struct XDR *__xdrs, long *__lp); int (*x_putlong)(struct XDR *__xdrs, long *__lp); int (*x_getbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); int (*x_putbytes)(struct XDR *__xdrs, char *__addr, unsigned int __len); unsigned int (*x_getpostn)(struct XDR *__xdrs); int (*x_setpostn)(struct XDR *__xdrs, unsigned int __pos); int *(*x_inline)(struct XDR *__xdrs, unsigned int __len); void (*x_destroy)(struct XDR *__xdrs); int (*x_getint32)(struct XDR *__xdrs, int *__ip); int (*x_putint32)(struct XDR *__xdrs, int *__ip); }


repo: wolog/loopcast

decompiled_code:
void sigusr1_dontwait()
{
waitclients = 0;
signal(10, sigusr1_dontwait);
}

canonical_decompiled_code:
void func0()
{
waitclients = 0;
signal(10, sigusr1_dontwait);
}

original_code:
void sigusr1_dontwait(int i)
{
 waitclients = 0;
 signal(10, sigusr1_dontwait);
}


decompiled_code:
void sigusr1_dummy()
{
signal(10, sigusr1_dummy);
}

canonical_decompiled_code:
void func1()
{
signal(10, sigusr1_dummy);
}

original_code:
void sigusr1_dummy(int i)
{
 signal(10, sigusr1_dummy);
}


decompiled_code:
void sigusr2_dummy()
{
signal(12, sigusr2_dummy);
}

canonical_decompiled_code:
void func2()
{
signal(12, sigusr2_dummy);
}

original_code:
void sigusr2_dummy(int i)
{
 signal(12, sigusr2_dummy);
}


decompiled_code:
void sigalarm_unlock()
{
lock = 0;
signal(14, sigalarm_unlock);
timer.it_interval = (timeval)_mm_load_si128((const __m128i *)&reftimer);
timer.it_value = (timeval)_mm_load_si128((const __m128i *)&reftimer + 1);
setitimer(ITIMER_REAL, &timer, 0LL);
}

canonical_decompiled_code:
void func3()
{
lock = 0;
signal(14, sigalarm_unlock);
timer.it_interval = (timeval)_mm_load_si128((const __m128i *)&reftimer);
timer.it_value = (timeval)_mm_load_si128((const __m128i *)&reftimer + 1);
setitimer(ITIMER_REAL, &timer, 0LL);
}

original_code:
void sigalarm_unlock(int i)
{
 lock = 0;
 signal(14, sigalarm_unlock);
 timer = reftimer;
 setitimer(ITIMER_REAL, &timer, ((void *)0));
}


decompiled_code:
void sigusr2_dumpclients()
{
network_dump_keepalives(sigusr2_options, sigusr2_network);
signal(12, sigusr2_dumpclients);
}

canonical_decompiled_code:
void func4()
{
network_dump_keepalives(sigusr2_options, sigusr2_network);
signal(12, sigusr2_dumpclients);
}

original_code:
void sigusr2_dumpclients(int i)
{
 network_dump_keepalives(sigusr2_options, sigusr2_network);
 signal(12, sigusr2_dumpclients);
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er14
time_t v4; // r12
unsigned int i; // ebx
time_t v6; // rax
double v7; // xmm1_8
time_t v9; // rbx
__int64 v10; // rdx
unsigned int v11; // eax
unsigned int v12; // er12
timeval v13; // xmm1
timeval v14; // xmm0
time_t v15; // rax
int v16; // [rsp+0h] [rbp-12B8h] BYREF
unsigned int v17; // [rsp+8h] [rbp-12B0h]
char v18[192]; // [rsp+20h] [rbp-1298h] BYREF
char v19[8]; // [rsp+E0h] [rbp-11D8h] BYREF
int v20; // [rsp+E8h] [rbp-11D0h]
int v21; // [rsp+ECh] [rbp-11CCh]
unsigned int v22; // [rsp+F0h] [rbp-11C8h]
int v23; // [rsp+118h] [rbp-11A0h]
__m128i v24; // [rsp+120h] [rbp-1198h] BYREF
__m128i v25; // [rsp+130h] [rbp-1188h] BYREF
int v26; // [rsp+140h] [rbp-1178h]
__int64 v27; // [rsp+268h] [rbp-1050h]
char v28[4]; // [rsp+280h] [rbp-1038h] BYREF
int v29; // [rsp+284h] [rbp-1034h]

signal(10, (__sighandler_t)sigusr1_dummy);
signal(12, (__sighandler_t)sigusr2_dummy);
options_init(v19, 1LL, (unsigned int)argc, argv);
network_init(v19, v18);
buffer_init(v19, &v16, stdin);
v29 = v16;
signal(10, (__sighandler_t)sigusr1_dontwait);
sigusr2_options = (__int64)v19;
sigusr2_network = (__int64)v18;
signal(12, (__sighandler_t)sigusr2_dumpclients);
if ( !v22 )
{
LABEL_2:
if ( v20 )
goto LABEL_39;
goto LABEL_3;
}
v9 = time(0LL);
do
{
sleep(1u);
v11 = network_recv_keepalives(v19, v18, v9);
v12 = v11;
if ( !v20 )
{
v10 = v22;
if ( (int)v22 <= (int)v11 )
break;
continue;
}
do_printf("Expecting %d clients, found %d\n", v22, v11);
v10 = v22;
if ( (int)v22 <= (int)v12 )
break;
}
while ( waitclients );
if ( v20 )
{
if ( !waitclients )
{
do_printf("SIGUSR1 received, starting with %d clients, where %d were expected\n", v12, v10);
goto LABEL_2;
}
LABEL_39:
puts("Start main loop");
}
LABEL_3:
if ( v27 )
network_dump_keepalives(v19, v18);
if ( v23 )
{
lock = 1;
signal(14, (__sighandler_t)sigalarm_unlock);
v13 = (timeval)_mm_loadu_si128(&v24);
v14 = (timeval)_mm_loadu_si128(&v25);
reftimer = (__int128)v13;
*(&reftimer + 1) = (__int128)v14;
timer.it_interval = v13;
timer.it_value = v14;
setitimer(ITIMER_REAL, &timer, 0LL);
}
v3 = 0;
v4 = time(0LL);
while ( 2 )
{
while ( 2 )
{
++v3;
if ( v20 )
{
printf("Loop %u :", v3);
if ( v17 )
goto LABEL_10;
LABEL_15:
if ( v20 )
puts("done");
}
else if ( v17 )
{
LABEL_10:
for ( i = 0; i < v17; ++i )
{
buffer_send(&v16, i, v28);
network_send(v18, v28);
if ( v23 )
{
lock = 1;
do
pause();
while ( lock );
}
if ( v26 && !(unsigned int)network_recv_keepalives(v19, v18, v4) )
break;
}
goto LABEL_15;
}
if ( !v26 )
{
if ( v21 )
{
v6 = time(0LL);
v7 = difftime(v6, v4);
if ( v7 > (double)v21 )
{
if ( v20 )
{
v15 = time(0LL);
difftime(v15, v4);
do_printf("Max time reached after %ld seconds, stop sending\n", v4);
}
goto LABEL_22;
}
}
continue;
}
break;
}
if ( (unsigned int)network_recv_keepalives(v19, v18, v4) )
continue;
break;
}
if ( v20 )
do_printf("no keepalive received, stop sending\n");
LABEL_22:
network_clean(v18);
buffer_clean(&v16);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 buffer_t buffer;
 message_t message;
 network_t network;
 options_t options;
 uint32_t i;
 uint32_t loop = 0;
 time_t starttime;
 int clients;
 signal(10, sigusr1_dummy);
 signal(12, sigusr2_dummy);
 ;
 options_init(&options, 1, argc, argv);
 ;
 network_init(&options, &network);
 ;
 buffer_init(&options, &buffer, stdin);
 message.length = buffer.length;
 signal(10, sigusr1_dontwait);
 sigusr2_options = &options;
 sigusr2_network = &network;
 signal(12, sigusr2_dumpclients);
 if (options.clientsnumber) {
  starttime = time(((void *)0));
  do {
   sleep(1);
   clients =
       network_recv_keepalives(&options, &network,
          starttime);
   if (options.verbose) {
    do_printf("Expecting %d clients, found %d\n",
       options.clientsnumber, clients);
   }
  } while (clients < options.clientsnumber && waitclients);
  if (options.verbose && !waitclients) {
   do_printf
       ("SIGUSR1 received, starting with %d clients, where %d were expected\n",
        clients, options.clientsnumber);
  }
 }
 if (options.verbose) {
  printf("Start main loop\n");
 }
 if (options.output) {
  network_dump_keepalives(&options, &network);
 }
 if (options.bwlimit) {
  lock = 1;
  signal(14, sigalarm_unlock);
  reftimer = options.bwlimit_itimer;
  timer = reftimer;
  setitimer(ITIMER_REAL, &timer, ((void *)0));
 }
 starttime = time(((void *)0));
 while (1) {
  loop++;
  if (options.verbose) {
   printf("Loop %u :", loop);
  }
  for (i = 0; i < buffer.nchunks; i++) {
   buffer_send(&buffer, i, &message);
   network_send(&network, &message);
   if (options.bwlimit) {
    lock = 1;
    while (lock) {
     pause();
    }
   }
   if (options.keepalives) {
    if (!network_recv_keepalives
        (&options, &network, starttime)) {
     break;
    }
   }
  }
  if (options.verbose) {
   printf("done\n");
  }
  if (options.keepalives) {
   if (!network_recv_keepalives
       (&options, &network, starttime)) {
    if (options.verbose) {
     do_printf
         ("no keepalive received, stop sending\n");
    }
    break;
   }
  } else {
   if (options.maxwait
       && (difftime(time(((void *)0)), starttime) >
    options.maxwait)) {
    if (options.verbose) {
     do_printf
         ("Max time reached after %ld seconds, stop sending\n",
          difftime(time(((void *)0)), starttime));
    }
    break;
   }
  }
 }
 network_clean(&network);
 buffer_clean(&buffer);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct buffer_s buffer;
 struct message_s message;
 struct network_s network;
 struct options_s options;
 unsigned int i;
 unsigned int loop = 0;
 long starttime;
 int clients;
 signal(10, sigusr1_dummy);
 signal(12, sigusr2_dummy);
 ;
 options_init(&options, 1, argc, argv);
 ;
 network_init(&options, &network);
 ;
 buffer_init(&options, &buffer, stdin);
 message.length = buffer.length;
 signal(10, sigusr1_dontwait);
 sigusr2_options = &options;
 sigusr2_network = &network;
 signal(12, sigusr2_dumpclients);
 if (options.clientsnumber) {
  starttime = time(((void *)0));
  do {
   sleep(1);
   clients =
       network_recv_keepalives(&options, &network,
          starttime);
   if (options.verbose) {
    do_printf("Expecting %d clients, found %d\n",
       options.clientsnumber, clients);
   }
  } while (clients < options.clientsnumber && waitclients);
  if (options.verbose && !waitclients) {
   do_printf
       ("SIGUSR1 received, starting with %d clients, where %d were expected\n",
        clients, options.clientsnumber);
  }
 }
 if (options.verbose) {
  printf("Start main loop\n");
 }
 if (options.output) {
  network_dump_keepalives(&options, &network);
 }
 if (options.bwlimit) {
  lock = 1;
  signal(14, sigalarm_unlock);
  reftimer = options.bwlimit_itimer;
  timer = reftimer;
  setitimer(ITIMER_REAL, &timer, ((void *)0));
 }
 starttime = time(((void *)0));
 while (1) {
  loop++;
  if (options.verbose) {
   printf("Loop %u :", loop);
  }
  for (i = 0; i < buffer.nchunks; i++) {
   buffer_send(&buffer, i, &message);
   network_send(&network, &message);
   if (options.bwlimit) {
    lock = 1;
    while (lock) {
     pause();
    }
   }
   if (options.keepalives) {
    if (!network_recv_keepalives
        (&options, &network, starttime)) {
     break;
    }
   }
  }
  if (options.verbose) {
   printf("done\n");
  }
  if (options.keepalives) {
   if (!network_recv_keepalives
       (&options, &network, starttime)) {
    if (options.verbose) {
     do_printf
         ("no keepalive received, stop sending\n");
    }
    break;
   }
  } else {
   if (options.maxwait
       && (difftime(time(((void *)0)), starttime) >
    options.maxwait)) {
    if (options.verbose) {
     do_printf
         ("Max time reached after %ld seconds, stop sending\n",
          difftime(time(((void *)0)), starttime));
    }
    break;
   }
  }
 }
 network_clean(&network);
 buffer_clean(&buffer);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct buffer_s { unsigned int length; unsigned int maxchunks; unsigned int nchunks; unsigned int last_chunk_number; struct chunk_s { unsigned short n; unsigned char returnvalue; unsigned char data[4096]; } *chunks; }

variable_types: struct message_s { unsigned int crc; unsigned int length; unsigned int nchunks; struct chunk_s { unsigned short n; unsigned char returnvalue; unsigned char data[4096]; } chunk; }

variable_types: struct network_s { int percent; unsigned int id; long received_packets; struct netsock_s { int sock; 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]; } saddr; struct ip_mreq { struct in_addr imr_multiaddr; struct in_addr imr_interface; } imreq; struct in_addr iaddr; struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; } interface; } data; struct netsock_s keepalive; struct keepalive_s { long time; unsigned char value; } *keepalives; }

variable_types: struct options_s { unsigned short maxchunks; int sender; int verbose; int maxwait; int clientsnumber; struct itimerval { struct timeval { long tv_sec; long tv_usec; } it_interval; struct timeval it_value; } maxwait_itimer; int bwlimit; struct itimerval bwlimit_itimer; int keepalives; char statuscmd[-1]; int statusstep; unsigned short ip_port; unsigned long ip_addr; char interface[16]; char *output; unsigned char returnvalue; int exitonvalue; }

variable_types:
i
unsigned int

variable_types:
loop
unsigned int

variable_types: starttime long

variable_types: clients int

user_defined_types: struct buffer_s { unsigned int length; unsigned int maxchunks; unsigned int nchunks; unsigned int last_chunk_number; struct chunk_s *chunks; }

user_defined_types: struct message_s { unsigned int crc; unsigned int length; unsigned int nchunks; struct chunk_s chunk; }

user_defined_types: struct network_s { int percent; unsigned int id; long received_packets; struct netsock_s data; struct netsock_s keepalive; struct keepalive_s *keepalives; }

user_defined_types: struct options_s { unsigned short maxchunks; int sender; int verbose; int maxwait; int clientsnumber; struct itimerval maxwait_itimer; int bwlimit; struct itimerval bwlimit_itimer; int keepalives; char statuscmd[-1]; int statusstep; unsigned short ip_port; unsigned long ip_addr; char interface[16]; char *output; unsigned char returnvalue; int exitonvalue; }

user_defined_types: struct netsock_s { int sock; struct sockaddr_in saddr; struct ip_mreq imreq; struct in_addr iaddr; struct ifreq interface; }

user_defined_types: struct itimerval { struct timeval it_interval; struct timeval it_value; }

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

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


decompiled_code:
void alarm_maxwait()
{
signal(14, alarm_maxwait);
timer.it_interval = (timeval)_mm_load_si128((const __m128i *)&reftimer);
timer.it_value = (timeval)_mm_load_si128((const __m128i *)&reftimer + 1);
setitimer(ITIMER_REAL, &timer, 0LL);
network_send_keepalive(&network);
}

canonical_decompiled_code:
void func0()
{
signal(14, alarm_maxwait);
timer.it_interval = (timeval)_mm_load_si128((const __m128i *)&reftimer);
timer.it_value = (timeval)_mm_load_si128((const __m128i *)&reftimer + 1);
setitimer(ITIMER_REAL, &timer, 0LL);
network_send_keepalive(&network);
}

original_code:
void alarm_maxwait(int i)
{
 signal(14, alarm_maxwait);
 timer = reftimer;
 setitimer(ITIMER_REAL, &timer, ((void *)0));
 network_send_keepalive(&network);
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // bl
unsigned int v4; // er12
timeval v6; // xmm1
timeval v7; // xmm0
_QWORD v8[4]; // [rsp+0h] [rbp-11E8h] BYREF
char v9[8]; // [rsp+20h] [rbp-11C8h] BYREF
int v10; // [rsp+28h] [rbp-11C0h]
__m128i v11; // [rsp+38h] [rbp-11B0h] BYREF
__m128i v12[3]; // [rsp+48h] [rbp-11A0h] BYREF
int v13; // [rsp+80h] [rbp-1168h]
int v14; // [rsp+1B4h] [rbp-1034h]
char v15[4136]; // [rsp+1C0h] [rbp-1028h] BYREF

options_init(v9, 0LL, (unsigned int)argc, argv);
network_init(v9, &network);
buffer_init(v9, v8, 0LL);
if ( v13 )
{
network_send_keepalive(&network);
signal(14, (__sighandler_t)alarm_maxwait);
v6 = (timeval)_mm_loadu_si128(&v11);
v7 = (timeval)_mm_loadu_si128(v12);
reftimer = (__int128)v6;
*(&reftimer + 1) = (__int128)v7;
timer.it_interval = v6;
timer.it_value = v7;
setitimer(ITIMER_REAL, &timer, 0LL);
}
v3 = 0;
while ( 1 )
{
do
{
while ( !(unsigned int)network_recv(v9, &network, v15) )
;
}
while ( !(unsigned int)buffer_recv(v9, v8, v15) );
if ( v14 )
break;
if ( !++v3 && (unsigned int)buffer_dump(v8, stdout) )
{
network_clean(&network);
v4 = *(unsigned __int8 *)(v8[2] + 2LL);
buffer_clean(v8);
if ( v10 )
do_printf("Successfully received\n");
return v4;
}
}
signal(14, (__sighandler_t)((char *)alarm_maxwait + 1));
network_clean(&network);
v4 = (unsigned __int8)v15[14];
buffer_clean(v8);
if ( v10 )
do_printf("Return code is now known (=%d), exiting\n", v4);
return v4;
}

original_code:
int main(int argc, char *argv[])
{
 buffer_t buffer;
 message_t message;
 options_t options;
 uint8_t loop;
 int returnvalue;
 ;
 options_init(&options, 0, argc, argv);
 ;
 network_init(&options, &network);
 ;
 buffer_init(&options, &buffer, ((void *)0));
 if (options.keepalives) {
  ;
  network_send_keepalive(&network);
  signal(14, alarm_maxwait);
  reftimer = options.maxwait_itimer;
  timer = reftimer;
  setitimer(ITIMER_REAL, &timer, ((void *)0));
 }
 loop = 0;
 while (1) {
  ;
  if (network_recv(&options, &network, &message)) {
   if (buffer_recv(&options, &buffer, &message)) {
    if (options.exitonvalue) {
     signal(14, ((__sighandler_t) 1));
     network_clean(&network);
     returnvalue = message.chunk.returnvalue;
     buffer_clean(&buffer);
     if (options.verbose) {
      do_printf
          ("Return code is now known (=%d), exiting\n",
           returnvalue);
     }
     return returnvalue;
    }
    loop++;
    if (!(loop % ((2 * 1024 * 1024) / 4096))) {
     if (buffer_dump(&buffer, stdout)) {
      network_clean(&network);
      returnvalue =
          buffer.
          chunks[0].returnvalue;
      buffer_clean(&buffer);
      if (options.verbose) {
       do_printf
           ("Successfully received\n");
      }
      break;
     }
    }
   }
  }
 }
 return returnvalue;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 struct buffer_s buffer;
 struct message_s message;
 struct options_s options;
 unsigned char loop;
 int returnvalue;
 ;
 options_init(&options, 0, argc, argv);
 ;
 network_init(&options, &network);
 ;
 buffer_init(&options, &buffer, ((void *)0));
 if (options.keepalives) {
  ;
  network_send_keepalive(&network);
  signal(14, alarm_maxwait);
  reftimer = options.maxwait_itimer;
  timer = reftimer;
  setitimer(ITIMER_REAL, &timer, ((void *)0));
 }
 loop = 0;
 while (1) {
  ;
  if (network_recv(&options, &network, &message)) {
   if (buffer_recv(&options, &buffer, &message)) {
    if (options.exitonvalue) {
     signal(14, ((void (*)(int)) 1));
     network_clean(&network);
     returnvalue = message.chunk.returnvalue;
     buffer_clean(&buffer);
     if (options.verbose) {
      do_printf
          ("Return code is now known (=%d), exiting\n",
           returnvalue);
     }
     return returnvalue;
    }
    loop++;
    if (!(loop % ((2 * 1024 * 1024) / 4096))) {
     if (buffer_dump(&buffer, stdout)) {
      network_clean(&network);
      returnvalue =
          buffer.
          chunks[0].returnvalue;
      buffer_clean(&buffer);
      if (options.verbose) {
       do_printf
           ("Successfully received\n");
      }
      break;
     }
    }
   }
  }
 }
 return returnvalue;
}

variable_types:
loop
unsigned char

variable_types: returnvalue int

user_defined_types: struct chunk_s { unsigned short n; unsigned char returnvalue; unsigned char data[4096]; }

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


decompiled_code:
void __fastcall free_pair_list(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func20(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

if ( ptr )
{
v1 = ptr;
do
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 2);
free(v2);
}
while ( v1 );
}
}

original_code:
void free_pair_list( l_pair* head ){
 l_pair* temp;
 while( head ){
  temp = head;
  head = head->next;
  free( temp );
 }
}

canonical_original_code:
void free_pair_list(struct l_pair_ *head){
 struct l_pair_ *temp;
 while( head ){
  temp = head;
  head = head->next;
  free( temp );
 }
}

variable_types: struct l_pair_ { char keyword[10]; int value; struct l_pair_ *next; } *


decompiled_code:
__int64 __fastcall handle_effect(char *src, __int64 *a2)
{
__int64 v2; // rbx
__int64 result; // rax
char *v4; // rax
char *v5; // rax

v2 = *a2;
if ( *a2 )
{
while ( strcmp((const char *)v2, src) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_6;
}
result = *((unsigned int *)src + 3);
*(_DWORD *)(v2 + 12) += result;
}
else
{
LABEL_6:
v4 = (char *)malloc(0x18uLL);
*((_QWORD *)v4 + 2) = 0LL;
v5 = strcpy(v4, src);
*((_DWORD *)v5 + 3) = *((_DWORD *)src + 3);
result = append_pair(a2, v5);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *src, __int64 *a2)
{
__int64 v2; // rbx
__int64 result; // rax
char *v4; // rax
char *v5; // rax

v2 = *a2;
if ( *a2 )
{
while ( strcmp((const char *)v2, src) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
goto LABEL_6;
}
result = *((unsigned int *)src + 3);
*(_DWORD *)(v2 + 12) += result;
}
else
{
LABEL_6:
v4 = (char *)malloc(0x18uLL);
*((_QWORD *)v4 + 2) = 0LL;
v5 = strcpy(v4, src);
*((_DWORD *)v5 + 3) = *((_DWORD *)src + 3);
result = append_pair(a2, v5);
}
return result;
}

original_code:
void handle_effect( l_pair* effect, l_pair** player_e_head ){
 l_pair* curstat = *player_e_head;
 while( curstat != ((void *)0) ){
  if( strcmp( curstat->keyword, effect->keyword ) == 0 ){
   curstat->value += effect->value;
   return;
  } else {
   curstat = curstat->next;
  }
 }
 l_pair* new_effect = malloc( sizeof( l_pair ));
 new_effect->next = ((void *)0);
 strcpy( new_effect->keyword, effect->keyword );
 new_effect->value = effect->value;
 append_pair( player_e_head, new_effect );
}

canonical_original_code:
void handle_effect(struct l_pair_ *effect, struct l_pair_ **player_e_head){
 struct l_pair_ *curstat = *player_e_head;
 while( curstat != ((void *)0) ){
  if( strcmp( curstat->keyword, effect->keyword ) == 0 ){
   curstat->value += effect->value;
   return;
  } else {
   curstat = curstat->next;
  }
 }
 struct l_pair_ *new_effect = malloc( sizeof( l_pair ));
 new_effect->next = ((void *)0);
 strcpy( new_effect->keyword, effect->keyword );
 new_effect->value = effect->value;
 append_pair( player_e_head, new_effect );
}

user_defined_types: struct l_pair_ { char keyword[10]; int value; struct l_pair_ *next; }


decompiled_code:
__int64 __fastcall do_effects(__int64 *a1, __int64 *a2)
{
__int64 i; // rbx
__int64 result; // rax

if ( a1 )
{
for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = handle_effect((char *)i, a2);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 *a1, __int64 *a2)
{
__int64 i; // rbx
__int64 result; // rax

if ( a1 )
{
for ( i = *a1; i; i = *(_QWORD *)(i + 16) )
result = func1((char *)i, a2);
}
return result;
}

original_code:
void do_effects( l_pair** effects, l_pair** player_e_head ){
 if( effects == ((void *)0) ){
  return;
 }
 l_pair* effect = *effects;
 while( effect != ((void *)0) ){
  handle_effect( effect, player_e_head );
  effect = effect->next;
 }
}

canonical_original_code:
void do_effects(struct l_pair_ **effects, struct l_pair_ **player_e_head){
 if( effects == ((void *)0) ){
  return;
 }
 struct l_pair_ *effect = *effects;
 while( effect != ((void *)0) ){
  handle_effect( effect, player_e_head );
  effect = effect->next;
 }
}

variable_types: struct l_pair_ { char keyword[10]; int value; struct l_pair_ *next; } **