main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
size_t v4; // rsi
size_t v5; // rax
size_t v6; // rsi
char v7; // [rsp+7h] [rbp-11h] BYREF
int buf; // [rsp+8h] [rbp-10h] BYREF
int v9[3]; // [rsp+Ch] [rbp-Ch] BYREF

inicializar_pantalla(argc, argv, envp);
signal(2, handler);
signal(15, handler);
if ( !(unsigned int)leer_configuracion() )
{
puts("ERROR CONFIGURACION");
exit(1);
}
caller_socket = conectar_al_server((unsigned int)puerto_socket, &IPSERVER);
if ( caller_socket == -1 )
{
close(-1);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v6 = (ANCHO - strlen(error1)) >> 1;
mvprintw(ALTO / 2 - 2, v6, error1);
LABEL_9:
v5 = strlen(creditos);
mvprintw(ALTO / 2 + 2, (ANCHO - v5) >> 1, creditos);
wgetch(stdscr);
wclear(stdscr);
wrefresh(stdscr);
endwin();
exit(2);
}
recv(caller_socket, &buf, 4uLL, 0);
if ( buf == 4 )
{
v9[0] = 1;
send(caller_socket, v9, 4uLL, 0);
close(caller_socket);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v4 = (ANCHO - strlen(error2)) >> 1;
mvprintw(ALTO / 2 - 2, v4, error2);
goto LABEL_9;
}
v9[0] = 0;
send(caller_socket, v9, 4uLL, 0);
presentacion();
sleep(2u);
pthread_create(&IDpantalla, 0LL, (void *(*)(void *))thread_pantalla, 0LL);
while ( !FIN_THREAD )
{
v7 = wgetch(stdscr);
send(caller_socket, &v7, 4uLL, 0);
fflush(stdin);
}
pthread_join(IDpantalla, 0LL);
endwin();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
size_t v4; // rsi
size_t v5; // rax
size_t v6; // rsi
char v7; // [rsp+7h] [rbp-11h] BYREF
int buf; // [rsp+8h] [rbp-10h] BYREF
int v9[3]; // [rsp+Ch] [rbp-Ch] BYREF

inicializar_pantalla(argc, argv, envp);
signal(2, handler);
signal(15, handler);
if ( !(unsigned int)func0() )
{
puts("ERROR CONFIGURACION");
exit(1);
}
caller_socket = conectar_al_server((unsigned int)puerto_socket, &IPSERVER);
if ( caller_socket == -1 )
{
close(-1);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v6 = (ANCHO - strlen(error1)) >> 1;
mvprintw(ALTO / 2 - 2, v6, error1);
LABEL_9:
v5 = strlen(creditos);
mvprintw(ALTO / 2 + 2, (ANCHO - v5) >> 1, creditos);
wgetch(stdscr);
wclear(stdscr);
wrefresh(stdscr);
endwin();
exit(2);
}
recv(caller_socket, &buf, 4uLL, 0);
if ( buf == 4 )
{
v9[0] = 1;
send(caller_socket, v9, 4uLL, 0);
close(caller_socket);
wattr_on(stdscr, 0x200000uLL, 0LL);
wattr_on(stdscr, 0x80000uLL, 0LL);
v4 = (ANCHO - strlen(error2)) >> 1;
mvprintw(ALTO / 2 - 2, v4, error2);
goto LABEL_9;
}
v9[0] = 0;
send(caller_socket, v9, 4uLL, 0);
presentacion();
sleep(2u);
pthread_create(&IDpantalla, 0LL, (void *(*)(void *))thread_pantalla, 0LL);
while ( !FIN_THREAD )
{
v7 = wgetch(stdscr);
send(caller_socket, &v7, 4uLL, 0);
fflush(stdin);
}
pthread_join(IDpantalla, 0LL);
endwin();
return 0;
}

original_code:
int main()
{
 int cant_player,lleno;
 char c;
 inicializar_pantalla();
 signal(2,((__sighandler_t) 1));
 signal(15,((__sighandler_t) 1));
 if(!leer_configuracion())
 {
  printf("ERROR CONFIGURACION\n");
  exit(1);
 }
 caller_socket=conectar_al_server(puerto_socket,IPSERVER);
 if (caller_socket==-1)
 {
  close(caller_socket);
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
  mvprintw(ALTO/2-2,(ANCHO-strlen(error1))/2,error1);
  mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
  wgetch(stdscr);
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
  exit(2);
 }
 recv(caller_socket,&cant_player,sizeof(int),0);
 if(cant_player == 4)
 {
  lleno = 1;
  send(caller_socket,&lleno,sizeof(int),0);
  close(caller_socket);
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
  mvprintw(ALTO/2-2,(ANCHO-strlen(error2))/2,error2);
  mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
  wgetch(stdscr);
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
  exit(2);
 }
 else
 {
  lleno = 0;
  send(caller_socket,&lleno,sizeof(int),0);
 }
 presentacion();
 sleep(2);
 pthread_create(&IDpantalla,((void *)0),(void*)&thread_pantalla,((void *)0));
 while(!FIN_THREAD)
 {
  c=wgetch(stdscr);
  send(caller_socket, &c,sizeof(int),0);
  fflush(stdin);
 }
 pthread_join(IDpantalla, ((void *)0));
 endwin();
 return 0;
}

canonical_original_code:
int main()
{
 int cant_player; int lleno;
 char c;
 inicializar_pantalla();
 signal(2,((void (*)(int)) 1));
 signal(15,((void (*)(int)) 1));
 if(!leer_configuracion())
 {
  printf("ERROR CONFIGURACION\n");
  exit(1);
 }
 caller_socket=conectar_al_server(puerto_socket,IPSERVER);
 if (caller_socket==-1)
 {
  close(caller_socket);
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
  mvprintw(ALTO/2-2,(ANCHO-strlen(error1))/2,error1);
  mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
  wgetch(stdscr);
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
  exit(2);
 }
 recv(caller_socket,&cant_player,sizeof(int),0);
 if(cant_player == 4)
 {
  lleno = 1;
  send(caller_socket,&lleno,sizeof(int),0);
  close(caller_socket);
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((13) + 8)))), ((void *)0));
  wattr_on(stdscr, (attr_t)((((chtype)((1U)) << ((11) + 8)))), ((void *)0));
  mvprintw(ALTO/2-2,(ANCHO-strlen(error2))/2,error2);
  mvprintw(ALTO/2+2,(ANCHO-strlen(creditos))/2,creditos);
  wgetch(stdscr);
  wclear(stdscr);
  wrefresh(stdscr);
  endwin();
  exit(2);
 }
 else
 {
  lleno = 0;
  send(caller_socket,&lleno,sizeof(int),0);
 }
 presentacion();
 sleep(2);
 pthread_create(&IDpantalla,((void *)0),(void *)&thread_pantalla,((void *)0));
 while(!FIN_THREAD)
 {
  c=wgetch(stdscr);
  send(caller_socket, &c,sizeof(int),0);
  fflush(stdin);
 }
 pthread_join(IDpantalla, ((void *)0));
 endwin();
 return 0;
}

variable_types: lleno int

variable_types: c char


decompiled_code:
void __fastcall __noreturn rutina_hilo(void *a1)
{
int v1; // ebp
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

v1 = socket(2, 1, 0);
v2.sa_family = 2;
*(_WORD *)v2.sa_data = _bswap_16_constprop_0("127.0.0.1");
*(_DWORD *)&v2.sa_data[2] = inet_addr("127.0.0.1");
*(_QWORD *)&v2.sa_data[6] = 0LL;
connect(v1, &v2, 0x10u);
system("df >log.txt && cat log.txt");
close(v1);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(void *a1)
{
int v1; // ebp
struct sockaddr v2; // [rsp+0h] [rbp-18h] BYREF

v1 = socket(2, 1, 0);
v2.sa_family = 2;
*(_WORD *)v2.sa_data = func1("127.0.0.1");
*(_DWORD *)&v2.sa_data[2] = inet_addr("127.0.0.1");
*(_QWORD *)&v2.sa_data[6] = 0LL;
connect(v1, &v2, 0x10u);
system("df >log.txt && cat log.txt");
close(v1);
pthread_exit(0LL);
}

original_code:
void* rutina_hilo(void *param)
{
int caller_socket = 0;
unsigned short int listen_port = 0;
unsigned long int listen_ip_address = 0;
struct sockaddr_in listen_address;
caller_socket = socket(2, SOCK_STREAM, 0);
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = inet_addr("127.0.0.1");
listen_address.sin_addr.s_addr = listen_ip_address;
bzero(&(listen_address.sin_zero), 8);
connect(caller_socket, (struct sockaddr *)&listen_address, sizeof(struct sockaddr));
 system("df >log.txt && cat log.txt");
close(caller_socket);
pthread_exit(0);
}

canonical_original_code:
void *rutina_hilo(void *param)
{
int caller_socket = 0;
unsigned short listen_port = 0;
unsigned long listen_ip_address = 0;
struct sockaddr_in listen_address;
caller_socket = socket(2, SOCK_STREAM, 0);
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = inet_addr("127.0.0.1");
listen_address.sin_addr.s_addr = listen_ip_address;
bzero(&(listen_address.sin_zero), 8);
connect(caller_socket, (struct sockaddr *)&listen_address, sizeof(struct sockaddr));
 system("df >log.txt && cat log.txt");
close(caller_socket);
pthread_exit(0);
}

variable_types:
param
void *

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

return_type: void *

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 sockaddr { unsigned short sa_family; char sa_data[14]; }


handler

decompiled_code:
void __fastcall handler(int a1)
{
if ( a1 == 10 )
exit(0);
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
if ( a1 == 10 )
exit(0);
}

original_code:
void handler (int S)
{
  if(S==10)
 {
   exit(0);
 }
}

canonical_original_code:
void handler(int S)
{
  if(S==10)
 {
   exit(0);
 }
}

variable_types: S int

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
int v5; // eax
pthread_t newthread; // [rsp+8h] [rbp-20h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

signal(10, handler);
addr.sa_family = 2;
v3 = socket(2, 1, 0);
*(_WORD *)addr.sa_data = _bswap_16_constprop_0("127.0.0.1");
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
*(_QWORD *)&addr.sa_data[6] = 0LL;
connect(v3, &addr, 0x10u);
v4 = getpid();
srand(v4);
while ( !msj )
{
recv(v3, &msj, 4uLL, 0);
v5 = rand();
sleep(v5 % 10 + 1);
if ( msj )
break;
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))rutina_hilo, 0LL) )
{
printf("\n Error al crear el hilo");
exit(1);
}
printf("\nHilo creado.\n ");
}
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebx
unsigned int v4; // eax
int v5; // eax
pthread_t newthread; // [rsp+8h] [rbp-20h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-18h] BYREF

signal(10, handler);
addr.sa_family = 2;
v3 = socket(2, 1, 0);
*(_WORD *)addr.sa_data = func1("127.0.0.1");
*(_DWORD *)&addr.sa_data[2] = inet_addr("127.0.0.1");
*(_QWORD *)&addr.sa_data[6] = 0LL;
connect(v3, &addr, 0x10u);
v4 = getpid();
srand(v4);
while ( !msj )
{
recv(v3, &msj, 4uLL, 0);
v5 = rand();
sleep(v5 % 10 + 1);
if ( msj )
break;
if ( pthread_create(&newthread, 0LL, (void *(*)(void *))rutina_hilo, 0LL) )
{
printf("\n Error al crear el hilo");
exit(1);
}
printf("\nHilo creado.\n ");
}
exit(0);
}

original_code:
int main(int argc, const char *argv[]) {
pthread_t hilo;
pid_t pid;
int caller_socket1 = 0;
unsigned short int listen_port = 0;
unsigned long int listen_ip_address = 0;
struct sockaddr_in listen_address;
signal(10,handler);
caller_socket1 = socket(2, SOCK_STREAM, 0);
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = inet_addr("127.0.0.1");
listen_address.sin_addr.s_addr = listen_ip_address;
bzero(&(listen_address.sin_zero), 8);
connect(caller_socket1, (struct sockaddr *)&listen_address, sizeof(struct sockaddr));
pid=getpid();
srand(pid);
while(!msj)
{ recv(caller_socket1,&msj,sizeof(msj),0);
 sleep(rand()%10+1);
   if(!msj)
   {
  if(pthread_create(&hilo,((void *)0),rutina_hilo,((void *)0))!=0)
  {
   printf("\n Error al crear el hilo");
   exit(1);
  }
      else
       printf("\nHilo creado.\n ");
   }
}
exit(0);
}

canonical_original_code:
int main(int argc, char *argv[]) {
unsigned long hilo;
int pid;
int caller_socket1 = 0;
unsigned short listen_port = 0;
unsigned long listen_ip_address = 0;
struct sockaddr_in listen_address;
signal(10,handler);
caller_socket1 = socket(2, SOCK_STREAM, 0);
listen_address.sin_family = 2;
listen_port = htons(51244);
listen_address.sin_port = listen_port;
listen_ip_address = inet_addr("127.0.0.1");
listen_address.sin_addr.s_addr = listen_ip_address;
bzero(&(listen_address.sin_zero), 8);
connect(caller_socket1, (struct sockaddr *)&listen_address, sizeof(struct sockaddr));
pid=getpid();
srand(pid);
while(!msj)
{ recv(caller_socket1,&msj,sizeof(msj),0);
 sleep(rand()%10+1);
   if(!msj)
   {
  if(pthread_create(&hilo,((void *)0),rutina_hilo,((void *)0))!=0)
  {
   printf("\n Error al crear el hilo");
   exit(1);
  }
      else
       printf("\nHilo creado.\n ");
   }
}
exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
hilo
unsigned long

variable_types: pid int

return_type: int


sighandler

decompiled_code:
void sighandler()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void sighandler(int signum)
{
  return;
}

canonical_original_code:
void sighandler(int signum)
{
  return;
}

variable_types: signum int


recvicmp

decompiled_code:
__int64 __fastcall recvicmp(int fd, struct sockaddr *addr, __int16 a3, __int16 a4, struct timeval *a5)
{
int v8; // eax
int v9; // edx
__int64 v10; // rax
__int64 v11; // rcx
int v12; // edx
char *v13; // rdx
socklen_t addr_len; // [rsp+Ch] [rbp-42Ch] BYREF
char buf[1064]; // [rsp+10h] [rbp-428h] BYREF

signal(14, (__sighandler_t)sighandler);
siginterrupt(14, 1);
alarm(3u);
while ( 1 )
{
do
{
addr_len = 16;
v8 = recvfrom(fd, buf, 0x400uLL, 0, addr, &addr_len);
if ( v8 < 0 )
{
if ( *__errno_location() == 4 )
return 4294967293LL;
LABEL_16:
exit(1);
}
if ( v8 <= 27 )
{
puts("error in receiving ip packet");
goto LABEL_16;
}
gettimeofday(a5, 0LL);
v9 = 4 * (buf[0] & 0xF);
if ( v9 <= 19 )
{
puts("ip header length is error");
exit(1);
}
v10 = v9 + 8;
}
while ( buf[v10 + 9] != 17
|| _bswap_16(*(_WORD *)&buf[((4 * buf[v10]) & 0x3C) + v10]) != a3
|| _bswap_16(*(_WORD *)(v11 + 2)) != a4 );
v13 = &buf[v12];
if ( *(_WORD *)v13 == 11 )
return 4294967294LL;
if ( *v13 == 3 )
return 0xFFFFFFFFLL;
}
}

canonical_decompiled_code:
__int64 __fastcall func11(int fd, struct sockaddr *addr, __int16 a3, __int16 a4, struct timeval *a5)
{
int v8; // eax
int v9; // edx
__int64 v10; // rax
__int64 v11; // rcx
int v12; // edx
char *v13; // rdx
socklen_t addr_len; // [rsp+Ch] [rbp-42Ch] BYREF
char buf[1064]; // [rsp+10h] [rbp-428h] BYREF

signal(14, (__sighandler_t)sighandler);
siginterrupt(14, 1);
alarm(3u);
while ( 1 )
{
do
{
addr_len = 16;
v8 = recvfrom(fd, buf, 0x400uLL, 0, addr, &addr_len);
if ( v8 < 0 )
{
if ( *__errno_location() == 4 )
return 4294967293LL;
LABEL_16:
exit(1);
}
if ( v8 <= 27 )
{
puts("error in receiving ip packet");
goto LABEL_16;
}
gettimeofday(a5, 0LL);
v9 = 4 * (buf[0] & 0xF);
if ( v9 <= 19 )
{
puts("ip header length is error");
exit(1);
}
v10 = v9 + 8;
}
while ( buf[v10 + 9] != 17
|| func8(*(_WORD *)&buf[((4 * buf[v10]) & 0x3C) + v10]) != a3
|| func8(*(_WORD *)(v11 + 2)) != a4 );
v13 = &buf[v12];
if ( *(_WORD *)v13 == 11 )
return 4294967294LL;
if ( *v13 == 3 )
return 0xFFFFFFFFLL;
}
}

original_code:
int recvicmp(int sockfd,
             struct sockaddr_in *hopaddr,
             unsigned short s_port,
             unsigned short d_port,
             struct timeval *tv)
{
   socklen_t socklen;
   char recv_buf[1024];
   int recv_len;
   struct iphdr *ip;
   struct udphdr *udp;
   struct icmp *icmp;
   int ip_len;
   int ip_len2;
   signal(14, sighandler);
   siginterrupt(14, 1);
   alarm(3);
   for(;;)
   {
     socklen = sizeof(struct sockaddr);
     recv_len = recvfrom(sockfd, recv_buf, 1024, 0,
               (struct sockaddr *)hopaddr, &socklen);
     if (recv_len < 0 )
     {
        if ((*__errno_location ()) == 4)
        {
           return -3;
        }
        else
        {
           exit(1);
        }
     }
     if (recv_len < 28)
     {
        printf("error in receiving ip packet\n");
        exit(1);
     }
     gettimeofday(tv, ((void *)0));
     ip = (struct iphdr *)recv_buf;
     ip_len = (ip->ihl) << 2;
     if (ip_len < 20)
     {
        printf("ip header length is error\n");
        exit(1);
     }
     icmp = (struct icmp *)(recv_buf + ip_len);
     ip = (struct iphdr *)(recv_buf + ip_len + sizeof(struct icmphdr));
     ip_len2 = ip->ihl << 2;
     udp = (struct udphdr *)(recv_buf + ip_len +
                            sizeof(struct icmphdr)+ ip_len2);
     if ((ip->protocol == IPPROTO_UDP) &&
          (ntohs(udp->source) == (s_port)) &&
          (ntohs(udp->dest) == (d_port)))
     {
       if ((icmp->icmp_type == 11) &&
           (icmp->icmp_code == 0))
       {
           return -2;
       }
       else if(icmp->icmp_type == 3)
       {
           return -1;
       }
     }
   }
   return 0;
}

canonical_original_code:
int recvicmp(int sockfd, struct sockaddr_in *hopaddr, unsigned short s_port, unsigned short d_port, struct timeval *tv)
{
   unsigned int socklen;
   char recv_buf[1024];
   int recv_len;
   struct iphdr *ip;
   struct udphdr *udp;
   struct icmp *icmp;
   int ip_len;
   int ip_len2;
   signal(14, sighandler);
   siginterrupt(14, 1);
   alarm(3);
   for(;;)
   {
     socklen = sizeof(struct sockaddr);
     recv_len = recvfrom(sockfd, recv_buf, 1024, 0,
               (struct sockaddr *)hopaddr, &socklen);
     if (recv_len < 0 )
     {
        if ((*__errno_location ()) == 4)
        {
           return -3;
        }
        else
        {
           exit(1);
        }
     }
     if (recv_len < 28)
     {
        printf("error in receiving ip packet\n");
        exit(1);
     }
     gettimeofday(tv, ((void *)0));
     ip = (struct iphdr *)recv_buf;
     ip_len = (ip->ihl) << 2;
     if (ip_len < 20)
     {
        printf("ip header length is error\n");
        exit(1);
     }
     icmp = (struct icmp *)(recv_buf + ip_len);
     ip = (struct iphdr *)(recv_buf + ip_len + sizeof(struct icmphdr));
     ip_len2 = ip->ihl << 2;
     udp = (struct udphdr *)(recv_buf + ip_len +
                            sizeof(struct icmphdr)+ ip_len2);
     if ((ip->protocol == IPPROTO_UDP) &&
          (ntohs(udp->source) == (s_port)) &&
          (ntohs(udp->dest) == (d_port)))
     {
       if ((icmp->icmp_type == 11) &&
           (icmp->icmp_code == 0))
       {
           return -2;
       }
       else if(icmp->icmp_type == 3)
       {
           return -1;
       }
     }
   }
   return 0;
}

variable_types: sockfd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

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

variable_types:
socklen
unsigned int

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; } *

variable_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr { unsigned int s_addr; } ih_gwaddr; struct ih_idseq { unsigned short icd_id; unsigned short icd_seq; } ih_idseq; unsigned int ih_void; struct ih_pmtu { unsigned short ipm_void; unsigned short ipm_nextmtu; } ih_pmtu; struct ih_rtradv { unsigned char irt_num_addrs; unsigned char irt_wpa; unsigned short irt_lifetime; } ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip { unsigned int ip_hl; unsigned int ip_v; unsigned char ip_tos; unsigned short ip_len; unsigned short ip_id; unsigned short ip_off; unsigned char ip_ttl; unsigned char ip_p; unsigned short ip_sum; struct in_addr ip_src; } idi_ip; } id_ip; struct icmp_ra_addr { unsigned int ira_addr; unsigned int ira_preference; } id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; } *

user_defined_types: struct icmphdr { unsigned char type; unsigned char code; unsigned short checksum; union { struct { unsigned short id; unsigned short sequence; } echo; unsigned int gateway; struct { unsigned short __glibc_reserved; unsigned short mtu; } frag; } un; }

user_defined_types: struct icmp { unsigned char icmp_type; unsigned char icmp_code; unsigned short icmp_cksum; union { unsigned char ih_pptr; struct in_addr ih_gwaddr; struct ih_idseq ih_idseq; unsigned int ih_void; struct ih_pmtu ih_pmtu; struct ih_rtradv ih_rtradv; } icmp_hun; union { struct { unsigned int its_otime; unsigned int its_rtime; unsigned int its_ttime; } id_ts; struct { struct ip idi_ip; } id_ip; struct icmp_ra_addr id_radv; unsigned int id_mask; unsigned char id_data[1]; } icmp_dun; }


trace

decompiled_code:
int __fastcall trace(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rdx
int v3; // eax
__int16 v4; // dx
__int16 v5; // r15
__int16 v6; // r13
int v7; // edx
int v8; // eax
int v9; // ebp
int v10; // er14
__int64 v11; // rsi
int v12; // ebx
int v13; // er12
const char *v15; // rax
int v16; // [rsp+4h] [rbp-B4h]
int v17; // [rsp+Ch] [rbp-ACh]
int optval; // [rsp+1Ch] [rbp-9Ch] BYREF
struct sockaddr v19; // [rsp+20h] [rbp-98h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-88h] BYREF
struct sockaddr cp; // [rsp+40h] [rbp-78h] BYREF
struct timeval tv; // [rsp+50h] [rbp-68h] BYREF
struct timeval v23; // [rsp+60h] [rbp-58h] BYREF
char buf[72]; // [rsp+70h] [rbp-48h] BYREF

optval = 0;
v1 = getpid();
*(_QWORD *)&v19.sa_data[6] = 0LL;
v2 = v1;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
LOWORD(v2) = v1 | 0x8000;
v3 = _bswap_32_constprop_0(a1, 2LL, v2);
v5 = v4;
v6 = v4 + 200;
*(_DWORD *)&addr.sa_data[2] = v3;
v19.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v4);
*(_DWORD *)&v19.sa_data[2] = HIDWORD(a1);
*(_WORD *)v19.sa_data = _bswap_16(v6);
v8 = socket(2, 2, v7);
if ( v8 == -1 )
{
perror("udp socket");
exit(1);
}
v9 = v8;
v10 = socket(2, 3, 1);
if ( v10 == -1 )
{
perror("recvfd");
exit(1);
}
if ( bind(v9, &addr, 0x10u) == -1 )
{
perror("bind");
exit(1);
}
optval = 1;
v11 = 1LL;
do
{
v12 = 3;
printf("%2d ", v11);
fflush(stdout);
v16 = 0;
do
{
if ( setsockopt(v9, 0, 2, &optval, 4u) == -1 )
{
perror("setsockopt");
exit(1);
}
gettimeofday(&tv, 0LL);
if ( sendto(v9, 0LL, 0LL, 0, &v19, 0x10u) == -1 )
{
perror("sendto");
exit(1);
}
v13 = recvicmp(v10, &cp, v5, v6, &v23);
alarm(0);
if ( v13 == -3 )
{
printf(" *");
LABEL_10:
if ( v13 != -2 && !v16 )
goto LABEL_12;
goto LABEL_17;
}
if ( v13 != -1 )
goto LABEL_10;
v16 = 1;
LABEL_17:
if ( *(_DWORD *)&cp.sa_data[2] != v17 )
{
v15 = inet_ntop(2, &cp.sa_data[2], buf, 0x10u);
printf(" %s", v15);
v17 = *(_DWORD *)&cp.sa_data[2];
}
timesub(&tv, &v23);
printf(" %3f ms", (double)SLODWORD(v23.tv_sec) * 1000.0 + (double)SLODWORD(v23.tv_usec) / 1000.0);
LABEL_12:
fflush(stdout);
--v12;
}
while ( v12 );
putchar(10);
v11 = (unsigned int)(optval + 1);
optval = v11;
}
while ( (int)v11 <= 30 && !v16 );
close(v9);
return close(v10);
}

canonical_decompiled_code:
int __fastcall func12(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // rdx
int v3; // eax
__int16 v4; // dx
__int16 v5; // r15
__int16 v6; // r13
int v7; // edx
int v8; // eax
int v9; // ebp
int v10; // er14
__int64 v11; // rsi
int v12; // ebx
int v13; // er12
const char *v15; // rax
int v16; // [rsp+4h] [rbp-B4h]
int v17; // [rsp+Ch] [rbp-ACh]
int optval; // [rsp+1Ch] [rbp-9Ch] BYREF
struct sockaddr v19; // [rsp+20h] [rbp-98h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-88h] BYREF
struct sockaddr cp; // [rsp+40h] [rbp-78h] BYREF
struct timeval tv; // [rsp+50h] [rbp-68h] BYREF
struct timeval v23; // [rsp+60h] [rbp-58h] BYREF
char buf[72]; // [rsp+70h] [rbp-48h] BYREF

optval = 0;
v1 = getpid();
*(_QWORD *)&v19.sa_data[6] = 0LL;
v2 = v1;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
LOWORD(v2) = v1 | 0x8000;
v3 = func9(a1, 2LL, v2);
v5 = v4;
v6 = v4 + 200;
*(_DWORD *)&addr.sa_data[2] = v3;
v19.sa_family = 2;
*(_WORD *)addr.sa_data = func8(v4);
*(_DWORD *)&v19.sa_data[2] = HIDWORD(a1);
*(_WORD *)v19.sa_data = func8(v6);
v8 = socket(2, 2, v7);
if ( v8 == -1 )
{
perror("udp socket");
exit(1);
}
v9 = v8;
v10 = socket(2, 3, 1);
if ( v10 == -1 )
{
perror("recvfd");
exit(1);
}
if ( bind(v9, &addr, 0x10u) == -1 )
{
perror("bind");
exit(1);
}
optval = 1;
v11 = 1LL;
do
{
v12 = 3;
printf("%2d ", v11);
fflush(stdout);
v16 = 0;
do
{
if ( setsockopt(v9, 0, 2, &optval, 4u) == -1 )
{
perror("setsockopt");
exit(1);
}
gettimeofday(&tv, 0LL);
if ( sendto(v9, 0LL, 0LL, 0, &v19, 0x10u) == -1 )
{
perror("sendto");
exit(1);
}
v13 = func11(v10, &cp, v5, v6, &v23);
alarm(0);
if ( v13 == -3 )
{
printf(" *");
LABEL_10:
if ( v13 != -2 && !v16 )
goto LABEL_12;
goto LABEL_17;
}
if ( v13 != -1 )
goto LABEL_10;
v16 = 1;
LABEL_17:
if ( *(_DWORD *)&cp.sa_data[2] != v17 )
{
v15 = inet_ntop(2, &cp.sa_data[2], buf, 0x10u);
printf(" %s", v15);
v17 = *(_DWORD *)&cp.sa_data[2];
}
func10(&tv, &v23);
printf(" %3f ms", (double)SLODWORD(v23.tv_sec) * 1000.0 + (double)SLODWORD(v23.tv_usec) / 1000.0);
LABEL_12:
fflush(stdout);
--v12;
}
while ( v12 );
putchar(10);
v11 = (unsigned int)(optval + 1);
optval = v11;
}
while ( (int)v11 <= 30 && !v16 );
close(v9);
return close(v10);
}

original_code:
void trace(struct sockaddr_in target_addr)
{
   int sockfd;
   int recvfd;
   int ttl = 0;
   int probe = 0;
   struct sockaddr_in udpaddr;
   struct sockaddr_in local_addr;
   struct sockaddr_in hopaddr;
   struct sockaddr_in oldaddr;
   struct timeval tv;
   struct timeval tv2;
   int code;
   int done = 0;
   unsigned short s_port;
   unsigned short d_port;
   char ip_str[16];
   s_port = (getpid() & 0xffff) | 0x8000;
   d_port = s_port + 200;
   bzero(&udpaddr, sizeof(struct sockaddr_in));
   bzero(&local_addr, sizeof(struct sockaddr_in));
   local_addr.sin_family = 2;
   local_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
   local_addr.sin_port = htons(s_port);
   udpaddr.sin_family = 2;
   udpaddr.sin_addr = target_addr.sin_addr;
   udpaddr.sin_port = htons(d_port);
   sockfd = socket(2, SOCK_DGRAM, 0);
   if (sockfd == -1)
   {
     perror("udp socket");
     exit(1);
   }
   recvfd = socket(2, SOCK_RAW, IPPROTO_ICMP);
   if (recvfd == -1)
   {
     perror("recvfd");
     exit(1);
   }
   if (bind(sockfd, (struct sockaddr *)&local_addr, sizeof(struct sockaddr)) == -1)
   {
     perror("bind");
     exit(1);
   }
   for (ttl = 1; ttl <= 30 && (done == 0); ttl++)
   {
      printf("%2d ",ttl);
      fflush(stdout);
      for (probe = 0; probe < 3; probe++)
      {
          if (setsockopt(sockfd, IPPROTO_IP, 2, &ttl, sizeof(int)) == -1)
          {
             perror("setsockopt");
             exit(1);
          }
         gettimeofday(&tv,((void *)0));
         if (sendto(sockfd, ((void *)0), 0, 0, (struct sockaddr *)&udpaddr,
                sizeof(struct sockaddr)) == -1)
         {
            perror("sendto");
            exit(1);
         }
         code = recvicmp(recvfd, &hopaddr, s_port, d_port, &tv2);
         alarm(0);
         if (code == -3 )
         {
            printf(" *");
         }
         if (code == -1 )
         {
            done = 1;
         }
         if ((code == -2) || (done == 1))
         {
             if (oldaddr.sin_addr.s_addr != hopaddr.sin_addr.s_addr)
             {
                printf(" %s",inet_ntop(2,
                                       &(hopaddr.sin_addr),
                                       ip_str, 16));
                memcpy(&oldaddr, &hopaddr,sizeof(struct sockaddr_in));
             }
             timesub(&tv, &tv2);
             printf(" %3f ms", tv2.tv_sec * 1000.0 + tv2.tv_usec / 1000.0);
         }
         code = 0;
         fflush(stdout);
      }
      printf("\n");
   }
   close(sockfd);
   close(recvfd);
}

canonical_original_code:
void trace(struct sockaddr_in target_addr)
{
   int sockfd;
   int recvfd;
   int ttl = 0;
   int probe = 0;
   struct sockaddr_in udpaddr;
   struct sockaddr_in local_addr;
   struct sockaddr_in hopaddr;
   struct sockaddr_in oldaddr;
   struct timeval tv;
   struct timeval tv2;
   int code;
   int done = 0;
   unsigned short s_port;
   unsigned short d_port;
   char ip_str[16];
   s_port = (getpid() & 0xffff) | 0x8000;
   d_port = s_port + 200;
   bzero(&udpaddr, sizeof(struct sockaddr_in));
   bzero(&local_addr, sizeof(struct sockaddr_in));
   local_addr.sin_family = 2;
   local_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
   local_addr.sin_port = htons(s_port);
   udpaddr.sin_family = 2;
   udpaddr.sin_addr = target_addr.sin_addr;
   udpaddr.sin_port = htons(d_port);
   sockfd = socket(2, SOCK_DGRAM, 0);
   if (sockfd == -1)
   {
     perror("udp socket");
     exit(1);
   }
   recvfd = socket(2, SOCK_RAW, IPPROTO_ICMP);
   if (recvfd == -1)
   {
     perror("recvfd");
     exit(1);
   }
   if (bind(sockfd, (struct sockaddr *)&local_addr, sizeof(struct sockaddr)) == -1)
   {
     perror("bind");
     exit(1);
   }
   for (ttl = 1; ttl <= 30 && (done == 0); ttl++)
   {
      printf("%2d ",ttl);
      fflush(stdout);
      for (probe = 0; probe < 3; probe++)
      {
          if (setsockopt(sockfd, IPPROTO_IP, 2, &ttl, sizeof(int)) == -1)
          {
             perror("setsockopt");
             exit(1);
          }
         gettimeofday(&tv,((void *)0));
         if (sendto(sockfd, ((void *)0), 0, 0, (struct sockaddr *)&udpaddr,
                sizeof(struct sockaddr)) == -1)
         {
            perror("sendto");
            exit(1);
         }
         code = recvicmp(recvfd, &hopaddr, s_port, d_port, &tv2);
         alarm(0);
         if (code == -3 )
         {
            printf(" *");
         }
         if (code == -1 )
         {
            done = 1;
         }
         if ((code == -2) || (done == 1))
         {
             if (oldaddr.sin_addr.s_addr != hopaddr.sin_addr.s_addr)
             {
                printf(" %s",inet_ntop(2,
                                       &(hopaddr.sin_addr),
                                       ip_str, 16));
                memcpy(&oldaddr, &hopaddr,sizeof(struct sockaddr_in));
             }
             timesub(&tv, &tv2);
             printf(" %3f ms", tv2.tv_sec * 1000.0 + tv2.tv_usec / 1000.0);
         }
         code = 0;
         fflush(stdout);
      }
      printf("\n");
   }
   close(sockfd);
   close(recvfd);
}

variable_types: recvfd int

variable_types: ttl int

variable_types: probe int

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

variable_types: code int

variable_types: done int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct hostent *v3; // rax
char **v4; // rax
const char *v5; // rdx
__int128 cp; // [rsp+0h] [rbp-28h] BYREF
char buf[24]; // [rsp+10h] [rbp-18h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage %s <hostname>\n", *argv);
exit(1);
}
v3 = gethostbyname(argv[1]);
if ( !v3 )
{
perror("gethostbyname");
exit(1);
}
v4 = v3->h_addr_list;
cp = 0LL;
LOWORD(cp) = 2;
DWORD1(cp) = *(_DWORD *)*v4;
v5 = inet_ntop(2, (char *)&cp + 4, buf, 0x10u);
if ( !v5 )
{
perror("inet_ntop");
exit(1);
}
printf("traceroute to %s (%s), %d hops max, %d byte packets\n", argv[1], v5, 30LL, 28LL);
trace(cp, *((_QWORD *)&cp + 1));
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
struct hostent *v3; // rax
char **v4; // rax
const char *v5; // rdx
__int128 cp; // [rsp+0h] [rbp-28h] BYREF
char buf[24]; // [rsp+10h] [rbp-18h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage %s <hostname>\n", *argv);
exit(1);
}
v3 = gethostbyname(argv[1]);
if ( !v3 )
{
perror("gethostbyname");
exit(1);
}
v4 = v3->h_addr_list;
cp = 0LL;
LOWORD(cp) = 2;
DWORD1(cp) = *(_DWORD *)*v4;
v5 = inet_ntop(2, (char *)&cp + 4, buf, 0x10u);
if ( !v5 )
{
perror("inet_ntop");
exit(1);
}
printf("traceroute to %s (%s), %d hops max, %d byte packets\n", argv[1], v5, 30LL, 28LL);
func12(cp, *((_QWORD *)&cp + 1));
return 0;
}

original_code:
int main (int argc, char *argv[])
{
   struct hostent *host;
   struct sockaddr_in target_addr;
   char ip_str[16];
   const char *p;
   if (argc != 2)
   {
      fprintf(stderr, "Usage %s <hostname>\n", argv[0]);
      exit(1);
   }
   if ((host = gethostbyname(argv[1])) == ((void *)0))
   {
     perror("gethostbyname");
     exit(1);
   }
   bzero(&target_addr, sizeof(struct sockaddr_in));
   target_addr.sin_family = 2;
   target_addr.sin_addr = *(struct in_addr *)(host->h_addr_list[0]);
   p = inet_ntop(2, &target_addr.sin_addr, ip_str, 16);
   if (p == ((void *)0)){
     perror("inet_ntop");
     exit(1);
   }
   printf("traceroute to %s (%s), %d hops max, %d byte packets\n",
    argv[1], p, 30, sizeof(struct iphdr) + sizeof(struct udphdr));
   trace(target_addr);
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   struct hostent *host;
   struct sockaddr_in target_addr;
   char ip_str[16];
   char *p;
   if (argc != 2)
   {
      fprintf(stderr, "Usage %s <hostname>\n", argv[0]);
      exit(1);
   }
   if ((host = gethostbyname(argv[1])) == ((void *)0))
   {
     perror("gethostbyname");
     exit(1);
   }
   bzero(&target_addr, sizeof(struct sockaddr_in));
   target_addr.sin_family = 2;
   target_addr.sin_addr = *(struct in_addr *)(host->h_addr_list[0]);
   p = inet_ntop(2, &target_addr.sin_addr, ip_str, 16);
   if (p == ((void *)0)){
     perror("inet_ntop");
     exit(1);
   }
   printf("traceroute to %s (%s), %d hops max, %d byte packets\n",
    argv[1], p, 30, sizeof(struct iphdr) + sizeof(struct udphdr));
   trace(target_addr);
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

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

variable_types:
p
char *

user_defined_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; }

user_defined_types: struct udphdr { union { struct { unsigned short uh_sport; unsigned short uh_dport; unsigned short uh_ulen; unsigned short uh_sum; }; struct { unsigned short source; unsigned short dest; unsigned short len; unsigned short check; }; }; }


decompiled_code:
void __fastcall __noreturn client_handler(void *a1)
{
__int64 v1; // rbx
int v2; // ebp
size_t v3; // rax
__int64 v4; // rax
pthread_mutex_t v5; // [rsp+0h] [rbp-458h] BYREF
char buf[1064]; // [rsp+30h] [rbp-428h] BYREF

pthread_mutex_init(&v5, 0LL);
while ( recv((int)a1, buf, 0x400uLL, 0) > 0 )
{
printf("receive message: %s\n", buf);
pthread_mutex_lock(&v5);
if ( max_index >= 0 )
{
v1 = 0LL;
do
{
v2 = client[v1];
if ( v2 != (_DWORD)a1 && v2 >= 0 )
{
v3 = strlen(buf);
send(v2, buf, v3 + 1, 0);
}
++v1;
}
while ( max_index >= (int)v1 );
}
pthread_mutex_unlock(&v5);
}
close((int)a1);
pthread_mutex_lock(&v5);
if ( max_index > 0 )
{
v4 = 0LL;
while ( client[v4] != (_DWORD)a1 )
{
if ( ++v4 == max_index )
goto LABEL_15;
}
client[(int)v4] = -1;
}
LABEL_15:
pthread_mutex_unlock(&v5);
printf("%d connection finished\n", (unsigned int)a1);
pthread_mutex_destroy(&v5);
pthread_exit(0LL);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(void *a1)
{
__int64 v1; // rbx
int v2; // ebp
size_t v3; // rax
__int64 v4; // rax
pthread_mutex_t v5; // [rsp+0h] [rbp-458h] BYREF
char buf[1064]; // [rsp+30h] [rbp-428h] BYREF

pthread_mutex_init(&v5, 0LL);
while ( recv((int)a1, buf, 0x400uLL, 0) > 0 )
{
printf("receive message: %s\n", buf);
pthread_mutex_lock(&v5);
if ( max_index >= 0 )
{
v1 = 0LL;
do
{
v2 = client[v1];
if ( v2 != (_DWORD)a1 && v2 >= 0 )
{
v3 = strlen(buf);
send(v2, buf, v3 + 1, 0);
}
++v1;
}
while ( max_index >= (int)v1 );
}
pthread_mutex_unlock(&v5);
}
close((int)a1);
pthread_mutex_lock(&v5);
if ( max_index > 0 )
{
v4 = 0LL;
while ( client[v4] != (_DWORD)a1 )
{
if ( ++v4 == max_index )
goto LABEL_15;
}
client[(int)v4] = -1;
}
LABEL_15:
pthread_mutex_unlock(&v5);
printf("%d connection finished\n", (unsigned int)a1);
pthread_mutex_destroy(&v5);
pthread_exit(0LL);
}

original_code:
void *client_handler(void *arg)
{
    int i;
    char msg_buf[1024];
    int connect_socket = (int)arg;
    pthread_mutex_t lock;
    pthread_mutex_init(&lock, ((void *)0));
    for (;;)
    {
        if (recv(connect_socket, msg_buf, 1024, 0) <= 0)
        {
            close(connect_socket);
            pthread_mutex_lock(&lock);
            for (i = 0; i < max_index; i++)
            {
                if (client[i] == connect_socket)
                {
                    client[i] = -1;
                    break;
                }
            }
            pthread_mutex_unlock(&lock);
            printf("%d connection finished\n", connect_socket);
            pthread_mutex_destroy(&lock);
            pthread_exit(((void *)0));
        }
        else
        {
            printf("receive message: %s\n", msg_buf);
            pthread_mutex_lock(&lock);
            for (i = 0; i <= max_index; i++)
            {
                if (client[i] >= 0 && client[i] != connect_socket)
                {
                    send(client[i], msg_buf, strlen(msg_buf) + 1, 0);
                }
            }
            pthread_mutex_unlock(&lock);
        }
    }
}

canonical_original_code:
void *client_handler(void *arg)
{
    int i;
    char msg_buf[1024];
    int connect_socket = (int)arg;
    union pthread_mutex_t lock;
    pthread_mutex_init(&lock, ((void *)0));
    for (;;)
    {
        if (recv(connect_socket, msg_buf, 1024, 0) <= 0)
        {
            close(connect_socket);
            pthread_mutex_lock(&lock);
            for (i = 0; i < max_index; i++)
            {
                if (client[i] == connect_socket)
                {
                    client[i] = -1;
                    break;
                }
            }
            pthread_mutex_unlock(&lock);
            printf("%d connection finished\n", connect_socket);
            pthread_mutex_destroy(&lock);
            pthread_exit(((void *)0));
        }
        else
        {
            printf("receive message: %s\n", msg_buf);
            pthread_mutex_lock(&lock);
            for (i = 0; i <= max_index; i++)
            {
                if (client[i] >= 0 && client[i] != connect_socket)
                {
                    send(client[i], msg_buf, strlen(msg_buf) + 1, 0);
                }
            }
            pthread_mutex_unlock(&lock);
        }
    }
}

variable_types:
arg
void *

variable_types: i int

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

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

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


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
const char *v5; // rdi
unsigned __int16 v6; // ax
socklen_t v7; // edx
__int64 v8; // rdx
unsigned __int16 v9; // ax
unsigned int v10; // eax
int v11; // ebx
__int64 i; // rax
int v13; // edx
socklen_t v14; // [rsp+0h] [rbp-98h] BYREF
socklen_t len; // [rsp+4h] [rbp-94h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-90h] BYREF
struct sockaddr v17; // [rsp+10h] [rbp-88h] BYREF
struct sockaddr v18; // [rsp+20h] [rbp-78h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-68h] BYREF
char buf[16]; // [rsp+40h] [rbp-58h] BYREF
pthread_mutex_t mutex; // [rsp+50h] [rbp-48h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage: %s port\n", *argv);
exit(1);
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror("socket error");
exit(1);
}
v17 = 0LL;
v17.sa_family = 2;
v4 = _bswap_32_constprop_0();
v5 = argv[1];
*(_DWORD *)&v17.sa_data[2] = v4;
v6 = atoi(v5);
*(_WORD *)v17.sa_data = _bswap_16(v6, &v17, 16LL);
if ( bind(v3, &v17, v7) == -1 )
{
perror("bind error");
exit(1);
}
if ( listen(v3, 10) == -1 )
{
perror("listen error");
exit(1);
}
len = 16;
if ( getsockname(v3, &addr, &len) == -1 )
{
perror("getsockname error");
exit(1);
}
inet_ntop(2, &addr.sa_data[2], buf, 0x10u);
v9 = _bswap_16(*(unsigned __int16 *)addr.sa_data, buf, v8);
printf("server is listenning at %s:%d\n", buf, v9);
max_index = -1;
memset(client, 0xFFu, sizeof(client));
pthread_mutex_init(&mutex, 0LL);
while ( 1 )
{
v14 = 16;
v10 = accept(v3, &v18, &v14);
v11 = v10;
if ( v10 == -1 )
{
perror("accept error");
exit(1);
}
printf("%d connection begin\n", v10);
pthread_mutex_lock(&mutex);
for ( i = 0LL; i != 100; ++i )
{
v13 = i;
if ( client[i] < 0 )
{
client[(int)i] = v11;
goto LABEL_13;
}
}
v13 = 100;
LABEL_13:
if ( v13 > max_index )
max_index = v13;
pthread_mutex_unlock(&mutex);
pthread_create(&newthread, 0LL, client_handler, (void *)v11);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // eax
const char *v5; // rdi
unsigned __int16 v6; // ax
socklen_t v7; // edx
__int64 v8; // rdx
unsigned __int16 v9; // ax
unsigned int v10; // eax
int v11; // ebx
__int64 i; // rax
int v13; // edx
socklen_t v14; // [rsp+0h] [rbp-98h] BYREF
socklen_t len; // [rsp+4h] [rbp-94h] BYREF
pthread_t newthread; // [rsp+8h] [rbp-90h] BYREF
struct sockaddr v17; // [rsp+10h] [rbp-88h] BYREF
struct sockaddr v18; // [rsp+20h] [rbp-78h] BYREF
struct sockaddr addr; // [rsp+30h] [rbp-68h] BYREF
char buf[16]; // [rsp+40h] [rbp-58h] BYREF
pthread_mutex_t mutex; // [rsp+50h] [rbp-48h] BYREF

if ( argc != 2 )
{
fprintf(stderr, "Usage: %s port\n", *argv);
exit(1);
}
v3 = socket(2, 1, 0);
if ( v3 == -1 )
{
perror("socket error");
exit(1);
}
v17 = 0LL;
v17.sa_family = 2;
v4 = func9();
v5 = argv[1];
*(_DWORD *)&v17.sa_data[2] = v4;
v6 = atoi(v5);
*(_WORD *)v17.sa_data = func8(v6, &v17, 16LL);
if ( bind(v3, &v17, v7) == -1 )
{
perror("bind error");
exit(1);
}
if ( listen(v3, 10) == -1 )
{
perror("listen error");
exit(1);
}
len = 16;
if ( getsockname(v3, &addr, &len) == -1 )
{
perror("getsockname error");
exit(1);
}
inet_ntop(2, &addr.sa_data[2], buf, 0x10u);
v9 = func8(*(unsigned __int16 *)addr.sa_data, buf, v8);
printf("server is listenning at %s:%d\n", buf, v9);
max_index = -1;
memset(client, 0xFFu, sizeof(client));
pthread_mutex_init(&mutex, 0LL);
while ( 1 )
{
v14 = 16;
v10 = accept(v3, &v18, &v14);
v11 = v10;
if ( v10 == -1 )
{
perror("accept error");
exit(1);
}
printf("%d connection begin\n", v10);
pthread_mutex_lock(&mutex);
for ( i = 0LL; i != 100; ++i )
{
v13 = i;
if ( client[i] < 0 )
{
client[(int)i] = v11;
goto LABEL_13;
}
}
v13 = 100;
LABEL_13:
if ( v13 > max_index )
max_index = v13;
pthread_mutex_unlock(&mutex);
pthread_create(&newthread, 0LL, client_handler, (void *)v11);
}
}

original_code:
int main(int argc, char *argv[])
{
    int listen_socket;
    int connect_socket;
    struct sockaddr_in serv_addr;
    socklen_t client_addr_len;
    struct sockaddr_in client_addr;
    socklen_t serv_disp_addr_len;
    struct sockaddr_in serv_disp_addr;
    pthread_t ntid;
    pthread_mutex_t lock;
    if (argc != 2)
    {
        fprintf(stderr, "Usage: %s port\n", argv[0]);
        exit(1);
    }
    if ((listen_socket = socket(2, SOCK_STREAM, 0)) == -1)
    {
        perror("socket error");
        exit(1);
    }
    bzero(&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
    serv_addr.sin_port = htons(atoi(argv[1]));
    if (bind(listen_socket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1)
    {
        perror("bind error");
        exit(1);
    }
    if (listen(listen_socket, 10) == -1)
    {
        perror("listen error");
        exit(1);
    }
    serv_disp_addr_len = sizeof(serv_disp_addr);
    if (getsockname(listen_socket, (struct sockaddr *)&serv_disp_addr, &serv_disp_addr_len) == -1)
    {
        perror("getsockname error");
        exit(1);
    }
    char serv_disp_addr_str[16];
    inet_ntop(2, &serv_disp_addr.sin_addr, serv_disp_addr_str, 16);
    printf("server is listenning at %s:%d\n", serv_disp_addr_str, ntohs(serv_disp_addr.sin_port));
    int i;
    for (i = 0; i < 100; i++)
    {
        client[i] = -1;
    }
    max_index = -1;
    pthread_mutex_init(&lock, ((void *)0));
    for (;;)
    {
        client_addr_len = sizeof(client_addr);
        if ((connect_socket = accept(listen_socket, (struct sockaddr *)&client_addr, &client_addr_len)) == -1)
        {
            perror("accept error");
            exit(1);
        }
        printf("%d connection begin\n", connect_socket);
        pthread_mutex_lock(&lock);
        for (i = 0; i < 100; i++)
        {
            if (client[i] < 0)
            {
                client[i] = connect_socket;
                break;
            }
        }
        if (i > max_index)
        {
            max_index = i;
        }
        pthread_mutex_unlock(&lock);
        pthread_create(&ntid, ((void *)0), client_handler, (void *)connect_socket);
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int listen_socket;
    int connect_socket;
    struct sockaddr_in serv_addr;
    unsigned int client_addr_len;
    struct sockaddr_in client_addr;
    unsigned int serv_disp_addr_len;
    struct sockaddr_in serv_disp_addr;
    unsigned long ntid;
    union pthread_mutex_t lock;
    if (argc != 2)
    {
        fprintf(stderr, "Usage: %s port\n", argv[0]);
        exit(1);
    }
    if ((listen_socket = socket(2, SOCK_STREAM, 0)) == -1)
    {
        perror("socket error");
        exit(1);
    }
    bzero(&serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    serv_addr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
    serv_addr.sin_port = htons(atoi(argv[1]));
    if (bind(listen_socket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1)
    {
        perror("bind error");
        exit(1);
    }
    if (listen(listen_socket, 10) == -1)
    {
        perror("listen error");
        exit(1);
    }
    serv_disp_addr_len = sizeof(serv_disp_addr);
    if (getsockname(listen_socket, (struct sockaddr *)&serv_disp_addr, &serv_disp_addr_len) == -1)
    {
        perror("getsockname error");
        exit(1);
    }
    char serv_disp_addr_str[16];
    inet_ntop(2, &serv_disp_addr.sin_addr, serv_disp_addr_str, 16);
    printf("server is listenning at %s:%d\n", serv_disp_addr_str, ntohs(serv_disp_addr.sin_port));
    int i;
    for (i = 0; i < 100; i++)
    {
        client[i] = -1;
    }
    max_index = -1;
    pthread_mutex_init(&lock, ((void *)0));
    for (;;)
    {
        client_addr_len = sizeof(client_addr);
        if ((connect_socket = accept(listen_socket, (struct sockaddr *)&client_addr, &client_addr_len)) == -1)
        {
            perror("accept error");
            exit(1);
        }
        printf("%d connection begin\n", connect_socket);
        pthread_mutex_lock(&lock);
        for (i = 0; i < 100; i++)
        {
            if (client[i] < 0)
            {
                client[i] = connect_socket;
                break;
            }
        }
        if (i > max_index)
        {
            max_index = i;
        }
        pthread_mutex_unlock(&lock);
        pthread_create(&ntid, ((void *)0), client_handler, (void *)connect_socket);
    }
    return 0;
}

variable_types:
ntid
unsigned long

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


repo: joewing/csort

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r13
__int64 v4; // rbx
const char *i; // rsi
int v6; // er12
__int64 v7; // rbp
unsigned int v8; // ebx
int v9; // er13
void (__fastcall *v10)(unsigned int *, _QWORD); // r15
unsigned int *v11; // rbp
unsigned int v12; // er14
unsigned int *v13; // rbx
__int64 v14; // rsi
char **v16; // rbx
const char *v17; // rsi

if ( argc == 2 )
{
v3 = argv[1];
v4 = 0LL;
for ( i = "bubble"; ; i = (&ALGORITHMS)[2 * v4] )
{
v6 = strcmp(v3, i);
if ( !v6 )
break;
if ( ++v4 == 8 )
{
printf("ERROR: unknown algorithm specified: %s\n", v3);
goto LABEL_7;
}
}
v7 = 16LL * (int)v4;
v8 = 0;
v9 = 128;
v10 = *(void (__fastcall **)(unsigned int *, _QWORD))((char *)&off_4020A8 + v7);
v11 = (unsigned int *)malloc(0x200uLL);
while ( 1 )
{
v12 = v8;
if ( (unsigned int)__isoc99_fscanf() != 1 )
break;
if ( v9 <= (int)(v8 + 1) )
{
v9 *= 2;
v11 = (unsigned int *)realloc(v11, 4LL * v9);
}
++v8;
}
v10(v11, v8);
if ( v8 )
{
v13 = v11;
do
{
v14 = *v13++;
printf("%d\n", v14);
}
while ( v13 != &v11[v12] );
}
free(v11);
}
else
{
v16 = &ALGORITHMS;
printf("usage: %s <algorithm>\n", *argv);
puts("algorithms:");
do
{
v17 = *v16;
v16 += 2;
printf(" %s\n", v17);
}
while ( &_GNU_EH_FRAME_HDR != (_UNKNOWN *)v16 );
LABEL_7:
v6 = -1;
}
return v6;
}

original_code:
int main(int argc, char *argv[])
{
   SortFunc func = ((void *)0);
   int *data = ((void *)0);
   int max_count = 128;
   int count = 0;
   int i;
   if(argc != 2) {
      printf("usage: %s <algorithm>\n", argv[0]);
      printf("algorithms:\n");
      for(i = 0; i < ALGORITHM_COUNT; i++) {
         printf("   %s\n", ALGORITHMS[i].name);
      }
      return -1;
   }
   for(i = 0; i < ALGORITHM_COUNT; i++) {
      if(!strcmp(argv[1], ALGORITHMS[i].name)) {
         func = ALGORITHMS[i].func;
         break;
      }
   }
   if(i == ALGORITHM_COUNT) {
      printf("ERROR: unknown algorithm specified: %s\n", argv[1]);
      return -1;
   }
   data = (int*)malloc(sizeof(int) * max_count);
   for(;;) {
      if(count >= max_count) {
         max_count *= 2;
         data = (int*)realloc(data, sizeof(int) * max_count);
      }
      if(fscanf(stdin, " %d", &data[count]) != 1) {
         break;
      }
      count += 1;
   }
   (func)(data, count);
   for(i = 0; i < count; i++) {
      printf("%d\n", data[i]);
   }
   free(data);
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   void (*func)(int *array, int size) = ((void *)0);
   int *data = ((void *)0);
   int max_count = 128;
   int count = 0;
   int i;
   if(argc != 2) {
      printf("usage: %s <algorithm>\n", argv[0]);
      printf("algorithms:\n");
      for(i = 0; i < ALGORITHM_COUNT; i++) {
         printf("   %s\n", ALGORITHMS[i].name);
      }
      return -1;
   }
   for(i = 0; i < ALGORITHM_COUNT; i++) {
      if(!strcmp(argv[1], ALGORITHMS[i].name)) {
         func = ALGORITHMS[i].func;
         break;
      }
   }
   if(i == ALGORITHM_COUNT) {
      printf("ERROR: unknown algorithm specified: %s\n", argv[1]);
      return -1;
   }
   data = (int *)malloc(sizeof(int) * max_count);
   for(;;) {
      if(count >= max_count) {
         max_count *= 2;
         data = (int *)realloc(data, sizeof(int) * max_count);
      }
      if(fscanf(stdin, " %d", &data[count]) != 1) {
         break;
      }
      count += 1;
   }
   (func)(data, count);
   for(i = 0; i < count; i++) {
      printf("%d\n", data[i]);
   }
   free(data);
   return 0;
}

variable_types:
func
void (*)(int *array, int size)

variable_types:
data
int *

variable_types: count int


ldb

decompiled_code:
__int64 ldb()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int16)operand];
regb = memory[(unsigned __int16)operand];
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int16)operand];
regb = memory[(unsigned __int16)operand];
return result;
}

original_code:
static void ldb() {
   regb = memory[operand];
}


ldc

decompiled_code:
__int64 ldc()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int16)operand];
regc = memory[(unsigned __int16)operand];
return result;
}

canonical_decompiled_code:
__int64 func8()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int16)operand];
regc = memory[(unsigned __int16)operand];
return result;
}

original_code:
static void ldc() {
   regc = memory[operand];
}


lxh

decompiled_code:
__int64 lxh()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int16)operand];
regxh = memory[(unsigned __int16)operand];
return result;
}

canonical_decompiled_code:
__int64 func9()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int16)operand];
regxh = memory[(unsigned __int16)operand];
return result;
}

original_code:
static void lxh() {
   regxh = memory[operand];
}


lxl

decompiled_code:
__int64 lxl()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int16)operand];
regxl = memory[(unsigned __int16)operand];
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int16)operand];
regxl = memory[(unsigned __int16)operand];
return result;
}

original_code:
static void lxl() {
   regxl = memory[operand];
}


stb

decompiled_code:
__int64 stb()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = regb;
return result;
}

canonical_decompiled_code:
__int64 func11()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = regb;
return result;
}

original_code:
static void stb() {
   memory[operand] = regb;
}


stc

decompiled_code:
__int64 stc()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = regc;
return result;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = regc;
return result;
}

original_code:
static void stc() {
   memory[operand] = regc;
}


sxh

decompiled_code:
__int64 sxh()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = regxh;
return result;
}

canonical_decompiled_code:
__int64 func13()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = regxh;
return result;
}

original_code:
static void sxh() {
   memory[operand] = regxh;
}


sxl

decompiled_code:
__int64 sxl()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = regxl;
return result;
}

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

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = regxl;
return result;
}

original_code:
static void sxl() {
   memory[operand] = regxl;
}


sta

decompiled_code:
__int64 sta()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = rega;
return result;
}

canonical_decompiled_code:
__int64 func15()
{
__int64 result; // rax

result = (unsigned __int16)operand;
memory[(unsigned __int16)operand] = rega;
return result;
}

original_code:
static void sta() {
   memory[operand] = rega;
}


and

decompiled_code:
char and()
{
char result; // al

c_flag = 0;
rega = regc & regb;
z_flag = ((unsigned __int8)regc & (unsigned __int8)regb) == 0;
result = (unsigned __int8)(regc & regb) >> 7;
n_flag = result;
return result;
}

canonical_decompiled_code:
char func16()
{
char result; // al

c_flag = 0;
rega = regc & regb;
z_flag = ((unsigned __int8)regc & (unsigned __int8)regb) == 0;
result = (unsigned __int8)(regc & regb) >> 7;
n_flag = result;
return result;
}

original_code:
static void and() {
   rega = regb & regc;
   c_flag = 0;
   z_flag = rega == 0;
   n_flag = rega >> 7;
}


or

decompiled_code:
char or()
{
char result; // al

c_flag = 0;
rega = regc | regb;
z_flag = __PAIR16__(regb, regc) == 0;
result = (unsigned __int8)(regc | regb) >> 7;
n_flag = result;
return result;
}

canonical_decompiled_code:
char func17()
{
char result; // al

c_flag = 0;
rega = regc | regb;
z_flag = __PAIR16__(regb, regc) == 0;
result = (unsigned __int8)(regc | regb) >> 7;
n_flag = result;
return result;
}

original_code:
static void or() {
   rega = regb | regc;
   c_flag = 0;
   z_flag = rega == 0;
   n_flag = rega >> 7;
}


shl

decompiled_code:
char shl()
{
char result; // al

rega = 2 * regb;
z_flag = 2 * regb == 0;
result = (unsigned __int8)(2 * regb) >> 7;
c_flag = (unsigned __int8)regb >> 7;
n_flag = result;
return result;
}

canonical_decompiled_code:
char func18()
{
char result; // al

rega = 2 * regb;
z_flag = 2 * regb == 0;
result = (unsigned __int8)(2 * regb) >> 7;
c_flag = (unsigned __int8)regb >> 7;
n_flag = result;
return result;
}

original_code:
static void shl() {
   rega = regb << 1;
   c_flag = regb >> 7;
   z_flag = rega == 0;
   n_flag = rega >> 7;
}


shr

decompiled_code:
__int64 shr()
{
__int64 result; // rax

n_flag = 0;
result = regb & 1;
c_flag = regb & 1;
rega = (unsigned __int8)regb >> 1;
z_flag = (unsigned __int8)regb >> 1 == 0;
return result;
}

canonical_decompiled_code:
__int64 func19()
{
__int64 result; // rax

n_flag = 0;
result = regb & 1;
c_flag = regb & 1;
rega = (unsigned __int8)regb >> 1;
z_flag = (unsigned __int8)regb >> 1 == 0;
return result;
}

original_code:
static void shr() {
   rega = regb >> 1;
   c_flag = regb & 1;
   z_flag = rega == 0;
   n_flag = rega >> 7;
}


add

decompiled_code:
__int64 add()
{
__int64 result; // rax

result = (unsigned __int8)regb + (unsigned int)(unsigned __int8)regc;
rega = regb + regc;
c_flag = (unsigned __int16)((unsigned __int8)regb + (unsigned __int8)regc) > 0xFFu;
z_flag = regb + regc == 0;
n_flag = (unsigned __int8)(regb + regc) >> 7;
return result;
}

canonical_decompiled_code:
__int64 func20()
{
__int64 result; // rax

result = (unsigned __int8)regb + (unsigned int)(unsigned __int8)regc;
rega = regb + regc;
c_flag = (unsigned __int16)((unsigned __int8)regb + (unsigned __int8)regc) > 0xFFu;
z_flag = regb + regc == 0;
n_flag = (unsigned __int8)(regb + regc) >> 7;
return result;
}

original_code:
static void add() {
   unsigned short temp = regb + regc;
   rega = (unsigned char)temp;
   c_flag = temp > 255;
   z_flag = rega == 0;
   n_flag = rega >> 7;
}

variable_types:
temp
unsigned short


inc

decompiled_code:
char inc()
{
char result; // al

rega = regb + 1;
result = (unsigned __int8)(regb + 1) >> 7;
c_flag = regb == -1;
z_flag = regb == -1;
n_flag = result;
return result;
}

canonical_decompiled_code:
char func21()
{
char result; // al

rega = regb + 1;
result = (unsigned __int8)(regb + 1) >> 7;
c_flag = regb == -1;
z_flag = regb == -1;
n_flag = result;
return result;
}

original_code:
static void inc() {
   rega = regb + 1;
   c_flag = regb == 255;
   z_flag = rega == 0;
   n_flag = rega >> 7;
}


dec

decompiled_code:
char dec()
{
char result; // al

c_flag = regb == 0;
rega = regb - 1;
z_flag = regb == 1;
result = (unsigned __int8)(regb - 1) >> 7;
n_flag = result;
return result;
}

canonical_decompiled_code:
char func22()
{
char result; // al

c_flag = regb == 0;
rega = regb - 1;
z_flag = regb == 1;
result = (unsigned __int8)(regb - 1) >> 7;
n_flag = result;
return result;
}

original_code:
static void dec() {
   rega = regb - 1;
   c_flag = regb == 0;
   z_flag = rega == 0;
   n_flag = rega >> 7;
}


not

decompiled_code:
char not()
{
char result; // al

c_flag = 0;
rega = ~regb;
z_flag = regb == -1;
result = (unsigned __int8)~regb >> 7;
n_flag = result;
return result;
}

canonical_decompiled_code:
char func23()
{
char result; // al

c_flag = 0;
rega = ~regb;
z_flag = regb == -1;
result = (unsigned __int8)~regb >> 7;
n_flag = result;
return result;
}

original_code:
static void not() {
   rega = ~regb;
   c_flag = 0;
   z_flag = rega == 0;
   n_flag = rega >> 7;
}


clr

canonical_decompiled_code:
void func24()
{
rega = 0;
c_flag = 0;
z_flag = 1;
n_flag = 0;
}

original_code:
static void clr() {
   rega = 0;
   c_flag = 0;
   z_flag = 1;
   n_flag = 0;
}


mab

decompiled_code:
__int64 mab()
{
__int64 result; // rax

result = (unsigned __int8)rega;
regb = rega;
return result;
}

canonical_decompiled_code:
__int64 func25()
{
__int64 result; // rax

result = (unsigned __int8)rega;
regb = rega;
return result;
}

original_code:
static void mab() {
   regb = rega;
}

canonical_original_code:
static void mab() {
   regb = rega;
}


mac

decompiled_code:
__int64 mac()
{
__int64 result; // rax

result = (unsigned __int8)rega;
regc = rega;
return result;
}

canonical_decompiled_code:
__int64 func26()
{
__int64 result; // rax

result = (unsigned __int8)rega;
regc = rega;
return result;
}

original_code:
static void mac() {
   regc = rega;
}

canonical_original_code:
static void mac() {
   regc = rega;
}


sax

decompiled_code:
__int64 sax()
{
__int64 result; // rax

result = (unsigned __int8)regxl | ((unsigned __int8)regxh << 8);
memory[result] = rega;
return result;
}

canonical_decompiled_code:
__int64 func27()
{
__int64 result; // rax

result = (unsigned __int8)regxl | ((unsigned __int8)regxh << 8);
memory[result] = rega;
return result;
}

original_code:
static void sax() {
   memory[(regxh << 8) | regxl] = rega;
}


sbx

decompiled_code:
__int64 sbx()
{
__int64 result; // rax

result = (unsigned __int8)regxl | ((unsigned __int8)regxh << 8);
memory[result] = regb;
return result;
}

canonical_decompiled_code:
__int64 func28()
{
__int64 result; // rax

result = (unsigned __int8)regxl | ((unsigned __int8)regxh << 8);
memory[result] = regb;
return result;
}

original_code:
static void sbx() {
   memory[(regxh << 8) | regxl] = regb;
}


scx

decompiled_code:
__int64 scx()
{
__int64 result; // rax

result = (unsigned __int8)regxl | ((unsigned __int8)regxh << 8);
memory[result] = regc;
return result;
}

canonical_decompiled_code:
__int64 func29()
{
__int64 result; // rax

result = (unsigned __int8)regxl | ((unsigned __int8)regxh << 8);
memory[result] = regc;
return result;
}

original_code:
static void scx() {
   memory[(regxh << 8) | regxl] = regc;
}


lbx

decompiled_code:
__int64 lbx()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int8)regxl | ((unsigned __int8)regxh << 8)];
regb = memory[(unsigned __int8)regxl | ((unsigned __int8)regxh << 8)];
return result;
}

canonical_decompiled_code:
__int64 func30()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int8)regxl | ((unsigned __int8)regxh << 8)];
regb = memory[(unsigned __int8)regxl | ((unsigned __int8)regxh << 8)];
return result;
}

original_code:
static void lbx() {
   regb = memory[(regxh << 8) | regxl];
}


lcx

decompiled_code:
__int64 lcx()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int8)regxl | ((unsigned __int8)regxh << 8)];
regc = memory[(unsigned __int8)regxl | ((unsigned __int8)regxh << 8)];
return result;
}

canonical_decompiled_code:
__int64 func31()
{
__int64 result; // rax

result = (unsigned __int8)memory[(unsigned __int8)regxl | ((unsigned __int8)regxh << 8)];
regc = memory[(unsigned __int8)regxl | ((unsigned __int8)regxh << 8)];
return result;
}

original_code:
static void lcx() {
   regc = memory[(regxh << 8) | regxl];
}


ret

decompiled_code:
__int64 ret()
{
__int64 result; // rax

result = ((unsigned __int8)regxh << 8) | (unsigned int)(unsigned __int8)regxl;
preg = ((unsigned __int8)regxh << 8) | (unsigned __int8)regxl;
return result;
}

canonical_decompiled_code:
__int64 func32()
{
__int64 result; // rax

result = ((unsigned __int8)regxh << 8) | (unsigned int)(unsigned __int8)regxl;
preg = ((unsigned __int8)regxh << 8) | (unsigned __int8)regxl;
return result;
}

original_code:
static void ret() {
   preg = (regxh << 8) | regxl;
}


hlt

decompiled_code:
void hlt()
{
halted = 1;
}

canonical_decompiled_code:
void func33()
{
halted = 1;
}

original_code:
static void hlt() {
   halted = 1;
}

canonical_original_code:
static void hlt() {
   halted = 1;
}


decompiled_code:
char __fastcall j_inst(unsigned __int8 a1)
{
__int16 v1; // si
unsigned __int16 v2; // cx
__int16 v3; // si
unsigned __int16 v4; // ax

v1 = (unsigned __int8)memory[(unsigned __int16)preg];
v2 = preg + 2;
v4 = preg + 1;
preg += 2;
v3 = (unsigned __int8)memory[v4] | (unsigned __int16)(v1 << 8);
operand = v3;
LOBYTE(v4) = (z_flag | ((a1 & 2) == 0)) & (n_flag | ((a1 & 4) == 0));
if ( ((unsigned __int8)(c_flag | ((a1 & 1) == 0)) & (unsigned __int8)v4) != 0 )
{
LOBYTE(v4) = a1 >> 3;
if ( a1 >> 3 )
{
regxl = v2;
v4 = HIBYTE(v2);
regxh = HIBYTE(v2);
}
preg = v3;
}
return v4;
}

canonical_decompiled_code:
char __fastcall func34(unsigned __int8 a1)
{
__int16 v1; // si
unsigned __int16 v2; // cx
__int16 v3; // si
unsigned __int16 v4; // ax

v1 = (unsigned __int8)memory[(unsigned __int16)preg];
v2 = preg + 2;
v4 = preg + 1;
preg += 2;
v3 = (unsigned __int8)memory[v4] | (unsigned __int16)(v1 << 8);
operand = v3;
LOBYTE(v4) = (z_flag | ((a1 & 2) == 0)) & (n_flag | ((a1 & 4) == 0));
if ( ((unsigned __int8)(c_flag | ((a1 & 1) == 0)) & (unsigned __int8)v4) != 0 )
{
LOBYTE(v4) = a1 >> 3;
if ( a1 >> 3 )
{
regxl = v2;
v4 = HIBYTE(v2);
regxh = HIBYTE(v2);
}
preg = v3;
}
return v4;
}

original_code:
static void j_inst(unsigned char func) {
   const unsigned char c_func = (func >> 0) & 1;
   const unsigned char z_func = (func >> 1) & 1;
   const unsigned char n_func = (func >> 2) & 1;
   const unsigned char is_call = (func >> 3) & 1;
   operand = (unsigned short)memory[preg++] << 8;
   operand |= memory[preg++];
   if((!c_func | c_flag) & (!z_func | z_flag) & (!n_func | n_flag)) {
      if(is_call) {
         regxh = preg >> 8;
         regxl = preg & 0xFF;
      }
      preg = operand;
   }
}

canonical_original_code:
static void j_inst(unsigned char func) {
   unsigned char c_func = (func >> 0) & 1;
   unsigned char z_func = (func >> 1) & 1;
   unsigned char n_func = (func >> 2) & 1;
   unsigned char is_call = (func >> 3) & 1;
   operand = (unsigned short)memory[preg++] << 8;
   operand |= memory[preg++];
   if((!c_func | c_flag) & (!z_func | z_flag) & (!n_func | n_flag)) {
      if(is_call) {
         regxh = preg >> 8;
         regxl = preg & 0xFF;
      }
      preg = operand;
   }
}

variable_types:
func
unsigned char


decompiled_code:
int __fastcall ls_inst(unsigned __int8 a1)
{
__int64 (__fastcall *v1)(); // rcx
__int64 v2; // rsi
__int64 v3; // rax
__int64 v4; // rdx
int result; // eax

v1 = ls_class[a1];
v2 = (unsigned int)(unsigned __int16)preg + 2;
v3 = (unsigned __int16)(preg + 1);
v4 = (unsigned __int8)memory[(unsigned __int16)preg] << 8;
preg += 2;
operand = v4 | (unsigned __int8)memory[v3];
if ( v1 )
result = ((__int64 (__fastcall *)(_QWORD, __int64, __int64, __int64 (__fastcall *)(), _QWORD))v1)(
a1,
v2,
v4,
v1,
a1);
else
result = fprintf(stderr, "ERROR: invalid LS instruction: %u\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func35(unsigned __int8 a1)
{
__int64 (__fastcall *v1)(); // rcx
__int64 v2; // rsi
__int64 v3; // rax
__int64 v4; // rdx
int result; // eax

v1 = ls_class[a1];
v2 = (unsigned int)(unsigned __int16)preg + 2;
v3 = (unsigned __int16)(preg + 1);
v4 = (unsigned __int8)memory[(unsigned __int16)preg] << 8;
preg += 2;
operand = v4 | (unsigned __int8)memory[v3];
if ( v1 )
result = ((__int64 (__fastcall *)(_QWORD, __int64, __int64, __int64 (__fastcall *)(), _QWORD))v1)(
a1,
v2,
v4,
v1,
a1);
else
result = fprintf(stderr, "ERROR: invalid LS instruction: %u\n", a1);
return result;
}

original_code:
static void ls_inst(unsigned char func) {
   void (*inst)() = ls_class[func];
   operand = (unsigned short)memory[preg++] << 8;
   operand |= memory[preg++];
   if(inst) {
      (inst)();
   } else {
      fprintf(stderr, "ERROR: invalid LS instruction: %u\n",
         (unsigned int)func);
   }
}

variable_types:
inst
void (*)()


decompiled_code:
char __fastcall math_inst(unsigned __int8 a1)
{
char (__fastcall *v1)(); // rdx
char result; // al

v1 = (char (__fastcall *)())math_class[a1];
if ( v1 )
result = v1();
else
result = fprintf(stderr, "ERROR: invalid MATH instruction: %u\n", a1);
return result;
}

canonical_decompiled_code:
char __fastcall func36(unsigned __int8 a1)
{
char (__fastcall *v1)(); // rdx
char result; // al

v1 = (char (__fastcall *)())math_class[a1];
if ( v1 )
result = v1();
else
result = fprintf(stderr, "ERROR: invalid MATH instruction: %u\n", a1);
return result;
}

original_code:
static void math_inst(unsigned char func) {
   void (*inst)() = math_class[func];
   if(inst) {
      (inst)();
   } else {
      fprintf(stderr, "ERROR: invalid MATH instruction: %u\n",
         (unsigned int)func);
   }
}


decompiled_code:
int __fastcall misc_inst(unsigned __int8 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 (__fastcall *v4)(); // rdx
int result; // eax

v4 = misc_class[a1];
if ( v4 )
result = ((__int64 (__fastcall *)(_QWORD, __int64, __int64 (__fastcall *)(), __int64, _QWORD))v4)(
a1,
a2,
v4,
a4,
a1);
else
result = fprintf(stderr, "ERROR: invalid MISC instruction: %u\n", a1);
return result;
}

canonical_decompiled_code:
int __fastcall func37(unsigned __int8 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 (__fastcall *v4)(); // rdx
int result; // eax

v4 = misc_class[a1];
if ( v4 )
result = ((__int64 (__fastcall *)(_QWORD, __int64, __int64 (__fastcall *)(), __int64, _QWORD))v4)(
a1,
a2,
v4,
a4,
a1);
else
result = fprintf(stderr, "ERROR: invalid MISC instruction: %u\n", a1);
return result;
}

original_code:
static void misc_inst(unsigned char func) {
   void (*inst)() = misc_class[func];
   if(inst) {
      (inst)();
   } else {
      fprintf(stderr, "ERROR: invalid MISC instruction: %u\n",
         (unsigned int)func);
   }
}


next

decompiled_code:
char __fastcall next(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int8 v4; // di
__int64 v5; // rdx
char result; // al

v5 = (unsigned __int8)memory[(unsigned __int16)preg++];
v4 = v5 & 0xF;
LOBYTE(v5) = (unsigned __int8)v5 >> 4;
if ( (_BYTE)v5 == 2 )
{
result = math_inst(v4);
clocks += 9;
}
else if ( (unsigned __int8)v5 > 2u )
{
if ( (_BYTE)v5 == 3 )
{
result = misc_inst(v4, a2, v5, a4);
clocks += 9;
}
else
{
result = fprintf(stderr, "ERROR: invalid instruction class: %u\n", (unsigned __int8)v5);
}
}
else
{
if ( (_BYTE)v5 )
result = ls_inst(v4);
else
result = j_inst(v4);
clocks += 21;
}
return result;
}

canonical_decompiled_code:
char __fastcall func38(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned __int8 v4; // di
__int64 v5; // rdx
char result; // al

v5 = (unsigned __int8)memory[(unsigned __int16)preg++];
v4 = v5 & 0xF;
LOBYTE(v5) = (unsigned __int8)v5 >> 4;
if ( (_BYTE)v5 == 2 )
{
result = func36(v4);
clocks += 9;
}
else if ( (unsigned __int8)v5 > 2u )
{
if ( (_BYTE)v5 == 3 )
{
result = func37(v4, a2, v5, a4);
clocks += 9;
}
else
{
result = fprintf(stderr, "ERROR: invalid instruction class: %u\n", (unsigned __int8)v5);
}
}
else
{
if ( (_BYTE)v5 )
result = func35(v4);
else
result = func34(v4);
clocks += 21;
}
return result;
}

original_code:
static void next() {
   opcode = memory[preg];
   const unsigned char inst_class = opcode >> 4;
   const unsigned char inst_func = opcode & 0x0F;
   ++preg;
   switch(inst_class) {
   case 0:
      j_inst(inst_func);
      clocks += 7 * 3;
      break;
   case 1:
      ls_inst(inst_func);
      clocks += 7 * 3;
      break;
   case 2:
      math_inst(inst_func);
      clocks += 3 * 3;
      break;
   case 3:
      misc_inst(inst_func);
      clocks += 3 * 3;
      break;
   default:
      fprintf(stderr, "ERROR: invalid instruction class: %u\n",
         (unsigned int)inst_class);
      break;
   }
}

canonical_original_code:
static void next() {
   opcode = memory[preg];
   unsigned char inst_class = opcode >> 4;
   unsigned char inst_func = opcode & 0x0F;
   ++preg;
   switch(inst_class) {
   case 0:
      j_inst(inst_func);
      clocks += 7 * 3;
      break;
   case 1:
      ls_inst(inst_func);
      clocks += 7 * 3;
      break;
   case 2:
      math_inst(inst_func);
      clocks += 3 * 3;
      break;
   case 3:
      misc_inst(inst_func);
      clocks += 3 * 3;
      break;
   default:
      fprintf(stderr, "ERROR: invalid instruction class: %u\n",
         (unsigned int)inst_class);
      break;
   }
}


DisplayByte

decompiled_code:
int __fastcall DisplayByte(unsigned __int8 a1)
{
int v1; // ebp
unsigned int v2; // ebx
int result; // eax
bool v4; // cf

v1 = a1;
v2 = 7;
do
{
while ( _bittest(&v1, v2) )
{
result = putchar(111);
v4 = v2-- == 0;
if ( v4 )
return result;
}
result = putchar(45);
v4 = v2-- == 0;
}
while ( !v4 );
return result;
}

canonical_decompiled_code:
int __fastcall func39(unsigned __int8 a1)
{
int v1; // ebp
unsigned int v2; // ebx
int result; // eax
bool v4; // cf

v1 = a1;
v2 = 7;
do
{
while ( _bittest(&v1, v2) )
{
result = putchar(111);
v4 = v2-- == 0;
if ( v4 )
return result;
}
result = putchar(45);
v4 = v2-- == 0;
}
while ( !v4 );
return result;
}

original_code:
static void DisplayByte(unsigned char byte) {
   int x;
   for(x = 0; x < 8; x++) {
      if(byte & (1 << (7 - x))) {
         printf("o");
      } else {
         printf("-");
      }
   }
}

variable_types:
byte
unsigned char

variable_types: x int


DisplayWord

decompiled_code:
int __fastcall DisplayWord(__int16 a1)
{
DisplayByte(HIBYTE(a1));
putchar(32);
return DisplayByte(a1);
}

canonical_decompiled_code:
int __fastcall func40(__int16 a1)
{
func39(HIBYTE(a1));
putchar(32);
return func39(a1);
}

original_code:
static void DisplayWord(unsigned short word) {
   DisplayByte((unsigned char)(word >> 8));
   printf(" ");
   DisplayByte((unsigned char)word);
}

variable_types:
word
unsigned short


DisplayState

decompiled_code:
int DisplayState()
{
const char *v0; // rdi
const char *v1; // rdi
const char *v2; // rdi
unsigned int v3; // er12
int v4; // ebx
__int64 v5; // rbp

printf("\x1B[2J\x1B[;H");
printf("CLOCKS: %u\n", (unsigned int)clocks);
printf("PC: ");
DisplayWord(preg);
printf(" %u\n", (unsigned __int16)preg);
printf("A: ");
DisplayByte(rega);
v0 = " C ";
if ( !c_flag )
v0 = " ";
printf(v0);
v1 = "Z ";
if ( !z_flag )
v1 = " ";
printf(v1);
v2 = "N ";
if ( !n_flag )
v2 = " ";
v3 = 0;
printf(v2);
printf("%u\n", (unsigned __int8)rega);
printf("B: ");
DisplayByte(regb);
printf(" %u\n", (unsigned __int8)regb);
printf("C: ");
DisplayByte(regc);
printf(" %u\n", (unsigned __int8)regc);
printf("X: ");
DisplayByte(regxh);
putchar(32);
DisplayByte(regxl);
printf(" %u\n", (unsigned __int8)regxl | ((unsigned __int8)regxh << 8));
do
{
v4 = 0;
printf("%04x:", v3);
do
{
v5 = v3 + v4;
if ( (v4 & 7) == 0 )
putchar(32);
++v4;
printf("%02x ", (unsigned __int8)memory[v5]);
}
while ( v4 != 16 );
v3 += 16;
putchar(10);
}
while ( v3 != 240 );
return usleep(0x186A0u);
}

canonical_decompiled_code:
int func41()
{
const char *v0; // rdi
const char *v1; // rdi
const char *v2; // rdi
unsigned int v3; // er12
int v4; // ebx
__int64 v5; // rbp

printf("\x1B[2J\x1B[;H");
printf("CLOCKS: %u\n", (unsigned int)clocks);
printf("PC: ");
func40(preg);
printf(" %u\n", (unsigned __int16)preg);
printf("A: ");
func39(rega);
v0 = " C ";
if ( !c_flag )
v0 = " ";
printf(v0);
v1 = "Z ";
if ( !z_flag )
v1 = " ";
printf(v1);
v2 = "N ";
if ( !n_flag )
v2 = " ";
v3 = 0;
printf(v2);
printf("%u\n", (unsigned __int8)rega);
printf("B: ");
func39(regb);
printf(" %u\n", (unsigned __int8)regb);
printf("C: ");
func39(regc);
printf(" %u\n", (unsigned __int8)regc);
printf("X: ");
func39(regxh);
putchar(32);
func39(regxl);
printf(" %u\n", (unsigned __int8)regxl | ((unsigned __int8)regxh << 8));
do
{
v4 = 0;
printf("%04x:", v3);
do
{
v5 = v3 + v4;
if ( (v4 & 7) == 0 )
putchar(32);
++v4;
printf("%02x ", (unsigned __int8)memory[v5]);
}
while ( v4 != 16 );
v3 += 16;
putchar(10);
}
while ( v3 != 240 );
return usleep(0x186A0u);
}

original_code:
void DisplayState() {
   unsigned int x, y;
   printf("\033[2J\033[;H");
   printf("CLOCKS: %u\n", clocks);
   printf("PC: "); DisplayWord(preg);
   printf("       %u\n", (unsigned int)preg);
   printf("A:           "); DisplayByte(rega);
   printf(c_flag ? " C " : "   ");
   printf(z_flag ? "Z " : "  ");
   printf(n_flag ? "N " : "  ");
   printf("%u\n", (unsigned int)rega);
   printf("B:           "); DisplayByte(regb);
   printf("       %u\n", (unsigned int)regb);
   printf("C:           "); DisplayByte(regc);
   printf("       %u\n", (unsigned int)regc);
   printf("X:  "); DisplayByte(regxh); printf(" ");
                   DisplayByte(regxl);
   printf("       %u\n", ((unsigned int)regxh << 8) | regxl);
   x = 0;
   while(x < (8 * 2) * (24 - 9)) {
      printf("%04x:", x);
      for(y = 0; y < (8 * 2); y++, x++) {
         if((y & 7) == 0) {
            printf(" ");
         }
         printf("%02x ", (unsigned int)memory[x]);
      }
      printf("\n");
   }
   usleep(100000);
}

canonical_original_code:
void DisplayState() {
   unsigned int x; unsigned int y;
   printf("\033[2J\033[;H");
   printf("CLOCKS: %u\n", clocks);
   printf("PC: "); DisplayWord(preg);
   printf("       %u\n", (unsigned int)preg);
   printf("A:           "); DisplayByte(rega);
   printf(c_flag ? " C " : "   ");
   printf(z_flag ? "Z " : "  ");
   printf(n_flag ? "N " : "  ");
   printf("%u\n", (unsigned int)rega);
   printf("B:           "); DisplayByte(regb);
   printf("       %u\n", (unsigned int)regb);
   printf("C:           "); DisplayByte(regc);
   printf("       %u\n", (unsigned int)regc);
   printf("X:  "); DisplayByte(regxh); printf(" ");
                   DisplayByte(regxl);
   printf("       %u\n", ((unsigned int)regxh << 8) | regxl);
   x = 0;
   while(x < (8 * 2) * (24 - 9)) {
      printf("%04x:", x);
      for(y = 0; y < (8 * 2); y++, x++) {
         if((y & 7) == 0) {
            printf(" ");
         }
         printf("%02x ", (unsigned int)memory[x]);
      }
      printf("\n");
   }
   usleep(100000);
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int


ShowUsage

repo: joewing/wmtest

decompiled_code:
int __fastcall ShowUsage(const char *a1)
{
return printf("usage: %s [options]\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("usage: %s [options]\n", a1);
}

original_code:
static void ShowUsage(const char *name)
{
   printf("usage: %s [options]\n", name);
}

canonical_original_code:
static void ShowUsage(char *name)
{
   printf("usage: %s [options]\n", name);
}

variable_types:
name
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // edi
const char **v5; // r8
char v6; // cf
bool v7; // zf
unsigned __int64 v8; // r11
__int64 v9; // r10
unsigned __int64 v10; // rax
__int64 v11; // rcx
const char *v12; // rdi
int v13; // edx
const char *v14; // rbp
const char *v15; // rdi
Display *v16; // rdx
__int64 v17; // rax
__int64 v18; // rdx

if ( argc <= 1 )
{
v15 = 0LL;
display = XOpenDisplay(0LL);
v16 = display;
if ( display )
goto LABEL_10;
goto LABEL_12;
}
v3 = argc - 2;
v4 = argc - 1;
v5 = argv;
v6 = v4 & 1;
v4 >>= 1;
v7 = v4 == 0;
v8 = 2LL * (v3 >> 1) + 3;
v9 = 2LL * v4 + 1;
v10 = 1LL;
do
{
argv = (const char **)v5[v10];
v11 = 9LL;
v12 = "-display";
do
{
if ( !v11 )
break;
v6 = *(_BYTE *)argv < *v12;
v7 = *(_BYTE *)argv == *v12;
argv = (const char **)((char *)argv + 1);
++v12;
--v11;
}
while ( v7 );
if ( !(v6 | v7) != v6 || (v13 = v10 + 1, v10 == v9) )
{
ShowUsage(*v5);
exit(-1);
}
v10 += 2LL;
v6 = v8 < v10;
v7 = v8 == v10;
}
while ( v8 != v10 );
v14 = v5[v13];
v15 = v14;
display = XOpenDisplay(v14);
v16 = display;
if ( !display )
{
if ( v14 )
{
printf("error: could not open display %s\n", v14);
LABEL_13:
exit(-1);
}
LABEL_12:
puts("error: could not open display");
goto LABEL_13;
}
LABEL_10:
rootScreen = v16->default_screen;
v17 = (__int64)&v16->screens[(__int64)rootScreen];
v18 = *(_QWORD *)(v17 + 16);
rootDepth = *(_DWORD *)(v17 + 56);
rootWindow = v18;
TestMap(v15, argv);
TestGravity();
TestDesktop();
TestResize();
XCloseDisplay(display);
printf("Errors: %u\n", (unsigned int)errorCount);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
unsigned int v4; // edi
const char **v5; // r8
char v6; // cf
bool v7; // zf
unsigned __int64 v8; // r11
__int64 v9; // r10
unsigned __int64 v10; // rax
__int64 v11; // rcx
const char *v12; // rdi
int v13; // edx
const char *v14; // rbp
const char *v15; // rdi
Display *v16; // rdx
__int64 v17; // rax
__int64 v18; // rdx

if ( argc <= 1 )
{
v15 = 0LL;
display = XOpenDisplay(0LL);
v16 = display;
if ( display )
goto LABEL_10;
goto LABEL_12;
}
v3 = argc - 2;
v4 = argc - 1;
v5 = argv;
v6 = v4 & 1;
v4 >>= 1;
v7 = v4 == 0;
v8 = 2LL * (v3 >> 1) + 3;
v9 = 2LL * v4 + 1;
v10 = 1LL;
do
{
argv = (const char **)v5[v10];
v11 = 9LL;
v12 = "-display";
do
{
if ( !v11 )
break;
v6 = *(_BYTE *)argv < *v12;
v7 = *(_BYTE *)argv == *v12;
argv = (const char **)((char *)argv + 1);
++v12;
--v11;
}
while ( v7 );
if ( !(v6 | v7) != v6 || (v13 = v10 + 1, v10 == v9) )
{
func0(*v5);
exit(-1);
}
v10 += 2LL;
v6 = v8 < v10;
v7 = v8 == v10;
}
while ( v8 != v10 );
v14 = v5[v13];
v15 = v14;
display = XOpenDisplay(v14);
v16 = display;
if ( !display )
{
if ( v14 )
{
printf("error: could not open display %s\n", v14);
LABEL_13:
exit(-1);
}
LABEL_12:
puts("error: could not open display");
goto LABEL_13;
}
LABEL_10:
rootScreen = v16->default_screen;
v17 = (__int64)&v16->screens[(__int64)rootScreen];
v18 = *(_QWORD *)(v17 + 16);
rootDepth = *(_DWORD *)(v17 + 56);
rootWindow = v18;
TestMap(v15, argv);
TestGravity();
TestDesktop();
TestResize();
XCloseDisplay(display);
printf("Errors: %u\n", (unsigned int)errorCount);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
   const char *displayString = ((void *)0);
   int i;
   for(i = 1; i < argc; i++) {
      if(!strcmp(argv[i], "-display") && i + 1 < argc) {
         i += 1;
         displayString = argv[i];
      } else {
         ShowUsage(argv[0]);
         exit(-1);
      }
   }
   display = XOpenDisplay(displayString);
   if(!display) {
      if(displayString) {
         printf("error: could not open display %s\n", displayString);
      } else {
         printf("error: could not open display\n");
      }
      exit(-1);
   }
   rootScreen = (((_XPrivDisplay)(display))->default_screen);
   rootWindow = ((&((_XPrivDisplay)(display))->screens[rootScreen])->root);
   rootDepth = ((&((_XPrivDisplay)(display))->screens[rootScreen])->root_depth);
   TestMap();
   TestGravity();
   TestDesktop();
   TestResize();
   XCloseDisplay(display);
   printf("Errors: %u\n", errorCount);
   return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
   char *displayString = ((void *)0);
   int i;
   for(i = 1; i < argc; i++) {
      if(!strcmp(argv[i], "-display") && i + 1 < argc) {
         i += 1;
         displayString = argv[i];
      } else {
         ShowUsage(argv[0]);
         exit(-1);
      }
   }
   display = XOpenDisplay(displayString);
   if(!display) {
      if(displayString) {
         printf("error: could not open display %s\n", displayString);
      } else {
         printf("error: could not open display\n");
      }
      exit(-1);
   }
   rootScreen = (((_XPrivDisplay)(display))->default_screen);
   rootWindow = ((&((_XPrivDisplay)(display))->screens[rootScreen])->root);
   rootDepth = ((&((_XPrivDisplay)(display))->screens[rootScreen])->root_depth);
   TestMap();
   TestGravity();
   TestDesktop();
   TestResize();
   XCloseDisplay(display);
   printf("Errors: %u\n", errorCount);
   return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
displayString
char *


decompiled_code:
int TestResize2()
{
Window v0; // rax
XSizeHints v2; // [rsp+0h] [rbp-58h] BYREF

v2.flags = 0LL;
v0 = CreateWindow_constprop_0(&v2);
return XDestroyWindow(display, v0);
}

canonical_decompiled_code:
int func1()
{
Window v0; // rax
XSizeHints v2; // [rsp+0h] [rbp-58h] BYREF

v2.flags = 0LL;
v0 = func0(&v2);
return XDestroyWindow(display, v0);
}

original_code:
static void TestResize2()
{
   Window w;
   XSizeHints hints;
   hints.flags = 0;
   w = CreateWindow(&hints);
   XDestroyWindow(display, w);
}

canonical_original_code:
static void TestResize2()
{
   unsigned long w;
   struct XSizeHints hints;
   hints.flags = 0;
   w = CreateWindow(&hints);
   XDestroyWindow(display, w);
}

variable_types:
w
unsigned long

variable_types: struct XSizeHints { long flags; int x; int width; int min_width; int max_width; int width_inc; struct { int x; int y; } min_aspect; int base_width; int win_gravity; }


TestResize

decompiled_code:
int TestResize()
{
TestResize1();
return TestResize2();
}

canonical_decompiled_code:
int func3()
{
func2();
return func1();
}

original_code:
void TestResize()
{
   TestResize1();
   TestResize2();
   TestResize3();
   TestResize4();
}


TestGravity

decompiled_code:
int TestGravity()
{
DoTestGravity(2);
DoTestGravity(8);
DoTestGravity(6);
DoTestGravity(4);
DoTestGravity(3);
DoTestGravity(1);
DoTestGravity(9);
DoTestGravity(7);
DoTestGravity(5);
return DoTestGravity(10);
}

original_code:
void TestGravity()
{
   DoTestGravity(2);
   DoTestGravity(8);
   DoTestGravity(6);
   DoTestGravity(4);
   DoTestGravity(3);
   DoTestGravity(1);
   DoTestGravity(9);
   DoTestGravity(7);
   DoTestGravity(5);
   DoTestGravity(10);
}


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

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
free(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}

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

if ( *(int *)ptr > 0 )
{
v2 = 0LL;
do
{
v3 = *(void **)(*((_QWORD *)ptr + 1) + 8 * v2++);
free(v3);
}
while ( *(_DWORD *)ptr > (int)v2 );
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Tokenize_String_Delete(struct tokenized_string *ts)
{
 int i;
 for (i=0; i<ts->count; i++)
 {
  free(ts->tokens[i]);
 }
 free(ts->tokens);
 free(ts);
}

variable_types: struct tokenized_string { int count; char **tokens; } *

variable_types: i int


decompiled_code:
char *__fastcall Get_Userinfo_Value_By_Key(const char *a1, const char *a2)
{
char *v2; // rax
const char *v3; // rdi
const char *v4; // rax
int v5; // esi
char v6; // dl
char v8[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v8, "\\%s\\", a1);
v2 = strstr(a2, v8);
if ( !v2 )
return 0LL;
v3 = &v2[strlen(v8)];
if ( *v3 == 92 || !*v3 )
return strndup(v3, 0LL);
v4 = v3;
do
{
v5 = 1 - (_DWORD)v3 + (_DWORD)v4;
v6 = *++v4;
}
while ( v6 != 92 && v6 );
return strndup(v3, v5);
}

canonical_decompiled_code:
char *__fastcall func0(const char *a1, const char *a2)
{
char *v2; // rax
const char *v3; // rdi
const char *v4; // rax
int v5; // esi
char v6; // dl
char v8[152]; // [rsp+0h] [rbp-98h] BYREF

sprintf(v8, "\\%s\\", a1);
v2 = strstr(a2, v8);
if ( !v2 )
return 0LL;
v3 = &v2[strlen(v8)];
if ( *v3 == 92 || !*v3 )
return strndup(v3, 0LL);
v4 = v3;
do
{
v5 = 1 - (_DWORD)v3 + (_DWORD)v4;
v6 = *++v4;
}
while ( v6 != 92 && v6 );
return strndup(v3, v5);
}

original_code:
char *Get_Userinfo_Value_By_Key(char *key, char *userinfo)
{
 char buf[128];
 char *index = ((void *)0);
 char *index_org = ((void *)0);
 int _size = 0;
 char *r;
 sprintf(buf, "\\%s\\", key);
 index = strstr(userinfo, buf);
 if (index == ((void *)0))
  return ((void *)0);
 index += strlen(buf);
 index_org = index;
 while (*index != '\\' && *index != 0)
 {
  _size++;
  index++;
 }
 return strndup(index_org, _size);
}

variable_types:
key
char *

variable_types:
userinfo
char *

variable_types:
buf
char [128]

variable_types:
index
char *

variable_types:
r
char *

return_type: char *


VectorDistance

decompiled_code:
float __fastcall VectorDistance(float *a1, float *a2)
{
double v2; // xmm0_8
float result; // xmm0_4

v2 = (float)(a1[1] - a2[1]) * (float)(a1[1] - a2[1])
+ (float)(*a1 - *a2) * (float)(*a1 - *a2)
+ (float)(a1[2] - a2[2]) * (float)(a1[2] - a2[2]);
if ( v2 < 0.0 )
result = sqrt(v2);
else
result = sqrt(v2);
return result;
}

canonical_decompiled_code:
float __fastcall func1(float *a1, float *a2)
{
double v2; // xmm0_8
float result; // xmm0_4

v2 = (float)(a1[1] - a2[1]) * (float)(a1[1] - a2[1])
+ (float)(*a1 - *a2) * (float)(*a1 - *a2)
+ (float)(a1[2] - a2[2]) * (float)(a1[2] - a2[2]);
if ( v2 < 0.0 )
result = sqrt(v2);
else
result = sqrt(v2);
return result;
}

variable_types:
a
float [3]

variable_types:
b
float [3]

variable_types:
c
float [3]

return_type: float


original_code:
int is_player(struct player *p)
{
 if (p->name == ((void *)0))
  return 0;
 if (p->name[0] == '\0')
  return 0;
 if (p->spectator == 1)
  return 0;
 return 1;
}

variable_types: struct player { int userid; char *name; char *name_readable; char *team; char *team_readable; float entertime; int ping; int pl; int frags; int flags; char *userinfo; int spectator; unsigned char topcolor; unsigned char bottomcolor; int stats[32]; float angles[3]; float origin[3]; struct stats { int sg_attacks; int ssg_attacks; int ng_attacks; int sng_attacks; int gl_attacks; int rl_attacks; int lg_attacks; int jumps; int ga; int mh; int quad; int ssg; int deaths; } *statistics; } *

user_defined_types: struct player { int userid; char *name; char *name_readable; char *team; char *team_readable; float entertime; int ping; int pl; int frags; int flags; char *userinfo; int spectator; unsigned char topcolor; unsigned char bottomcolor; int stats[32]; float angles[3]; float origin[3]; struct stats *statistics; }


decompiled_code:
int drop_root()
{
setgid(0x62u);
return setuid(0x63u);
}

canonical_decompiled_code:
int func0()
{
setgid(0x62u);
return setuid(0x63u);
}

original_code:
void drop_root(){
   setgid(98);
   setuid(99);
}


tvdiff

decompiled_code:
__int64 __fastcall tvdiff(int a1, int a2, int a3, int a4)
{
return (unsigned int)(int)(double)(a2 + 1000000 * a1 - (a4 + 1000000 * a3));
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4)
{
return (unsigned int)(int)(double)(a2 + 1000000 * a1 - (a4 + 1000000 * a3));
}

original_code:
long tvdiff(struct timeval a, struct timeval b){
   double res;
   res = (a.tv_sec * 1000000 + a.tv_usec) - (b.tv_sec * 1000000 + b.tv_usec);
   return (long) res;
}

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

variable_types:
b
struct timeval

variable_types: res double

return_type: long


decompiled_code:
__int64 __fastcall resolve_host(char *name)
{
in_addr_t v1; // eax
__int64 v2; // r8
__int64 result; // rax
struct hostent *v4; // rax

v1 = inet_addr(name);
v2 = v1;
if ( v1 == -1 && (v4 = gethostbyname(name), v2 = 0LL, v4) )
result = **(_QWORD **)v4->h_addr_list;
else
result = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *name)
{
in_addr_t v1; // eax
__int64 v2; // r8
__int64 result; // rax
struct hostent *v4; // rax

v1 = inet_addr(name);
v2 = v1;
if ( v1 == -1 && (v4 = gethostbyname(name), v2 = 0LL, v4) )
result = **(_QWORD **)v4->h_addr_list;
else
result = v2;
return result;
}

original_code:
unsigned long resolve_host(char *h){
   struct hostent *host;
   struct in_addr addr;
   if((addr.s_addr = inet_addr(h)) == -1){
       if((host = gethostbyname(h)) == ((void *)0)){
          return 0;
       }
       else return *(unsigned long*)host->h_addr_list[0];
   }
   else return addr.s_addr;
}

canonical_original_code:
unsigned long resolve_host(char *h){
   struct hostent *host;
   struct in_addr addr;
   if((addr.s_addr = inet_addr(h)) == -1){
       if((host = gethostbyname(h)) == ((void *)0)){
          return 0;
       }
       else return *(unsigned long *)host->h_addr_list[0];
   }
   else return addr.s_addr;
}

variable_types:
h
char *

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

variable_types:
addr
struct in_addr { unsigned int s_addr; }

return_type: unsigned long


readudppacket

decompiled_code:
ssize_t __fastcall readudppacket(int fd, void *buf, int a3, int a4, __int64 a5)
{
int v6; // eax
int v7; // er8
ssize_t result; // rax
struct sockaddr addr; // [rsp+8h] [rbp-C0h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-ACh] BYREF
struct timeval timeout; // [rsp+20h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-98h] BYREF

*(_QWORD *)&addr.sa_family = a5;
addr_len = 16;
memset(&readfds, 0, sizeof(readfds));
v6 = fd + 63;
timeout.tv_sec = a4;
if ( fd >= 0 )
v6 = fd;
timeout.tv_usec = 0LL;
readfds.fds_bits[v6 >> 6] |= 1LL << (fd % 64);
v7 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
result = 0LL;
if ( v7 > 0 )
result = recvfrom(fd, buf, a3, 0, &addr, &addr_len);
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func4(int fd, void *buf, int a3, int a4, __int64 a5)
{
int v6; // eax
int v7; // er8
ssize_t result; // rax
struct sockaddr addr; // [rsp+8h] [rbp-C0h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-ACh] BYREF
struct timeval timeout; // [rsp+20h] [rbp-A8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-98h] BYREF

*(_QWORD *)&addr.sa_family = a5;
addr_len = 16;
memset(&readfds, 0, sizeof(readfds));
v6 = fd + 63;
timeout.tv_sec = a4;
if ( fd >= 0 )
v6 = fd;
timeout.tv_usec = 0LL;
readfds.fds_bits[v6 >> 6] |= 1LL << (fd % 64);
v7 = select(fd + 1, &readfds, 0LL, 0LL, &timeout);
result = 0LL;
if ( v7 > 0 )
result = recvfrom(fd, buf, a3, 0, &addr, &addr_len);
return result;
}

original_code:
int readudppacket(int sd, char *buf, int size, int timeout, struct sockaddr *client_addr){
   struct timeval tv;
   fd_set rfds;
   int retval, n, size_of;
   size_of = sizeof(struct sockaddr);
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&rfds)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))));
   tv.tv_sec = timeout;
   tv.tv_usec = 0;
   retval = select(sd+1, &rfds, ((void *)0), ((void *)0), &tv);
   if(retval <= 0)
      return 0;
   n = recvfrom(sd, buf, size, 0, (struct sockaddr *)&client_addr, &size_of);
   return n;
}

canonical_original_code:
int readudppacket(int sd, char *buf, int size, int timeout, struct sockaddr *client_addr){
   struct timeval tv;
   struct fd_set rfds;
   int retval; int n; int size_of;
   size_of = sizeof(struct sockaddr);
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&rfds)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&rfds)->__fds_bits)[((sd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sd) % (8 * (int) sizeof (__fd_mask)))))));
   tv.tv_sec = timeout;
   tv.tv_usec = 0;
   retval = select(sd+1, &rfds, ((void *)0), ((void *)0), &tv);
   if(retval <= 0)
      return 0;
   n = recvfrom(sd, buf, size, 0, (struct sockaddr *)&client_addr, &size_of);
   return n;
}

variable_types: sd int

variable_types:
buf
char *

variable_types: size int

variable_types: timeout int

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

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

variable_types: retval int

variable_types: n int

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


main

repo: john-kolt/efim

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

v3 = 10;
puts("Hello World!");
v4 = (int *)listCreate("Hello World!", argv);
*v4 = rand() % 256;
do
{
v5 = rand();
listAdd(v4, (unsigned int)(v5 % 256), 0LL);
--v3;
}
while ( v3 );
listPrint(v4);
return 0;
}

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

v3 = 10;
puts("Hello World!");
v4 = (int *)func12("Hello World!", argv);
*v4 = rand() % 256;
do
{
v5 = rand();
func16(v4, (unsigned int)(v5 % 256), 0LL);
--v3;
}
while ( v3 );
func19(v4);
return 0;
}

original_code:
int main(void)
{
    printf("Hello World!\n");
    pList list = listCreate();
    list->uid = rand()%256;
    for(int i=0; i<10; i++)
        listAdd(list, rand()%256, 0);
    listPrint(list);
    return 0;
}

canonical_original_code:
int main()
{
    printf("Hello World!\n");
    struct tList *list = listCreate();
    list->uid = rand()%256;
    for(int i = 0; i<10; i++)
        listAdd(list, rand()%256, 0);
    listPrint(list);
    return 0;
}

variable_types: struct tList { int uid; int data; int level; struct tList *left; struct tList *right; } *

variable_types: i int


routerConnect

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

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

original_code:
int routerConnect() {
  return(0);
}

canonical_original_code:
int routerConnect() {
  return(0);
}


routerDisconnect

decompiled_code:
__int64 routerDisconnect()
{
return routerConnect();
}

canonical_decompiled_code:
__int64 func8()
{
return func7();
}

original_code:
int routerDisconnect() {
  return(0);
}

canonical_original_code:
int routerDisconnect() {
  return(0);
}


routerLoadConfig

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

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

original_code:
int routerLoadConfig(char *fileName) {
  return(0);
}

variable_types:
fileName
char *


routerSend

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

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

original_code:
int routerSend(tUID toUid, tData data) {
  return(0);
}

canonical_original_code:
int routerSend(char *toUid, char *data) {
  return(0);
}

variable_types:
toUid
char *

variable_types:
data
char *


routerOnReceive

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

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

original_code:
void *routerOnReceive(tUID fromUid, tData data) {
  return(0);
}

canonical_original_code:
void *routerOnReceive(char *fromUid, char *data) {
  return(0);
}

variable_types:
fromUid
char *


listCreate

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

result = malloc(0x20uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
*((_QWORD *)result + 3) = 0LL;
*((_QWORD *)result + 2) = 0LL;
}
return result;
}

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

result = malloc(0x20uLL);
if ( result )
{
*(_QWORD *)result = 0LL;
result[2] = 0;
*((_QWORD *)result + 3) = 0LL;
*((_QWORD *)result + 2) = 0LL;
}
return result;
}

original_code:
pList listCreate()
{
    pList result = malloc(sizeof(tList));
    if(result != 0)
    {
        result->uid = 0;
        result->data = 0;
        result->level = 0;
        result->left = result->right = 0;
    }
    return result;
}

canonical_original_code:
struct tList *listCreate()
{
    struct tList *result = malloc(sizeof(tList));
    if(result != 0)
    {
        result->uid = 0;
        result->data = 0;
        result->level = 0;
        result->left = result->right = 0;
    }
    return result;
}

return_type: struct tList { int uid; int data; int level; struct tList *left; struct tList *right; } *


listSwap

decompiled_code:
void listSwap()
{
;
}

canonical_decompiled_code:
void func13()
{
;
}

original_code:
void listSwap(pList from, pList to)
{
    pList tmp = to;
    to = from;
    from = tmp;
}

canonical_original_code:
void listSwap(struct tList *from, struct tList *to)
{
    struct tList *tmp = to;
    to = from;
    from = tmp;
}

variable_types:
to
struct tList *

user_defined_types: struct tList { int uid; int data; int level; struct tList *left; struct tList *right; }