decompiled_code:
__int64 __fastcall client_write(int fd, void *ptr)
{
size_t v2; // rdx
int v3; // eax
bool v4; // zf
unsigned int v5; // er12
unsigned int v6; // er12

v2 = *((int *)ptr + 136);
if ( (_DWORD)v2 )
{
v3 = write(fd, *((const void **)ptr + 67), v2);
v4 = v3 == 0;
if ( v3 > 0 )
goto LABEL_3;
}
else
{
*((_DWORD *)ptr + 136) = 87;
*((_QWORD *)ptr + 67) = "HTTP/1.1 200 OK\r\n"
"Content-Length: 0\r\n"
"Content-Type: text/html\r\n"
"Connection: keep-alive\r\n"
"\r\n";
v3 = write(
fd,
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: text/html\r\nConnection: keep-alive\r\n\r\n",
0x57uLL);
v4 = v3 == 0;
if ( v3 > 0 )
{
LABEL_3:
v5 = *((_DWORD *)ptr + 136) - v3;
*((_QWORD *)ptr + 67) += v3;
*((_DWORD *)ptr + 136) = v5;
if ( v5 )
return 0;
goto LABEL_10;
}
}
if ( !v4 && *_errno_location() != 11 )
{
v6 = 123;
close(fd);
event_destroy(*((_QWORD *)ptr + 69));
free(ptr);
return v6;
}
v5 = *((_DWORD *)ptr + 136);
if ( v5 )
return 0;
LABEL_10:
event_mod(*((_QWORD *)ptr + 69), 1LL);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func1(int fd, void *ptr)
{
size_t v2; // rdx
int v3; // eax
bool v4; // zf
unsigned int v5; // er12
unsigned int v6; // er12

v2 = *((int *)ptr + 136);
if ( (_DWORD)v2 )
{
v3 = write(fd, *((const void **)ptr + 67), v2);
v4 = v3 == 0;
if ( v3 > 0 )
goto LABEL_3;
}
else
{
*((_DWORD *)ptr + 136) = 87;
*((_QWORD *)ptr + 67) = "HTTP/1.1 200 OK\r\n"
"Content-Length: 0\r\n"
"Content-Type: text/html\r\n"
"Connection: keep-alive\r\n"
"\r\n";
v3 = write(
fd,
"HTTP/1.1 200 OK\r\nContent-Length: 0\r\nContent-Type: text/html\r\nConnection: keep-alive\r\n\r\n",
0x57uLL);
v4 = v3 == 0;
if ( v3 > 0 )
{
LABEL_3:
v5 = *((_DWORD *)ptr + 136) - v3;
*((_QWORD *)ptr + 67) += v3;
*((_DWORD *)ptr + 136) = v5;
if ( v5 )
return 0;
goto LABEL_10;
}
}
if ( !v4 && *_errno_location() != 11 )
{
v6 = 123;
close(fd);
event_destroy(*((_QWORD *)ptr + 69));
free(ptr);
return v6;
}
v5 = *((_DWORD *)ptr + 136);
if ( v5 )
return 0;
LABEL_10:
event_mod(*((_QWORD *)ptr + 69), 1LL);
return v5;
}

original_code:
static int client_write(int fd, void *priv)
{
 const char *buff =
  "HTTP/1.1 200 OK\r\n"
  "Content-Length: 0\r\n"
  "Content-Type: text/html\r\n"
  "Connection: keep-alive\r\n"
  "\r\n";
 struct node *n = priv;
 int ret;
 if (n->len_write == 0) {
  n->len_write = strlen(buff);
  n->pos_write = (char*)buff;
 }
 if ((ret = write(fd, n->pos_write, n->len_write)) > 0) {
  n->len_write -= ret;
  n->pos_write += ret;
 } else if (ret < 0 && (*__errno_location ()) != 11) {
  goto close_connection;
 }
 if (n->len_write == 0) {
  event_mod(n->handle, EPOLLIN);
 }
 return 0;
close_connection:
 close(fd);
 event_destroy(n->handle);
 free(n);
 return 123;
}

canonical_original_code:
static int client_write(int fd, void *priv)
{
 char *buff = "HTTP/1.1 200 OK\r\n"
  "Content-Length: 0\r\n"
  "Content-Type: text/html\r\n"
  "Connection: keep-alive\r\n"
  "\r\n";
 struct node *n = priv;
 int ret;
 if (n->len_write == 0) {
  n->len_write = strlen(buff);
  n->pos_write = (char *)buff;
 }
 if ((ret = write(fd, n->pos_write, n->len_write)) > 0) {
  n->len_write -= ret;
  n->pos_write += ret;
 } else if (ret < 0 && (*__errno_location ()) != 11) {
  goto close_connection;
 }
 if (n->len_write == 0) {
  event_mod(n->handle, EPOLLIN);
 }
 return 0;
close_connection:
 close(fd);
 event_destroy(n->handle);
 free(n);
 return 123;
}

variable_types:
buff
char *


repo: yangxks/Model

decompiled_code:
__int64 __fastcall client_read(int fd, void *ptr)
{
int v2; // eax
int v3; // eax

v2 = read(fd, (char *)ptr + *((int *)ptr + 133) + 20, 512 - *((_DWORD *)ptr + 133));
if ( v2 > 0 )
{
v3 = *((_DWORD *)ptr + 133) + v2;
*((_DWORD *)ptr + 133) = v3;
if ( v3 <= 511 )
{
*((_BYTE *)ptr + v3 + 20) = 0;
if ( v3 <= 3 )
return 0LL;
}
else
{
*((_BYTE *)ptr + 531) = 0;
}
if ( strstr((const char *)ptr + 20, "\n\n") || strstr((const char *)ptr + 20, "\r\n\r\n") )
{
*((_DWORD *)ptr + 133) = 0;
event_mod(*((_QWORD *)ptr + 69), 5LL);
}
return 0LL;
}
close(fd);
event_destroy(*((_QWORD *)ptr + 69));
free(ptr);
return 123LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *ptr)
{
int v2; // eax
int v3; // eax

v2 = read(fd, (char *)ptr + *((int *)ptr + 133) + 20, 512 - *((_DWORD *)ptr + 133));
if ( v2 > 0 )
{
v3 = *((_DWORD *)ptr + 133) + v2;
*((_DWORD *)ptr + 133) = v3;
if ( v3 <= 511 )
{
*((_BYTE *)ptr + v3 + 20) = 0;
if ( v3 <= 3 )
return 0LL;
}
else
{
*((_BYTE *)ptr + 531) = 0;
}
if ( strstr((const char *)ptr + 20, "\n\n") || strstr((const char *)ptr + 20, "\r\n\r\n") )
{
*((_DWORD *)ptr + 133) = 0;
event_mod(*((_QWORD *)ptr + 69), 5LL);
}
return 0LL;
}
close(fd);
event_destroy(*((_QWORD *)ptr + 69));
free(ptr);
return 123LL;
}

original_code:
static int client_read(int fd, void *priv)
{
 int ret;
 struct node *n = priv;
 if ((ret = read(fd, n->request + n->len_read,
     512 - n->len_read)) <= 0) {
  goto close_connection;
 }
 n->len_read += ret;
 if (n->len_read >= 512) {
  n->request[512 -1] = 0;
 } else {
  n->request[n->len_read] = 0;
 }
 if (n->len_read < 4) {
  return 0;
 }
 if (strstr(n->request, "\n\n") != ((void *)0) ||
   strstr(n->request, "\r\n\r\n") != ((void *)0)) {
  n->len_read = 0;
  event_mod(n->handle, EPOLLIN | EPOLLOUT);
 }
 return 0;
close_connection:
 close(fd);
 event_destroy(n->handle);
 free(n);
 return 123;
}

variable_types: fd int

variable_types:
priv
void *

variable_types: ret int

variable_types: struct node { int fd; 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]; } addr; char request[512]; int len_read; char *pos_write; int len_write; void *handle; } *

return_type: int

user_defined_types: struct node { int fd; struct sockaddr_in addr; char request[512]; int len_read; char *pos_write; int len_write; void *handle; }

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


usage

decompiled_code:
void __noreturn usage()
{
puts("\nserver: -D -i ip -p port");
puts("\t\t-D: Daemon process");
puts("\t\t-i ip: Server ip to be listened");
puts("\t\t-p port: Server port to be listened");
puts("\t\t-h: Show this help.");
putchar(10);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func4()
{
puts("\nserver: -D -i ip -p port");
puts("\t\t-D: Daemon process");
puts("\t\t-i ip: Server ip to be listened");
puts("\t\t-p port: Server port to be listened");
puts("\t\t-h: Show this help.");
putchar(10);
exit(-1);
}

original_code:
static void usage(void)
{
 printf("\nserver: -D -i ip -p port\n");
 printf("\t\t-D:         Daemon process\n");
 printf("\t\t-i ip:      Server ip to be listened\n");
 printf("\t\t-p port:    Server port to be listened\n");
 printf("\t\t-h:         Show this help.\n");
 printf("\n");
 exit(-1);
}

canonical_original_code:
static void usage()
{
 printf("\nserver: -D -i ip -p port\n");
 printf("\t\t-D:         Daemon process\n");
 printf("\t\t-i ip:      Server ip to be listened\n");
 printf("\t\t-p port:    Server port to be listened\n");
 printf("\t\t-h:         Show this help.\n");
 printf("\n");
 exit(-1);
}

return_type: void


decompiled_code:
void thread_key_create(void)
{
unsigned __int16 v0; // ax

v0 = atoi(listen_port);
server_listen((__int64)listen_ip, v0);
pthread_key_create(&thread_spec_key, 0LL);
}

canonical_decompiled_code:
void func6(void)
{
unsigned __int16 v0; // ax

v0 = atoi(listen_port);
func5((__int64)listen_ip, v0);
pthread_key_create(&thread_spec_key, 0LL);
}

original_code:
static void thread_key_create(void)
{
 server_listen(listen_ip, atoi(listen_port));
 pthread_key_create(&thread_spec_key, ((void *)0));
}

canonical_original_code:
static void thread_key_create()
{
 server_listen(listen_ip, atoi(listen_port));
 pthread_key_create(&thread_spec_key, ((void *)0));
}


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "i:p:Dh");
if ( v4 <= 0 )
break;
if ( v4 == 105 )
{
listen_ip = optarg;
}
else if ( v4 == 112 )
{
listen_port = optarg;
}
else
{
v3 = 1;
if ( v4 != 68 )
usage();
}
}
if ( v3 )
daemon(1, 1);
if ( !getuid() )
set_nolimit();
if ( (int)event_init() >= 0 )
{
event_dispatch_loop();
event_timer(0LL, server_timer);
while ( 1 )
sleep(1u);
}
perror("event_init");
exit(-1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "i:p:Dh");
if ( v4 <= 0 )
break;
if ( v4 == 105 )
{
listen_ip = optarg;
}
else if ( v4 == 112 )
{
listen_port = optarg;
}
else
{
v3 = 1;
if ( v4 != 68 )
func4();
}
}
if ( v3 )
daemon(1, 1);
if ( !getuid() )
set_nolimit();
if ( (int)event_init() >= 0 )
{
event_dispatch_loop();
event_timer(0LL, server_timer);
while ( 1 )
sleep(1u);
}
perror("event_init");
exit(-1);
}

original_code:
int main(int argc, char **argv)
{
 int c;
 int tobe_daemon = 0;
 extern char *optarg;
 while ((c = getopt(argc, argv, "i:p:Dh")) > 0) {
  switch (c) {
   case 'i':
    listen_ip = optarg;
    break;
   case 'p':
    listen_port = optarg;
    break;
   case 'D':
    tobe_daemon = 1;
    break;
   default:
    usage();
    break;
  }
 }
 if (tobe_daemon) {
  daemon(1, 1);
 }
 if (getuid() == 0) {
  set_nolimit();
 }
 if (event_init() < 0) {
  do { perror("event_init"); exit(-1); } while (0);
 }
 event_dispatch_loop();
 event_timer(((void *)0), server_timer);
 while (1) {
  sleep(1);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: c int

variable_types:
optarg
char *


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

_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*v1 = 0LL;
v1[1] = 0LL;
}

original_code:
static inline void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = ((void *)0);
 entry->prev = ((void *)0);
}

variable_types: struct list_head { struct list_head *next; struct list_head *prev; } *


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

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

original_code:
int event_init(void)
{
 return 0;
}

canonical_original_code:
int event_init()
{
 return 0;
}


decompiled_code:
void __fastcall event_destroy(__int64 a1)
{
void *v1; // r8

list_del(a1 + 32);
free(v1);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
void *v1; // r8

func4(a1 + 32);
free(v1);
}

original_code:
void event_destroy(void *handle)
{
 struct event *e = handle;
 list_del(&e->list);
 free(e);
}

variable_types:
handle
void *

variable_types: struct event { int epfd; int fd; void *priv; int dure_sec; long last; struct list_head { struct list_head *next; struct list_head *prev; } list; int (*read)(int fd, void *priv); int (*write)(int fd, void *priv); int (*timeout)(int fd, void *priv); } *

user_defined_types: struct event { int epfd; int fd; void *priv; int dure_sec; long last; struct list_head list; int (*read)(int fd, void *priv); int (*write)(int fd, void *priv); int (*timeout)(int fd, void *priv); }


decompiled_code:
__int64 __fastcall event_add(epoll_data_t a1, uint32_t a2)
{
void *v3; // rax
int v4; // edx
int v5; // edi
void *v6; // rbp
unsigned int v7; // er12
__int64 v8; // rax
struct epoll_event event; // [rsp+4h] [rbp-24h] BYREF

v3 = spec_get();
v4 = *(_DWORD *)(a1.u64 + 4);
v5 = *(_DWORD *)a1.ptr;
event.events = a2;
v6 = v3;
event.data = a1;
if ( epoll_ctl(v5, 1, v4, &event) )
{
v7 = -1;
perror("epoll_ctl");
}
else
{
v7 = 0;
*(_QWORD *)(a1.u64 + 24) = time(0LL);
v8 = 16LL * (i_1++ & 0xF);
list_add_tail((_QWORD *)(a1.u64 + 32), (__int64)v6 + v8 + 8);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func10(epoll_data_t a1, uint32_t a2)
{
void *v3; // rax
int v4; // edx
int v5; // edi
void *v6; // rbp
unsigned int v7; // er12
__int64 v8; // rax
struct epoll_event event; // [rsp+4h] [rbp-24h] BYREF

v3 = func5();
v4 = *(_DWORD *)(a1.u64 + 4);
v5 = *(_DWORD *)a1.ptr;
event.events = a2;
v6 = v3;
event.data = a1;
if ( epoll_ctl(v5, 1, v4, &event) )
{
v7 = -1;
perror("epoll_ctl");
}
else
{
v7 = 0;
*(_QWORD *)(a1.u64 + 24) = time(0LL);
v8 = 16LL * (i_1++ & 0xF);
func2((_QWORD *)(a1.u64 + 32), (__int64)v6 + v8 + 8);
}
return v7;
}

original_code:
int event_add(void *handle, unsigned int event)
{
 struct epoll_event ev;
 struct event *e = handle;
 struct thread_spec *s = spec_get();
 static int i = 0;
 memset(&ev, '\0', sizeof(struct epoll_event));
 ev.events = event;
 ev.data.ptr = e;
 if (epoll_ctl(e->epfd, 1, e->fd, &ev) != 0) {
  perror("epoll_ctl");
  goto out;
 }
 e->last = time(((void *)0));
 list_add_tail(&e->list, &s->queue[(i++)&(16 -1)]);
 return 0;
out:
 return -1;
}

variable_types:
event
unsigned int

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }

variable_types: struct thread_spec { int epfd; struct list_head { struct list_head *next; struct list_head *prev; } queue[16]; } *

variable_types: i int

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

user_defined_types: struct thread_spec { int epfd; struct list_head queue[16]; }


decompiled_code:
__int64 __fastcall event_mod(epoll_data_t a1, uint32_t a2)
{
int v3; // edx
int v4; // edi
__int64 result; // rax
struct epoll_event event; // [rsp+14h] [rbp-14h] BYREF

v3 = *(_DWORD *)(a1.u64 + 4);
event.data = a1;
v4 = *(_DWORD *)a1.ptr;
event.events = a2;
if ( epoll_ctl(v4, 3, v3, &event) == -1 )
{
perror("epoll_ctl");
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a1.u64 + 24) = time(0LL);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(epoll_data_t a1, uint32_t a2)
{
int v3; // edx
int v4; // edi
__int64 result; // rax
struct epoll_event event; // [rsp+14h] [rbp-14h] BYREF

v3 = *(_DWORD *)(a1.u64 + 4);
event.data = a1;
v4 = *(_DWORD *)a1.ptr;
event.events = a2;
if ( epoll_ctl(v4, 3, v3, &event) == -1 )
{
perror("epoll_ctl");
result = 0xFFFFFFFFLL;
}
else
{
*(_QWORD *)(a1.u64 + 24) = time(0LL);
result = 0LL;
}
return result;
}

original_code:
extern int event_mod(void *handle, unsigned int event)
{
 struct epoll_event ev;
 struct event *e = handle;
 memset(&ev, '\0', sizeof(struct epoll_event));
 ev.events = event;
 ev.data.ptr = e;
 if (epoll_ctl(e->epfd, 3, e->fd, &ev) == -1) {
  perror("epoll_ctl");
  goto out;
 }
 e->last = time(((void *)0));
 return 0;
out:
 return -1;
}

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }

user_defined_types: struct list_head { struct list_head *next; struct list_head *prev; }


decompiled_code:
void __fastcall event_timer(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x20uLL);
if ( v2 )
{
v2[2] = a1;
v2[3] = a2;
list_add_tail(v2, (__int64)&time_queue);
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

v2 = malloc(0x20uLL);
if ( v2 )
{
v2[2] = a1;
v2[3] = a2;
func2(v2, (__int64)&time_queue);
}
}

original_code:
int event_timer(void *priv, int (*timer)(void *priv))
{
 struct ev_timer *t;
 if ((t = malloc(sizeof(struct ev_timer))) == ((void *)0)) {
  return -1;
 }
 t->priv = priv;
 t->timer = timer;
 list_add_tail(&t->list, &time_queue);
 return 0;
}

variable_types:
timer
int (*)(void *priv)

variable_types: struct ev_timer { struct list_head { struct list_head *next; struct list_head *prev; } list; void *priv; int (*timer)(void *priv); } *

user_defined_types: struct ev_timer { struct list_head list; void *priv; int (*timer)(void *priv); }


decompiled_code:
int event_dispatch_loop()
{
int v0; // ebx
int result; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v0 = 4;
do
{
result = pthread_create(newthread, 0LL, (void *(*)(void *))event_thread, 0LL);
if ( result )
{
perror("pthread_create");
exit(-1);
}
--v0;
}
while ( v0 );
return result;
}

canonical_decompiled_code:
int func13()
{
int v0; // ebx
int result; // eax
pthread_t newthread[2]; // [rsp+8h] [rbp-10h] BYREF

v0 = 4;
do
{
result = pthread_create(newthread, 0LL, (void *(*)(void *))event_thread, 0LL);
if ( result )
{
perror("pthread_create");
exit(-1);
}
--v0;
}
while ( v0 );
return result;
}

original_code:
void event_dispatch_loop(void)
{
 int i;
 pthread_t pid;
 for (i = 0; i < 4; i++) {
  if (pthread_create(&pid, ((void *)0), event_thread, ((void *)0)) != 0) {
   do { perror("pthread_create"); exit(-1); } while (0);
  }
 }
}

canonical_original_code:
void event_dispatch_loop()
{
 int i;
 unsigned long pid;
 for (i = 0; i < 4; i++) {
  if (pthread_create(&pid, ((void *)0), event_thread, ((void *)0)) != 0) {
   do { perror("pthread_create"); exit(-1); } while (0);
  }
 }
}

variable_types:
pid
unsigned long


doit

decompiled_code:
void __fastcall __noreturn doit(void *a1)
{
time_t v1; // r13
_QWORD *v2; // rbp
pthread_t v3; // rax
int v4; // er12
int v5; // ebx
int v6; // eax
int v7; // eax
struct epoll_event *v8; // rbx
struct epoll_event *v9; // r14
int v10; // edi
time_t v11; // rax
__int64 v12; // rdx
struct epoll_event event; // [rsp+4h] [rbp-18034h] BYREF
struct epoll_event events; // [rsp+10h] [rbp-18028h] BYREF
_DWORD v15[24583]; // [rsp+1Ch] [rbp-1801Ch] BYREF

v1 = time(0LL);
v2 = spec_get();
v3 = pthread_self();
pthread_detach(v3);
v4 = epoll_create(4096);
if ( v4 < 0 )
exit(-1);
while ( 1 )
{
v5 = 1000;
do
{
v6 = tcp_connect(remote_ip, (unsigned __int16)remote_port, bind_ip);
if ( v6 < 0 )
break;
event.events = 5;
event.data.fd = v6;
epoll_ctl(v4, 1, v6, &event);
++*(_DWORD *)v2;
--v5;
}
while ( v5 );
v7 = epoll_wait(v4, &events, 0x2000, 0);
if ( v7 > 0 )
{
v8 = &events;
v9 = (struct epoll_event *)&v15[3 * (v7 - 1)];
do
{
while ( 1 )
{
v10 = v8->data.fd;
if ( (v8->events & 1) == 0 )
break;
close(v10);
++v8;
++*((_DWORD *)v2 + 2);
if ( v8 == v9 )
goto LABEL_12;
}
if ( (v8->events & 4) != 0 )
{
close(v10);
++*((_DWORD *)v2 + 1);
}
++v8;
}
while ( v8 != v9 );
}
LABEL_12:
v11 = time(0LL);
if ( v1 != v11 )
{
*((_DWORD *)v2 + 3) = *(_DWORD *)v2;
v12 = *(_QWORD *)((char *)v2 + 4);
*v2 = 0LL;
v2[2] = v12;
*((_DWORD *)v2 + 2) = 0;
}
v1 = v11;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func5(void *a1)
{
time_t v1; // r13
_QWORD *v2; // rbp
pthread_t v3; // rax
int v4; // er12
int v5; // ebx
int v6; // eax
int v7; // eax
struct epoll_event *v8; // rbx
struct epoll_event *v9; // r14
int v10; // edi
time_t v11; // rax
__int64 v12; // rdx
struct epoll_event event; // [rsp+4h] [rbp-18034h] BYREF
struct epoll_event events; // [rsp+10h] [rbp-18028h] BYREF
_DWORD v15[24583]; // [rsp+1Ch] [rbp-1801Ch] BYREF

v1 = time(0LL);
v2 = func4();
v3 = pthread_self();
pthread_detach(v3);
v4 = epoll_create(4096);
if ( v4 < 0 )
exit(-1);
while ( 1 )
{
v5 = 1000;
do
{
v6 = tcp_connect(remote_ip, (unsigned __int16)remote_port, bind_ip);
if ( v6 < 0 )
break;
event.events = 5;
event.data.fd = v6;
epoll_ctl(v4, 1, v6, &event);
++*(_DWORD *)v2;
--v5;
}
while ( v5 );
v7 = epoll_wait(v4, &events, 0x2000, 0);
if ( v7 > 0 )
{
v8 = &events;
v9 = (struct epoll_event *)&v15[3 * (v7 - 1)];
do
{
while ( 1 )
{
v10 = v8->data.fd;
if ( (v8->events & 1) == 0 )
break;
close(v10);
++v8;
++*((_DWORD *)v2 + 2);
if ( v8 == v9 )
goto LABEL_12;
}
if ( (v8->events & 4) != 0 )
{
close(v10);
++*((_DWORD *)v2 + 1);
}
++v8;
}
while ( v8 != v9 );
}
LABEL_12:
v11 = time(0LL);
if ( v1 != v11 )
{
*((_DWORD *)v2 + 3) = *(_DWORD *)v2;
v12 = *(_QWORD *)((char *)v2 + 4);
*v2 = 0LL;
v2[2] = v12;
*((_DWORD *)v2 + 2) = 0;
}
v1 = v11;
}
}

original_code:
static void *doit(void *arg)
{
 int epfd;
 int i, ret;
 int fd;
 time_t last = time(((void *)0)), now;
 struct thread_spec *s = spec_get();
 pthread_detach(pthread_self());
 if ((epfd = epoll_create(4096)) < 0) {
  exit(-1);
 }
 while (1) {
  struct epoll_event ev;
  struct epoll_event evs[8192];
  for (i = 0; i < 1000; i ++) {
   if ((fd = tcp_connect(remote_ip, remote_port, bind_ip)) < 0) {
    break;
   }
   ev.events = EPOLLIN | EPOLLOUT;
   ev.data.fd = fd;
   epoll_ctl(epfd, 1, fd, &ev);
   s->cur_sec_connectings ++;
  }
  ret = epoll_wait(epfd, evs, 8192, 0);
  for (i = 0; i < ret; i ++) {
   fd = evs[i].data.fd;
   if (evs[i].events & EPOLLIN) {
    close(fd);
    s->cur_sec_errors ++;
   } else if (evs[i].events & EPOLLOUT) {
    close(fd);
    s->cur_sec_connections ++;
   }
  }
  if (last != (now = time(((void *)0)))) {
   s->l_sec_connections = s->cur_sec_connections;
   s->l_sec_connectings = s->cur_sec_connectings;
   s->l_sec_errors = s->cur_sec_errors;
   s->cur_sec_connectings = 0;
   s->cur_sec_connections = 0;
   s->cur_sec_errors = 0;
   last = now;
  }
 }
 pthread_exit(((void *)0));
}

canonical_original_code:
static void *doit(void *arg)
{
 int epfd;
 int i; int ret;
 int fd;
 long last = time(((void *)0)); long now;
 struct thread_spec *s = spec_get();
 pthread_detach(pthread_self());
 if ((epfd = epoll_create(4096)) < 0) {
  exit(-1);
 }
 while (1) {
  struct epoll_event ev;
  struct epoll_event evs[8192];
  for (i = 0; i < 1000; i ++) {
   if ((fd = tcp_connect(remote_ip, remote_port, bind_ip)) < 0) {
    break;
   }
   ev.events = EPOLLIN | EPOLLOUT;
   ev.data.fd = fd;
   epoll_ctl(epfd, 1, fd, &ev);
   s->cur_sec_connectings ++;
  }
  ret = epoll_wait(epfd, evs, 8192, 0);
  for (i = 0; i < ret; i ++) {
   fd = evs[i].data.fd;
   if (evs[i].events & EPOLLIN) {
    close(fd);
    s->cur_sec_errors ++;
   } else if (evs[i].events & EPOLLOUT) {
    close(fd);
    s->cur_sec_connections ++;
   }
  }
  if (last != (now = time(((void *)0)))) {
   s->l_sec_connections = s->cur_sec_connections;
   s->l_sec_connectings = s->cur_sec_connectings;
   s->l_sec_errors = s->cur_sec_errors;
   s->cur_sec_connectings = 0;
   s->cur_sec_connections = 0;
   s->cur_sec_errors = 0;
   last = now;
  }
 }
 pthread_exit(((void *)0));
}

variable_types:
arg
void *

variable_types: epfd int

variable_types: fd int

variable_types: last long

variable_types: now long

variable_types: struct thread_spec { unsigned int cur_sec_connectings; unsigned int cur_sec_connections; unsigned int cur_sec_errors; unsigned int l_sec_connectings; unsigned int l_sec_connections; unsigned int l_sec_errors; struct list_head { struct list_head *next; struct list_head *prev; } list; } *

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } [8192]

return_type: void *

user_defined_types: struct thread_spec { unsigned int cur_sec_connectings; unsigned int cur_sec_connections; unsigned int cur_sec_errors; unsigned int l_sec_connectings; unsigned int l_sec_connections; unsigned int l_sec_errors; struct list_head list; }


usage

decompiled_code:
void __noreturn usage()
{
puts("\nclient: -D -i ip -p port -b bindip");
puts("\t\t-D: Daemon process");
puts("\t\t-i ip: Server ip to be connected");
puts("\t\t-p port: Server port to be connected");
puts("\t\t-b bindip: Local ip.");
puts("\t\t-h: Show this help.");
putchar(10);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts("\nclient: -D -i ip -p port -b bindip");
puts("\t\t-D: Daemon process");
puts("\t\t-i ip: Server ip to be connected");
puts("\t\t-p port: Server port to be connected");
puts("\t\t-b bindip: Local ip.");
puts("\t\t-h: Show this help.");
putchar(10);
exit(-1);
}

original_code:
static void usage(void)
{
 printf("\nclient: -D -i ip -p port -b bindip\n");
 printf("\t\t-D:         Daemon process\n");
 printf("\t\t-i ip:      Server ip to be connected\n");
 printf("\t\t-p port:    Server port to be connected\n");
 printf("\t\t-b bindip:  Local ip.\n");
 printf("\t\t-h:         Show this help.\n");
 printf("\n");
 exit(-1);
}

canonical_original_code:
static void usage()
{
 printf("\nclient: -D -i ip -p port -b bindip\n");
 printf("\t\t-D:         Daemon process\n");
 printf("\t\t-i ip:      Server ip to be connected\n");
 printf("\t\t-p port:    Server port to be connected\n");
 printf("\t\t-b bindip:  Local ip.\n");
 printf("\t\t-h:         Show this help.\n");
 printf("\n");
 exit(-1);
}


repo: yangxks/Test

decompiled_code:
__int64 __fastcall account_1(const char *a1)
{
CLIENT *v1; // rbp
unsigned int *v2; // rax
unsigned int *v3; // rax
int v5; // [rsp+8h] [rbp-10h] BYREF
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = 10;
v6[0] = 20;
v1 = clnt_create(a1, 0x20010929uLL, 1uLL, "tcp");
v2 = (unsigned int *)deposit_1(&v5, v1);
printf("result=%d\n", *v2);
v3 = (unsigned int *)withdraw_1(v6, v1);
printf("result=%d\n", *v3);
return ((__int64 (__fastcall *)(CLIENT *))v1->cl_ops->cl_destroy)(v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
CLIENT *v1; // rbp
unsigned int *v2; // rax
unsigned int *v3; // rax
int v5; // [rsp+8h] [rbp-10h] BYREF
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5 = 10;
v6[0] = 20;
v1 = clnt_create(a1, 0x20010929uLL, 1uLL, "tcp");
v2 = (unsigned int *)deposit_1(&v5, v1);
printf("result=%d\n", *v2);
v3 = (unsigned int *)withdraw_1(v6, v1);
printf("result=%d\n", *v3);
return ((__int64 (__fastcall *)(CLIENT *))v1->cl_ops->cl_destroy)(v1);
}

original_code:
void account_1(char *host) {
    CLIENT *clnt;
    int *result_1;
    int deposit_1_arg=10;
    int *result_2;
    int withdraw_1_arg=20;
    clnt=clnt_create(host, 0x20010929, 1,"tcp");
    result_1=deposit_1(&deposit_1_arg,clnt);
    printf("result=%d\n", *result_1);
    result_2=withdraw_1(&withdraw_1_arg,clnt);
    printf("result=%d\n", *result_2);
    ((*(clnt)->cl_ops->cl_destroy)(clnt));
}

canonical_original_code:
void account_1(char *host) {
    struct CLIENT *clnt;
    int *result_1;
    int deposit_1_arg = 10;
    int *result_2;
    int withdraw_1_arg = 20;
    clnt=clnt_create(host, 0x20010929, 1,"tcp");
    result_1=deposit_1(&deposit_1_arg,clnt);
    printf("result=%d\n", *result_1);
    result_2=withdraw_1(&withdraw_1_arg,clnt);
    printf("result=%d\n", *result_2);
    ((*(clnt)->cl_ops->cl_destroy)(clnt));
}

variable_types:
host
char *

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

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


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx

if ( argc > 1 )
{
v3 = argv[1];
while ( 1 )
{
account_1(v3);
sleep(2u);
}
}
printf("usage:%s server_host\n", *argv);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbx

if ( argc > 1 )
{
v3 = argv[1];
while ( 1 )
{
func0(v3);
sleep(2u);
}
}
printf("usage:%s server_host\n", *argv);
exit(1);
}

original_code:
int main (int argc, char *argv[]) {
    char *host;
    if (argc < 2) { printf ("usage:%s server_host\n", argv[0]);exit (1); }
    host=argv[1];
    while(1) {
        account_1(host);
        sleep(2);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    char *host;
    if (argc < 2) { printf ("usage:%s server_host\n", argv[0]);exit (1); }
    host=argv[1];
    while(1) {
        account_1(host);
        sleep(2);
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void __fastcall testprog_1(struct svc_req *a1, SVCXPRT *a2)
{
rpcproc_t v2; // rax
__int64 (__fastcall *v3)(); // rbx
bool_t (*v4)(XDR *, void *, ...); // r13
const struct SVCXPRT::xp_ops *v5; // rax
char *v6; // rdx
__int64 v7[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = a1->rq_proc;
if ( v2 == 2 )
{
v3 = get_str_len_1;
v4 = (bool_t (*)(XDR *, void *, ...))xdr_wrapstring;
}
else if ( v2 > 2 )
{
v3 = add_1;
v4 = (bool_t (*)(XDR *, void *, ...))xdr_add_1_argument;
if ( v2 != 3 )
{
svcerr_noproc(a2);
return;
}
}
else
{
if ( !v2 )
{
svc_sendreply(a2, (xdrproc_t)xdr_void, 0LL);
return;
}
v3 = (__int64 (__fastcall *)())int_echo_1;
v4 = (bool_t (*)(XDR *, void *, ...))xdr_int;
}
v5 = a2->xp_ops;
v7[0] = 0LL;
if ( v5->xp_getargs(a2, v4, (caddr_t)v7) )
{
v6 = (char *)((__int64 (__fastcall *)(__int64 *, struct svc_req *))v3)(v7, a1);
if ( v6 && !svc_sendreply(a2, (xdrproc_t)xdr_int, v6) )
svcerr_systemerr(a2);
if ( !a2->xp_ops->xp_freeargs(a2, v4, (caddr_t)v7) )
{
fwrite("unable to free arguments", 1uLL, 0x18uLL, stderr);
exit(1);
}
}
else
{
svcerr_decode(a2);
}
}

canonical_decompiled_code:
void __fastcall func7(struct svc_req *a1, SVCXPRT *a2)
{
rpcproc_t v2; // rax
__int64 (__fastcall *v3)(); // rbx
bool_t (*v4)(XDR *, void *, ...); // r13
const struct SVCXPRT::xp_ops *v5; // rax
char *v6; // rdx
__int64 v7[6]; // [rsp+8h] [rbp-30h] BYREF

v2 = a1->rq_proc;
if ( v2 == 2 )
{
v3 = get_str_len_1;
v4 = (bool_t (*)(XDR *, void *, ...))xdr_wrapstring;
}
else if ( v2 > 2 )
{
v3 = add_1;
v4 = (bool_t (*)(XDR *, void *, ...))xdr_add_1_argument;
if ( v2 != 3 )
{
svcerr_noproc(a2);
return;
}
}
else
{
if ( !v2 )
{
svc_sendreply(a2, (xdrproc_t)xdr_void, 0LL);
return;
}
v3 = (__int64 (__fastcall *)())int_echo_1;
v4 = (bool_t (*)(XDR *, void *, ...))xdr_int;
}
v5 = a2->xp_ops;
v7[0] = 0LL;
if ( v5->xp_getargs(a2, v4, (caddr_t)v7) )
{
v6 = (char *)((__int64 (__fastcall *)(__int64 *, struct svc_req *))v3)(v7, a1);
if ( v6 && !svc_sendreply(a2, (xdrproc_t)xdr_int, v6) )
svcerr_systemerr(a2);
if ( !a2->xp_ops->xp_freeargs(a2, v4, (caddr_t)v7) )
{
fwrite("unable to free arguments", 1uLL, 0x18uLL, stderr);
exit(1);
}
}
else
{
svcerr_decode(a2);
}
}

original_code:
void
testprog_1(char *host)
{
 CLIENT *clnt;
 int *result_1;
 int int_echo_1_arg1;
 int *result_2;
 char *get_str_len_1_arg1="Hello, world";
 int *result_3;
 int add_1_arg1=10;
 int add_1_arg2=20;
 clnt = clnt_create (host, 30000, 1, "udp");
 if (clnt == ((void *)0)) {
  clnt_pcreateerror (host);
  exit (1);
 }
 result_1 = int_echo_1(int_echo_1_arg1, clnt);
 if (result_1 == (int *) ((void *)0)) {
  clnt_perror (clnt, "call failed");
 }
    else
        printf("[PRC1] echo %d, source %d\n", *result_1,
               int_echo_1_arg1);
 result_2 = get_str_len_1(get_str_len_1_arg1, clnt);
 if (result_2 == (int *) ((void *)0)) {
  clnt_perror (clnt, "call failed");
 }
    else
        printf("[RPC2] return %d, should %d\n", *result_2,
               strlen(get_str_len_1_arg1));
 result_3 = add_1(add_1_arg1, add_1_arg2, clnt);
 if (result_3 == (int *) ((void *)0)) {
  clnt_perror (clnt, "call failed");
 }
    else
        printf("[PRC3] %d+%d=%d\n", add_1_arg1, add_1_arg2,
               *result_3);
 ((*(clnt)->cl_ops->cl_destroy)(clnt));
}

canonical_original_code:
void testprog_1(char *host)
{
 struct CLIENT *clnt;
 int *result_1;
 int int_echo_1_arg1;
 int *result_2;
 char *get_str_len_1_arg1 = "Hello, world";
 int *result_3;
 int add_1_arg1 = 10;
 int add_1_arg2 = 20;
 clnt = clnt_create (host, 30000, 1, "udp");
 if (clnt == ((void *)0)) {
  clnt_pcreateerror (host);
  exit (1);
 }
 result_1 = int_echo_1(int_echo_1_arg1, clnt);
 if (result_1 == (int *) ((void *)0)) {
  clnt_perror (clnt, "call failed");
 }
    else
        printf("[PRC1] echo %d, source %d\n", *result_1,
               int_echo_1_arg1);
 result_2 = get_str_len_1(get_str_len_1_arg1, clnt);
 if (result_2 == (int *) ((void *)0)) {
  clnt_perror (clnt, "call failed");
 }
    else
        printf("[RPC2] return %d, should %d\n", *result_2,
               strlen(get_str_len_1_arg1));
 result_3 = add_1(add_1_arg1, add_1_arg2, clnt);
 if (result_3 == (int *) ((void *)0)) {
  clnt_perror (clnt, "call failed");
 }
    else
        printf("[PRC3] %d+%d=%d\n", add_1_arg1, add_1_arg2,
               *result_3);
 ((*(clnt)->cl_ops->cl_destroy)(clnt));
}

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 timeval { long tv_sec; long tv_usec; }

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 }

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:
__int64 __fastcall add_1(unsigned int *a1, __int64 a2)
{
return add_1_svc(*a1, a1[1], a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1, __int64 a2)
{
return func13(*a1, a1[1], a2);
}

original_code:
int *
add_1(int arg1, int arg2, CLIENT *clnt)
{
 add_1_argument arg;
 static int clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 arg.arg1 = arg1;
 arg.arg2 = arg2;
 if (((*(clnt)->cl_ops->cl_call)(clnt, 3, (xdrproc_t) xdr_add_1_argument, (caddr_t) &arg, (xdrproc_t) xdr_int, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return (&clnt_res);
}

canonical_original_code:
int *add_1(int arg1, int arg2, struct CLIENT *clnt)
{
 struct add_1_argument arg;
 static int clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 arg.arg1 = arg1;
 arg.arg2 = arg2;
 if (((*(clnt)->cl_ops->cl_call)(clnt, 3, (int (*)(struct XDR *, void *, ...)) xdr_add_1_argument, (caddr_t) &arg, (int (*)(struct XDR *, void *, ...)) xdr_int, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return (&clnt_res);
}

variable_types: struct add_1_argument { int arg1; int arg2; }

return_type: int *


decompiled_code:
__int64 __fastcall get_str_len_1(_QWORD *a1)
{
return get_str_len_1_svc(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
return func12(*a1);
}

original_code:
int *
get_str_len_1(char *arg1, CLIENT *clnt)
{
 static int clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 2, (xdrproc_t) xdr_wrapstring, (caddr_t) &arg1, (xdrproc_t) xdr_int, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return (&clnt_res);
}

canonical_original_code:
int *get_str_len_1(char *arg1, struct CLIENT *clnt)
{
 static int clnt_res;
 memset((char *)&clnt_res, 0, sizeof(clnt_res));
 if (((*(clnt)->cl_ops->cl_call)(clnt, 2, (int (*)(struct XDR *, void *, ...)) xdr_wrapstring, (caddr_t) &arg1, (int (*)(struct XDR *, void *, ...)) xdr_int, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return (&clnt_res);
}


decompiled_code:
__int64 __fastcall int_echo_1(unsigned int *a1)
{
return int_echo_1_svc(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
return func11(*a1);
}

original_code:
int *
int_echo_1(int arg1, 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_int, (caddr_t) &arg1, (xdrproc_t) xdr_int, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return (&clnt_res);
}

canonical_original_code:
int *int_echo_1(int arg1, 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_int, (caddr_t) &arg1, (int (*)(struct XDR *, void *, ...)) xdr_int, (caddr_t) &clnt_res, TIMEOUT)) != RPC_SUCCESS) {
  return (((void *)0));
 }
 return (&clnt_res);
}


decompiled_code:
int *__fastcall int_echo_1_svc(unsigned int a1)
{
result_2 = a1;
printf("[RPC1] source=%d, echo=%d\n", a1, a1);
return &result_2;
}

canonical_decompiled_code:
int *__fastcall func11(unsigned int a1)
{
result_2 = a1;
printf("[RPC1] source=%d, echo=%d\n", a1, a1);
return &result_2;
}

original_code:
int *
int_echo_1_svc(int arg1, struct svc_req *rqstp)
{
 static int result;
    result=arg1;
    printf("[RPC1] source=%d, echo=%d\n", arg1, result);
 return &result;
}

canonical_original_code:
int *int_echo_1_svc(int arg1, struct svc_req *rqstp)
{
 static int result;
    result=arg1;
    printf("[RPC1] source=%d, echo=%d\n", arg1, result);
 return &result;
}

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

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


decompiled_code:
int *__fastcall get_str_len_1_svc(const char *a1)
{
size_t v1; // rax

v1 = strlen(a1);
result_1 = v1;
printf("[PRC2] str=%s, len=%d\n", a1, v1);
return &result_1;
}

canonical_decompiled_code:
int *__fastcall func12(const char *a1)
{
size_t v1; // rax

v1 = strlen(a1);
result_1 = v1;
printf("[PRC2] str=%s, len=%d\n", a1, v1);
return &result_1;
}

original_code:
int *
get_str_len_1_svc(char *arg1, struct svc_req *rqstp)
{
 static int result;
     result=strlen(arg1);
     printf("[PRC2] str=%s, len=%d\n", arg1, result);
     return &result;
}

canonical_original_code:
int *get_str_len_1_svc(char *arg1, struct svc_req *rqstp)
{
 static int result;
     result=strlen(arg1);
     printf("[PRC2] str=%s, len=%d\n", arg1, result);
     return &result;
}

user_defined_types: enum xprt_stat { XPRT_DIED=0, XPRT_MOREREQS=1, XPRT_IDLE=2 }

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: enum reply_stat { MSG_ACCEPTED=0, MSG_DENIED=1 }

user_defined_types: enum accept_stat { SUCCESS=0, PROG_UNAVAIL=1, PROG_MISMATCH=2, PROC_UNAVAIL=3, GARBAGE_ARGS=4, SYSTEM_ERR=5 }

user_defined_types: enum reject_stat { RPC_MISMATCH=0, AUTH_ERROR=1 }


decompiled_code:
int *__fastcall add_1_svc(unsigned int a1, unsigned int a2)
{
result_0 = a1 + a2;
printf("[RPC3] %d+%d=%d\n", a1, a2, a1 + a2);
return &result_0;
}

canonical_decompiled_code:
int *__fastcall func13(unsigned int a1, unsigned int a2)
{
result_0 = a1 + a2;
printf("[RPC3] %d+%d=%d\n", a1, a2, a1 + a2);
return &result_0;
}

original_code:
int *
add_1_svc(int arg1, int arg2, struct svc_req *rqstp)
{
 static int result;
     result=arg1+arg2;
     printf("[RPC3] %d+%d=%d\n", arg1, arg2, result);
 return &result;
}

canonical_original_code:
int *add_1_svc(int arg1, int arg2, struct svc_req *rqstp)
{
 static int result;
     result=arg1+arg2;
     printf("[RPC3] %d+%d=%d\n", arg1, arg2, result);
 return &result;
}

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

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:
bool_t __fastcall xdr_add_1_argument(XDR *xdrs, int *a2)
{
bool_t result; // eax

result = xdr_int(xdrs, a2);
if ( result )
result = xdr_int(xdrs, a2 + 1) != 0;
return result;
}

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

result = xdr_int(xdrs, a2);
if ( result )
result = xdr_int(xdrs, a2 + 1) != 0;
return result;
}

original_code:
bool_t
xdr_add_1_argument (XDR *xdrs, add_1_argument *objp)
{
  if (!xdr_int (xdrs, &objp->arg1))
   return (0);
  if (!xdr_int (xdrs, &objp->arg2))
   return (0);
 return (1);
}

canonical_original_code:
int xdr_add_1_argument(struct XDR *xdrs, struct add_1_argument *objp)
{
  if (!xdr_int (xdrs, &objp->arg1))
   return (0);
  if (!xdr_int (xdrs, &objp->arg2))
   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 add_1_argument { int arg1; int arg2; } *


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
SVCXPRT *v3; // rax
SVCXPRT *v4; // rdi

pmap_unset(0x7530uLL, 1uLL);
v3 = svcudp_create(-1);
if ( v3 )
{
if ( svc_register(v3, 0x7530uLL, 1uLL, testprog_1, 0x11uLL) )
{
v4 = svctcp_create(-1, 0, 0);
if ( v4 )
{
if ( !svc_register(v4, 0x7530uLL, 1uLL, testprog_1, 6uLL) )
{
fwrite("unable to register (TESTPROG, VERSION, tcp).", 1uLL, 0x2CuLL, 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 (TESTPROG, VERSION, udp).", 1uLL, 0x2CuLL, stderr);
exit(1);
}
fwrite("cannot create udp service.", 1uLL, 0x1AuLL, stderr);
exit(1);
}

original_code:
int
main (int argc, char *argv[])
{
 char *host;
 if (argc < 2) {
  printf ("usage: %s server_host\n", argv[0]);
  exit (1);
 }
 host = argv[1];
 testprog_1 (host);
    exit (0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 char *host;
 if (argc < 2) {
  printf ("usage: %s server_host\n", argv[0]);
  exit (1);
 }
 host = argv[1];
 testprog_1 (host);
    exit (0);
}


decompiled_code:
int *__fastcall deposit_1_svc(_DWORD *a1)
{
__int64 v1; // rsi

v1 = (unsigned int)(*a1 + total);
total = v1;
result_1 = v1;
printf("new total = %d \n", v1);
return &result_1;
}

canonical_decompiled_code:
int *__fastcall func0(_DWORD *a1)
{
__int64 v1; // rsi

v1 = (unsigned int)(*a1 + total);
total = v1;
result_1 = v1;
printf("new total = %d \n", v1);
return &result_1;
}

original_code:
int *deposit_1_svc(int *argp, struct svc_req *rqstp){
    static int result;
    total = total + *argp;
    result = total;
    printf("new total = %d \n",total);
    return &result;
}

variable_types:
argp
int *

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:
int *__fastcall withdraw_1_svc(_DWORD *a1)
{
__int64 v1; // rsi

v1 = (unsigned int)(total - *a1);
total = v1;
result_0 = v1;
printf("new total = %d \n", v1);
return &result_0;
}

canonical_decompiled_code:
int *__fastcall func1(_DWORD *a1)
{
__int64 v1; // rsi

v1 = (unsigned int)(total - *a1);
total = v1;
result_0 = v1;
printf("new total = %d \n", v1);
return &result_0;
}

original_code:
int *withdraw_1_svc(int *argp, struct svc_req *rqstp){
    static int result;
    total = total - *argp;
    result = total;
    printf("new total = %d \n",total);
    return &result;
}

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

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:
int *__fastcall int_echo_1(int a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, bool_t (*)(XDR *, int *), int *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD); // rax
bool v3; // zf
int *result; // rax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

canonical_decompiled_code:
int *__fastcall func7(int a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, bool_t (*)(XDR *, int *), int *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD); // rax
bool v3; // zf
int *result; // rax
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

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: union des_block { struct { unsigned int high; unsigned int low; } key; char c[8]; }

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: 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 timeval { long tv_sec; long tv_usec; }

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


decompiled_code:
int *__fastcall get_str_len_1(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, bool_t (*)(XDR *, char **), __int64 *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD); // rax
bool v3; // zf
int *result; // rax
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v2 = *(unsigned int (__fastcall ***)(__int64, __int64, bool_t (*)(XDR *, char **), __int64 *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD))(a2 + 8);
clnt_res_1 = 0;
v5 = a1;
v3 = (*v2)(a2, 2LL, xdr_wrapstring, &v5, xdr_int, &clnt_res_1, TIMEOUT, 0LL) == 0;
result = &clnt_res_1;
if ( !v3 )
result = 0LL;
return result;
}

canonical_decompiled_code:
int *__fastcall func8(__int64 a1, __int64 a2)
{
unsigned int (__fastcall **v2)(__int64, __int64, bool_t (*)(XDR *, char **), __int64 *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD); // rax
bool v3; // zf
int *result; // rax
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v2 = *(unsigned int (__fastcall ***)(__int64, __int64, bool_t (*)(XDR *, char **), __int64 *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD))(a2 + 8);
clnt_res_1 = 0;
v5 = a1;
v3 = (*v2)(a2, 2LL, xdr_wrapstring, &v5, xdr_int, &clnt_res_1, TIMEOUT, 0LL) == 0;
result = &clnt_res_1;
if ( !v3 )
result = 0LL;
return result;
}


decompiled_code:
int *__fastcall add_1(int a1, int a2, __int64 a3)
{
unsigned int (__fastcall **v3)(__int64, __int64, __int64 (__fastcall *)(XDR *), int *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD); // rax
bool v4; // zf
int *result; // rax
int v6[4]; // [rsp+8h] [rbp-10h] BYREF

v3 = *(unsigned int (__fastcall ***)(__int64, __int64, __int64 (__fastcall *)(XDR *), int *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD))(a3 + 8);
v6[0] = a1;
v6[1] = a2;
clnt_res_0 = 0;
v4 = (*v3)(a3, 3LL, xdr_add_1_argument, v6, xdr_int, &clnt_res_0, TIMEOUT, 0LL) == 0;
result = &clnt_res_0;
if ( !v4 )
result = 0LL;
return result;
}

canonical_decompiled_code:
int *__fastcall func9(int a1, int a2, __int64 a3)
{
unsigned int (__fastcall **v3)(__int64, __int64, __int64 (__fastcall *)(XDR *), int *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD); // rax
bool v4; // zf
int *result; // rax
int v6[4]; // [rsp+8h] [rbp-10h] BYREF

v3 = *(unsigned int (__fastcall ***)(__int64, __int64, __int64 (__fastcall *)(XDR *), int *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD))(a3 + 8);
v6[0] = a1;
v6[1] = a2;
clnt_res_0 = 0;
v4 = (*v3)(a3, 3LL, xdr_add_1_argument, v6, xdr_int, &clnt_res_0, TIMEOUT, 0LL) == 0;
result = &clnt_res_0;
if ( !v4 )
result = 0LL;
return result;
}

user_defined_types: struct add_1_argument { int arg1; int arg2; }


decompiled_code:
__int64 __fastcall testprog_1(char *msg)
{
CLIENT *v1; // rax
CLIENT *v2; // rbp
int *v3; // rax
int *v4; // rax
int *v5; // rax

v1 = clnt_create(msg, 0x7530uLL, 1uLL, "udp");
if ( !v1 )
{
clnt_pcreateerror(msg);
exit(1);
}
v2 = v1;
v3 = int_echo_1(0, (__int64)v1);
if ( v3 )
printf("[PRC1] echo %d, source %d\n", (unsigned int)*v3, 0LL);
else
clnt_perror(v2, "call failed");
v4 = get_str_len_1((__int64)"Hello, world", (__int64)v2);
if ( v4 )
printf("[RPC2] return %d, should %d\n", (unsigned int)*v4, 12LL);
else
clnt_perror(v2, "call failed");
v5 = add_1(10, 20, (__int64)v2);
if ( v5 )
printf("[PRC3] %d+%d=%d\n", 10LL, 20LL, (unsigned int)*v5);
else
clnt_perror(v2, "call failed");
return ((__int64 (__fastcall *)(CLIENT *))v2->cl_ops->cl_destroy)(v2);
}

canonical_decompiled_code:
__int64 __fastcall func10(char *msg)
{
CLIENT *v1; // rax
CLIENT *v2; // rbp
int *v3; // rax
int *v4; // rax
int *v5; // rax

v1 = clnt_create(msg, 0x7530uLL, 1uLL, "udp");
if ( !v1 )
{
clnt_pcreateerror(msg);
exit(1);
}
v2 = v1;
v3 = func7(0, (__int64)v1);
if ( v3 )
printf("[PRC1] echo %d, source %d\n", (unsigned int)*v3, 0LL);
else
clnt_perror(v2, "call failed");
v4 = func8((__int64)"Hello, world", (__int64)v2);
if ( v4 )
printf("[RPC2] return %d, should %d\n", (unsigned int)*v4, 12LL);
else
clnt_perror(v2, "call failed");
v5 = func9(10, 20, (__int64)v2);
if ( v5 )
printf("[PRC3] %d+%d=%d\n", 10LL, 20LL, (unsigned int)*v5);
else
clnt_perror(v2, "call failed");
return ((__int64 (__fastcall *)(CLIENT *))v2->cl_ops->cl_destroy)(v2);
}


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

result = xdr_int(xdrs, a2);
if ( result )
result = xdr_int(xdrs, a2 + 1) != 0;
return result;
}


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
{
testprog_1((char *)argv[1]);
exit(0);
}
printf("usage: %s server_host\n", *argv);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc > 1 )
{
func10((char *)argv[1]);
exit(0);
}
printf("usage: %s server_host\n", *argv);
exit(1);
}


decompiled_code:
int __fastcall print_heap(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rsi

result = *(_DWORD *)(a1 + 400);
if ( result > 0 )
{
v2 = 1LL;
do
{
v3 = *(unsigned int *)(a1 + 4 * v2++);
result = printf("%d\n", v3);
}
while ( *(_DWORD *)(a1 + 400) >= (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rsi

result = *(_DWORD *)(a1 + 400);
if ( result > 0 )
{
v2 = 1LL;
do
{
v3 = *(unsigned int *)(a1 + 4 * v2++);
result = printf("%d\n", v3);
}
while ( *(_DWORD *)(a1 + 400) >= (int)v2 );
}
return result;
}

original_code:
void print_heap(heap_t *heap)
{
    int i;
    for(i = 1; i <= heap->heap_size; i++){
        printf("%d\n",heap->array[i].key);
    }
}

canonical_original_code:
void print_heap(struct heap_s *heap)
{
    int i;
    for(i = 1; i <= heap->heap_size; i++){
        printf("%d\n",heap->array[i].key);
    }
}

variable_types: struct heap_s { struct node_s { int key; } array[100]; int heap_size; } *

variable_types: i int

user_defined_types: struct heap_s { struct node_s array[100]; int heap_size; }


minify

decompiled_code:
__int64 __fastcall minify(__int64 a1, int a2)
{
int v3; // ecx
__int64 result; // rax
int v5; // edi
int v6; // er9
int v7; // ecx

v3 = 2 * a2;
result = *(unsigned int *)(a1 + 400);
if ( 2 * a2 <= (int)result )
{
while ( 1 )
{
v5 = *(_DWORD *)(a1 + 4LL * a2);
v6 = *(_DWORD *)(a1 + 4LL * v3);
if ( v5 <= v6 )
{
if ( v3 >= (int)result )
return result;
result = ++v3;
if ( v5 <= *(_DWORD *)(a1 + 4LL * v3) )
return result;
}
else if ( v3 < (int)result )
{
result = (unsigned int)(v3 + 1);
if ( v6 > *(_DWORD *)(a1 + 4LL * (int)result) )
++v3;
}
if ( v3 != a2 )
{
swap((_DWORD *)(a1 + 4LL * a2), (_DWORD *)(a1 + 4LL * v3));
a2 = v7;
result = *(unsigned int *)(a1 + 400);
v3 = 2 * v7;
if ( v3 <= (int)result )
continue;
}
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
int v3; // ecx
__int64 result; // rax
int v5; // edi
int v6; // er9
int v7; // ecx

v3 = 2 * a2;
result = *(unsigned int *)(a1 + 400);
if ( 2 * a2 <= (int)result )
{
while ( 1 )
{
v5 = *(_DWORD *)(a1 + 4LL * a2);
v6 = *(_DWORD *)(a1 + 4LL * v3);
if ( v5 <= v6 )
{
if ( v3 >= (int)result )
return result;
result = ++v3;
if ( v5 <= *(_DWORD *)(a1 + 4LL * v3) )
return result;
}
else if ( v3 < (int)result )
{
result = (unsigned int)(v3 + 1);
if ( v6 > *(_DWORD *)(a1 + 4LL * (int)result) )
++v3;
}
if ( v3 != a2 )
{
func8((_DWORD *)(a1 + 4LL * a2), (_DWORD *)(a1 + 4LL * v3));
a2 = v7;
result = *(unsigned int *)(a1 + 400);
v3 = 2 * v7;
if ( v3 <= (int)result )
continue;
}
return result;
}
}
return result;
}

original_code:
void minify(heap_t *heap,int pos)
{
    int min;
    min = pos;
    if( (2*pos <= heap->heap_size) && (heap->array[min].key > heap->array[2*pos].key)) {
        min = 2*pos;
    }
    if((2*pos+1 <= heap->heap_size) && (heap->array[min].key > heap->array[2*pos+1].key)){
        min = 2*pos+1;
    }
    if(min != pos){
        swap(heap->array+pos,heap->array+min);
        minify(heap,min);
    }
}

canonical_original_code:
void minify(struct heap_s *heap, int pos)
{
    int min;
    min = pos;
    if( (2*pos <= heap->heap_size) && (heap->array[min].key > heap->array[2*pos].key)) {
        min = 2*pos;
    }
    if((2*pos+1 <= heap->heap_size) && (heap->array[min].key > heap->array[2*pos+1].key)){
        min = 2*pos+1;
    }
    if(min != pos){
        swap(heap->array+pos,heap->array+min);
        minify(heap,min);
    }
}

variable_types: pos int

variable_types: min int


decompiled_code:
__int64 __fastcall heap_minimum(__int64 a1)
{
return a1 + 4;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return a1 + 4;
}

original_code:
node_t * heap_minimum(heap_t *heap)
{
    return &heap->array[1];
}

canonical_original_code:
struct node_s *heap_minimum(struct heap_s *heap)
{
    return &heap->array[1];
}

variable_types: struct heap_s { struct node_s array[100]; int heap_size; } *

return_type: struct node_s { int key; } *


original_code:
void heap_extract_min(heap_t *heap, node_t *min)
{
    *min = heap->array[1];
    swap(heap->array+1,heap->array+heap->heap_size);
    heap->heap_size -= 1;
    minify(heap,1);
    return;
}

canonical_original_code:
void heap_extract_min(struct heap_s *heap, struct node_s *min)
{
    *min = heap->array[1];
    swap(heap->array+1,heap->array+heap->heap_size);
    heap->heap_size -= 1;
    minify(heap,1);
    return;
}

variable_types:
min
struct node_s *


original_code:
void heap_decrease_key(heap_t *heap,int pos, int key)
{
    if(heap->array[pos].key <= key){
        return;
    }
    heap->array[pos].key = key;
    while((pos > 1) &&(heap->array[pos].key < heap->array[pos/2].key) ){
        swap(heap->array+pos,heap->array+pos/2);
        pos = pos/2;
    }
}

canonical_original_code:
void heap_decrease_key(struct heap_s *heap, int pos, int key)
{
    if(heap->array[pos].key <= key){
        return;
    }
    heap->array[pos].key = key;
    while((pos > 1) &&(heap->array[pos].key < heap->array[pos/2].key) ){
        swap(heap->array+pos,heap->array+pos/2);
        pos = pos/2;
    }
}

variable_types: key int


decompiled_code:
__int64 __fastcall heap_insert(__int64 a1, int a2)
{
int v3; // esi

v3 = *(_DWORD *)(a1 + 400) + 1;
*(_DWORD *)(a1 + 400) = v3;
*(_DWORD *)(a1 + 4LL * v3) = 99999;
return heap_decrease_key(a1, v3, a2);
}

original_code:
void heap_insert(heap_t *heap,int key)
{
    heap->heap_size += 1;
    heap->array[heap->heap_size].key = 99999 ;
    heap_decrease_key(heap,heap->heap_size,key);
}

canonical_original_code:
void heap_insert(struct heap_s *heap, int key)
{
    heap->heap_size += 1;
    heap->array[heap->heap_size].key = 99999 ;
    heap_decrease_key(heap,heap->heap_size,key);
}


decompiled_code:
__int64 __fastcall min_heapify(__int64 a1)
{
__int64 result; // rax
int v3; // er10
int v4; // er10

result = *(unsigned int *)(a1 + 400);
v3 = *(_DWORD *)(a1 + 400) / 2;
if ( (int)result > 1 )
{
do
{
result = minify(a1, v3);
v3 = v4 - 1;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 result; // rax
int v3; // er10
int v4; // er10

result = *(unsigned int *)(a1 + 400);
v3 = *(_DWORD *)(a1 + 400) / 2;
if ( (int)result > 1 )
{
do
{
result = func9(a1, v3);
v3 = v4 - 1;
}
while ( v3 );
}
return result;
}

original_code:
void min_heapify(heap_t *heap)
{
    int i;
    for(i = heap->heap_size/2; i > 0; i--) {
        minify(heap,i);
    }
}

canonical_original_code:
void min_heapify(struct heap_s *heap)
{
    int i;
    for(i = heap->heap_size/2; i > 0; i--) {
        minify(heap,i);
    }
}


decompiled_code:
void *make_heap()
{
return calloc(0x194uLL, 1uLL);
}

canonical_decompiled_code:
void *func15()
{
return calloc(0x194uLL, 1uLL);
}

original_code:
heap_t* make_heap()
{
    heap_t *heap;
    heap = (heap_t *)malloc(sizeof(heap_t));
    memset(heap,0,sizeof(heap_t));
    return heap;
}

canonical_original_code:
struct heap_s *make_heap()
{
    struct heap_s *heap;
    heap = (struct heap_s *)malloc(sizeof(heap_t));
    memset(heap,0,sizeof(heap_t));
    return heap;
}

return_type: struct heap_s { struct node_s { int key; } array[100]; int heap_size; } *


main

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

v3 = make_heap(argc, argv, envp);
freopen("input.txt", "r", _bss_start);
while ( (unsigned int)__isoc99_scanf() != -1 )
heap_insert(v3, v7[0]);
puts("after insert :");
print_heap(v3, v7);
heap_extract_min(v3, &v6);
v4 = v6;
printf("min:%d\n", v6);
puts("after one extract min");
print_heap(v3, v4);
return 0;
}

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

v3 = func15(argc, argv, envp);
freopen("input.txt", "r", _bss_start);
while ( (unsigned int)__isoc99_scanf() != -1 )
func13(v3, v7[0]);
puts("after insert :");
func7(v3, v7);
func11(v3, &v6);
v4 = v6;
printf("min:%d\n", v6);
puts("after one extract min");
func7(v3, v4);
return 0;
}

original_code:
int main()
{
    heap_t *heap;
    node_t node;
    int key;
    heap = make_heap();
    freopen("input.txt","r",stdin);
    while((scanf("%d",&key))!= (-1)){
        heap_insert(heap,key);
    }
    printf("after insert :\n");
    print_heap(heap);
    heap_extract_min(heap,&node);
    printf("min:%d\n",node.key);
    printf("after one extract min\n");
    print_heap(heap);
    return 0;
}

canonical_original_code:
int main()
{
    struct heap_s *heap;
    struct node_s node;
    int key;
    heap = make_heap();
    freopen("input.txt","r",stdin);
    while((scanf("%d",&key))!= (-1)){
        heap_insert(heap,key);
    }
    printf("after insert :\n");
    print_heap(heap);
    heap_extract_min(heap,&node);
    printf("min:%d\n",node.key);
    printf("after one extract min\n");
    print_heap(heap);
    return 0;
}

variable_types:
node
struct node_s { int key; }


swap

decompiled_code:
__int64 __fastcall swap(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

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

result = (unsigned int)*a1;
*a1 = *a2;
*a2 = result;
return result;
}

original_code:
void swap(node_t *x, node_t *y)
{
    node_t tmp;
    tmp = *x;
    *x = *y;
    *y = tmp;
}

canonical_original_code:
void swap(struct node_s *x, struct node_s *y)
{
    struct node_s tmp;
    tmp = *x;
    *x = *y;
    *y = tmp;
}

variable_types:
x
struct node_s { int key; } *

variable_types:
y
struct node_s *

variable_types:
tmp
struct node_s { int key; }


decompiled_code:
__int64 __fastcall printf_array(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi

if ( a2 <= 0 )
return 0LL;
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = (unsigned int)i;
printf("%dth:%d\n", v5, v4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 v2; // rbp
__int64 i; // rbx
__int64 v4; // rdx
__int64 v5; // rsi

if ( a2 <= 0 )
return 0LL;
v2 = a2;
for ( i = 0LL; i != v2; ++i )
{
v4 = *(unsigned int *)(a1 + 4 * i);
v5 = (unsigned int)i;
printf("%dth:%d\n", v5, v4);
}
return 0LL;
}

original_code:
int printf_array(int *A, int len)
{
    int i;
    for(i = 0; i < len; i++) {
        printf("%dth:%d\n", i, A[i]);
    }
    return 0;
}

variable_types:
A
int *

variable_types: len int


decompiled_code:
__int64 __fastcall non_recursive_quick_sort(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // r12
__int64 v5; // rsi
int v6; // ebx
__int64 result; // rax
int *v8; // rbp
int *v9; // r14
int v10; // ebx
__int64 v11; // rsi

v4 = stack_init();
stack_push_key(v4, a3);
stack_push_key(v4, a2);
LABEL_3:
for ( result = stack_is_empty(v4); !(_DWORD)result; result = stack_is_empty(v4) )
{
v8 = (int *)stack_pop(v4);
v9 = (int *)stack_pop(v4);
v10 = partition(a1, *v8, *v9);
v11 = (unsigned int)(v10 - 1);
if ( *v8 >= (int)v11 )
{
v5 = (unsigned int)*v9;
v6 = v10 + 1;
if ( (int)v5 <= v6 )
goto LABEL_3;
}
else
{
v6 = v10 + 1;
stack_push_key(v4, v11);
stack_push_key(v4, (unsigned int)*v8);
v5 = (unsigned int)*v9;
if ( (int)v5 <= v6 )
goto LABEL_3;
}
stack_push_key(v4, v5);
stack_push_key(v4, (unsigned int)v6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // r12
__int64 v5; // rsi
int v6; // ebx
__int64 result; // rax
int *v8; // rbp
int *v9; // r14
int v10; // ebx
__int64 v11; // rsi

v4 = func11();
func13(v4, a3);
func13(v4, a2);
LABEL_3:
for ( result = func15(v4); !(_DWORD)result; result = func15(v4) )
{
v8 = (int *)func14(v4);
v9 = (int *)func14(v4);
v10 = func9(a1, *v8, *v9);
v11 = (unsigned int)(v10 - 1);
if ( *v8 >= (int)v11 )
{
v5 = (unsigned int)*v9;
v6 = v10 + 1;
if ( (int)v5 <= v6 )
goto LABEL_3;
}
else
{
v6 = v10 + 1;
func13(v4, v11);
func13(v4, (unsigned int)*v8);
v5 = (unsigned int)*v9;
if ( (int)v5 <= v6 )
goto LABEL_3;
}
func13(v4, v5);
func13(v4, (unsigned int)v6);
}
return result;
}

original_code:
void non_recursive_quick_sort(int *array,int start,int end)
{
    stack_t *stack;
    stack_node_t *start_node,*end_node;
    int p;
    stack = stack_init();
    stack_push_key(stack,end);
    stack_push_key(stack,start);
    while(!stack_is_empty(stack)){
        start_node = stack_pop(stack);
        end_node = stack_pop(stack);
        p = partition(array,start_node->key,end_node->key);
        if(start_node->key < p-1){
            stack_push_key(stack,p-1);
            stack_push_key(stack,start_node->key);
        }
        if(end_node->key > p+1){
            stack_push_key(stack,end_node->key);
            stack_push_key(stack,p+1);
        }
    }
}

canonical_original_code:
void non_recursive_quick_sort(int *array, int start, int end)
{
    struct stack_s *stack;
    struct stack_node_s *start_node; struct stack_node_s *end_node;
    int p;
    stack = stack_init();
    stack_push_key(stack,end);
    stack_push_key(stack,start);
    while(!stack_is_empty(stack)){
        start_node = stack_pop(stack);
        end_node = stack_pop(stack);
        p = partition(array,start_node->key,end_node->key);
        if(start_node->key < p-1){
            stack_push_key(stack,p-1);
            stack_push_key(stack,start_node->key);
        }
        if(end_node->key > p+1){
            stack_push_key(stack,end_node->key);
            stack_push_key(stack,p+1);
        }
    }
}

variable_types:
array
int *

variable_types: start int

variable_types: end int

variable_types: struct stack_s { int node_num; struct stack_node_s { int key; struct stack_node_s *next; } *data; } *

variable_types: p int

user_defined_types: struct stack_s { int node_num; struct stack_node_s *data; }


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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a2 + 8) = result;
++*(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a2 + 8) = result;
++*(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void stack_push_node(stack_t *stack,stack_node_t *node)
{
    node->next = stack->data;
    stack->data = node;
    stack->node_num += 1;
}

canonical_original_code:
void stack_push_node(struct stack_s *stack, struct stack_node_s *node)
{
    node->next = stack->data;
    stack->data = node;
    stack->node_num += 1;
}

variable_types:
node
struct stack_node_s *

user_defined_types: struct stack_node_s { int key; struct stack_node_s *next; }


decompiled_code:
__int64 __fastcall stack_push_key(__int64 a1, int a2)
{
_DWORD *v2; // rax

v2 = stack_create_node(a2);
return stack_push_node(a1, (__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, int a2)
{
_DWORD *v2; // rax

v2 = stack_create_node(a2);
return func12(a1, (__int64)v2);
}

original_code:
void stack_push_key(stack_t *stack,int key)
{
    stack_node_t *node = ((void *)0);
    node = stack_create_node(key);
    stack_push_node(stack,node);
}

canonical_original_code:
void stack_push_key(struct stack_s *stack, int key)
{
    struct stack_node_s *node = ((void *)0);
    node = stack_create_node(key);
    stack_push_node(stack,node);
}

variable_types: struct stack_node_s { int key; struct stack_node_s *next; } *


original_code:
void swap(int *x,int *y)
{
    int tmp;
    tmp = *x;
    *x = *y;
    *y = tmp;
}

canonical_original_code:
void swap(int *x, int *y)
{
    int tmp;
    tmp = *x;
    *x = *y;
    *y = tmp;
}

variable_types:
x
int *

variable_types:
y
int *

variable_types: tmp int


partition

decompiled_code:
__int64 __fastcall partition(__int64 a1, int a2, int a3)
{
int v4; // er8
int *v5; // rbp
int v6; // er10
_DWORD *v7; // rcx
unsigned __int64 v8; // r11
unsigned int v9; // er10

v4 = a2 - 1;
v5 = (int *)(a1 + 4LL * a3);
v6 = *v5;
if ( a2 < a3 )
{
v7 = (_DWORD *)(a1 + 4LL * a2);
v8 = a1 + 4 * (a2 + (unsigned __int64)(unsigned int)(a3 - 1 - a2)) + 4;
do
{
while ( *v7 >= v6 )
{
if ( ++v7 == (_DWORD *)v8 )
goto LABEL_6;
}
swap((_DWORD *)(a1 + 4LL * (v4 + 1)), v7);
}
while ( v7 != (_DWORD *)v8 );
}
LABEL_6:
swap((_DWORD *)(a1 + 4LL * v4 + 4), v5);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3)
{
int v4; // er8
int *v5; // rbp
int v6; // er10
_DWORD *v7; // rcx
unsigned __int64 v8; // r11
unsigned int v9; // er10

v4 = a2 - 1;
v5 = (int *)(a1 + 4LL * a3);
v6 = *v5;
if ( a2 < a3 )
{
v7 = (_DWORD *)(a1 + 4LL * a2);
v8 = a1 + 4 * (a2 + (unsigned __int64)(unsigned int)(a3 - 1 - a2)) + 4;
do
{
while ( *v7 >= v6 )
{
if ( ++v7 == (_DWORD *)v8 )
goto LABEL_6;
}
func8((_DWORD *)(a1 + 4LL * (v4 + 1)), v7);
}
while ( v7 != (_DWORD *)v8 );
}
LABEL_6:
func8((_DWORD *)(a1 + 4LL * v4 + 4), v5);
return v9;
}

original_code:
int partition(int *array, int start,int end)
{
    int i,j,x;
    i = start-1;
    x = array[end];
    for(j = start; j <= end-1;j++){
        if(array[j] < x){
            i=i+1;
            swap(array+i,array+j);
        }
    }
    swap(array+i+1,array+end);
    return i+1;
}

canonical_original_code:
int partition(int *array, int start, int end)
{
    int i; int j; int x;
    i = start-1;
    x = array[end];
    for(j = start; j <= end-1;j++){
        if(array[j] < x){
            i=i+1;
            swap(array+i,array+j);
        }
    }
    swap(array+i+1,array+end);
    return i+1;
}

variable_types: i int

variable_types: j int

variable_types: x int


decompiled_code:
void *stack_init()
{
void *result; // rax

result = calloc(0x10uLL, 1uLL);
if ( !result )
{
printf("error malloc:%s:%d\n", "stack.c", 9LL);
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *func11()
{
void *result; // rax

result = calloc(0x10uLL, 1uLL);
if ( !result )
{
printf("error malloc:%s:%d\n", "stack.c", 9LL);
exit(-1);
}
return result;
}

original_code:
stack_t* stack_init()
{
    stack_t *stack;
    if((stack=(stack_t*)malloc(sizeof(stack_t))) == ((void *)0)){
        printf("error malloc:%s:%d\n","stack.c",9);
        exit(-1);
    }
    memset(stack,0,sizeof(stack_t));
    return stack;
}

canonical_original_code:
struct stack_s *stack_init()
{
    struct stack_s *stack;
    if((stack=(struct stack_s *)malloc(sizeof(stack_t))) == ((void *)0)){
        printf("error malloc:%s:%d\n","stack.c",9);
        exit(-1);
    }
    memset(stack,0,sizeof(stack_t));
    return stack;
}

return_type: struct stack_s { int node_num; struct stack_node_s { int key; struct stack_node_s *next; } *data; } *


decompiled_code:
__int64 __fastcall stack_pop(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = *(_QWORD *)(a1 + 8);
if ( result )
{
v2 = *(_QWORD *)(result + 8);
--*(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = *(_QWORD *)(a1 + 8);
if ( result )
{
v2 = *(_QWORD *)(result + 8);
--*(_DWORD *)a1;
*(_QWORD *)(a1 + 8) = v2;
}
return result;
}

original_code:
stack_node_t *stack_pop(stack_t *stack)
{
    stack_node_t *pop_node=((void *)0);
    if(stack->data != ((void *)0)){
        pop_node = stack->data;
        stack->data = stack->data->next;
        stack->node_num -= 1;
    }
    return pop_node;
}

canonical_original_code:
struct stack_node_s *stack_pop(struct stack_s *stack)
{
    struct stack_node_s *pop_node = ((void *)0);
    if(stack->data != ((void *)0)){
        pop_node = stack->data;
        stack->data = stack->data->next;
        stack->node_num -= 1;
    }
    return pop_node;
}

variable_types: struct stack_s { int node_num; struct stack_node_s *data; } *

return_type: struct stack_node_s { int key; struct stack_node_s *next; } *


decompiled_code:
_BOOL8 __fastcall stack_is_empty(_DWORD *a1)
{
return *a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func15(_DWORD *a1)
{
return *a1 == 0;
}

original_code:
int stack_is_empty(stack_t *stack)
{
     return (stack->node_num == 0)?1:0;
}

canonical_original_code:
int stack_is_empty(struct stack_s *stack)
{
     return (stack->node_num == 0)?1:0;
}


merge

original_code:
int merge(int *array, int left, int mid, int right)
{
    int i;
    int store_left;
    int *tmp;
    int left_end,tmp_pos;
    tmp = (int*)calloc(right-left+1,sizeof(int));
    if(tmp == ((void *)0)){
        err_exit("calloc error");
    }
    tmp_pos = 0;
    store_left = left;
    left_end = mid - 1;
    while(left <= left_end && mid <= right){
        if(array[left] < array[mid]){
            tmp[tmp_pos] = array[left];
            left++;
            tmp_pos++;
        } else {
            tmp[tmp_pos] = array[mid];
            mid++;
            tmp_pos++;
        }
   }
   while(left <= left_end){
       tmp[tmp_pos]=array[left];
       left++;
       tmp_pos++;
   }
   while(mid <= right){
       tmp[tmp_pos]=array[mid];
       mid++;
       tmp_pos++;
   }
   for (i = 0; i < tmp_pos; i++){
       array[store_left+i] = tmp[i];
   }
   return 0;
}

canonical_original_code:
int merge(int *array, int left, int mid, int right)
{
    int i;
    int store_left;
    int *tmp;
    int left_end; int tmp_pos;
    tmp = (int *)calloc(right-left+1,sizeof(int));
    if(tmp == ((void *)0)){
        err_exit("calloc error");
    }
    tmp_pos = 0;
    store_left = left;
    left_end = mid - 1;
    while(left <= left_end && mid <= right){
        if(array[left] < array[mid]){
            tmp[tmp_pos] = array[left];
            left++;
            tmp_pos++;
        } else {
            tmp[tmp_pos] = array[mid];
            mid++;
            tmp_pos++;
        }
   }
   while(left <= left_end){
       tmp[tmp_pos]=array[left];
       left++;
       tmp_pos++;
   }
   while(mid <= right){
       tmp[tmp_pos]=array[mid];
       mid++;
       tmp_pos++;
   }
   for (i = 0; i < tmp_pos; i++){
       array[store_left+i] = tmp[i];
   }
   return 0;
}

variable_types: left int

variable_types: mid int

variable_types: right int

variable_types:
tmp
int *


decompiled_code:
__int64 __fastcall merge_sort(__int64 a1, __int64 a2, int a3)
{
__int64 v5; // rdx
unsigned int v6; // er14

if ( (int)a2 < a3 )
{
v5 = (unsigned int)(((int)a2 + a3) / 2);
v6 = v5 + 1;
merge_sort(a1, a2, v5);
merge_sort(a1, v6, (unsigned int)a3);
merge(a1, a2, v6, a3);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, int a3)
{
__int64 v5; // rdx
unsigned int v6; // er14

if ( (int)a2 < a3 )
{
v5 = (unsigned int)(((int)a2 + a3) / 2);
v6 = v5 + 1;
func9(a1, a2, v5);
func9(a1, v6, (unsigned int)a3);
func8(a1, a2, v6, a3);
}
return 0LL;
}

original_code:
int merge_sort(int *array, int p, int r)
{
    int q;
    if ( p < r) {
        q = (p + r)/2;
        merge_sort(array, p, q);
        merge_sort(array, q+1, r);
        merge(array, p, q+1, r);
    }
    return 0;
}

variable_types:
array
int *

variable_types: r int

variable_types: q int


decompiled_code:
void __noreturn err_exit(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
printf("%s:%d", "merge_sort.c", 15LL);
vprintf(format, arg);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
printf("%s:%d", "merge_sort.c", 15LL);
vprintf(format, arg);
exit(0);
}

original_code:
void err_exit(char *fmt,...)
{
    va_list va;
    __builtin_va_start(va,fmt);
    printf("%s:%d","merge_sort.c",15);
    vprintf(fmt,va);
    __builtin_va_end(va);
    exit(0);
}

canonical_original_code:
void err_exit(char *fmt, ...)
{
    __builtin_va_list va;
    __builtin_va_start(va,fmt);
    printf("%s:%d","merge_sort.c",15);
    vprintf(fmt,va);
    __builtin_va_end(va);
    exit(0);
}

variable_types:
fmt
char *


cbinit

decompiled_code:
void *__fastcall cbinit(__int64 a1, int a2)
{
int v2; // esi
void *result; // rax

v2 = a2 + 1;
*(_DWORD *)a1 = v2;
*(_QWORD *)(a1 + 4) = 0LL;
result = calloc(v2, 4uLL);
*(_QWORD *)(a1 + 16) = result;
if ( !result )
err_exit("calloc error\n");
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, int a2)
{
int v2; // esi
void *result; // rax

v2 = a2 + 1;
*(_DWORD *)a1 = v2;
*(_QWORD *)(a1 + 4) = 0LL;
result = calloc(v2, 4uLL);
*(_QWORD *)(a1 + 16) = result;
if ( !result )
func7("calloc error\n");
return result;
}

original_code:
void
cbinit(circular_buffer *cb, int size)
{
    cb->size = size + 1;
    cb->start = 0;
    cb->end = 0;
    cb->elems = (elem_type*)calloc(cb->size, sizeof(elem_type));
    if (cb->elems == ((void *)0)) {
        err_exit("calloc error\n");
    }
}

canonical_original_code:
void cbinit(struct circular_buffer *cb, int size)
{
    cb->size = size + 1;
    cb->start = 0;
    cb->end = 0;
    cb->elems = (struct elem_type *)calloc(cb->size, sizeof(elem_type));
    if (cb->elems == ((void *)0)) {
        err_exit("calloc error\n");
    }
}

variable_types: struct circular_buffer { int size; int start; int end; struct elem_type { int value; } *elems; } *

variable_types: size int

user_defined_types: struct circular_buffer { int size; int start; int end; struct elem_type *elems; }


cbfree

decompiled_code:
void __fastcall cbfree(__int64 a1)
{
free(*(void **)(a1 + 16));
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
free(*(void **)(a1 + 16));
}

original_code:
void
cbfree(circular_buffer *cb)
{
    free(cb->elems);
}

canonical_original_code:
void cbfree(struct circular_buffer *cb)
{
    free(cb->elems);
}


decompiled_code:
_BOOL8 __fastcall cb_is_full(_DWORD *a1)
{
return (a1[2] + 1) % *a1 == a1[1];
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(_DWORD *a1)
{
return (a1[2] + 1) % *a1 == a1[1];
}

original_code:
int
cb_is_full(circular_buffer *cb)
{
    return (cb->end + 1) % cb->size == cb->start;
}

canonical_original_code:
int cb_is_full(struct circular_buffer *cb)
{
    return (cb->end + 1) % cb->size == cb->start;
}


decompiled_code:
_BOOL8 __fastcall cb_is_empty(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1)
{
return *(_DWORD *)(a1 + 8) == *(_DWORD *)(a1 + 4);
}

original_code:
int
cb_is_empty(circular_buffer *cb)
{
    return cb->end == cb->start;
}

canonical_original_code:
int cb_is_empty(struct circular_buffer *cb)
{
    return cb->end == cb->start;
}


decompiled_code:
__int64 __fastcall cb_write(int *a1, _DWORD *a2)
{
int v2; // eax
int v3; // ecx
int v4; // edx
__int64 result; // rax
int v6; // edx
__int64 v7; // rt2
int v8; // edx
unsigned int v9; // kr08_4

v2 = a1[2];
*(_DWORD *)(*((_QWORD *)a1 + 2) + 4LL * v2) = *a2;
v3 = *a1;
v4 = ++v2 >> 31;
v7 = __SPAIR64__(v4, v2) % *a1;
LODWORD(result) = __SPAIR64__(v4, v2) / *a1;
v6 = v7;
result = (unsigned int)result;
a1[2] = v7;
if ( (_DWORD)v7 == a1[1] )
{
v9 = v6 + 1;
v8 = (v6 + 1) >> 31;
result = (unsigned int)(__SPAIR64__(v8, v9) / v3);
a1[1] = __SPAIR64__(v8, v9) % v3;
}
return result;
}

original_code:
void
cb_write(circular_buffer *cb, elem_type *elem)
{
    cb->elems[cb->end] = *elem;
    cb->end = (cb->end + 1) % cb->size;
    if(cb->end == cb->start) {
        cb->start = (cb->start + 1) % cb->size ;
    }
}

canonical_original_code:
void cb_write(struct circular_buffer *cb, struct elem_type *elem)
{
    cb->elems[cb->end] = *elem;
    cb->end = (cb->end + 1) % cb->size;
    if(cb->end == cb->start) {
        cb->start = (cb->start + 1) % cb->size ;
    }
}

variable_types:
elem
struct elem_type *


decompiled_code:
__int64 __fastcall cb_read(__int64 a1, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edx

v2 = *(_DWORD *)(a1 + 4) + 1;
*a2 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * *(int *)(a1 + 4));
v4 = v2 % *(_DWORD *)a1;
result = (unsigned int)(v2 / *(_DWORD *)a1);
*(_DWORD *)(a1 + 4) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, _DWORD *a2)
{
int v2; // eax
__int64 result; // rax
int v4; // edx

v2 = *(_DWORD *)(a1 + 4) + 1;
*a2 = *(_DWORD *)(*(_QWORD *)(a1 + 16) + 4LL * *(int *)(a1 + 4));
v4 = v2 % *(_DWORD *)a1;
result = (unsigned int)(v2 / *(_DWORD *)a1);
*(_DWORD *)(a1 + 4) = v4;
return result;
}

original_code:
void
cb_read(circular_buffer *cb, elem_type *elem)
{
    *elem = cb->elems[cb->start];
    cb->start = (cb->start + 1) % cb->size;
}

canonical_original_code:
void cb_read(struct circular_buffer *cb, struct elem_type *elem)
{
    *elem = cb->elems[cb->start];
    cb->start = (cb->start + 1) % cb->size;
}


decompiled_code:
void __noreturn err_exit(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
printf("%s:%d", "queue.c", 17LL);
vprintf(format, arg);
exit(0);
}

canonical_decompiled_code:
void __noreturn func7(char *format, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

va_start(arg, format);
printf("%s:%d", "queue.c", 17LL);
vprintf(format, arg);
exit(0);
}

original_code:
void err_exit(char *fmt,...)
{
    va_list va;
    __builtin_va_start(va,fmt);
    printf("%s:%d","queue.c",17);
    vprintf(fmt,va);
    __builtin_va_end(va);
    exit(0);
}

canonical_original_code:
void err_exit(char *fmt, ...)
{
    __builtin_va_list va;
    __builtin_va_start(va,fmt);
    printf("%s:%d","queue.c",17);
    vprintf(fmt,va);
    __builtin_va_end(va);
    exit(0);
}


decompiled_code:
__int64 __fastcall rbtree_right_rotate(_QWORD *a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v4; // rcx
_QWORD *v5; // rcx

result = *a3;
v4 = *(_QWORD *)(*a3 + 8LL);
*a3 = v4;
if ( v4 != a2 )
*(_QWORD *)(v4 + 16) = a3;
v5 = (_QWORD *)a3[2];
*(_QWORD *)(result + 16) = v5;
if ( (_QWORD *)*a1 == a3 )
{
*a1 = result;
a3[2] = result;
*(_QWORD *)(result + 8) = a3;
}
else
{
if ( (_QWORD *)*v5 == a3 )
*v5 = result;
else
v5[1] = result;
a3[2] = result;
*(_QWORD *)(result + 8) = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, __int64 a2, _QWORD *a3)
{
__int64 result; // rax
__int64 v4; // rcx
_QWORD *v5; // rcx

result = *a3;
v4 = *(_QWORD *)(*a3 + 8LL);
*a3 = v4;
if ( v4 != a2 )
*(_QWORD *)(v4 + 16) = a3;
v5 = (_QWORD *)a3[2];
*(_QWORD *)(result + 16) = v5;
if ( (_QWORD *)*a1 == a3 )
{
*a1 = result;
a3[2] = result;
*(_QWORD *)(result + 8) = a3;
}
else
{
if ( (_QWORD *)*v5 == a3 )
*v5 = result;
else
v5[1] = result;
a3[2] = result;
*(_QWORD *)(result + 8) = a3;
}
return result;
}

original_code:
void
rbtree_right_rotate(rbtree_node_t ** root,rbtree_node_t * sentinel,rbtree_node_t *node)
{
    rbtree_node_t * temp;
     temp = node->left;
     node->left = temp->right;
    if(temp->right != sentinel){
          temp->right->parent = node;
     }
     temp->parent = node->parent;
     if(*root == node){
        *root = temp;
     }else if(node == node->parent->left){
        node->parent->left = temp;
     }else{
         node->parent->right = temp;
     }
     node->parent = temp;
     temp->right = node;
}

canonical_original_code:
void rbtree_right_rotate(struct rbtree_node_s **root, struct rbtree_node_s *sentinel, struct rbtree_node_s *node)
{
    struct rbtree_node_s *temp;
     temp = node->left;
     node->left = temp->right;
    if(temp->right != sentinel){
          temp->right->parent = node;
     }
     temp->parent = node->parent;
     if(*root == node){
        *root = temp;
     }else if(node == node->parent->left){
        node->parent->left = temp;
     }else{
         node->parent->right = temp;
     }
     node->parent = temp;
     temp->right = node;
}

variable_types: struct rbtree_node_s { struct rbtree_node_s *left; struct rbtree_node_s *right; struct rbtree_node_s *parent; int key; int color; } **

variable_types:
sentinel
struct rbtree_node_s *

variable_types:
node
struct rbtree_node_s *


decompiled_code:
__int64 __fastcall rbtree_init(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2[1];
*a1 = v2;
v2[2] = a2;
*v2 = v3;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, __int64 a2)
{
_QWORD *v2; // rax
__int64 v3; // rdx

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = v2[1];
*a1 = v2;
v2[2] = a2;
*v2 = v3;
return 0LL;
}

original_code:
int
rbtree_init(rbtree_t ** rbtree,insert_node_to_tree_pt insert)
{
     rbtree_t * new_rbtree = (rbtree_t*)malloc(sizeof(rbtree_t));
     if(((void *)0) == new_rbtree)
          return -1;
     *rbtree = new_rbtree;
     new_rbtree->root = new_rbtree->sentinel;
     new_rbtree->insert = insert;
     return 0;
}

canonical_original_code:
int rbtree_init(struct rbtree_s **rbtree, void (*insert)(struct rbtree_node_s *temp, struct rbtree_node_s *sentinel, struct rbtree_node_s *node))
{
     struct rbtree_s *new_rbtree = (rbtree_t*)malloc(sizeof(rbtree_t));
     if(((void *)0) == new_rbtree)
          return -1;
     *rbtree = new_rbtree;
     new_rbtree->root = new_rbtree->sentinel;
     new_rbtree->insert = insert;
     return 0;
}

variable_types: struct rbtree_s { struct rbtree_node_s { struct rbtree_node_s *left; struct rbtree_node_s *right; struct rbtree_node_s *parent; int key; int color; } *root; struct rbtree_node_s *sentinel; void (*insert)(struct rbtree_node_s *temp, struct rbtree_node_s *sentinel, struct rbtree_node_s *node); } **

variable_types: void (*)(struct rbtree_node_s *temp, struct rbtree_node_s *sentinel, struct rbtree_node_s *node)

user_defined_types: struct rbtree_s { struct rbtree_node_s *root; struct rbtree_node_s *sentinel; void (*insert)(struct rbtree_node_s *temp, struct rbtree_node_s *sentinel, struct rbtree_node_s *node); }


decompiled_code:
int __fastcall rbtree_traverse(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax

if ( a2 != a1 )
{
v2 = a1;
do
{
rbtree_traverse(*(_QWORD *)v2, a2);
result = printf("key : %d color :%d\n", *(unsigned int *)(v2 + 24), *(unsigned int *)(v2 + 28));
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 != a2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
int result; // eax

if ( a2 != a1 )
{
v2 = a1;
do
{
func3(*(_QWORD *)v2, a2);
result = printf("key : %d color :%d\n", *(unsigned int *)(v2 + 24), *(unsigned int *)(v2 + 28));
v2 = *(_QWORD *)(v2 + 8);
}
while ( v2 != a2 );
}
return result;
}

original_code:
void
rbtree_traverse(rbtree_node_t *node,rbtree_node_t * sentinel)
{
 if(node == sentinel)
  return ;
 rbtree_traverse(node->left,sentinel);
 printf("key : %d color :%d\n",node->key,node->color);
 rbtree_traverse(node->right,sentinel);
}

canonical_original_code:
void rbtree_traverse(struct rbtree_node_s *node, struct rbtree_node_s *sentinel)
{
 if(node == sentinel)
  return ;
 rbtree_traverse(node->left,sentinel);
 printf("key : %d color :%d\n",node->key,node->color);
 rbtree_traverse(node->right,sentinel);
}

variable_types: struct rbtree_node_s { struct rbtree_node_s *left; struct rbtree_node_s *right; struct rbtree_node_s *parent; int key; int color; } *


original_code:
void
rbtree_delete(rbtree_t *rbtree,rbtree_node_t *node)
{
 rbtree_node_t * temp,*subst;
    if(node->left == rbtree->sentinel){
     subst = node;
     temp = subst->right;
    }else if(node->right == rbtree->sentinel){
     subst = node;
     temp = subst->left;
    }else{
     subst = rbtree_min_node(node->right,rbtree->sentinel);
     temp = subst->right;
    }
    if(temp != rbtree->sentinel)
     temp->parent = subst->parent;
    if(subst->parent == ((void *)0))
     rbtree->root = temp;
    else if(subst == subst->parent->right)
     subst->parent->right = temp;
    else
     subst->parent->left = temp;
    if(subst != node){
     node->key = subst->key;
    }
   free(subst);
}

canonical_original_code:
void rbtree_delete(struct rbtree_s *rbtree, struct rbtree_node_s *node)
{
 struct rbtree_node_s *temp; struct rbtree_node_s *subst;
    if(node->left == rbtree->sentinel){
     subst = node;
     temp = subst->right;
    }else if(node->right == rbtree->sentinel){
     subst = node;
     temp = subst->left;
    }else{
     subst = rbtree_min_node(node->right,rbtree->sentinel);
     temp = subst->right;
    }
    if(temp != rbtree->sentinel)
     temp->parent = subst->parent;
    if(subst->parent == ((void *)0))
     rbtree->root = temp;
    else if(subst == subst->parent->right)
     subst->parent->right = temp;
    else
     subst->parent->left = temp;
    if(subst != node){
     node->key = subst->key;
    }
   free(subst);
}

variable_types: struct rbtree_s { struct rbtree_node_s { struct rbtree_node_s *left; struct rbtree_node_s *right; struct rbtree_node_s *parent; int key; int color; } *root; struct rbtree_node_s *sentinel; void (*insert)(struct rbtree_node_s *temp, struct rbtree_node_s *sentinel, struct rbtree_node_s *node); } *