doit

decompiled_code:
void __fastcall __noreturn doit(void *a1)
{
time_t v1; // r13
_DWORD *v2; // rbp
pthread_t v3; // rax
int v4; // er12
struct epoll_event *v5; // rbx
int v6; // edi
time_t v7; // rax
int v8; // ebx
int v9; // eax
int v10; // eax
struct epoll_event *v11; // r14
struct epoll_event event; // [rsp+4h] [rbp-18034h] BYREF
struct epoll_event events; // [rsp+10h] [rbp-18028h] BYREF
_DWORD v14[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 )
{
v8 = 1000;
do
{
v9 = tcp_connect(remote_ip, (unsigned __int16)remote_port, bind_ip);
if ( v9 < 0 )
break;
event.events = 5;
event.data.fd = v9;
epoll_ctl(v4, 1, v9, &event);
++*v2;
--v8;
}
while ( v8 );
v10 = epoll_wait(v4, &events, 0x2000, 0);
if ( v10 > 0 )
{
v5 = &events;
v11 = (struct epoll_event *)&v14[3 * (v10 - 1)];
do
{
v6 = v5->data.fd;
if ( (v5->events & 1) != 0 )
{
close(v6);
++v2[2];
}
else if ( (v5->events & 4) != 0 )
{
close(v6);
++v2[1];
}
++v5;
}
while ( v5 != v11 );
}
v7 = time(0LL);
if ( v1 != v7 )
{
v2[4] = v2[1];
v2[3] = *v2;
v2[5] = v2[2];
*v2 = 0;
v2[1] = 0;
v2[2] = 0;
}
v1 = v7;
}
}

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

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

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: ret 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

repo: yangxks/Model

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 func5()
{
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);
}

return_type: void


repo: yangxks/Test

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

v6[0] = 10;
v5 = 20;
v1 = clnt_create(a1, 0x20010929uLL, 1uLL, "tcp");
v2 = (unsigned int *)deposit_1(v6, v1);
printf("result=%d\n", *v2);
v3 = (unsigned int *)withdraw_1(&v5, 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; // rbx
unsigned int *v2; // rax
unsigned int *v3; // rax
int v5; // [rsp+8h] [rbp-10h] BYREF
int v6[3]; // [rsp+Ch] [rbp-Ch] BYREF

v6[0] = 10;
v5 = 20;
v1 = clnt_create(a1, 0x20010929uLL, 1uLL, "tcp");
v2 = (unsigned int *)deposit_1(v6, v1);
printf("result=%d\n", *v2);
v3 = (unsigned int *)withdraw_1(&v5, 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

canonical_name: 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 *[]

return_type: int


decompiled_code:
void __fastcall testprog_1(struct svc_req *a1, SVCXPRT *a2)
{
rpcproc_t v2; // rax
__int64 (__fastcall *v3)(); // r13
bool_t (*v4)(XDR *, void *, ...); // r12
char *v5; // rax
__int64 v6[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;
}
v6[0] = 0LL;
if ( a2->xp_ops->xp_getargs(a2, v4, (caddr_t)v6) )
{
v5 = (char *)((__int64 (__fastcall *)(__int64 *, struct svc_req *))v3)(v6, a1);
if ( v5 && !svc_sendreply(a2, (xdrproc_t)xdr_int, v5) )
svcerr_systemerr(a2);
if ( !a2->xp_ops->xp_freeargs(a2, v4, (caddr_t)v6) )
{
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)(); // r13
bool_t (*v4)(XDR *, void *, ...); // r12
char *v5; // rax
__int64 v6[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;
}
v6[0] = 0LL;
if ( a2->xp_ops->xp_getargs(a2, v4, (caddr_t)v6) )
{
v5 = (char *)((__int64 (__fastcall *)(__int64 *, struct svc_req *))v3)(v6, a1);
if ( v5 && !svc_sendreply(a2, (xdrproc_t)xdr_int, v5) )
svcerr_systemerr(a2);
if ( !a2->xp_ops->xp_freeargs(a2, v4, (caddr_t)v6) )
{
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) )
{
fwrite("unable to register (TESTPROG, VERSION, udp).", 1uLL, 0x2CuLL, stderr);
exit(1);
}
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("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)
{
bool v2; // zf
int *result; // rax
int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

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

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

v4[0] = a1;
clnt_res_2 = 0;
v2 = (**(unsigned int (__fastcall ***)(__int64, __int64, bool_t (*)(XDR *, int *), int *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD))(a2 + 8))(
a2,
1LL,
xdr_int,
v4,
xdr_int,
&clnt_res_2,
TIMEOUT,
0LL) == 0;
result = &clnt_res_2;
if ( !v2 )
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)
{
bool v2; // zf
int *result; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

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

canonical_decompiled_code:
int *__fastcall func8(__int64 a1, __int64 a2)
{
bool v2; // zf
int *result; // rax
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

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


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

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

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

clnt_res_0 = 0;
v5[0] = a1;
v5[1] = a2;
v3 = (**(unsigned int (__fastcall ***)(__int64, __int64, __int64 (__fastcall *)(XDR *), int *, bool_t (*)(XDR *, int *), int *, __int64, _QWORD))(a3 + 8))(
a3,
3LL,
xdr_add_1_argument,
v5,
xdr_int,
&clnt_res_0,
TIMEOUT,
0LL) == 0;
result = &clnt_res_0;
if ( !v3 )
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; // rbx
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; // rbx
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)
{
__int64 v1; // rbx
int result; // eax

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

canonical_decompiled_code:
int __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

if ( *(int *)(a1 + 400) > 0 )
{
v1 = 1LL;
do
result = printf("%d\n", *(unsigned int *)(a1 + 4 * v1++));
while ( *(_DWORD *)(a1 + 400) >= (int)v1 );
}
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 v2; // ebp
__int64 result; // rax

v2 = 2 * a2;
result = *(unsigned int *)(a1 + 400);
if ( 2 * a2 <= (int)result && *(_DWORD *)(a1 + 4LL * a2) > *(_DWORD *)(a1 + 4LL * v2) )
{
if ( v2 < (int)result )
{
result = (unsigned int)(v2 + 1);
if ( *(_DWORD *)(a1 + 4LL * v2) > *(_DWORD *)(a1 + 4LL * (int)result) )
++v2;
}
goto LABEL_9;
}
if ( v2 < (int)result )
{
++v2;
result = a2;
if ( *(_DWORD *)(a1 + 4LL * a2) > *(_DWORD *)(a1 + 4LL * v2) )
{
LABEL_9:
if ( v2 != a2 )
{
swap((_DWORD *)(a1 + 4LL * a2), (_DWORD *)(a1 + 4LL * v2));
result = minify(a1, (unsigned int)v2);
}
return result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
int v2; // ebp
__int64 result; // rax

v2 = 2 * a2;
result = *(unsigned int *)(a1 + 400);
if ( 2 * a2 <= (int)result && *(_DWORD *)(a1 + 4LL * a2) > *(_DWORD *)(a1 + 4LL * v2) )
{
if ( v2 < (int)result )
{
result = (unsigned int)(v2 + 1);
if ( *(_DWORD *)(a1 + 4LL * v2) > *(_DWORD *)(a1 + 4LL * (int)result) )
++v2;
}
goto LABEL_9;
}
if ( v2 < (int)result )
{
++v2;
result = a2;
if ( *(_DWORD *)(a1 + 4LL * a2) > *(_DWORD *)(a1 + 4LL * v2) )
{
LABEL_9:
if ( v2 != a2 )
{
func8((_DWORD *)(a1 + 4LL * a2), (_DWORD *)(a1 + 4LL * v2));
result = func9(a1, (unsigned int)v2);
}
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 *


decompiled_code:
__int64 __fastcall heap_decrease_key(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // er12
__int64 v5; // rdx
int v6; // ebp
int v7; // esi

result = a2;
if ( *(_DWORD *)(a1 + 4LL * a2) > a3 )
{
v4 = a2;
*(_DWORD *)(a1 + 4LL * a2) = a3;
if ( a2 > 1 )
{
do
{
v5 = v4;
v6 = v4;
v7 = v4 / 2;
v4 = v7;
result = *(unsigned int *)(a1 + 4LL * v7);
if ( *(_DWORD *)(a1 + 4 * v5) >= (int)result )
break;
result = swap((_DWORD *)(a1 + 4LL * v6), (_DWORD *)(a1 + 4LL * v7));
}
while ( v6 > 3 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2, int a3)
{
__int64 result; // rax
int v4; // er12
__int64 v5; // rdx
int v6; // ebp
int v7; // esi

result = a2;
if ( *(_DWORD *)(a1 + 4LL * a2) > a3 )
{
v4 = a2;
*(_DWORD *)(a1 + 4LL * a2) = a3;
if ( a2 > 1 )
{
do
{
v5 = v4;
v6 = v4;
v7 = v4 / 2;
v4 = v7;
result = *(unsigned int *)(a1 + 4LL * v7);
if ( *(_DWORD *)(a1 + 4 * v5) >= (int)result )
break;
result = func8((_DWORD *)(a1 + 4LL * v6), (_DWORD *)(a1 + 4LL * v7));
}
while ( v6 > 3 );
}
}
return result;
}

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 v2; // ebx

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

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

result = *(unsigned int *)(a1 + 400);
v2 = *(_DWORD *)(a1 + 400) / 2;
if ( (int)result > 1 )
{
do
result = func9(a1, v2--);
while ( v2 > 0 );
}
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:
_DWORD *make_heap()
{
_DWORD *v0; // rdx

v0 = malloc(0x194uLL);
memset(v0, 0, 0x190uLL);
v0[100] = 0;
return v0;
}

canonical_decompiled_code:
_DWORD *func15()
{
_DWORD *v0; // rdx

v0 = malloc(0x194uLL);
memset(v0, 0, 0x190uLL);
v0[100] = 0;
return v0;
}

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; // rbx
unsigned int v5; // [rsp+8h] [rbp-10h]
unsigned int v6[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, v5);
puts("after insert :");
print_heap(v3);
heap_extract_min(v3, v6);
printf("min:%d\n", v6[0]);
puts("after one extract min");
print_heap(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
unsigned int v5; // [rsp+8h] [rbp-10h]
unsigned int v6[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, v5);
puts("after insert :");
func7(v3);
func11(v3, v6);
printf("min:%d\n", v6[0]);
puts("after one extract min");
func7(v3);
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 i; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, int a2)
{
__int64 i; // rbx

if ( a2 <= 0 )
return 0LL;
for ( i = 0LL; i != a2; ++i )
printf("%dth:%d\n", (unsigned int)i, *(unsigned int *)(a1 + 4 * i));
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; // r13
__int64 v5; // rsi
int v6; // ebx
__int64 result; // rax
int *v8; // rbp
int *v9; // r12
int v10; // ebx
__int64 v11; // rsi

v4 = stack_init();
stack_push_key(v4, a3);
stack_push_key(v4, a2);
while ( 1 )
{
result = stack_is_empty(v4);
if ( (_DWORD)result )
break;
v8 = (int *)stack_pop(v4);
v9 = (int *)stack_pop(v4);
v10 = partition(a1, *v8, *v9);
v11 = (unsigned int)(v10 - 1);
if ( *v8 < (int)v11 )
{
stack_push_key(v4, v11);
stack_push_key(v4, (unsigned int)*v8);
}
v5 = (unsigned int)*v9;
v6 = v10 + 1;
if ( (int)v5 > v6 )
{
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; // r13
__int64 v5; // rsi
int v6; // ebx
__int64 result; // rax
int *v8; // rbp
int *v9; // r12
int v10; // ebx
__int64 v11; // rsi

v4 = func11();
func13(v4, a3);
func13(v4, a2);
while ( 1 )
{
result = func15(v4);
if ( (_DWORD)result )
break;
v8 = (int *)func14(v4);
v9 = (int *)func14(v4);
v10 = func9(a1, *v8, *v9);
v11 = (unsigned int)(v10 - 1);
if ( *v8 < (int)v11 )
{
func13(v4, v11);
func13(v4, (unsigned int)*v8);
}
v5 = (unsigned int)*v9;
v6 = v10 + 1;
if ( (int)v5 > v6 )
{
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;
*(_QWORD *)(a1 + 8) = a2;
++*(_DWORD *)a1;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a2 + 8) = result;
*(_QWORD *)(a1 + 8) = a2;
++*(_DWORD *)a1;
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

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:
_QWORD *stack_init()
{
_QWORD *result; // rax

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

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

result = malloc(0x10uLL);
if ( !result )
{
printf("error malloc:%s:%d\n", "stack.c", 9LL);
exit(-1);
}
*result = 0LL;
result[1] = 0LL;
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

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

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

result = *(_QWORD *)(a1 + 8);
if ( result )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)(result + 8);
--*(_DWORD *)a1;
}
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)
{
unsigned int v5; // er13

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

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

if ( (int)a2 < a3 )
{
v5 = ((int)a2 + a3) / 2;
func9(a1, a2, v5++);
func9(a1, v5, (unsigned int)a3);
func8(a1, a2, v5, 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;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
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;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = 0;
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; // ecx
int v3; // edx
__int64 result; // rax
unsigned int v5; // eax
int v6; // edx
__int64 v7; // rt2

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

canonical_decompiled_code:
__int64 __fastcall func12(int *a1, _DWORD *a2)
{
int v2; // ecx
int v3; // edx
__int64 result; // rax
unsigned int v5; // eax
int v6; // edx
__int64 v7; // rt2

*(_DWORD *)(*((_QWORD *)a1 + 2) + 4LL * a1[2]) = *a2;
v2 = *a1;
v3 = (a1[2] + 1) % *a1;
a1[2] = v3;
result = (unsigned int)a1[1];
if ( v3 == (_DWORD)result )
{
v6 = ((int)result + 1) >> 31;
v5 = result + 1;
v7 = __SPAIR64__(v6, v5) % v2;
result = (unsigned int)(__SPAIR64__(v6, v5) / v2);
a1[1] = v7;
}
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 *


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;
}
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 func7(_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;
}
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

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

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

v2 = malloc(0x18uLL);
if ( !v2 )
return 0xFFFFFFFFLL;
*a1 = v2;
*v2 = v2[1];
v2[2] = a2;
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:
__int64 __fastcall rbtree_traverse(__int64 a1, __int64 a2)
{
__int64 result; // rax

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

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

if ( a1 != a2 )
{
func10(*(_QWORD *)a1, a2);
printf("key : %d color :%d\n", *(unsigned int *)(a1 + 24), *(unsigned int *)(a1 + 28));
result = func10(*(_QWORD *)(a1 + 8), 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); } *


original_code:
void
rbtree_fixup_delete(rbtree_t *rbtree,rbtree_node_t *node)
{
 rbtree_node_t * temp,*subst;
 rbtree_node_t * w;
 int red = 0;
    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;
    }
     temp->parent = subst->parent;
    if(subst->parent == rbtree->sentinel)
     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;
    }
    red = ( (subst)->color == 1);
    if(1 == red){
     printf("delete red node\n");
     return ;
    }
    while((temp != rbtree->root) && (( (temp)->color == 0)) ){
     if(temp == temp->parent->left){
      w = temp->parent->right;
      if(( (w)->color == 1)){
       ( (w)->color = 0);
       ( (temp->parent)->color = 1);
       rbtree_left_rotate(&rbtree->root,rbtree->sentinel,temp->parent);
       w = temp->parent->right;
      }
      if(( (w->right)->color == 0) && ( (w->left)->color == 0)){
       ( (w)->color = 1);
       temp = temp->parent;
      }else {
       if(( (w->right)->color == 0)){
        ( (w->left)->color = 0);
           ( (temp->parent)->color = 1);
           rbtree_right_rotate(&rbtree->root,rbtree->sentinel,w);
           w = temp->parent->right;
          }
    ( (w)->color = (temp->parent)->color );
    ( (temp->parent)->color = 0);
    ( (w->right)->color = 0);
    rbtree_left_rotate(&rbtree->root,rbtree->sentinel,temp->parent);
    temp = rbtree->root;
      }
     }else {
      w = temp->parent->left;
      if(( (w)->color == 1)){
       ( (w)->color = 0);
       ( (temp->parent)->color = 1);
       rbtree_right_rotate(&rbtree->root,rbtree->sentinel,temp->parent);
          w = temp->parent->left;
      }
      if(( (w->right)->color == 0) && ( (w->left)->color == 0)){
       ( (w)->color = 1);
          temp = temp->parent;
       }else {
        if(( (w->left)->color == 0)){
        ( (w->right)->color = 0);
     ( (temp->parent)->color = 1);
     rbtree_left_rotate(&rbtree->root,rbtree->sentinel,w);
     w = temp->parent->left;
          }
     ( (w)->color = (temp->parent)->color );
     ( (temp->parent)->color = 0);
     ( (w->left)->color = 0);
     rbtree_right_rotate(&rbtree->root,rbtree->sentinel,temp->parent);
     temp = rbtree->root;
       }
     }
    }
    ( (temp)->color = 0);
}

canonical_original_code:
void rbtree_fixup_delete(struct rbtree_s *rbtree, struct rbtree_node_s *node)
{
 struct rbtree_node_s *temp; struct rbtree_node_s *subst;
 struct rbtree_node_s *w;
 int red = 0;
    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;
    }
     temp->parent = subst->parent;
    if(subst->parent == rbtree->sentinel)
     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;
    }
    red = ( (subst)->color == 1);
    if(1 == red){
     printf("delete red node\n");
     return ;
    }
    while((temp != rbtree->root) && (( (temp)->color == 0)) ){
     if(temp == temp->parent->left){
      w = temp->parent->right;
      if(( (w)->color == 1)){
       ( (w)->color = 0);
       ( (temp->parent)->color = 1);
       rbtree_left_rotate(&rbtree->root,rbtree->sentinel,temp->parent);
       w = temp->parent->right;
      }
      if(( (w->right)->color == 0) && ( (w->left)->color == 0)){
       ( (w)->color = 1);
       temp = temp->parent;
      }else {
       if(( (w->right)->color == 0)){
        ( (w->left)->color = 0);
           ( (temp->parent)->color = 1);
           rbtree_right_rotate(&rbtree->root,rbtree->sentinel,w);
           w = temp->parent->right;
          }
    ( (w)->color = (temp->parent)->color );
    ( (temp->parent)->color = 0);
    ( (w->right)->color = 0);
    rbtree_left_rotate(&rbtree->root,rbtree->sentinel,temp->parent);
    temp = rbtree->root;
      }
     }else {
      w = temp->parent->left;
      if(( (w)->color == 1)){
       ( (w)->color = 0);
       ( (temp->parent)->color = 1);
       rbtree_right_rotate(&rbtree->root,rbtree->sentinel,temp->parent);
          w = temp->parent->left;
      }
      if(( (w->right)->color == 0) && ( (w->left)->color == 0)){
       ( (w)->color = 1);
          temp = temp->parent;
       }else {
        if(( (w->left)->color == 0)){
        ( (w->right)->color = 0);
     ( (temp->parent)->color = 1);
     rbtree_left_rotate(&rbtree->root,rbtree->sentinel,w);
     w = temp->parent->left;
          }
     ( (w)->color = (temp->parent)->color );
     ( (temp->parent)->color = 0);
     ( (w->left)->color = 0);
     rbtree_right_rotate(&rbtree->root,rbtree->sentinel,temp->parent);
     temp = rbtree->root;
       }
     }
    }
    ( (temp)->color = 0);
}

variable_types: red int

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


decompiled_code:
_QWORD *init_double_link()
{
_QWORD *result; // rax

result = calloc(1uLL, 0x18uLL);
if ( !result )
err_exit("calloc error\n");
*result = result;
result[1] = result;
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *result; // rax

result = calloc(1uLL, 0x18uLL);
if ( !result )
func7("calloc error\n");
*result = result;
result[1] = result;
return result;
}

original_code:
dll_t *
init_double_link( )
{
    dll_t *dll;
    dll = (dll_t*)calloc(1,sizeof(dll_t));
    if(dll == ((void *)0)) {
        err_exit("calloc error\n");
    }
    dll->prev = dll;
    dll->next = dll;
    return dll;
}

canonical_original_code:
struct dll_s *init_double_link()
{
    struct dll_s *dll;
    dll = (struct dll_s *)calloc(1,sizeof(dll_t));
    if(dll == ((void *)0)) {
        err_exit("calloc error\n");
    }
    dll->prev = dll;
    dll->next = dll;
    return dll;
}

variable_types: struct dll_s { struct dll_s *prev; struct dll_s *next; int key; } *


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

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

original_code:
dll_t *
search_last_element_dll(dll_t *dll)
{
    return dll->prev;
}

canonical_original_code:
struct dll_s *search_last_element_dll(struct dll_s *dll)
{
    return dll->prev;
}

variable_types:
dll
struct dll_s *

return_type: struct dll_s { struct dll_s *prev; struct dll_s *next; int key; } *


original_code:
int
insert_elem_double_link(dll_t *dll, dll_t *new_elem)
{
    dll_t *last_elem;
    last_elem = search_last_element_dll(dll);
    new_elem->next = last_elem->next;
    last_elem->next->prev = new_elem;
    last_elem->next = new_elem;
    new_elem->prev = last_elem;
    return 0;
}

canonical_original_code:
int insert_elem_double_link(struct dll_s *dll, struct dll_s *new_elem)
{
    struct dll_s *last_elem;
    last_elem = search_last_element_dll(dll);
    new_elem->next = last_elem->next;
    last_elem->next->prev = new_elem;
    last_elem->next = new_elem;
    new_elem->prev = last_elem;
    return 0;
}

user_defined_types: struct dll_s { struct dll_s *prev; struct dll_s *next; int key; }


original_code:
int
insert_key_double_link(dll_t *dll, int key)
{
    dll_t *last_elem,*new_elem;
    new_elem = (dll_t*)calloc(1,sizeof(dll_t));
    if(new_elem == ((void *)0)) {
        err_exit("calloc error\n");
    }
    new_elem->key = key;
    last_elem = search_last_element_dll(dll);
    new_elem->next = last_elem->next;
    last_elem->next->prev = new_elem;
    last_elem->next = new_elem;
    new_elem->prev = last_elem;
    return 0;
}

canonical_original_code:
int insert_key_double_link(struct dll_s *dll, int key)
{
    struct dll_s *last_elem; struct dll_s *new_elem;
    new_elem = (struct dll_s *)calloc(1,sizeof(dll_t));
    if(new_elem == ((void *)0)) {
        err_exit("calloc error\n");
    }
    new_elem->key = key;
    last_elem = search_last_element_dll(dll);
    new_elem->next = last_elem->next;
    last_elem->next->prev = new_elem;
    last_elem->next = new_elem;
    new_elem->prev = last_elem;
    return 0;
}

variable_types: key int


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

result = *(_QWORD *)(a1 + 8);
if ( a1 == result )
return 0LL;
while ( *(_DWORD *)(result + 16) != a2 )
{
result = *(_QWORD *)(result + 8);
if ( a1 == result )
return 0LL;
}
if ( a1 == result )
result = 0LL;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
if ( a1 == result )
return 0LL;
while ( *(_DWORD *)(result + 16) != a2 )
{
result = *(_QWORD *)(result + 8);
if ( a1 == result )
return 0LL;
}
if ( a1 == result )
result = 0LL;
return result;
}

original_code:
dll_t *
search_double_link(dll_t *dll, int value)
{
     dll_t *tmp;
     tmp = dll->next;
     while(tmp != dll) {
         if(tmp->key == value) {
            break;
         }
         tmp = tmp->next;
     }
     if(tmp == dll) {
        tmp = ((void *)0);
     }
     return tmp;
}

canonical_original_code:
struct dll_s *search_double_link(struct dll_s *dll, int value)
{
     struct dll_s *tmp;
     tmp = dll->next;
     while(tmp != dll) {
         if(tmp->key == value) {
            break;
         }
         tmp = tmp->next;
     }
     if(tmp == dll) {
        tmp = ((void *)0);
     }
     return tmp;
}

variable_types: value int


decompiled_code:
__int64 __fastcall delete_element(_QWORD *a1, __int64 a2)
{
_QWORD *v3; // rdi
__int64 result; // rax
_QWORD *v5; // rax

v3 = (_QWORD *)a1[1];
if ( a1 == v3 )
goto LABEL_4;
while ( *((_DWORD *)v3 + 4) != (_DWORD)a2 )
{
v3 = (_QWORD *)v3[1];
if ( a1 == v3 )
goto LABEL_4;
}
if ( a1 == v3 )
{
LABEL_4:
printf("NO %d value\n", a2);
result = 0LL;
}
else
{
v5 = (_QWORD *)v3[1];
*(_QWORD *)(*v3 + 8LL) = v5;
*v5 = *v3;
free(v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1, __int64 a2)
{
_QWORD *v3; // rdi
__int64 result; // rax
_QWORD *v5; // rax

v3 = (_QWORD *)a1[1];
if ( a1 == v3 )
goto LABEL_4;
while ( *((_DWORD *)v3 + 4) != (_DWORD)a2 )
{
v3 = (_QWORD *)v3[1];
if ( a1 == v3 )
goto LABEL_4;
}
if ( a1 == v3 )
{
LABEL_4:
printf("NO %d value\n", a2);
result = 0LL;
}
else
{
v5 = (_QWORD *)v3[1];
*(_QWORD *)(*v3 + 8LL) = v5;
*v5 = *v3;
free(v3);
result = 1LL;
}
return result;
}

original_code:
int
delete_element(dll_t *dll, int value)
{
    int res;
    dll_t *tmp;
    tmp = dll->next;
     while(tmp != dll) {
         if(tmp->key == value) {
            break;
         }
         tmp = tmp->next;
     }
     if(tmp != dll) {
        tmp->prev->next = tmp->next;
        tmp->next->prev = tmp->prev;
        free(tmp);
        res = 1;
     } else {
        printf("NO %d value\n",value);
        res = 0;
     }
     return res;
}

canonical_original_code:
int delete_element(struct dll_s *dll, int value)
{
    int res;
    struct dll_s *tmp;
    tmp = dll->next;
     while(tmp != dll) {
         if(tmp->key == value) {
            break;
         }
         tmp = tmp->next;
     }
     if(tmp != dll) {
        tmp->prev->next = tmp->next;
        tmp->next->prev = tmp->prev;
        free(tmp);
        res = 1;
     } else {
        printf("NO %d value\n",value);
        res = 0;
     }
     return res;
}

variable_types: res 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", "double_linked_list.c", 16LL);
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", "double_linked_list.c", 16LL);
vprintf(format, arg);
exit(0);
}

original_code:
void
err_exit(char *fmt,...)
{
    va_list va;
    __builtin_va_start(va,fmt);
    printf("%s:%d","double_linked_list.c",16);
    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","double_linked_list.c",16);
    vprintf(fmt,va);
    __builtin_va_end(va);
    exit(0);
}

variable_types:
fmt
char *


traverse

decompiled_code:
int __fastcall traverse(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
int result; // eax

v1 = *(_QWORD *)(a1 + 8);
if ( a1 != v1 )
{
v2 = 0;
do
{
result = printf("%dth key:%d\n", v2++, *(unsigned int *)(v1 + 16));
v1 = *(_QWORD *)(v1 + 8);
}
while ( a1 != v1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // ebp
int result; // eax

v1 = *(_QWORD *)(a1 + 8);
if ( a1 != v1 )
{
v2 = 0;
do
{
result = printf("%dth key:%d\n", v2++, *(unsigned int *)(v1 + 16));
v1 = *(_QWORD *)(v1 + 8);
}
while ( a1 != v1 );
}
return result;
}

original_code:
void
traverse(dll_t *dll)
{
    int i;
    dll_t *tmp;
    i = 0;
    tmp = dll->next;
    while(tmp != dll) {
        printf("%dth key:%d\n",i,tmp->key);
        i++;
        tmp = tmp->next;
   }
    return;
}

canonical_original_code:
void traverse(struct dll_s *dll)
{
    int i;
    struct dll_s *tmp;
    i = 0;
    tmp = dll->next;
    while(tmp != dll) {
        printf("%dth key:%d\n",i,tmp->key);
        i++;
        tmp = tmp->next;
   }
    return;
}

variable_types: i int


bfs

decompiled_code:
__int64 __fastcall bfs(unsigned int a1)
{
__int64 v1; // r13
int *v2; // rax
int *v3; // rdx
int v4; // ebx
unsigned __int64 v5; // rbp
int *v6; // r12

v1 = queue_init();
if ( g_node_total > 0 )
{
v2 = g_traverse;
v3 = &g_traverse[3 * (g_node_total - 1) + 3];
do
{
v2[2] = 0;
v2[1] = 0;
*v2 = 9999;
v2 += 3;
}
while ( v2 != v3 );
}
g_traverse[3 * a1] = 0;
insert_value_queue(v1, a1);
while ( !(unsigned int)queue_is_empty(v1) )
{
v6 = (int *)dequeue(v1);
if ( g_node_total > 0 )
{
v5 = (unsigned int)((_DWORD)g_traverse + 12);
v4 = 1;
do
{
if ( g_graph[100 * *v6 + v4] )
{
if ( !*(_DWORD *)(v5 + 8) )
{
*(_DWORD *)v5 = g_traverse[3 * *v6] + 1;
*(_DWORD *)(v5 + 8) = 1;
*(_DWORD *)(v5 + 4) = *v6;
insert_value_queue(v1, (unsigned int)v4);
}
}
++v4;
v5 += 12LL;
}
while ( g_node_total >= v4 );
}
g_traverse[3 * *v6 + 2] = 2;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 v1; // r13
int *v2; // rax
int *v3; // rdx
int v4; // ebx
unsigned __int64 v5; // rbp
int *v6; // r12

v1 = queue_init();
if ( g_node_total > 0 )
{
v2 = g_traverse;
v3 = &g_traverse[3 * (g_node_total - 1) + 3];
do
{
v2[2] = 0;
v2[1] = 0;
*v2 = 9999;
v2 += 3;
}
while ( v2 != v3 );
}
g_traverse[3 * a1] = 0;
insert_value_queue(v1, a1);
while ( !(unsigned int)queue_is_empty(v1) )
{
v6 = (int *)dequeue(v1);
if ( g_node_total > 0 )
{
v5 = (unsigned int)((_DWORD)g_traverse + 12);
v4 = 1;
do
{
if ( g_graph[100 * *v6 + v4] )
{
if ( !*(_DWORD *)(v5 + 8) )
{
*(_DWORD *)v5 = g_traverse[3 * *v6] + 1;
*(_DWORD *)(v5 + 8) = 1;
*(_DWORD *)(v5 + 4) = *v6;
insert_value_queue(v1, (unsigned int)v4);
}
}
++v4;
v5 += 12LL;
}
while ( g_node_total >= v4 );
}
g_traverse[3 * *v6 + 2] = 2;
}
return 1LL;
}

original_code:
int bfs(int source)
{
    int i;
    queue_t *queue;
    queue_node_t *node;
    queue = queue_init();
    for(i = 0; i < g_node_total; i++) {
        g_traverse[i].color = white;
        g_traverse[i].parent = 0;
        g_traverse[i].distance = 9999;
    }
    g_traverse[source].distance = 0;
    insert_value_queue(queue,source);
    while(!queue_is_empty(queue)) {
        node = dequeue(queue);
        for(i= 1; i <= g_node_total; i++){
            if(g_graph[node->key][i] && (g_traverse[i].color == white)){
                g_traverse[i].distance = g_traverse[node->key].distance + 1;
                g_traverse[i].color = grey;
                g_traverse[i].parent = node->key;
                insert_value_queue(queue,i);
            }
        }
        g_traverse[node->key].color = black;
    }
    return 1;
}

canonical_original_code:
int bfs(int source)
{
    int i;
    struct queue_s *queue;
    struct queue_node_s *node;
    queue = queue_init();
    for(i = 0; i < g_node_total; i++) {
        g_traverse[i].color = white;
        g_traverse[i].parent = 0;
        g_traverse[i].distance = 9999;
    }
    g_traverse[source].distance = 0;
    insert_value_queue(queue,source);
    while(!queue_is_empty(queue)) {
        node = dequeue(queue);
        for(i= 1; i <= g_node_total; i++){
            if(g_graph[node->key][i] && (g_traverse[i].color == white)){
                g_traverse[i].distance = g_traverse[node->key].distance + 1;
                g_traverse[i].color = grey;
                g_traverse[i].parent = node->key;
                insert_value_queue(queue,i);
            }
        }
        g_traverse[node->key].color = black;
    }
    return 1;
}

variable_types: source int

variable_types: struct queue_s { struct queue_node_s { int key; struct queue_node_s *next; } *head; } *

user_defined_types: struct queue_s { struct queue_node_s *head; }


decompiled_code:
int __fastcall Print_Path(__int64 a1, unsigned int a2)
{
if ( (_DWORD)a1 == a2 )
return printf("%d", (unsigned int)a1);
if ( !g_traverse[3 * a2] )
return printf("No path from %d to %d\n", (unsigned int)a1, a2);
Print_Path(a1, (unsigned int)g_traverse[3 * a2 + 1]);
return printf("-> %d", a2);
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned int a2)
{
if ( (_DWORD)a1 == a2 )
return printf("%d", (unsigned int)a1);
if ( !g_traverse[3 * a2] )
return printf("No path from %d to %d\n", (unsigned int)a1, a2);
func1(a1, (unsigned int)g_traverse[3 * a2 + 1]);
return printf("-> %d", a2);
}

original_code:
void Print_Path(int sourse,int vertex)
{
    if(sourse == vertex)
        printf("%d",sourse);
    else if(g_traverse[vertex].distance == 0)
        printf("No path from %d to %d\n",sourse,vertex);
    else
    {
        Print_Path(sourse,g_traverse[vertex].parent);
        printf("-> %d",vertex);
    }
}

canonical_original_code:
void Print_Path(int sourse, int vertex)
{
    if(sourse == vertex)
        printf("%d",sourse);
    else if(g_traverse[vertex].distance == 0)
        printf("No path from %d to %d\n",sourse,vertex);
    else
    {
        Print_Path(sourse,g_traverse[vertex].parent);
        printf("-> %d",vertex);
    }
}

variable_types: sourse int

variable_types: vertex int


decompiled_code:
__int64 __fastcall max_heapify(__int64 a1, unsigned int a2, unsigned int a3)
{
int v3; // er12
unsigned int v4; // eax
__int64 result; // rax

v3 = a3;
v4 = 2 * a3;
if ( 2 * a3 <= a2 && *(_DWORD *)(a1 + 4LL * v4) > *(_DWORD *)(a1 + 4LL * a3) )
v3 = 2 * a3;
result = v4 + 1;
if ( a2 >= (unsigned int)result && *(_DWORD *)(a1 + 4LL * (unsigned int)result) > *(_DWORD *)(a1 + 4LL * v3) )
v3 = result;
if ( v3 != a3 )
{
swap((_DWORD *)(a1 + 4LL * v3), (_DWORD *)(a1 + 4LL * a3));
result = max_heapify(a1, a2, (unsigned int)v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2, unsigned int a3)
{
int v3; // er12
unsigned int v4; // eax
__int64 result; // rax

v3 = a3;
v4 = 2 * a3;
if ( 2 * a3 <= a2 && *(_DWORD *)(a1 + 4LL * v4) > *(_DWORD *)(a1 + 4LL * a3) )
v3 = 2 * a3;
result = v4 + 1;
if ( a2 >= (unsigned int)result && *(_DWORD *)(a1 + 4LL * (unsigned int)result) > *(_DWORD *)(a1 + 4LL * v3) )
v3 = result;
if ( v3 != a3 )
{
func7((_DWORD *)(a1 + 4LL * v3), (_DWORD *)(a1 + 4LL * a3));
result = func8(a1, a2, (unsigned int)v3);
}
return result;
}

original_code:
void max_heapify(int *array, int array_len, unsigned int i)
{
    int max;
    max = i;
    if(2*i <= array_len && array[2*i] > *(array +i))
        max = 2*i;
    if (2*i+1 <= array_len && array[2*i+1] > *(array+max))
        max = 2*i + 1;
    if (max != i){
        swap(array+max, array+i);
        max_heapify(array,array_len,max);
    }
}

variable_types:
array
int *

variable_types:
i
unsigned int

variable_types: max int


decompiled_code:
__int64 __fastcall build_heap(__int64 a1, signed int a2)
{
int v2; // ebx
__int64 result; // rax

v2 = a2 / 2;
if ( a2 > 1 )
{
do
result = max_heapify(a1, a2, v2--);
while ( v2 > 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, signed int a2)
{
int v2; // ebx
__int64 result; // rax

v2 = a2 / 2;
if ( a2 > 1 )
{
do
result = func8(a1, a2, v2--);
while ( v2 > 0 );
}
return result;
}

original_code:
void build_heap(int *array, int len)
{
    int i;
    for (i = len / 2; i > 0; i--) {
        max_heapify(array,len,i);
    }
}

variable_types: len int