main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // r12
int v4; // er13
char v6; // al
int v7; // ebx
struct in_addr inp; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

if ( argc <= 1 )
{
usage();
return -1;
}
v4 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "s:p:l");
if ( v6 == -1 )
break;
if ( v6 == 112 )
goto LABEL_5;
if ( v6 == 115 )
{
if ( !inet_aton(_bss_start, &inp) )
{
puts("wrong address format");
return -1;
}
LABEL_5:
v3 = atoi(_bss_start);
}
else
{
v4 = 1;
if ( v6 != 108 )
{
usage();
return -1;
}
}
}
v7 = socket(2, 1, 0);
if ( v7 == -1 )
{
perror("socket()");
exit(-1);
}
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v3);
*(struct in_addr *)&addr.sa_data[2] = inp;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( connect(v7, &addr, 0x10u) == -1 )
{
perror("connect()");
exit(-1);
}
if ( v4 )
long_lived_connection(v7);
else
short_lived_connection(v7);
close(v7);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // r12
int v4; // er13
char v6; // al
int v7; // ebx
struct in_addr inp; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-38h] BYREF

if ( argc <= 1 )
{
func10();
return -1;
}
v4 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "s:p:l");
if ( v6 == -1 )
break;
if ( v6 == 112 )
goto LABEL_5;
if ( v6 == 115 )
{
if ( !inet_aton(_bss_start, &inp) )
{
puts("wrong address format");
return -1;
}
LABEL_5:
v3 = atoi(_bss_start);
}
else
{
v4 = 1;
if ( v6 != 108 )
{
func10();
return -1;
}
}
}
v7 = socket(2, 1, 0);
if ( v7 == -1 )
{
perror("socket()");
exit(-1);
}
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func7(v3);
*(struct in_addr *)&addr.sa_data[2] = inp;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( connect(v7, &addr, 0x10u) == -1 )
{
perror("connect()");
exit(-1);
}
if ( v4 )
func9(v7);
else
func8(v7);
close(v7);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    int sockfd;
    struct sockaddr_in their_addr;
 struct in_addr server_ip;
 int port;
 char ch;
 int retcode;
 int long_lived = 0;
    if (argc < 2) {
        usage();
        return -1;
    }
    while ((ch = getopt (argc, argv, "s:p:l")) != -1) {
        switch (ch) {
  case 's':
   retcode = inet_aton(optarg, &server_ip);
   if (retcode == 0) {
    printf("wrong address format\n");
    return -1;
   }
        case 'p':
            port = atoi(optarg);
            break;
        case 'l':
            long_lived = 1;
            break;
        default:
            usage();
            return -1;
        }
    }
    if((sockfd = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("socket()");
        exit(-1);
    }
    their_addr.sin_family = 2;
    their_addr.sin_port = htons(port);
    their_addr.sin_addr.s_addr = server_ip.s_addr;
    memset(&(their_addr.sin_zero), '\0', 8);
    if(connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) {
        perror("connect()");
        exit(-1);
    }
 if (long_lived) {
  long_lived_connection(sockfd);
 } else {
  short_lived_connection(sockfd);
 }
    close(sockfd);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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

variable_types: ch char

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


repo: dropletzhu/msuite

decompiled_code:
__pid_t sigchld_handler()
{
__pid_t result; // eax

do
result = wait(0LL);
while ( result > 0 );
return result;
}

canonical_decompiled_code:
__pid_t func7()
{
__pid_t result; // eax

do
result = wait(0LL);
while ( result > 0 );
return result;
}

original_code:
void sigchld_handler(int s)
{
    while(wait(((void *)0)) > 0);
}

variable_types: s int

return_type: void


decompiled_code:
int __fastcall echo_server(int fd)
{
ssize_t v1; // rax
ssize_t v2; // rax
_BYTE savedregs[536]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x200uLL);
v1 = recv(fd, savedregs, 0x200uLL, 0);
printf("recv %d\n", v1);
v2 = send(fd, savedregs, 0x200uLL, 0);
return printf("send %d\n", v2);
}

canonical_decompiled_code:
int __fastcall func9(int fd)
{
ssize_t v1; // rax
ssize_t v2; // rax
_BYTE savedregs[536]; // [rsp+0h] [rbp+0h] BYREF

memset(savedregs, 0, 0x200uLL);
v1 = recv(fd, savedregs, 0x200uLL, 0);
printf("recv %d\n", v1);
v2 = send(fd, savedregs, 0x200uLL, 0);
return printf("send %d\n", v2);
}

original_code:
void echo_server(int socket_fd)
{
 int result;
 char buffer[512];
 memset(buffer, 0, 512);
 result = recv(socket_fd, buffer, 512, 0);
 printf("recv %d\n", result);
 result = send(socket_fd, buffer, 512, 0);
 printf("send %d\n", result);
}

variable_types: result int

variable_types:
buffer
char [512]


decompiled_code:
int __fastcall long_lived_server(int fd)
{
int v1; // er12
__int64 v2; // r13
int *v3; // rax
char *v4; // rax
int v6; // eax
int v7; // eax
int *v8; // rax
char *v9; // rax
__int64 v10; // [rsp+0h] [rbp-8A8h] BYREF
fd_set readfds; // [rsp+800h] [rbp-A8h] BYREF

v1 = fd / 64;
v2 = 1LL << (fd % 64);
do
{
while ( 1 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v1] |= v2;
v6 = select(fd + 1, &readfds, 0LL, 0LL, 0LL);
if ( v6 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_3;
}
if ( v6 <= 0 )
break;
if ( (readfds.fds_bits[v1] & v2) != 0 )
{
do
v7 = recv(fd, &v10, 0x800uLL, 0);
while ( v7 > 0 );
if ( v7 < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
printf("Error on recv(): %s\n", v9);
}
}
}
}
while ( v6 >= 0 );
LABEL_3:
v3 = __errno_location();
v4 = strerror(*v3);
return printf("Error on select(): %s\n", v4);
}

canonical_decompiled_code:
int __fastcall func10(int fd)
{
int v1; // er12
__int64 v2; // r13
int *v3; // rax
char *v4; // rax
int v6; // eax
int v7; // eax
int *v8; // rax
char *v9; // rax
__int64 v10; // [rsp+0h] [rbp-8A8h] BYREF
fd_set readfds; // [rsp+800h] [rbp-A8h] BYREF

v1 = fd / 64;
v2 = 1LL << (fd % 64);
do
{
while ( 1 )
{
while ( 1 )
{
memset(&readfds, 0, sizeof(readfds));
readfds.fds_bits[v1] |= v2;
v6 = select(fd + 1, &readfds, 0LL, 0LL, 0LL);
if ( v6 != -1 )
break;
if ( *__errno_location() != 4 )
goto LABEL_3;
}
if ( v6 <= 0 )
break;
if ( (readfds.fds_bits[v1] & v2) != 0 )
{
do
v7 = recv(fd, &v10, 0x800uLL, 0);
while ( v7 > 0 );
if ( v7 < 0 )
{
v8 = __errno_location();
v9 = strerror(*v8);
printf("Error on recv(): %s\n", v9);
}
}
}
}
while ( v6 >= 0 );
LABEL_3:
v3 = __errno_location();
v4 = strerror(*v3);
return printf("Error on select(): %s\n", v4);
}

original_code:
void long_lived_server(int socket_fd)
{
 int result;
 fd_set readset;
 char buffer[2048];
 while (1) {
  do {
   do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readset)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&readset)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
   result = select(socket_fd + 1, &readset, ((void *)0), ((void *)0), ((void *)0));
  } while (result == -1 && (*__errno_location ()) == 4);
  if (result > 0) {
   if (((((&readset)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    do {
     result = recv(socket_fd, buffer, 2048, 0);
    } while (result > 0);
    if (result < 0) {
     printf("Error on recv(): %s\n", strerror((*__errno_location ())));
    }
   }
  } else if (result < 0) {
   printf("Error on select(): %s\n", strerror((*__errno_location ())));
   break;
  }
 }
}

canonical_original_code:
void long_lived_server(int socket_fd)
{
 int result;
 struct fd_set readset;
 char buffer[2048];
 while (1) {
  do {
   do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&readset)->__fds_bits)[0]) : "memory"); } while (0);
   ((void) (((&readset)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))));
   result = select(socket_fd + 1, &readset, ((void *)0), ((void *)0), ((void *)0));
  } while (result == -1 && (*__errno_location ()) == 4);
  if (result > 0) {
   if (((((&readset)->__fds_bits)[((socket_fd) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((socket_fd) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    do {
     result = recv(socket_fd, buffer, 2048, 0);
    } while (result > 0);
    if (result < 0) {
     printf("Error on recv(): %s\n", strerror((*__errno_location ())));
    }
   }
  } else if (result < 0) {
   printf("Error on select(): %s\n", strerror((*__errno_location ())));
   break;
  }
 }
}

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

variable_types:
buffer
char [2048]


usage

decompiled_code:
int usage()
{
puts("Usage: ./tcpserver -p [port] -l");
puts(" -p [port]\t\tlisten on this port");
return puts(" -l\t\t\tcreate long-lived connection, by default, it is short-lived echo connection");
}

canonical_decompiled_code:
int func11()
{
puts("Usage: ./tcpserver -p [port] -l");
puts(" -p [port]\t\tlisten on this port");
return puts(" -l\t\t\tcreate long-lived connection, by default, it is short-lived echo connection");
}

original_code:
void usage()
{
 printf("Usage: ./tcpserver -p [port] -l\n");
 printf("  -p [port]		listen on this port\n");
 printf("  -l			create long-lived connection, by default, it is short-lived echo connection\n");
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // r12
int v4; // er13
char v5; // al
int v7; // ebp
int v8; // er12
unsigned __int16 v9; // bx
char *v10; // rax
int optval; // [rsp+Ch] [rbp-ECh] BYREF
struct sigaction v12; // [rsp+10h] [rbp-E8h] BYREF
socklen_t addr_len; // [rsp+ACh] [rbp-4Ch] BYREF
struct sockaddr v14; // [rsp+B0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+C0h] [rbp-38h] BYREF

optval = 1;
v4 = 0;
if ( argc > 1 )
{
while ( 1 )
{
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "p:l");
if ( v5 == -1 )
{
v7 = socket(2, 1, 0);
if ( v7 != -1 )
{
puts("Server-socket() sockfd is OK...");
if ( setsockopt(v7, 1, 2, &optval, 4u) != -1 )
{
puts("Server-setsockopt is OK...");
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(v3);
*(_DWORD *)&addr.sa_data[2] = 0;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( bind(v7, &addr, 0x10u) != -1 )
{
puts("Server-bind() is OK...");
if ( listen(v7, 10) != -1 )
{
v12.sa_handler = (__sighandler_t)sigchld_handler;
sigemptyset(&v12.sa_mask);
v12.sa_flags = 0x10000000;
if ( sigaction(17, &v12, 0LL) != -1 )
{
puts("Server-sigaction() is OK...");
while ( 1 )
{
while ( 1 )
{
addr_len = 16;
v8 = accept(v7, &v14, &addr_len);
if ( v8 != -1 )
break;
perror("Server-accept() error");
}
v9 = _bswap_16(*(__int16 *)v14.sa_data);
v10 = inet_ntoa(*(struct in_addr *)&v14.sa_data[2]);
printf("Server: Got connection from %s-%d\n", v10, v9);
if ( !fork() )
break;
close(v8);
}
close(v7);
if ( v4 )
long_lived_server(v8);
else
echo_server(v8);
close(v8);
exit(0);
}
perror("Server-sigaction() error");
exit(1);
}
perror("Server-listen() error");
exit(1);
}
perror("Server-bind() error");
exit(1);
}
perror("Server-setsockopt() error lol!");
exit(1);
}
perror("Server-socket() error lol!");
exit(1);
}
if ( v5 != 108 )
break;
v4 = 1;
}
if ( v5 != 112 )
break;
v3 = atoi(_bss_start);
}
}
usage();
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int16 v3; // r12
int v4; // er13
char v5; // al
int v7; // ebp
int v8; // er12
unsigned __int16 v9; // bx
char *v10; // rax
int optval; // [rsp+Ch] [rbp-ECh] BYREF
struct sigaction v12; // [rsp+10h] [rbp-E8h] BYREF
socklen_t addr_len; // [rsp+ACh] [rbp-4Ch] BYREF
struct sockaddr v14; // [rsp+B0h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+C0h] [rbp-38h] BYREF

optval = 1;
v4 = 0;
if ( argc > 1 )
{
while ( 1 )
{
while ( 1 )
{
v5 = getopt(argc, (char *const *)argv, "p:l");
if ( v5 == -1 )
{
v7 = socket(2, 1, 0);
if ( v7 != -1 )
{
puts("Server-socket() sockfd is OK...");
if ( setsockopt(v7, 1, 2, &optval, 4u) != -1 )
{
puts("Server-setsockopt is OK...");
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func8(v3);
*(_DWORD *)&addr.sa_data[2] = 0;
*(_QWORD *)&addr.sa_data[6] = 0LL;
if ( bind(v7, &addr, 0x10u) != -1 )
{
puts("Server-bind() is OK...");
if ( listen(v7, 10) != -1 )
{
v12.sa_handler = (__sighandler_t)sigchld_handler;
sigemptyset(&v12.sa_mask);
v12.sa_flags = 0x10000000;
if ( sigaction(17, &v12, 0LL) != -1 )
{
puts("Server-sigaction() is OK...");
while ( 1 )
{
while ( 1 )
{
addr_len = 16;
v8 = accept(v7, &v14, &addr_len);
if ( v8 != -1 )
break;
perror("Server-accept() error");
}
v9 = func8(*(__int16 *)v14.sa_data);
v10 = inet_ntoa(*(struct in_addr *)&v14.sa_data[2]);
printf("Server: Got connection from %s-%d\n", v10, v9);
if ( !fork() )
break;
close(v8);
}
close(v7);
if ( v4 )
func10(v8);
else
func9(v8);
close(v8);
exit(0);
}
perror("Server-sigaction() error");
exit(1);
}
perror("Server-listen() error");
exit(1);
}
perror("Server-bind() error");
exit(1);
}
perror("Server-setsockopt() error lol!");
exit(1);
}
perror("Server-socket() error lol!");
exit(1);
}
if ( v5 != 108 )
break;
v4 = 1;
}
if ( v5 != 112 )
break;
v3 = atoi(_bss_start);
}
}
func11();
return -1;
}

original_code:
int main(int argc, char *argv[ ])
{
    int sockfd, new_fd;
    struct sockaddr_in my_addr;
    struct sockaddr_in their_addr;
    int sin_size;
    struct sigaction sa;
    int yes = 1;
 int port;
 char ch;
 int long_lived = 0;
 if (argc < 2) {
  usage();
  return -1;
 }
 while ((ch = getopt (argc, argv, "p:l")) != -1) {
        switch (ch) {
        case 'p':
   port = atoi(optarg);
            break;
  case 'l':
   long_lived = 1;
   break;
  default:
   usage();
   return -1;
  }
 }
    if ((sockfd = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("Server-socket() error lol!");
        exit(1);
    } else {
        printf("Server-socket() sockfd is OK...\n");
    }
    if (setsockopt(sockfd, 1, 2, &yes, sizeof(int)) == -1) {
        perror("Server-setsockopt() error lol!");
        exit(1);
    } else {
        printf("Server-setsockopt is OK...\n");
    }
    my_addr.sin_family = 2;
    my_addr.sin_port = htons(port);
    my_addr.sin_addr.s_addr = ((in_addr_t) 0x00000000);
    memset(&(my_addr.sin_zero), '\0', 8);
    if(bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
        perror("Server-bind() error");
        exit(1);
    } else {
        printf("Server-bind() is OK...\n");
    }
    if(listen(sockfd, 10) == -1) {
        perror("Server-listen() error");
        exit(1);
    }
    sa.__sigaction_handler.sa_handler = sigchld_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0x10000000;
    if(sigaction(17, &sa, ((void *)0)) == -1) {
        perror("Server-sigaction() error");
        exit(1);
    } else {
        printf("Server-sigaction() is OK...\n");
    }
    while(1) {
        sin_size = sizeof(struct sockaddr_in);
        if((new_fd = accept(sockfd, (struct sockaddr *)&their_addr,(socklen_t*)&sin_size)) == -1) {
            perror("Server-accept() error");
            continue;
        }
        printf("Server: Got connection from %s-%d\n", inet_ntoa(their_addr.sin_addr), ntohs(their_addr.sin_port));
        if(!fork()) {
            close(sockfd);
   if (long_lived) {
    long_lived_server(new_fd);
   } else {
    echo_server(new_fd);
   }
            close(new_fd);
            exit(0);
        } else {
            close(new_fd);
        }
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int sockfd; int new_fd;
    struct sockaddr_in my_addr;
    struct sockaddr_in their_addr;
    int sin_size;
    struct sigaction sa;
    int yes = 1;
 int port;
 char ch;
 int long_lived = 0;
 if (argc < 2) {
  usage();
  return -1;
 }
 while ((ch = getopt (argc, argv, "p:l")) != -1) {
        switch (ch) {
        case 'p':
   port = atoi(optarg);
            break;
  case 'l':
   long_lived = 1;
   break;
  default:
   usage();
   return -1;
  }
 }
    if ((sockfd = socket(2, SOCK_STREAM, 0)) == -1) {
        perror("Server-socket() error lol!");
        exit(1);
    } else {
        printf("Server-socket() sockfd is OK...\n");
    }
    if (setsockopt(sockfd, 1, 2, &yes, sizeof(int)) == -1) {
        perror("Server-setsockopt() error lol!");
        exit(1);
    } else {
        printf("Server-setsockopt is OK...\n");
    }
    my_addr.sin_family = 2;
    my_addr.sin_port = htons(port);
    my_addr.sin_addr.s_addr = ((unsigned int) 0x00000000);
    memset(&(my_addr.sin_zero), '\0', 8);
    if(bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr)) == -1) {
        perror("Server-bind() error");
        exit(1);
    } else {
        printf("Server-bind() is OK...\n");
    }
    if(listen(sockfd, 10) == -1) {
        perror("Server-listen() error");
        exit(1);
    }
    sa.__sigaction_handler.sa_handler = sigchld_handler;
    sigemptyset(&sa.sa_mask);
    sa.sa_flags = 0x10000000;
    if(sigaction(17, &sa, ((void *)0)) == -1) {
        perror("Server-sigaction() error");
        exit(1);
    } else {
        printf("Server-sigaction() is OK...\n");
    }
    while(1) {
        sin_size = sizeof(struct sockaddr_in);
        if((new_fd = accept(sockfd, (struct sockaddr *)&their_addr,(unsigned int *)&sin_size)) == -1) {
            perror("Server-accept() error");
            continue;
        }
        printf("Server: Got connection from %s-%d\n", inet_ntoa(their_addr.sin_addr), ntohs(their_addr.sin_port));
        if(!fork()) {
            close(sockfd);
   if (long_lived) {
    long_lived_server(new_fd);
   } else {
    echo_server(new_fd);
   }
            close(new_fd);
            exit(0);
        } else {
            close(new_fd);
        }
    }
    return 0;
}

variable_types: sockfd int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types: yes int

return_type: int

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


error

decompiled_code:
void __fastcall __noreturn error(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func9(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void error(char *msg) {
  perror(msg);
  exit(1);
}

variable_types:
msg
char *


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int16 v3; // bx
int v4; // eax
int v5; // ebp
char *v6; // rsi
size_t v7; // rax
int optval; // [rsp+Ch] [rbp-44Ch] BYREF
char buf[1024]; // [rsp+10h] [rbp-448h] BYREF
struct sockaddr v10; // [rsp+410h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+420h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+43Ch] [rbp-1Ch] BYREF

if ( argc != 2 )
{
fprintf(stderr, "usage: %s <port>\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = socket(2, 2, 0);
v5 = v4;
if ( v4 >= 0 )
{
optval = 1;
setsockopt(v4, 1, 2, &optval, 4u);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)_bswap_32(0);
*(_WORD *)addr.sa_data = _bswap_16(v3);
if ( bind(v5, &addr, 0x10u) >= 0 )
{
addr_len[0] = 16;
while ( 1 )
{
memset(buf, 0, sizeof(buf));
if ( (int)recvfrom(v5, buf, 0x400uLL, 0, &v10, addr_len) < 0 )
break;
v6 = inet_ntoa(*(struct in_addr *)&v10.sa_data[2]);
if ( !v6 )
error("ERROR on inet_ntoa\n");
printf("server received datagram from %s\n", v6);
v7 = strlen(buf);
if ( (int)sendto(v5, buf, v7, 0, &v10, addr_len[0]) < 0 )
error("ERROR in sendto");
}
error("ERROR in recvfrom");
}
error("ERROR on binding");
}
error("ERROR opening socket");
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
__int16 v3; // bx
int v4; // eax
int v5; // ebp
char *v6; // rsi
size_t v7; // rax
int optval; // [rsp+Ch] [rbp-44Ch] BYREF
char buf[1024]; // [rsp+10h] [rbp-448h] BYREF
struct sockaddr v10; // [rsp+410h] [rbp-48h] BYREF
struct sockaddr addr; // [rsp+420h] [rbp-38h] BYREF
socklen_t addr_len[7]; // [rsp+43Ch] [rbp-1Ch] BYREF

if ( argc != 2 )
{
fprintf(stderr, "usage: %s <port>\n", *argv);
exit(1);
}
v3 = atoi(argv[1]);
v4 = socket(2, 2, 0);
v5 = v4;
if ( v4 >= 0 )
{
optval = 1;
setsockopt(v4, 1, 2, &optval, 4u);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[2] = (unsigned int)func7(0);
*(_WORD *)addr.sa_data = func8(v3);
if ( bind(v5, &addr, 0x10u) >= 0 )
{
addr_len[0] = 16;
while ( 1 )
{
memset(buf, 0, sizeof(buf));
if ( (int)recvfrom(v5, buf, 0x400uLL, 0, &v10, addr_len) < 0 )
break;
v6 = inet_ntoa(*(struct in_addr *)&v10.sa_data[2]);
if ( !v6 )
func9("ERROR on inet_ntoa\n");
printf("server received datagram from %s\n", v6);
v7 = strlen(buf);
if ( (int)sendto(v5, buf, v7, 0, &v10, addr_len[0]) < 0 )
func9("ERROR in sendto");
}
func9("ERROR in recvfrom");
}
func9("ERROR on binding");
}
func9("ERROR opening socket");
}

original_code:
int main(int argc, char **argv) {
  int sockfd;
  int portno;
  unsigned int clientlen;
  struct sockaddr_in serveraddr;
  struct sockaddr_in clientaddr;
  char buf[1024];
  char *hostaddrp;
  int optval;
  int n;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <port>\n", argv[0]);
    exit(1);
  }
  portno = atoi(argv[1]);
  sockfd = socket(2, SOCK_DGRAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  optval = 1;
  setsockopt(sockfd, 1, 2,
      (const void *)&optval , sizeof(int));
  bzero((char *) &serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = 2;
  serveraddr.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
  serveraddr.sin_port = htons((unsigned short)portno);
  if (bind(sockfd, (struct sockaddr *) &serveraddr,
    sizeof(serveraddr)) < 0)
    error("ERROR on binding");
  clientlen = sizeof(clientaddr);
  while (1) {
    bzero(buf, 1024);
    n = recvfrom(sockfd, buf, 1024, 0,
   (struct sockaddr *) &clientaddr, &clientlen);
    if (n < 0)
      error("ERROR in recvfrom");
    hostaddrp = inet_ntoa(clientaddr.sin_addr);
    if (hostaddrp == ((void *)0))
      error("ERROR on inet_ntoa\n");
    printf("server received datagram from %s\n", hostaddrp);
    n = sendto(sockfd, buf, strlen(buf), 0,
        (struct sockaddr *) &clientaddr, clientlen);
    if (n < 0)
      error("ERROR in sendto");
  }
}

canonical_original_code:
int main(int argc, char **argv) {
  int sockfd;
  int portno;
  unsigned int clientlen;
  struct sockaddr_in serveraddr;
  struct sockaddr_in clientaddr;
  char buf[1024];
  char *hostaddrp;
  int optval;
  int n;
  if (argc != 2) {
    fprintf(stderr, "usage: %s <port>\n", argv[0]);
    exit(1);
  }
  portno = atoi(argv[1]);
  sockfd = socket(2, SOCK_DGRAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  optval = 1;
  setsockopt(sockfd, 1, 2,
      (void *)&optval , sizeof(int));
  bzero((char *) &serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = 2;
  serveraddr.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
  serveraddr.sin_port = htons((unsigned short)portno);
  if (bind(sockfd, (struct sockaddr *) &serveraddr,
    sizeof(serveraddr)) < 0)
    error("ERROR on binding");
  clientlen = sizeof(clientaddr);
  while (1) {
    bzero(buf, 1024);
    n = recvfrom(sockfd, buf, 1024, 0,
   (struct sockaddr *) &clientaddr, &clientlen);
    if (n < 0)
      error("ERROR in recvfrom");
    hostaddrp = inet_ntoa(clientaddr.sin_addr);
    if (hostaddrp == ((void *)0))
      error("ERROR on inet_ntoa\n");
    printf("server received datagram from %s\n", hostaddrp);
    n = sendto(sockfd, buf, strlen(buf), 0,
        (struct sockaddr *) &clientaddr, clientlen);
    if (n < 0)
      error("ERROR in sendto");
  }
}

variable_types:
argv
char **

variable_types: portno int

variable_types:
clientlen
unsigned int

variable_types:
buf
char [1024]

variable_types:
hostaddrp
char *

variable_types: optval int

variable_types: n int


decompiled_code:
__int64 __fastcall buffer_push(__int64 a1, const char *a2)
{
pthread_mutex_t *v2; // r13
int v3; // eax
_QWORD *v4; // rbp
char *v5; // rax
__int64 v6; // rax
__int64 result; // rax

v2 = (pthread_mutex_t *)(a1 + 48);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
v3 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) == v3 && v3 )
{
pthread_mutex_unlock(v2);
++*(_QWORD *)(a1 + 16);
*_errno_location() = 105;
result = 0xFFFFFFFFLL;
}
else
{
v4 = malloc(0x20uLL);
if ( v4 )
{
v5 = strdup(a2);
*v4 = v5;
v4[1] = strlen(v5);
v4[3] = 0LL;
v6 = *(_QWORD *)(a1 + 96);
v4[2] = v6;
if ( v6 )
*(_QWORD *)(v6 + 24) = v4;
*(_QWORD *)(a1 + 96) = v4;
if ( !*(_QWORD *)(a1 + 88) )
*(_QWORD *)(a1 + 88) = v4;
++*(_DWORD *)(a1 + 8);
++*(_QWORD *)(a1 + 24);
pthread_mutex_unlock(v2);
result = 0LL;
}
else
{
pthread_mutex_unlock(v2);
++*(_QWORD *)(a1 + 16);
*_errno_location() = 12;
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char *a2)
{
pthread_mutex_t *v2; // r13
int v3; // eax
_QWORD *v4; // rbp
char *v5; // rax
__int64 v6; // rax
__int64 result; // rax

v2 = (pthread_mutex_t *)(a1 + 48);
pthread_mutex_lock((pthread_mutex_t *)(a1 + 48));
v3 = *(_DWORD *)(a1 + 12);
if ( *(_DWORD *)(a1 + 8) == v3 && v3 )
{
pthread_mutex_unlock(v2);
++*(_QWORD *)(a1 + 16);
*_errno_location() = 105;
result = 0xFFFFFFFFLL;
}
else
{
v4 = malloc(0x20uLL);
if ( v4 )
{
v5 = strdup(a2);
*v4 = v5;
v4[1] = strlen(v5);
v4[3] = 0LL;
v6 = *(_QWORD *)(a1 + 96);
v4[2] = v6;
if ( v6 )
*(_QWORD *)(v6 + 24) = v4;
*(_QWORD *)(a1 + 96) = v4;
if ( !*(_QWORD *)(a1 + 88) )
*(_QWORD *)(a1 + 88) = v4;
++*(_DWORD *)(a1 + 8);
++*(_QWORD *)(a1 + 24);
pthread_mutex_unlock(v2);
result = 0LL;
}
else
{
pthread_mutex_unlock(v2);
++*(_QWORD *)(a1 + 16);
*_errno_location() = 12;
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int buffer_push(buffer_t*buffer,const char*chunk_buffer) {
 buffer_chunk_t*bc_new;
 pthread_mutex_lock(&(buffer->mutex));
 if(buffer->nb_chunk == buffer->nb_chunk_max && buffer->nb_chunk_max != 0) {
  pthread_mutex_unlock(&(buffer->mutex));
  buffer->discarded++;
  (*__errno_location ())=105;
  return -1;
 }
 bc_new=malloc(sizeof(buffer_chunk_t));
 if(bc_new == ((void *)0)) {
  pthread_mutex_unlock(&(buffer->mutex));
  buffer->discarded++;
  (*__errno_location ())=12;
  return -1;
 }
 bc_new->buffer=strdup(chunk_buffer);
 bc_new->nb_chars=strlen(bc_new->buffer);
 bc_new->next=((void *)0);
 bc_new->prev=buffer->last;
 if(buffer->last != ((void *)0)) {
  buffer->last->next=bc_new;
 }
 buffer->last=bc_new;
 if(buffer->first == ((void *)0)) {
  buffer->first = buffer->last;
 }
 buffer->nb_chunk++;
 buffer->added++;
 pthread_mutex_unlock(&(buffer->mutex));
 return 0;
}

canonical_original_code:
int buffer_push(struct buffer *buffer, char *chunk_buffer) {
 struct buffer_chunk *bc_new;
 pthread_mutex_lock(&(buffer->mutex));
 if(buffer->nb_chunk == buffer->nb_chunk_max && buffer->nb_chunk_max != 0) {
  pthread_mutex_unlock(&(buffer->mutex));
  buffer->discarded++;
  (*__errno_location ())=105;
  return -1;
 }
 bc_new=malloc(sizeof(buffer_chunk_t));
 if(bc_new == ((void *)0)) {
  pthread_mutex_unlock(&(buffer->mutex));
  buffer->discarded++;
  (*__errno_location ())=12;
  return -1;
 }
 bc_new->buffer=strdup(chunk_buffer);
 bc_new->nb_chars=strlen(bc_new->buffer);
 bc_new->next=((void *)0);
 bc_new->prev=buffer->last;
 if(buffer->last != ((void *)0)) {
  buffer->last->next=bc_new;
 }
 buffer->last=bc_new;
 if(buffer->first == ((void *)0)) {
  buffer->first = buffer->last;
 }
 buffer->nb_chunk++;
 buffer->added++;
 pthread_mutex_unlock(&(buffer->mutex));
 return 0;
}

variable_types: struct buffer { char *separator; unsigned int nb_chunk; unsigned int nb_chunk_max; unsigned long long discarded; unsigned long long added; unsigned long long deleted; char *incomplete_chunk; 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; } mutex; struct buffer_chunk { char *buffer; long nb_chars; struct buffer_chunk *prev; struct buffer_chunk *next; } *first; struct buffer_chunk *last; } *

user_defined_types: struct buffer { char *separator; unsigned int nb_chunk; unsigned int nb_chunk_max; unsigned long long discarded; unsigned long long added; unsigned long long deleted; char *incomplete_chunk; union pthread_mutex_t mutex; struct buffer_chunk *first; struct buffer_chunk *last; }

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:
__int64 __fastcall buffer_push_vprintf(__int64 a1, const char *a2, void *a3)
{
unsigned int v4; // ebx
char *v5; // rax
char *v6; // rbp
int v7; // er12

v4 = vsnprintf(0LL, 0LL, a2, a3);
v5 = (char *)malloc((int)(v4 + 1));
if ( v5 )
{
v6 = v5;
vsprintf(v5, a2, a3);
v7 = buffer_push(a1, v6);
free(v6);
if ( v7 == -1 )
v4 = -1;
}
else
{
*_errno_location() = 12;
v4 = -1;
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, void *a3)
{
unsigned int v4; // ebx
char *v5; // rax
char *v6; // rbp
int v7; // er12

v4 = vsnprintf(0LL, 0LL, a2, a3);
v5 = (char *)malloc((int)(v4 + 1));
if ( v5 )
{
v6 = v5;
vsprintf(v5, a2, a3);
v7 = func0(a1, v6);
free(v6);
if ( v7 == -1 )
v4 = -1;
}
else
{
*_errno_location() = 12;
v4 = -1;
}
return v4;
}

original_code:
int buffer_push_vprintf(buffer_t*buffer,const char*format, va_list va) {
 char*chunk_buffer;
 int nb_chars;
 int result;
 nb_chars=vsnprintf(chunk_buffer,0,format,va);
 chunk_buffer=malloc((nb_chars+1)*sizeof(char));
 if(chunk_buffer == ((void *)0)) {
  (*__errno_location ())=12;
  return -1;
 }
 vsprintf(chunk_buffer,format,va);
 result = buffer_push(buffer,chunk_buffer);
 free(chunk_buffer);
 chunk_buffer=((void *)0);
 if(result == -1) {
  return -1;
 }
 return nb_chars;
}

canonical_original_code:
int buffer_push_vprintf(struct buffer *buffer, char *format, __builtin_va_list va) {
 char *chunk_buffer;
 int nb_chars;
 int result;
 nb_chars=vsnprintf(chunk_buffer,0,format,va);
 chunk_buffer=malloc((nb_chars+1)*sizeof(char));
 if(chunk_buffer == ((void *)0)) {
  (*__errno_location ())=12;
  return -1;
 }
 vsprintf(chunk_buffer,format,va);
 result = buffer_push(buffer,chunk_buffer);
 free(chunk_buffer);
 chunk_buffer=((void *)0);
 if(result == -1) {
  return -1;
 }
 return nb_chars;
}

variable_types:
format
char *

user_defined_types: struct buffer_chunk { char *buffer; long nb_chars; struct buffer_chunk *prev; struct buffer_chunk *next; }

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


decompiled_code:
__int64 buffer_push_printf(__int64 a1, const char *a2, ...)
{
unsigned int v2; // ebx
char *v3; // rbp
int v4; // er12
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v2 = vsnprintf(0LL, 0LL, a2, arg);
v3 = (char *)malloc((int)(v2 + 1));
if ( v3 )
{
va_end(arg);
va_start(arg, a2);
vsprintf(v3, a2, arg);
v4 = buffer_push(a1, v3);
free(v3);
if ( v4 == -1 )
v2 = -1;
}
else
{
*_errno_location() = 12;
v2 = -1;
}
return v2;
}

canonical_decompiled_code:
__int64 func2(__int64 a1, const char *a2, ...)
{
unsigned int v2; // ebx
char *v3; // rbp
int v4; // er12
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a2);
v2 = vsnprintf(0LL, 0LL, a2, arg);
v3 = (char *)malloc((int)(v2 + 1));
if ( v3 )
{
va_end(arg);
va_start(arg, a2);
vsprintf(v3, a2, arg);
v4 = func0(a1, v3);
free(v3);
if ( v4 == -1 )
v2 = -1;
}
else
{
*_errno_location() = 12;
v2 = -1;
}
return v2;
}

original_code:
int buffer_push_printf(buffer_t*buffer,const char*format, ...) {
 char*chunk_buffer;
 va_list va;
 int nb_chars;
 int result;
 __builtin_va_start(va,format);
 nb_chars=vsnprintf(chunk_buffer,0,format,va);
 __builtin_va_end(va);
 chunk_buffer=malloc((nb_chars+1)*sizeof(char));
 if(chunk_buffer == ((void *)0)) {
  (*__errno_location ())=12;
  return -1;
 }
 __builtin_va_start(va,format);
 vsprintf(chunk_buffer,format,va);
 __builtin_va_end(va);
 result = buffer_push(buffer,chunk_buffer);
 free(chunk_buffer);
 chunk_buffer=((void *)0);
 if(result == -1) {
  return -1;
 }
 return nb_chars;
}

canonical_original_code:
int buffer_push_printf(struct buffer *buffer, char *format, ...) {
 char *chunk_buffer;
 __builtin_va_list va;
 int nb_chars;
 int result;
 __builtin_va_start(va,format);
 nb_chars=vsnprintf(chunk_buffer,0,format,va);
 __builtin_va_end(va);
 chunk_buffer=malloc((nb_chars+1)*sizeof(char));
 if(chunk_buffer == ((void *)0)) {
  (*__errno_location ())=12;
  return -1;
 }
 __builtin_va_start(va,format);
 vsprintf(chunk_buffer,format,va);
 __builtin_va_end(va);
 result = buffer_push(buffer,chunk_buffer);
 free(chunk_buffer);
 chunk_buffer=((void *)0);
 if(result == -1) {
  return -1;
 }
 return nb_chars;
}

variable_types: result int


decompiled_code:
__int64 __fastcall buffer_push_vnprintf(__int64 a1, signed int a2, const char *a3, void *a4)
{
unsigned int v6; // ebx
char *v7; // rax
char *v8; // rbp
int v9; // er12

v6 = vsnprintf(0LL, 0LL, a3, a4);
if ( (int)(v6 - 1) > a2 )
{
*_errno_location() = 36;
v6 = -1;
}
else
{
v7 = (char *)malloc((int)(v6 + 1));
v8 = v7;
if ( v7 )
{
vsprintf(v7, a3, a4);
v9 = buffer_push(a1, v8);
free(v8);
if ( v9 == -1 )
v6 = -1;
}
else
{
*_errno_location() = 12;
v6 = -1;
}
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, signed int a2, const char *a3, void *a4)
{
unsigned int v6; // ebx
char *v7; // rax
char *v8; // rbp
int v9; // er12

v6 = vsnprintf(0LL, 0LL, a3, a4);
if ( (int)(v6 - 1) > a2 )
{
*_errno_location() = 36;
v6 = -1;
}
else
{
v7 = (char *)malloc((int)(v6 + 1));
v8 = v7;
if ( v7 )
{
vsprintf(v7, a3, a4);
v9 = func0(a1, v8);
free(v8);
if ( v9 == -1 )
v6 = -1;
}
else
{
*_errno_location() = 12;
v6 = -1;
}
}
return v6;
}

original_code:
int buffer_push_vnprintf(buffer_t*buffer,size_t size, const char*format, va_list va) {
 char*chunk_buffer;
 int nb_chars;
 int result;
 nb_chars=vsnprintf(chunk_buffer,0,format,va);
 if((nb_chars-1) > (int)size) {
  (*__errno_location ())=36;
  return -1;
 }
 chunk_buffer=malloc((nb_chars+1)*sizeof(char));
 if(chunk_buffer == ((void *)0)) {
  (*__errno_location ())=12;
  return -1;
 }
 vsprintf(chunk_buffer,format,va);
 result = buffer_push(buffer,chunk_buffer);
 free(chunk_buffer);
 chunk_buffer=((void *)0);
 if(result == -1) {
  return -1;
 }
 return nb_chars;
}

canonical_original_code:
int buffer_push_vnprintf(struct buffer *buffer, unsigned long size, char *format, __builtin_va_list va) {
 char *chunk_buffer;
 int nb_chars;
 int result;
 nb_chars=vsnprintf(chunk_buffer,0,format,va);
 if((nb_chars-1) > (int)size) {
  (*__errno_location ())=36;
  return -1;
 }
 chunk_buffer=malloc((nb_chars+1)*sizeof(char));
 if(chunk_buffer == ((void *)0)) {
  (*__errno_location ())=12;
  return -1;
 }
 vsprintf(chunk_buffer,format,va);
 result = buffer_push(buffer,chunk_buffer);
 free(chunk_buffer);
 chunk_buffer=((void *)0);
 if(result == -1) {
  return -1;
 }
 return nb_chars;
}

variable_types:
size
unsigned long


decompiled_code:
__int64 buffer_push_nprintf(__int64 a1, signed int a2, const char *a3, ...)
{
unsigned int v4; // ebx
char *v5; // rbp
int v6; // er12
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a3);
v4 = vsnprintf(0LL, 0LL, a3, arg);
if ( (int)(v4 - 1) > a2 )
{
*_errno_location() = 36;
v4 = -1;
}
else
{
v5 = (char *)malloc((int)(v4 + 1));
if ( v5 )
{
va_end(arg);
va_start(arg, a3);
vsprintf(v5, a3, arg);
v6 = buffer_push(a1, v5);
free(v5);
if ( v6 == -1 )
v4 = -1;
}
else
{
*_errno_location() = 12;
v4 = -1;
}
}
return v4;
}

canonical_decompiled_code:
__int64 func4(__int64 a1, signed int a2, const char *a3, ...)
{
unsigned int v4; // ebx
char *v5; // rbp
int v6; // er12
gcc_va_list arg; // [rsp+8h] [rbp-F0h] BYREF

va_start(arg, a3);
v4 = vsnprintf(0LL, 0LL, a3, arg);
if ( (int)(v4 - 1) > a2 )
{
*_errno_location() = 36;
v4 = -1;
}
else
{
v5 = (char *)malloc((int)(v4 + 1));
if ( v5 )
{
va_end(arg);
va_start(arg, a3);
vsprintf(v5, a3, arg);
v6 = func0(a1, v5);
free(v5);
if ( v6 == -1 )
v4 = -1;
}
else
{
*_errno_location() = 12;
v4 = -1;
}
}
return v4;
}

original_code:
int buffer_push_nprintf(buffer_t*buffer,size_t size, const char*format, ...) {
 char*chunk_buffer;
 va_list va;
 int nb_chars;
 int result;
 __builtin_va_start(va,format);
 nb_chars=vsnprintf(chunk_buffer,0,format,va);
 __builtin_va_end(va);
 if((nb_chars-1) > (int)size) {
  (*__errno_location ())=36;
  return -1;
 }
 chunk_buffer=malloc((nb_chars+1)*sizeof(char));
 if(chunk_buffer == ((void *)0)) {
  (*__errno_location ())=12;
  return -1;
 }
 __builtin_va_start(va,format);
 vsprintf(chunk_buffer,format,va);
 __builtin_va_end(va);
 result = buffer_push(buffer,chunk_buffer);
 free(chunk_buffer);
 chunk_buffer=((void *)0);
 if(result == -1) {
  return -1;
 }
 return nb_chars;
}

canonical_original_code:
int buffer_push_nprintf(struct buffer *buffer, unsigned long size, char *format, ...) {
 char *chunk_buffer;
 __builtin_va_list va;
 int nb_chars;
 int result;
 __builtin_va_start(va,format);
 nb_chars=vsnprintf(chunk_buffer,0,format,va);
 __builtin_va_end(va);
 if((nb_chars-1) > (int)size) {
  (*__errno_location ())=36;
  return -1;
 }
 chunk_buffer=malloc((nb_chars+1)*sizeof(char));
 if(chunk_buffer == ((void *)0)) {
  (*__errno_location ())=12;
  return -1;
 }
 __builtin_va_start(va,format);
 vsprintf(chunk_buffer,format,va);
 __builtin_va_end(va);
 result = buffer_push(buffer,chunk_buffer);
 free(chunk_buffer);
 chunk_buffer=((void *)0);
 if(result == -1) {
  return -1;
 }
 return nb_chars;
}


original_code:
int buffer_destroy(buffer_t**buffer) {
 buffer_chunk_t*bc_temp;
 if(*buffer == ((void *)0)) {
  return 0;
 }
 bc_temp=(**buffer).first;
 while(bc_temp != ((void *)0)) {
  free(bc_temp->buffer);
  bc_temp->buffer=((void *)0);
  if(bc_temp->next == ((void *)0)) {
   free(bc_temp);
   bc_temp=((void *)0);
  } else {
   bc_temp=bc_temp->next;
   free(bc_temp->prev);
   bc_temp->prev=((void *)0);
  }
 }
 if((**buffer).incomplete_chunk != ((void *)0)) {
  free((**buffer).incomplete_chunk);
  (**buffer).incomplete_chunk=((void *)0);
 }
 if((**buffer).separator != ((void *)0)) {
  free((**buffer).separator);
  (**buffer).separator=((void *)0);
 }
 free(*buffer);
 *buffer=((void *)0);
 return 0;
}

canonical_original_code:
int buffer_destroy(struct buffer **buffer) {
 struct buffer_chunk *bc_temp;
 if(*buffer == ((void *)0)) {
  return 0;
 }
 bc_temp=(**buffer).first;
 while(bc_temp != ((void *)0)) {
  free(bc_temp->buffer);
  bc_temp->buffer=((void *)0);
  if(bc_temp->next == ((void *)0)) {
   free(bc_temp);
   bc_temp=((void *)0);
  } else {
   bc_temp=bc_temp->next;
   free(bc_temp->prev);
   bc_temp->prev=((void *)0);
  }
 }
 if((**buffer).incomplete_chunk != ((void *)0)) {
  free((**buffer).incomplete_chunk);
  (**buffer).incomplete_chunk=((void *)0);
 }
 if((**buffer).separator != ((void *)0)) {
  free((**buffer).separator);
  (**buffer).separator=((void *)0);
 }
 free(*buffer);
 *buffer=((void *)0);
 return 0;
}

variable_types: struct buffer { char *separator; unsigned int nb_chunk; unsigned int nb_chunk_max; unsigned long long discarded; unsigned long long added; unsigned long long deleted; char *incomplete_chunk; 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; } mutex; struct buffer_chunk { char *buffer; long nb_chars; struct buffer_chunk *prev; struct buffer_chunk *next; } *first; struct buffer_chunk *last; } **


decompiled_code:
__sighandler_t __fastcall signal_ignore(int a1)
{
return signal(a1, (__sighandler_t)((char *)buffer_shift + 1));
}

canonical_decompiled_code:
__sighandler_t __fastcall func6(int a1)
{
return signal(a1, (__sighandler_t)((char *)buffer_shift + 1));
}

original_code:
void signal_ignore(int signo) {
 signal(signo,((__sighandler_t) 1));
}

canonical_original_code:
void signal_ignore(int signo) {
 signal(signo,((void (*)(int)) 1));
}

variable_types: signo int


decompiled_code:
__sighandler_t __fastcall signal_reset(int a1)
{
return signal(a1, 0LL);
}

canonical_decompiled_code:
__sighandler_t __fastcall func7(int a1)
{
return signal(a1, 0LL);
}

original_code:
void signal_reset(int signo) {
 signal(signo,((__sighandler_t) 0));
}

canonical_original_code:
void signal_reset(int signo) {
 signal(signo,((void (*)(int)) 0));
}


decompiled_code:
__int64 __fastcall ss_sleep(unsigned int a1)
{
unsigned int i; // edi

for ( i = sleep(a1); i; i = sleep(i) )
;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1)
{
unsigned int i; // edi

for ( i = sleep(a1); i; i = sleep(i) )
;
return 0LL;
}

original_code:
unsigned int ss_sleep(unsigned int seconds) {
 unsigned int result;
 result = sleep(seconds);
 while(result != 0) {
  result = sleep(result);
 }
 return 0;
}

variable_types:
seconds
unsigned int

variable_types:
result
unsigned int

return_type: unsigned int


decompiled_code:
ssize_t __fastcall ss_write(int fd, void *buf, size_t n)
{
ssize_t v4; // r14
int *v5; // r13
ssize_t v6; // rax

v4 = write(fd, buf, n);
if ( v4 == -1 )
{
v5 = _errno_location();
while ( *v5 == 4 )
{
puts("Ecriture interrompue, on reprend");
v6 = write(fd, buf, n);
if ( v6 != -1 )
return v6;
}
}
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func9(int fd, void *buf, size_t n)
{
ssize_t v4; // r14
int *v5; // r13
ssize_t v6; // rax

v4 = write(fd, buf, n);
if ( v4 == -1 )
{
v5 = _errno_location();
while ( *v5 == 4 )
{
puts("Ecriture interrompue, on reprend");
v6 = write(fd, buf, n);
if ( v6 != -1 )
return v6;
}
}
return v4;
}

original_code:
ssize_t ss_write(int fildes, const void *buf, size_t nbyte) {
 ssize_t result;
 result = write(fildes,buf,nbyte);
 while(result == -1 && (*__errno_location ()) == 4) {
  printf("Ecriture interrompue, on reprend\n");
  result = write(fildes,buf,nbyte);
 }
 return result;
}

canonical_original_code:
long ss_write(int fildes, void *buf, unsigned long nbyte) {
 long result;
 result = write(fildes,buf,nbyte);
 while(result == -1 && (*__errno_location ()) == 4) {
  printf("Ecriture interrompue, on reprend\n");
  result = write(fildes,buf,nbyte);
 }
 return result;
}

variable_types: fildes int

variable_types:
buf
void *

variable_types:
nbyte
unsigned long

variable_types: result long

return_type: long


decompiled_code:
ssize_t __fastcall ss_read(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // r14
int *v5; // r13
ssize_t v6; // rax

v4 = read(fd, buf, nbytes);
if ( v4 == -1 )
{
v5 = _errno_location();
while ( *v5 == 4 )
{
puts("Lecture interrompue, on reprend");
v6 = read(fd, buf, nbytes);
if ( v6 != -1 )
return v6;
}
}
return v4;
}

canonical_decompiled_code:
ssize_t __fastcall func10(int fd, void *buf, size_t nbytes)
{
ssize_t v4; // r14
int *v5; // r13
ssize_t v6; // rax

v4 = read(fd, buf, nbytes);
if ( v4 == -1 )
{
v5 = _errno_location();
while ( *v5 == 4 )
{
puts("Lecture interrompue, on reprend");
v6 = read(fd, buf, nbytes);
if ( v6 != -1 )
return v6;
}
}
return v4;
}

original_code:
ssize_t ss_read(int fildes, void *buf, size_t nbyte) {
 ssize_t result;
 result = read(fildes,buf,nbyte);
 while(result == -1 && (*__errno_location ()) == 4) {
  printf("Lecture interrompue, on reprend\n");
  result = read(fildes,buf,nbyte);
 }
 return result;
}

canonical_original_code:
long ss_read(int fildes, void *buf, unsigned long nbyte) {
 long result;
 result = read(fildes,buf,nbyte);
 while(result == -1 && (*__errno_location ()) == 4) {
  printf("Lecture interrompue, on reprend\n");
  result = read(fildes,buf,nbyte);
 }
 return result;
}


timers

decompiled_code:
__time_t __fastcall timers(int a1, unsigned __int16 a2)
{
__time_t result; // rax
const char *v3; // rax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

if ( first_time_2 == 1 )
{
v3 = (const char *)timers_status_1;
do
{
*(_DWORD *)v3 = 0;
v3 += 4;
}
while ( v3 != "Ecriture interrompue, on reprend" );
first_time_2 = 0;
}
if ( a2 > 0x1FFu )
{
*_errno_location() = 22;
result = 0LL;
}
else if ( a1 )
{
if ( a1 == 1 )
{
result = 0LL;
if ( timers_status_1[a2] )
{
gettimeofday(&v4, 0LL);
result = v4.tv_sec - timers_0[2 * a2] - (v4.tv_usec < qword_908[2 * a2]);
}
}
else
{
result = 0LL;
}
}
else
{
gettimeofday((struct timeval *)&timers_0[2 * a2], 0LL);
timers_status_1[a2] = 1;
result = timers_0[2 * a2];
}
return result;
}

canonical_decompiled_code:
__time_t __fastcall func11(int a1, unsigned __int16 a2)
{
__time_t result; // rax
const char *v3; // rax
struct timeval v4; // [rsp+0h] [rbp-18h] BYREF

if ( first_time_2 == 1 )
{
v3 = (const char *)timers_status_1;
do
{
*(_DWORD *)v3 = 0;
v3 += 4;
}
while ( v3 != "Ecriture interrompue, on reprend" );
first_time_2 = 0;
}
if ( a2 > 0x1FFu )
{
*_errno_location() = 22;
result = 0LL;
}
else if ( a1 )
{
if ( a1 == 1 )
{
result = 0LL;
if ( timers_status_1[a2] )
{
gettimeofday(&v4, 0LL);
result = v4.tv_sec - timers_0[2 * a2] - (v4.tv_usec < qword_908[2 * a2]);
}
}
else
{
result = 0LL;
}
}
else
{
gettimeofday((struct timeval *)&timers_0[2 * a2], 0LL);
timers_status_1[a2] = 1;
result = timers_0[2 * a2];
}
return result;
}

original_code:
struct timeval timers(timer_action_t action, unsigned short int index) {
 static struct timeval timers[512];
 static timer_status_t timers_status[512];
 static bool_t first_time = TRUE;
 unsigned short int i;
 struct timeval tv;
 struct timeval result;
 result.tv_sec=0;
 result.tv_usec=0;
 if(first_time == TRUE) {
  for(i=0;i<512;i++) {
   timers_status[i]=UNUSED;
  }
  first_time = FALSE;
 }
 if(index > 512 -1) {
  (*__errno_location ())=22;
  return result;
 }
 switch(action) {
  case RESET:
   gettimeofday(&timers[index],((void *)0));
   timers_status[index]=INUSE;
   result.tv_sec=timers[index].tv_sec;
   result.tv_usec=timers[index].tv_usec;
   break;
  case GET:
   if(timers_status[index] == UNUSED) {
    result.tv_sec=0;
    result.tv_usec=0;
   } else {
    gettimeofday(&tv,((void *)0));
    if(tv.tv_usec < timers[index].tv_usec) {
     result.tv_usec=tv.tv_usec+1000000-timers[index].tv_usec;
     i=1;
    } else {
     result.tv_usec=tv.tv_usec-timers[index].tv_usec;
     i=0;
    }
    result.tv_sec=tv.tv_sec-timers[index].tv_sec-i;
   }
   break;
 }
 return result;
}

canonical_original_code:
struct timeval timers(enum timer_action_t action, unsigned short index) {
 static struct timeval timers[512];
 static enum timer_status_t timers_status[512];
 static enum bool_t first_time = TRUE;
 unsigned short i;
 struct timeval tv;
 struct timeval result;
 result.tv_sec=0;
 result.tv_usec=0;
 if(first_time == TRUE) {
  for(i=0;i<512;i++) {
   timers_status[i]=UNUSED;
  }
  first_time = FALSE;
 }
 if(index > 512 -1) {
  (*__errno_location ())=22;
  return result;
 }
 switch(action) {
  case RESET:
   gettimeofday(&timers[index],((void *)0));
   timers_status[index]=INUSE;
   result.tv_sec=timers[index].tv_sec;
   result.tv_usec=timers[index].tv_usec;
   break;
  case GET:
   if(timers_status[index] == UNUSED) {
    result.tv_sec=0;
    result.tv_usec=0;
   } else {
    gettimeofday(&tv,((void *)0));
    if(tv.tv_usec < timers[index].tv_usec) {
     result.tv_usec=tv.tv_usec+1000000-timers[index].tv_usec;
     i=1;
    } else {
     result.tv_usec=tv.tv_usec-timers[index].tv_usec;
     i=0;
    }
    result.tv_sec=tv.tv_sec-timers[index].tv_sec-i;
   }
   break;
 }
 return result;
}

variable_types:
action
enum timer_action_t { RESET=0, GET=1 }

variable_types:
index
unsigned short

variable_types: struct timeval { long tv_sec; long tv_usec; } [512]

variable_types: enum timer_status_t { UNUSED=0, INUSE=1 } [512]

variable_types:
i
unsigned short


decompiled_code:
__int64 __fastcall a2open(char *cp)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // eax
struct sockaddr buf[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
perror("Cannot create socket");
v2 = -1;
}
else
{
v2 = v1;
*(_QWORD *)&buf[0].sa_family = 2LL;
*(_QWORD *)&buf[0].sa_data[6] = 0LL;
*(_WORD *)buf[0].sa_data = _bswap_16(6551);
v3 = inet_pton(2, cp, &buf[0].sa_data[2]);
if ( v3 < 0 )
{
perror("First parameter is not a valid address family");
close(v2);
v2 = -1;
}
else if ( v3 )
{
if ( connect(v2, buf, 0x10u) < 0 )
{
perror("Connect failed");
close(v2);
v2 = -1;
}
}
else
{
perror("Char string (second parameter does not contain valid ipaddress)");
close(v2);
v2 = -1;
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *cp)
{
int v1; // eax
unsigned int v2; // ebx
int v3; // eax
struct sockaddr buf[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 6);
if ( v1 < 0 )
{
perror("Cannot create socket");
v2 = -1;
}
else
{
v2 = v1;
*(_QWORD *)&buf[0].sa_family = 2LL;
*(_QWORD *)&buf[0].sa_data[6] = 0LL;
*(_WORD *)buf[0].sa_data = func7(6551);
v3 = inet_pton(2, cp, &buf[0].sa_data[2]);
if ( v3 < 0 )
{
perror("First parameter is not a valid address family");
close(v2);
v2 = -1;
}
else if ( v3 )
{
if ( connect(v2, buf, 0x10u) < 0 )
{
perror("Connect failed");
close(v2);
v2 = -1;
}
}
else
{
perror("Char string (second parameter does not contain valid ipaddress)");
close(v2);
v2 = -1;
}
}
return v2;
}

original_code:
int a2open(char *ipaddr)
{
    struct sockaddr_in piaddr;
    int res;
    int fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (fd < 0)
    {
        perror("Cannot create socket");
        return -1;
    }
    memset(&piaddr, 0, sizeof(piaddr));
    piaddr.sin_family = 2;
    piaddr.sin_port = htons(6551);
    res = inet_pton(2, ipaddr, &piaddr.sin_addr);
    if (res < 0)
    {
        perror("First parameter is not a valid address family");
        close(fd);
        return -1;
    }
    else if (res == 0)
    {
        perror("Char string (second parameter does not contain valid ipaddress)");
        close(fd);
        return -1;
    }
    if (connect(fd, (struct sockaddr *)&piaddr, sizeof(piaddr)) < 0)
    {
        perror("Connect failed");
        close(fd);
        return -1;
    }
    return fd;
}

variable_types:
ipaddr
char *

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

variable_types: fd int


decompiled_code:
int __fastcall a2close(int fd)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = -1;
write(fd, buf, 1uLL);
shutdown(fd, 2);
return close(fd);
}

canonical_decompiled_code:
int __fastcall func9(int fd)
{
char buf[9]; // [rsp+Fh] [rbp-9h] BYREF

buf[0] = -1;
write(fd, buf, 1uLL);
shutdown(fd, 2);
return close(fd);
}

original_code:
void a2close(int fd)
{
    char closepkt;
    closepkt = 0xFF;
    write(fd, &closepkt, 1);
    shutdown(fd, SHUT_RDWR);
    close(fd);
}

variable_types: closepkt char


decompiled_code:
_BOOL8 __fastcall a2read(int fd, __int16 a2, int a3, void *a4)
{
char buf; // [rsp+8h] [rbp-20h] BYREF
__int16 v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Bh] [rbp-1Dh]

buf = -112;
v8 = a2;
v9 = a3;
write(fd, &buf, 5uLL);
read(fd, a4, a3);
read(fd, &buf, 2uLL);
return buf == -98;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(int fd, __int16 a2, int a3, void *a4)
{
char buf; // [rsp+8h] [rbp-20h] BYREF
__int16 v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Bh] [rbp-1Dh]

buf = -112;
v8 = a2;
v9 = a3;
write(fd, &buf, 5uLL);
read(fd, a4, a3);
read(fd, &buf, 2uLL);
return buf == -98;
}

original_code:
int a2read(int fd, int address, int count, char *buffer)
{
    char readpkt[8];
    readpkt[0] = 0x90;
    readpkt[1] = address;
    readpkt[2] = address >> 8;
    readpkt[3] = count;
    readpkt[4] = count >> 8;
    write(fd, readpkt, 5);
    read(fd, buffer, count);
    read(fd, readpkt, 2);
    return ((unsigned char)readpkt[0] == 0x9E);
}

variable_types: address int

variable_types: count int

variable_types:
buffer
char *

variable_types:
readpkt
char [8]


decompiled_code:
_BOOL8 __fastcall a2write(int fd, __int16 a2, int a3, const void *a4)
{
char buf; // [rsp+8h] [rbp-20h] BYREF
__int16 v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Bh] [rbp-1Dh]

buf = -110;
v8 = a2;
v9 = a3;
write(fd, &buf, 5uLL);
write(fd, a4, a3);
read(fd, &buf, 2uLL);
return buf == -98;
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(int fd, __int16 a2, int a3, const void *a4)
{
char buf; // [rsp+8h] [rbp-20h] BYREF
__int16 v8; // [rsp+9h] [rbp-1Fh]
__int16 v9; // [rsp+Bh] [rbp-1Dh]

buf = -110;
v8 = a2;
v9 = a3;
write(fd, &buf, 5uLL);
write(fd, a4, a3);
read(fd, &buf, 2uLL);
return buf == -98;
}

original_code:
int a2write(int fd, int address, int count, char *buffer)
{
    char writepkt[8];
    writepkt[0] = 0x92;
    writepkt[1] = address;
    writepkt[2] = address >> 8;
    writepkt[3] = count;
    writepkt[4] = count >> 8;
    write(fd, writepkt, 5);
    write(fd, buffer, count);
    read(fd, writepkt, 2);
    return ((unsigned char)writepkt[0] == 0x9E);
}

variable_types:
writepkt
char [8]


decompiled_code:
_BOOL8 __fastcall a2call(int fd, __int16 a2, _DWORD *a3)
{
char buf; // [rsp+Ch] [rbp-1Ch] BYREF
__int16 v6; // [rsp+Dh] [rbp-1Bh]

buf = -102;
v6 = a2;
write(fd, &buf, 3uLL);
read(fd, &buf, 2uLL);
if ( a3 )
*a3 = (unsigned __int8)v6;
return buf == -98;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(int fd, __int16 a2, _DWORD *a3)
{
char buf; // [rsp+Ch] [rbp-1Ch] BYREF
__int16 v6; // [rsp+Dh] [rbp-1Bh]

buf = -102;
v6 = a2;
write(fd, &buf, 3uLL);
read(fd, &buf, 2uLL);
if ( a3 )
*a3 = (unsigned __int8)v6;
return buf == -98;
}

original_code:
int a2call(int fd, int address, int *result)
{
    char callpkt[4];
    callpkt[0] = 0x9A;
    callpkt[1] = address;
    callpkt[2] = address >> 8;
    write(fd, callpkt, 3);
    read(fd, callpkt, 2);
    if (result)
        *result = (unsigned char)callpkt[1];
    return ((unsigned char)callpkt[0] == 0x9E);
}

variable_types:
result
int *

variable_types:
callpkt
char [4]


decompiled_code:
_BOOL8 __fastcall a2quickcall(int fd, __int16 a2, _DWORD *a3)
{
char buf; // [rsp+Ch] [rbp-1Ch] BYREF
__int16 v6; // [rsp+Dh] [rbp-1Bh]

buf = -108;
v6 = a2;
write(fd, &buf, 3uLL);
read(fd, &buf, 2uLL);
if ( a3 )
*a3 = (unsigned __int8)v6;
return buf == -98;
}

canonical_decompiled_code:
_BOOL8 __fastcall func13(int fd, __int16 a2, _DWORD *a3)
{
char buf; // [rsp+Ch] [rbp-1Ch] BYREF
__int16 v6; // [rsp+Dh] [rbp-1Bh]

buf = -108;
v6 = a2;
write(fd, &buf, 3uLL);
read(fd, &buf, 2uLL);
if ( a3 )
*a3 = (unsigned __int8)v6;
return buf == -98;
}

original_code:
int a2quickcall(int fd, int address, int *result)
{
    char callpkt[4];
    callpkt[0] = 0x94;
    callpkt[1] = address;
    callpkt[2] = address >> 8;
    write(fd, callpkt, 3);
    read(fd, callpkt, 2);
    if (result)
        *result = (unsigned char)callpkt[1];
    return ((unsigned char)callpkt[0] == 0x9E);
}


prbytes

decompiled_code:
int __fastcall prbytes(unsigned int a1, int a2, unsigned __int8 *a3)
{
unsigned __int8 *v4; // rbx

printf("%04X:", a1);
if ( a2 > 0 )
{
v4 = a3;
do
printf(" %02X", *v4++);
while ( v4 != &a3[a2 - 1 + 1] );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func14(unsigned int a1, int a2, unsigned __int8 *a3)
{
unsigned __int8 *v4; // rbx

printf("%04X:", a1);
if ( a2 > 0 )
{
v4 = a3;
do
printf(" %02X", *v4++);
while ( v4 != &a3[a2 - 1 + 1] );
}
return putchar(10);
}

original_code:
void prbytes(int address, int count, char *data)
{
    int i;
    printf("%04X:", address);
    for (i = 0; i < count; i++)
 printf(" %02X", (unsigned char)data[i]);
    printf("\n");
}

variable_types:
data
char *

variable_types: i int


decompiled_code:
signed int *__fastcall a2exec(int fd, int a2, signed int *a3, signed int a4, void *a5, int *a6)
{
signed int v7; // ebx
signed int i; // er12
int v9; // ebp
signed int *result; // rax

if ( a2 == 146 )
{
if ( *a6 )
a2write(fd, *a3, *a6, a5);
result = (signed int *)(unsigned int)*a6;
*a3 += (int)result;
*a6 = 0;
}
else if ( a2 > 146 )
{
if ( a2 == 148 )
result = (signed int *)a2call(fd, *a3, 0LL);
}
else if ( a2 )
{
if ( a2 == 144 )
{
v7 = *a3;
if ( *a3 >= a4 )
a4 = *a3;
for ( i = a4; i >= v7; v7 += 16 )
{
v9 = i + 1 - v7;
if ( i > v7 + 15 )
v9 = 16;
a2read(fd, v7, v9, a5);
prbytes(v7, v9, (unsigned __int8 *)a5);
}
result = a3;
*a3 = i + 1;
}
}
else if ( a4 != -1 )
{
result = a3;
*a3 = a4;
}
return result;
}

canonical_decompiled_code:
signed int *__fastcall func15(int fd, int a2, signed int *a3, signed int a4, void *a5, int *a6)
{
signed int v7; // ebx
signed int i; // er12
int v9; // ebp
signed int *result; // rax

if ( a2 == 146 )
{
if ( *a6 )
func11(fd, *a3, *a6, a5);
result = (signed int *)(unsigned int)*a6;
*a3 += (int)result;
*a6 = 0;
}
else if ( a2 > 146 )
{
if ( a2 == 148 )
result = (signed int *)func12(fd, *a3, 0LL);
}
else if ( a2 )
{
if ( a2 == 144 )
{
v7 = *a3;
if ( *a3 >= a4 )
a4 = *a3;
for ( i = a4; i >= v7; v7 += 16 )
{
v9 = i + 1 - v7;
if ( i > v7 + 15 )
v9 = 16;
func10(fd, v7, v9, a5);
func14(v7, v9, (unsigned __int8 *)a5);
}
result = a3;
*a3 = i + 1;
}
}
else if ( a4 != -1 )
{
result = a3;
*a3 = a4;
}
return result;
}

original_code:
void a2exec(int fd, int cmd, int *address, int value, char *data, int *index)
{
    int a, c;
    switch (cmd)
    {
 case 0x00:
     if (value != -1)
  *address = value;
     break;
 case 0x90:
     if (value < *address)
  value = *address;
     for (a = *address; a <= value; a += 16)
     {
  c = a + 16 > value ? value - a + 1 : 16;
  a2read(fd, a, c, data);
  prbytes(a, c, data);
     }
     *address = value + 1;
     break;
 case 0x92:
     if (*index)
  a2write(fd, *address, *index, data);
     *address += *index;
     *index = 0;
     break;
 case 0x94:
     a2call(fd, *address, ((void *)0));
     break;
    }
}

canonical_original_code:
void a2exec(int fd, int cmd, int *address, int value, char *data, int *index)
{
    int a; int c;
    switch (cmd)
    {
 case 0x00:
     if (value != -1)
  *address = value;
     break;
 case 0x90:
     if (value < *address)
  value = *address;
     for (a = *address; a <= value; a += 16)
     {
  c = a + 16 > value ? value - a + 1 : 16;
  a2read(fd, a, c, data);
  prbytes(a, c, data);
     }
     *address = value + 1;
     break;
 case 0x92:
     if (*index)
  a2write(fd, *address, *index, data);
     *address += *index;
     *index = 0;
     break;
 case 0x94:
     a2call(fd, *address, ((void *)0));
     break;
    }
}

variable_types: cmd int

variable_types:
address
int *

variable_types: value int

variable_types:
index
int *

variable_types: a int

variable_types: c int


parsestr

decompiled_code:
__int64 __fastcall parsestr(int fd, _BYTE *a2)
{
int v3; // er13
signed int v4; // ebp
int v6; // eax
int v7; // eax
int v8; // [rsp+Ch] [rbp-42Ch] BYREF
char v9[1064]; // [rsp+10h] [rbp-428h] BYREF

v8 = 0;
v3 = 0;
v4 = -1;
while ( 1 )
{
switch ( *a2 )
{
case 0:
case 0xA:
if ( v4 != -1 )
{
if ( v3 == 146 )
{
v7 = v8++;
v9[v7] = v4;
}
else if ( !v3 )
{
addr_0 = v4;
v3 = 144;
}
}
a2exec(fd, v3, &addr_0, v4, v9, &v8);
return 1LL;
case 0x20:
if ( v4 != -1 )
{
if ( v3 == 146 )
{
v6 = v8++;
v9[v6] = v4;
}
else
{
a2exec(fd, v3, &addr_0, v4, v9, &v8);
}
v4 = -1;
}
goto LABEL_12;
case 0x2E:
a2exec(fd, v3, &addr_0, v4, v9, &v8);
v3 = 144;
v4 = -1;
goto LABEL_12;
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39:
goto LABEL_9;
case 0x3A:
a2exec(fd, v3, &addr_0, v4, v9, &v8);
v3 = 146;
v4 = -1;
goto LABEL_12;
case 0x41:
case 0x42:
case 0x43:
case 0x44:
case 0x45:
case 0x46:
goto LABEL_8;
case 0x51:
case 0x71:
return 0LL;
case 0x52:
case 0x72:
a2exec(fd, v3, &addr_0, v4, v9, &v8);
v3 = 148;
goto LABEL_12;
case 0x61:
case 0x62:
case 0x63:
case 0x64:
case 0x65:
case 0x66:
*a2 -= 32;
LABEL_8:
*a2 -= 7;
LABEL_9:
if ( v4 == -1 )
v4 = 0;
v4 = 16 * v4 + (char)*a2 - 48;
LABEL_12:
++a2;
break;
default:
return 1LL;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func16(int fd, _BYTE *a2)
{
int v3; // er13
signed int v4; // ebp
int v6; // eax
int v7; // eax
int v8; // [rsp+Ch] [rbp-42Ch] BYREF
char v9[1064]; // [rsp+10h] [rbp-428h] BYREF

v8 = 0;
v3 = 0;
v4 = -1;
while ( 1 )
{
switch ( *a2 )
{
case 0:
case 0xA:
if ( v4 != -1 )
{
if ( v3 == 146 )
{
v7 = v8++;
v9[v7] = v4;
}
else if ( !v3 )
{
addr_0 = v4;
v3 = 144;
}
}
func15(fd, v3, &addr_0, v4, v9, &v8);
return 1LL;
case 0x20:
if ( v4 != -1 )
{
if ( v3 == 146 )
{
v6 = v8++;
v9[v6] = v4;
}
else
{
func15(fd, v3, &addr_0, v4, v9, &v8);
}
v4 = -1;
}
goto LABEL_12;
case 0x2E:
func15(fd, v3, &addr_0, v4, v9, &v8);
v3 = 144;
v4 = -1;
goto LABEL_12;
case 0x30:
case 0x31:
case 0x32:
case 0x33:
case 0x34:
case 0x35:
case 0x36:
case 0x37:
case 0x38:
case 0x39:
goto LABEL_9;
case 0x3A:
func15(fd, v3, &addr_0, v4, v9, &v8);
v3 = 146;
v4 = -1;
goto LABEL_12;
case 0x41:
case 0x42:
case 0x43:
case 0x44:
case 0x45:
case 0x46:
goto LABEL_8;
case 0x51:
case 0x71:
return 0LL;
case 0x52:
case 0x72:
func15(fd, v3, &addr_0, v4, v9, &v8);
v3 = 148;
goto LABEL_12;
case 0x61:
case 0x62:
case 0x63:
case 0x64:
case 0x65:
case 0x66:
*a2 -= 32;
LABEL_8:
*a2 -= 7;
LABEL_9:
if ( v4 == -1 )
v4 = 0;
v4 = 16 * v4 + (char)*a2 - 48;
LABEL_12:
++a2;
break;
default:
return 1LL;
}
}
}

original_code:
int parsestr(int fd, char *cmdstr)
{
    char databuf[1024];
    static int addr = 0;
    int index = 0;
    int parseval = -1;
    int cmd =0 ;
    while (1)
    {
 switch (*cmdstr)
 {
     case ':':
  a2exec(fd, cmd, &addr, parseval, databuf, &index);
  cmd = 0x92;
  parseval = -1;
  break;
     case '.':
  a2exec(fd, cmd, &addr, parseval, databuf, &index);
  cmd = 0x90;
  parseval = -1;
  break;
     case 'R':
     case 'r':
  a2exec(fd, cmd, &addr, parseval, databuf, &index);
  cmd = 0x94;
  break;
     case 'a':
     case 'b':
     case 'c':
     case 'd':
     case 'e':
     case 'f':
  *cmdstr -= 'a' - 'A';
     case 'A':
     case 'B':
     case 'C':
     case 'D':
     case 'E':
     case 'F':
  *cmdstr -= 'A' - '9' - 1;
     case '0':
     case '1':
     case '2':
     case '3':
     case '4':
     case '5':
     case '6':
     case '7':
     case '8':
     case '9':
  if (parseval == -1)
      parseval = 0;
  parseval = parseval * 16 + *cmdstr - '0';
  break;
     case ' ':
  if (parseval != -1)
  {
      if (cmd == 0x92)
   databuf[index++] = parseval;
      else
   a2exec(fd, cmd, &addr, parseval, databuf, &index);
      parseval = -1;
  }
  break;
     case '\n':
     case '\0':
  if (parseval != -1)
  {
      if (cmd == 0x92)
   databuf[index++] = parseval;
      else if (cmd == 0)
      {
   addr = parseval;
   cmd = 0x90;
      }
  }
  a2exec(fd, cmd, &addr, parseval, databuf, &index);
  return 1;
  break;
     case 'Q':
     case 'q':
  return 0;
     default:
  return 1;
 }
 cmdstr++;
    }
    return 1;
}

canonical_original_code:
int parsestr(int fd, char *cmdstr)
{
    char databuf[1024];
    static int addr = 0;
    int index = 0;
    int parseval = -1;
    int cmd = 0;
    while (1)
    {
 switch (*cmdstr)
 {
     case ':':
  a2exec(fd, cmd, &addr, parseval, databuf, &index);
  cmd = 0x92;
  parseval = -1;
  break;
     case '.':
  a2exec(fd, cmd, &addr, parseval, databuf, &index);
  cmd = 0x90;
  parseval = -1;
  break;
     case 'R':
     case 'r':
  a2exec(fd, cmd, &addr, parseval, databuf, &index);
  cmd = 0x94;
  break;
     case 'a':
     case 'b':
     case 'c':
     case 'd':
     case 'e':
     case 'f':
  *cmdstr -= 'a' - 'A';
     case 'A':
     case 'B':
     case 'C':
     case 'D':
     case 'E':
     case 'F':
  *cmdstr -= 'A' - '9' - 1;
     case '0':
     case '1':
     case '2':
     case '3':
     case '4':
     case '5':
     case '6':
     case '7':
     case '8':
     case '9':
  if (parseval == -1)
      parseval = 0;
  parseval = parseval * 16 + *cmdstr - '0';
  break;
     case ' ':
  if (parseval != -1)
  {
      if (cmd == 0x92)
   databuf[index++] = parseval;
      else
   a2exec(fd, cmd, &addr, parseval, databuf, &index);
      parseval = -1;
  }
  break;
     case '\n':
     case '\0':
  if (parseval != -1)
  {
      if (cmd == 0x92)
   databuf[index++] = parseval;
      else if (cmd == 0)
      {
   addr = parseval;
   cmd = 0x90;
      }
  }
  a2exec(fd, cmd, &addr, parseval, databuf, &index);
  return 1;
  break;
     case 'Q':
     case 'q':
  return 0;
     default:
  return 1;
 }
 cmdstr++;
    }
    return 1;
}

variable_types: fd int

variable_types:
cmdstr
char *

variable_types:
databuf
char [1024]

variable_types: addr int

variable_types: index int

variable_types: parseval int


canonical_original_code:
int a2open(char *ipaddr)
{
    struct sockaddr_in piaddr;
    int res;
    int fd = socket(2, SOCK_STREAM, IPPROTO_TCP);
    if (fd < 0)
    {
        perror("Cannot create socket");
        return -1;
    }
    memset(&piaddr, 0, sizeof(piaddr));
    piaddr.sin_family = 2;
    piaddr.sin_port = htons(6551);
    res = inet_pton(2, ipaddr, &piaddr.sin_addr);
    if (res < 0)
    {
        perror("First parameter is not a valid address family");
        close(fd);
        return -1;
    }
    else if (res == 0)
    {
        perror("Char string (second parameter does not contain valid ipaddress)");
        close(fd);
        return -1;
    }
    if (connect(fd, (struct sockaddr *)&piaddr, sizeof(piaddr)) < 0)
    {
        perror("Connect failed");
        close(fd);
        return -1;
    }
    return fd;
}

variable_types:
ipaddr
char *

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


canonical_original_code:
void a2close(int fd)
{
    char closepkt;
    closepkt = 0xFF;
    write(fd, &closepkt, 1);
    shutdown(fd, SHUT_RDWR);
    close(fd);
}

variable_types: closepkt char


canonical_original_code:
int a2read(int fd, int address, int count, char *buffer)
{
    char readpkt[8];
    readpkt[0] = 0x90;
    readpkt[1] = address;
    readpkt[2] = address >> 8;
    readpkt[3] = count;
    readpkt[4] = count >> 8;
    write(fd, readpkt, 5);
    read(fd, buffer, count);
    read(fd, readpkt, 2);
    return ((unsigned char)readpkt[0] == 0x9E);
}

variable_types: address int

variable_types: count int

variable_types:
buffer
char *

variable_types:
readpkt
char [8]


canonical_original_code:
int a2write(int fd, int address, int count, char *buffer)
{
    char writepkt[8];
    writepkt[0] = 0x92;
    writepkt[1] = address;
    writepkt[2] = address >> 8;
    writepkt[3] = count;
    writepkt[4] = count >> 8;
    write(fd, writepkt, 5);
    write(fd, buffer, count);
    read(fd, writepkt, 2);
    return ((unsigned char)writepkt[0] == 0x9E);
}

variable_types:
writepkt
char [8]


canonical_original_code:
int a2call(int fd, int address, int *result)
{
    char callpkt[4];
    callpkt[0] = 0x9A;
    callpkt[1] = address;
    callpkt[2] = address >> 8;
    write(fd, callpkt, 3);
    read(fd, callpkt, 2);
    if (result)
        *result = (unsigned char)callpkt[1];
    return ((unsigned char)callpkt[0] == 0x9E);
}

variable_types:
result
int *

variable_types:
callpkt
char [4]


canonical_original_code:
int a2quickcall(int fd, int address, int *result)
{
    char callpkt[4];
    callpkt[0] = 0x94;
    callpkt[1] = address;
    callpkt[2] = address >> 8;
    write(fd, callpkt, 3);
    read(fd, callpkt, 2);
    if (result)
        *result = (unsigned char)callpkt[1];
    return ((unsigned char)callpkt[0] == 0x9E);
}

variable_types: fd int


createPacket

decompiled_code:
void *__fastcall createPacket(int a1, int a2)
{
return malloc(9 * a2 + 4LL * a1 + 20);
}

canonical_decompiled_code:
void *__fastcall func0(int a1, int a2)
{
return malloc(9 * a2 + 4LL * a1 + 20);
}

original_code:
char* createPacket(int numNeighbors, int numFiles){
 char* buf;
 buf = malloc(20*sizeof(char)+numNeighbors*sizeof(int)+numFiles*9);
 return buf;
}

canonical_original_code:
char *createPacket(int numNeighbors, int numFiles){
 char *buf;
 buf = malloc(20*sizeof(char)+numNeighbors*sizeof(int)+numFiles*9);
 return buf;
}

variable_types: numNeighbors int

variable_types: numFiles int

variable_types:
buf
char *

return_type: char *


addString

original_code:
char* addString(char* str, char* buf){
 memcpy(buf, str, 9);
 return buf+9;
}

canonical_original_code:
char *addString(char *str, char *buf){
 memcpy(buf, str, 9);
 return buf+9;
}

variable_types:
str
char *


readString

decompiled_code:
const char *__fastcall readString(char *a1, const char *a2)
{
strcpy(a1, a2);
return a2 + 9;
}

canonical_decompiled_code:
const char *__fastcall func2(char *a1, const char *a2)
{
strcpy(a1, a2);
return a2 + 9;
}

original_code:
char* readString(char str[9], char* buf){
 strcpy(str, buf);
 return buf + 9;
}

canonical_original_code:
char *readString(char str[9], char *buf){
 strcpy(str, buf);
 return buf + 9;
}

variable_types:
str
char [9]


addFiles

decompiled_code:
__int64 __fastcall addFiles(__int64 a1)
{
__int64 i; // rbx

for ( i = fileList; i; i = *(_QWORD *)(i + 8) )
{
addString(**(_QWORD **)i, a1);
a1 += 9LL;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 i; // rbx

for ( i = fileList; i; i = *(_QWORD *)(i + 8) )
{
func1(**(_QWORD **)i, a1);
a1 += 9LL;
}
return a1;
}

original_code:
char* addFiles(char* start){
 node* curr = fileList.head;
 char* ptr;
 ptr = start;
 while( curr != ((void *)0) ){
  fileEntry* fe = (fileEntry*)curr->data;
  addString(fe->objectName, ptr);
  ptr += 9;
  curr = curr->next;
 }
 return ptr;
}

canonical_original_code:
char *addFiles(char *start){
 struct node_s *curr = fileList.head;
 char *ptr;
 ptr = start;
 while( curr != ((void *)0) ){
  struct fe *fe = (fileEntry*)curr->data;
  addString(fe->objectName, ptr);
  ptr += 9;
  curr = curr->next;
 }
 return ptr;
}

variable_types:
start
char *

variable_types: struct node_s { void *data; struct node_s *next; } *

variable_types:
ptr
char *

variable_types: struct fe { char *objectName; char *path; } *


printBuf

decompiled_code:
int __fastcall printBuf(char *a1, int a2)
{
char *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
putchar(*v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return puts("\nend");
}

canonical_decompiled_code:
int __fastcall func4(char *a1, int a2)
{
char *v2; // rbx

if ( a2 > 0 )
{
v2 = a1;
do
putchar(*v2++);
while ( v2 != &a1[a2 - 1 + 1] );
}
return puts("\nend");
}

original_code:
void printBuf(char* buf, int len){
 int i;
 for( i = 0 ; i < len ; i++){
  printf("%c", buf[i]);
 }
 printf("\nend\n");
}

canonical_original_code:
void printBuf(char *buf, int len){
 int i;
 for( i = 0 ; i < len ; i++){
  printf("%c", buf[i]);
 }
 printf("\nend\n");
}

variable_types: len int

variable_types: i int


freeBuffer

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

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

original_code:
void freeBuffer(char* buf){
 if(buf != ((void *)0)){
  free(buf);
 }
}

canonical_original_code:
void freeBuffer(char *buf){
 if(buf != ((void *)0)){
  free(buf);
 }
}


addToResendList

decompiled_code:
int __fastcall addToResendList(int a1, unsigned int a2)
{
int *v2; // rax
int *v3; // rbx

v2 = isExist(a1, a2);
if ( v2 )
{
v3 = v2;
if ( *v2 != 1 )
{
LODWORD(v2) = printf("Add neighbor %d to resend list\n", a2);
*v3 = 1;
v3[2] = a1;
v3[1] = a2;
++numDeferMessages;
}
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func7(int a1, unsigned int a2)
{
int *v2; // rax
int *v3; // rbx

v2 = func6(a1, a2);
if ( v2 )
{
v3 = v2;
if ( *v2 != 1 )
{
LODWORD(v2) = printf("Add neighbor %d to resend list\n", a2);
*v3 = 1;
v3[2] = a1;
v3[1] = a2;
++numDeferMessages;
}
}
return (int)v2;
}

original_code:
void addToResendList(int senderId, int receiverId){
 deferredMessage* df = isExist( senderId, receiverId);
 if( df ){
  if(df->inUse != 1){
  printf("Add neighbor %d to resend list\n", receiverId);
  df->inUse = 1;
  df->senderId = senderId;
  df->receiverId = receiverId;
  numDeferMessages ++ ;
  }
 }
}

canonical_original_code:
void addToResendList(int senderId, int receiverId){
 struct df *df = isExist( senderId, receiverId);
 if( df ){
  if(df->inUse != 1){
  printf("Add neighbor %d to resend list\n", receiverId);
  df->inUse = 1;
  df->senderId = senderId;
  df->receiverId = receiverId;
  numDeferMessages ++ ;
  }
 }
}

variable_types: senderId int

variable_types: receiverId int

variable_types: struct df { int inUse; int receiverId; int senderId; } *


removeFromResendList

decompiled_code:
int __fastcall removeFromResendList(int a1, unsigned int a2)
{
int *v2; // rax
int *v3; // rbx

v2 = isExist(a1, a2);
if ( v2 )
{
v3 = v2;
LODWORD(v2) = printf("Remove neighbor %d from resend list\n", a2);
*v3 = 0;
--numDeferMessages;
}
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func8(int a1, unsigned int a2)
{
int *v2; // rax
int *v3; // rbx

v2 = func6(a1, a2);
if ( v2 )
{
v3 = v2;
LODWORD(v2) = printf("Remove neighbor %d from resend list\n", a2);
*v3 = 0;
--numDeferMessages;
}
return (int)v2;
}

original_code:
void removeFromResendList( int senderId, int receiverId ){
 deferredMessage* df = isExist( senderId , receiverId);
 if( df ){
  printf("Remove neighbor %d from resend list\n", receiverId);
  df->inUse = 0;
  numDeferMessages -- ;
 }
}

canonical_original_code:
void removeFromResendList(int senderId, int receiverId){
 struct df *df = isExist( senderId , receiverId);
 if( df ){
  printf("Remove neighbor %d from resend list\n", receiverId);
  df->inUse = 0;
  numDeferMessages -- ;
 }
}

user_defined_types: struct df { int inUse; int receiverId; int senderId; }


reTransmit

decompiled_code:
void __fastcall reTransmit(int a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax
__int64 v5; // r12
_BYTE *v6; // r15
_DWORD *v7; // rbx
__int64 i; // rbp
__int64 *j; // rbp
const struct sockaddr *v10; // rbp

v4 = getRoutingEntry(&routing, a3);
if ( v4 )
{
v5 = v4;
v6 = createPacket(*(_DWORD *)(v4 + 76), *(_DWORD *)(v4 + 72));
v7 = addHeader(v6, 32, 0, a3, *(_DWORD *)(v5 + 64), *(_DWORD *)(v5 + 76), *(_DWORD *)(v5 + 72));
for ( i = **(_QWORD **)(v5 + 8); i; i = *(_QWORD *)(i + 8) )
addInt(**(_DWORD **)i, v7++);
for ( j = **(__int64 ***)(v5 + 16); j; j = (__int64 *)j[1] )
{
addString(*j, (__int64)v7);
v7 = (_DWORD *)((char *)v7 + 9);
}
v10 = (const struct sockaddr *)getRoutingEntry(&routing, a2);
if ( v10 )
{
printf("Retrans from %d to %d\n", a3, a2);
if ( sendto(a1, v6, (int)v7 - (int)v6 + 1, 0, v10 + 5, 0x10u) <= 0 )
puts("This is really bad");
}
freeBuffer(v6);
}
}

canonical_decompiled_code:
void __fastcall func9(int a1, unsigned int a2, unsigned int a3)
{
__int64 v4; // rax
__int64 v5; // r12
_BYTE *v6; // r15
_DWORD *v7; // rbx
__int64 i; // rbp
__int64 *j; // rbp
const struct sockaddr *v10; // rbp

v4 = getRoutingEntry(&routing, a3);
if ( v4 )
{
v5 = v4;
v6 = func0(*(_DWORD *)(v4 + 76), *(_DWORD *)(v4 + 72));
v7 = addHeader(v6, 32, 0, a3, *(_DWORD *)(v5 + 64), *(_DWORD *)(v5 + 76), *(_DWORD *)(v5 + 72));
for ( i = **(_QWORD **)(v5 + 8); i; i = *(_QWORD *)(i + 8) )
addInt(**(_DWORD **)i, v7++);
for ( j = **(__int64 ***)(v5 + 16); j; j = (__int64 *)j[1] )
{
func1(*j, (__int64)v7);
v7 = (_DWORD *)((char *)v7 + 9);
}
v10 = (const struct sockaddr *)getRoutingEntry(&routing, a2);
if ( v10 )
{
printf("Retrans from %d to %d\n", a3, a2);
if ( sendto(a1, v6, (int)v7 - (int)v6 + 1, 0, v10 + 5, 0x10u) <= 0 )
puts("This is really bad");
}
func5(v6);
}
}

original_code:
void reTransmit(int udp, int receiverId, int senderId ){
 routingEntry* re = getRoutingEntry( &routing , senderId );
 char* ptr;
 if( re != ((void *)0) ){
  char* sendBuf = createPacket(re->numLinks , re->numFiles);
  ptr = addHeader(sendBuf, 32, 0, senderId, re->seqNumReceive, re->numLinks, re->numFiles);
  node* curr = re->neighbors->head;
  while( curr != ((void *)0) ){
   int* id = (int* )curr->data;
    addInt(*id, ptr);
   ptr += sizeof(int);
   curr = curr->next;
  }
  curr = re->objects->head;
  while( curr != ((void *)0) ){
   char* objectName = (char* )curr->data;
   addString(objectName, ptr);
   ptr+=9;
   curr = curr->next;
  }
  routingEntry* neighborToReceive = getRoutingEntry( &routing, receiverId );
  if( neighborToReceive!= ((void *)0) ){
      ssize_t sen;
       int packetSize = ptr - sendBuf + 1;
   printf("Retrans from %d to %d\n", senderId ,receiverId);
       sen = sendto(udp, sendBuf ,packetSize, 0, (struct sockaddr *)&(neighborToReceive->cli_addr), sizeof(neighborToReceive->cli_addr));
       if(sen <= 0 ){
        printf("This is really bad\n");
       }
  }
  freeBuffer(sendBuf);
 }
}

canonical_original_code:
void reTransmit(int udp, int receiverId, int senderId){
 struct re *re = getRoutingEntry( &routing , senderId );
 char *ptr;
 if( re != ((void *)0) ){
  char *sendBuf = createPacket(re->numLinks , re->numFiles);
  ptr = addHeader(sendBuf, 32, 0, senderId, re->seqNumReceive, re->numLinks, re->numFiles);
  struct node_s *curr = re->neighbors->head;
  while( curr != ((void *)0) ){
   int *id = (int* )curr->data;
    addInt(*id, ptr);
   ptr += sizeof(int);
   curr = curr->next;
  }
  curr = re->objects->head;
  while( curr != ((void *)0) ){
   char *objectName = (char* )curr->data;
   addString(objectName, ptr);
   ptr+=9;
   curr = curr->next;
  }
  struct re *neighborToReceive = getRoutingEntry( &routing, receiverId );
  if( neighborToReceive!= ((void *)0) ){
      long sen;
       int packetSize = ptr - sendBuf + 1;
   printf("Retrans from %d to %d\n", senderId ,receiverId);
       sen = sendto(udp, sendBuf ,packetSize, 0, (struct sockaddr *)&(neighborToReceive->cli_addr), sizeof(neighborToReceive->cli_addr));
       if(sen <= 0 ){
        printf("This is really bad\n");
       }
  }
  freeBuffer(sendBuf);
 }
}

variable_types: udp int

variable_types: struct re { int nodeId; int nextHop; struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; } *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; 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]; } cli_addr; int neighborCountDown; int LSACountDown; int isDown; } *

variable_types:
sendBuf
char *

variable_types:
id
int *

variable_types:
objectName
char *

variable_types: sen long

variable_types: packetSize int

user_defined_types: struct re { int nodeId; int nextHop; struct list *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; struct sockaddr_in cli_addr; int neighborCountDown; int LSACountDown; int isDown; }

user_defined_types: struct list { struct node_s *head; struct node_s *tail; }


forward

decompiled_code:
void __fastcall forward(int a1, _BYTE *a2, int a3, unsigned int a4, int a5)
{
const struct sockaddr **v5; // rbx
size_t v8; // r14
const struct sockaddr *v9; // rbp
__int64 v10; // rdx

--a2[1];
v5 = (const struct sockaddr **)routing;
if ( routing )
{
v8 = a3;
do
{
v9 = *v5;
if ( *(_DWORD *)&(*v5)[3].sa_data[10] )
{
v10 = *(unsigned int *)&v9->sa_family;
if ( (_DWORD)v10 != a5 && !*(_DWORD *)&v9[6].sa_data[6] )
{
printf("Start to forward packet from %d to node %d\n", a4, v10);
if ( sendto(a1, a2, v8, 0, v9 + 5, 0x10u) <= 0 )
puts("This is really bad");
addToResendList(a4, *(_DWORD *)&v9->sa_family);
}
}
v5 = (const struct sockaddr **)v5[1];
}
while ( v5 );
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, _BYTE *a2, int a3, unsigned int a4, int a5)
{
const struct sockaddr **v5; // rbx
size_t v8; // r14
const struct sockaddr *v9; // rbp
__int64 v10; // rdx

--a2[1];
v5 = (const struct sockaddr **)routing;
if ( routing )
{
v8 = a3;
do
{
v9 = *v5;
if ( *(_DWORD *)&(*v5)[3].sa_data[10] )
{
v10 = *(unsigned int *)&v9->sa_family;
if ( (_DWORD)v10 != a5 && !*(_DWORD *)&v9[6].sa_data[6] )
{
printf("Start to forward packet from %d to node %d\n", a4, v10);
if ( sendto(a1, a2, v8, 0, v9 + 5, 0x10u) <= 0 )
puts("This is really bad");
func7(a4, *(_DWORD *)&v9->sa_family);
}
}
v5 = (const struct sockaddr **)v5[1];
}
while ( v5 );
}
}

original_code:
void forward(int udp, char* packet, int packetSize, int senderId, int excludeId){
 char* ttl = packet+1;
 *ttl = *(ttl)-1;
 node* curr = routing.head;
 while( curr != ((void *)0) ){
  routingEntry* re = (routingEntry*)curr->data;
  if (re->isNeighbor && re->nodeId != excludeId && !re->isDown){
   ssize_t sen;
   printf("Start to forward packet from %d to node %d\n", senderId,re->nodeId);
   sen = sendto(udp, packet ,packetSize, 0, (struct sockaddr *)&(re->cli_addr), sizeof(re->cli_addr));
   if(sen <= 0 ){
    printf("This is really bad\n");
   }
   addToResendList(senderId, re->nodeId);
  }
  curr = curr->next;
 }
}

canonical_original_code:
void forward(int udp, char *packet, int packetSize, int senderId, int excludeId){
 char *ttl = packet+1;
 *ttl = *(ttl)-1;
 struct node_s *curr = routing.head;
 while( curr != ((void *)0) ){
  struct re *re = (routingEntry*)curr->data;
  if (re->isNeighbor && re->nodeId != excludeId && !re->isDown){
   long sen;
   printf("Start to forward packet from %d to node %d\n", senderId,re->nodeId);
   sen = sendto(udp, packet ,packetSize, 0, (struct sockaddr *)&(re->cli_addr), sizeof(re->cli_addr));
   if(sen <= 0 ){
    printf("This is really bad\n");
   }
   addToResendList(senderId, re->nodeId);
  }
  curr = curr->next;
 }
}

variable_types:
packet
char *

variable_types: excludeId int

variable_types:
ttl
char *

user_defined_types: struct node_s { void *data; struct node_s *next; }


sendAck

decompiled_code:
int __fastcall sendAck(int fd, int a2, int a3, __int64 a4, __int64 a5)
{
_BYTE *v6; // rbx
_BYTE *v7; // rax
_WORD *v8; // rax
_WORD *v9; // rax
_DWORD *v10; // rax
unsigned int v11; // eax
ssize_t v12; // rax
struct sockaddr v14; // [rsp+0h] [rbp-38h] BYREF

*(_QWORD *)&v14.sa_family = a4;
*(_QWORD *)&v14.sa_data[6] = a5;
v6 = malloc(0xCuLL);
v7 = addChar(49, v6);
v8 = addChar(32, v7);
v9 = addShort(1, v8);
v10 = addInt(a2, v9);
v11 = (unsigned int)addInt(a3, v10);
v12 = sendto(fd, v6, (int)(v11 - (_DWORD)v6 + 1), 0, &v14, 0x10u);
if ( v12 <= 0 )
LODWORD(v12) = puts("This is really bad");
return v12;
}

canonical_decompiled_code:
int __fastcall func12(int fd, int a2, int a3, __int64 a4, __int64 a5)
{
_BYTE *v6; // rbx
_BYTE *v7; // rax
_WORD *v8; // rax
_WORD *v9; // rax
_DWORD *v10; // rax
unsigned int v11; // eax
ssize_t v12; // rax
struct sockaddr v14; // [rsp+0h] [rbp-38h] BYREF

*(_QWORD *)&v14.sa_family = a4;
*(_QWORD *)&v14.sa_data[6] = a5;
v6 = malloc(0xCuLL);
v7 = addChar(49, v6);
v8 = addChar(32, v7);
v9 = addShort(1, v8);
v10 = addInt(a2, v9);
v11 = (unsigned int)addInt(a3, v10);
v12 = sendto(fd, v6, (int)(v11 - (_DWORD)v6 + 1), 0, &v14, 0x10u);
if ( v12 <= 0 )
LODWORD(v12) = puts("This is really bad");
return v12;
}

original_code:
void sendAck(int udp, int senderId, int seqNum, struct sockaddr_in cli_addr){
 char* ack = malloc(3*sizeof(int));
 char* ptr = ack;
 ptr = addChar('1', ptr);
 ptr = addChar(32,ptr);
 ptr = addShort(1, ptr);
 ptr = addInt(senderId, ptr);
 ptr = addInt(seqNum, ptr);
 int ackSize = ptr - ack + 1;
 ssize_t sen;
 sen = sendto(udp, ack, ackSize, 0, (struct sockaddr *)&cli_addr, sizeof(cli_addr));
 if(sen <= 0 ){
  printf("This is really bad\n");
 }
}

canonical_original_code:
void sendAck(int udp, int senderId, int seqNum, struct sockaddr_in cli_addr){
 char *ack = malloc(3*sizeof(int));
 char *ptr = ack;
 ptr = addChar('1', ptr);
 ptr = addChar(32,ptr);
 ptr = addShort(1, ptr);
 ptr = addInt(senderId, ptr);
 ptr = addInt(seqNum, ptr);
 int ackSize = ptr - ack + 1;
 long sen;
 sen = sendto(udp, ack, ackSize, 0, (struct sockaddr *)&cli_addr, sizeof(cli_addr));
 if(sen <= 0 ){
  printf("This is really bad\n");
 }
}

variable_types: seqNum 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:
ack
char *

variable_types:
ptr
char *

variable_types: ackSize int


advertise

decompiled_code:
void __fastcall advertise(int fd, int a2, int a3)
{
unsigned int **v3; // rbx
int *v4; // r14
unsigned int *v5; // rbp
_BYTE *v6; // r13
_DWORD *v7; // rax
_DWORD *v8; // rax
__int64 v9; // r12

v3 = (unsigned int **)routing;
v4 = (int *)getRoutingEntry(&routing, mynodeID);
++v4[16];
for ( ; v3; v3 = (unsigned int **)v3[1] )
{
v5 = *v3;
if ( (*v3)[15] )
{
v6 = createPacket(a2, a3);
v7 = addHeader(v6, 32, 0, mynodeID, v4[16], v4[19], v4[18]);
v8 = addNodeIds(v7, mynodeID);
v9 = (unsigned int)addFiles((__int64)v8) - (unsigned int)v6 + 1;
printf("The packet length is %d\n", v9);
printf("Advertise to node %d\n", *v5);
if ( sendto(fd, v6, (int)v9, 0, (const struct sockaddr *)v5 + 5, 0x10u) <= 0 )
puts("This is really bad");
addToResendList(mynodeID, *v5);
freeBuffer(v6);
}
}
}

canonical_decompiled_code:
void __fastcall func13(int fd, int a2, int a3)
{
unsigned int **v3; // rbx
int *v4; // r14
unsigned int *v5; // rbp
_BYTE *v6; // r13
_DWORD *v7; // rax
_DWORD *v8; // rax
__int64 v9; // r12

v3 = (unsigned int **)routing;
v4 = (int *)getRoutingEntry(&routing, mynodeID);
++v4[16];
for ( ; v3; v3 = (unsigned int **)v3[1] )
{
v5 = *v3;
if ( (*v3)[15] )
{
v6 = func0(a2, a3);
v7 = addHeader(v6, 32, 0, mynodeID, v4[16], v4[19], v4[18]);
v8 = addNodeIds(v7, mynodeID);
v9 = (unsigned int)func3((__int64)v8) - (unsigned int)v6 + 1;
printf("The packet length is %d\n", v9);
printf("Advertise to node %d\n", *v5);
if ( sendto(fd, v6, (int)v9, 0, (const struct sockaddr *)v5 + 5, 0x10u) <= 0 )
puts("This is really bad");
func7(mynodeID, *v5);
func5(v6);
}
}
}

original_code:
void advertise(int udp, int numLinks, int numFiles){
 node* curr = routing.head;
 char* ptr;
 routingEntry* me = getRoutingEntry(&routing, mynodeID);
 me->seqNumReceive++;
 while( curr != ((void *)0) ){
  routingEntry* re = (routingEntry*)curr->data;
  if (re->isNeighbor){
   char* sendBuf = createPacket(numLinks, numFiles);
   ptr = addHeader(sendBuf, 32, 0, mynodeID, me->seqNumReceive, me->numLinks, me->numFiles);
   ptr = addNodeIds(ptr, mynodeID);
   ptr = addFiles(ptr);
   int packetSize = ptr-sendBuf+1;
   printf("The packet length is %d\n",packetSize );
   ssize_t sen;
   printf("Advertise to node %d\n", re->nodeId);
   sen = sendto(udp, sendBuf,packetSize, 0, (struct sockaddr *)&(re->cli_addr), sizeof(re->cli_addr));
   if(sen <= 0 ){
    printf("This is really bad\n");
   }
   addToResendList(mynodeID, re->nodeId);
   freeBuffer(sendBuf);
  }
  curr = curr->next;
 }
}

canonical_original_code:
void advertise(int udp, int numLinks, int numFiles){
 struct node_s *curr = routing.head;
 char *ptr;
 struct re *me = getRoutingEntry(&routing, mynodeID);
 me->seqNumReceive++;
 while( curr != ((void *)0) ){
  struct re *re = (routingEntry*)curr->data;
  if (re->isNeighbor){
   char *sendBuf = createPacket(numLinks, numFiles);
   ptr = addHeader(sendBuf, 32, 0, mynodeID, me->seqNumReceive, me->numLinks, me->numFiles);
   ptr = addNodeIds(ptr, mynodeID);
   ptr = addFiles(ptr);
   int packetSize = ptr-sendBuf+1;
   printf("The packet length is %d\n",packetSize );
   long sen;
   printf("Advertise to node %d\n", re->nodeId);
   sen = sendto(udp, sendBuf,packetSize, 0, (struct sockaddr *)&(re->cli_addr), sizeof(re->cli_addr));
   if(sen <= 0 ){
    printf("This is really bad\n");
   }
   addToResendList(mynodeID, re->nodeId);
   freeBuffer(sendBuf);
  }
  curr = curr->next;
 }
}

variable_types: numLinks int

variable_types: numFiles int

variable_types: struct node_s { void *data; struct node_s *next; } *


countDown

decompiled_code:
void __fastcall countDown(int a1)
{
unsigned int **v1; // rbp
__int64 v2; // rsi
unsigned int *v3; // rbx
__int64 v4; // rdx
_BYTE *v5; // r15
_DWORD *v6; // r12
__int64 i; // r13
__int64 *j; // r13
__int64 v9; // r14
__int64 v10; // rax
__int64 v11; // rdx

v1 = (unsigned int **)routing;
if ( routing )
{
do
{
v3 = *v1;
if ( (*v1)[15] )
{
if ( !v3[26] )
{
v4 = v3[24] - advCycle;
v3[24] = v4;
printf("Time limit for neighbor %d : %d\n", *v3, v4);
if ( !v3[24] )
{
v5 = createPacket(v3[19], v3[18]);
v6 = addHeader(v5, 1, 0, *v3, v3[16], v3[19], v3[18]);
printf("**On behalf of %d", *v3);
for ( i = **((_QWORD **)v3 + 1); i; i = *(_QWORD *)(i + 8) )
addInt(**(_DWORD **)i, v6++);
for ( j = (__int64 *)**((_QWORD **)v3 + 2); j; j = (__int64 *)j[1] )
{
v9 = *j;
printf("**add file %s\n", (const char *)*j);
addString(v9, (__int64)v6);
v6 = (_DWORD *)((char *)v6 + 9);
}
forward(a1, v5, (_DWORD)v6 - (_DWORD)v5 + 1, *v3, *v3);
v3[26] = 1;
v10 = getRoutingEntry(&routing, mynodeID);
--*(_DWORD *)(v10 + 76);
printf("Neighbor %d is down\n", *v3);
}
}
}
else
{
v2 = *v3;
if ( (_DWORD)v2 != mynodeID )
{
v11 = v3[25] - advCycle;
v3[25] = v11;
printf("Time limit for LSA from node %d : %d\n", v2, v11);
if ( !v3[25] )
deleteRoutingEntry(*v3);
}
}
v1 = (unsigned int **)v1[1];
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func14(int a1)
{
unsigned int **v1; // rbp
__int64 v2; // rsi
unsigned int *v3; // rbx
__int64 v4; // rdx
_BYTE *v5; // r15
_DWORD *v6; // r12
__int64 i; // r13
__int64 *j; // r13
__int64 v9; // r14
__int64 v10; // rax
__int64 v11; // rdx

v1 = (unsigned int **)routing;
if ( routing )
{
do
{
v3 = *v1;
if ( (*v1)[15] )
{
if ( !v3[26] )
{
v4 = v3[24] - advCycle;
v3[24] = v4;
printf("Time limit for neighbor %d : %d\n", *v3, v4);
if ( !v3[24] )
{
v5 = func0(v3[19], v3[18]);
v6 = addHeader(v5, 1, 0, *v3, v3[16], v3[19], v3[18]);
printf("**On behalf of %d", *v3);
for ( i = **((_QWORD **)v3 + 1); i; i = *(_QWORD *)(i + 8) )
addInt(**(_DWORD **)i, v6++);
for ( j = (__int64 *)**((_QWORD **)v3 + 2); j; j = (__int64 *)j[1] )
{
v9 = *j;
printf("**add file %s\n", (const char *)*j);
func1(v9, (__int64)v6);
v6 = (_DWORD *)((char *)v6 + 9);
}
func11(a1, v5, (_DWORD)v6 - (_DWORD)v5 + 1, *v3, *v3);
v3[26] = 1;
v10 = getRoutingEntry(&routing, mynodeID);
--*(_DWORD *)(v10 + 76);
printf("Neighbor %d is down\n", *v3);
}
}
}
else
{
v2 = *v3;
if ( (_DWORD)v2 != mynodeID )
{
v11 = v3[25] - advCycle;
v3[25] = v11;
printf("Time limit for LSA from node %d : %d\n", v2, v11);
if ( !v3[25] )
deleteRoutingEntry(*v3);
}
}
v1 = (unsigned int **)v1[1];
}
while ( v1 );
}
}

original_code:
void countDown(int udp){
 node* curr = routing.head;
 while( curr != ((void *)0) ){
  routingEntry* re = (routingEntry* )curr->data;
  if( re->isNeighbor && !re->isDown){
   re->neighborCountDown -= advCycle;
   printf("Time limit for neighbor %d : %d\n", re->nodeId, re->neighborCountDown);
   if( re->neighborCountDown == 0 ){
   char* sendBuf = createPacket(re->numLinks, re->numFiles);
   char* ptr = sendBuf;
   ptr = addHeader(sendBuf,1,0, re->nodeId, re->seqNumReceive, re->numLinks, re->numFiles);
   printf("**On behalf of %d", re->nodeId);
   node* curr2 = re->neighbors->head;
   while( curr2 != ((void *)0) ){
    int* id = (int* )curr2->data;
     addInt(*id, ptr);
    ptr += sizeof(int);
    curr2 = curr2->next;
   }
   curr2 = re->objects->head;
   while( curr2 != ((void *)0) ){
    char* objectName = (char* )curr2->data;
    printf("**add file %s\n", objectName);
    addString(objectName, ptr);
    ptr+=9;
    curr2 = curr2->next;
   }
   int packetSize = ptr - sendBuf + 1;
   forward(udp, sendBuf, packetSize, re->nodeId, re->nodeId);
   re->isDown = 1;
   routingEntry* me = getRoutingEntry(&routing, mynodeID);
   me->numLinks--;
   printf("Neighbor %d is down\n", re->nodeId);
   }
  }
  else if( (!re->isNeighbor) && (re->nodeId != mynodeID)){
   re->LSACountDown -= advCycle;
   printf("Time limit for LSA from node %d : %d\n", re->nodeId, re->LSACountDown);
   if ( re->LSACountDown == 0){
    deleteRoutingEntry( re->nodeId );
   }
  }
  curr = curr->next;
 }
}

canonical_original_code:
void countDown(int udp){
 struct node_s *curr = routing.head;
 while( curr != ((void *)0) ){
  struct re *re = (routingEntry* )curr->data;
  if( re->isNeighbor && !re->isDown){
   re->neighborCountDown -= advCycle;
   printf("Time limit for neighbor %d : %d\n", re->nodeId, re->neighborCountDown);
   if( re->neighborCountDown == 0 ){
   char *sendBuf = createPacket(re->numLinks, re->numFiles);
   char *ptr = sendBuf;
   ptr = addHeader(sendBuf,1,0, re->nodeId, re->seqNumReceive, re->numLinks, re->numFiles);
   printf("**On behalf of %d", re->nodeId);
   struct node_s *curr2 = re->neighbors->head;
   while( curr2 != ((void *)0) ){
    int *id = (int* )curr2->data;
     addInt(*id, ptr);
    ptr += sizeof(int);
    curr2 = curr2->next;
   }
   curr2 = re->objects->head;
   while( curr2 != ((void *)0) ){
    char *objectName = (char* )curr2->data;
    printf("**add file %s\n", objectName);
    addString(objectName, ptr);
    ptr+=9;
    curr2 = curr2->next;
   }
   int packetSize = ptr - sendBuf + 1;
   forward(udp, sendBuf, packetSize, re->nodeId, re->nodeId);
   re->isDown = 1;
   struct re *me = getRoutingEntry(&routing, mynodeID);
   me->numLinks--;
   printf("Neighbor %d is down\n", re->nodeId);
   }
  }
  else if( (!re->isNeighbor) && (re->nodeId != mynodeID)){
   re->LSACountDown -= advCycle;
   printf("Time limit for LSA from node %d : %d\n", re->nodeId, re->LSACountDown);
   if ( re->LSACountDown == 0){
    deleteRoutingEntry( re->nodeId );
   }
  }
  curr = curr->next;
 }
}

variable_types: udp int

variable_types: struct re { int nodeId; int nextHop; struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; } *neighbors; struct list *objects; struct re *parent; int visited; char *hostName; int routingPort; int localPort; int serverPort; int isNeighbor; int seqNumReceive; int ttl; int numFiles; int numLinks; 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]; } cli_addr; int neighborCountDown; int LSACountDown; int isDown; } *


printLinkEnt

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

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
result = printf("link entry %d is %d", (unsigned int)i, *(unsigned int *)(a1 + 4 * i));
}
return result;
}

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

if ( a2 > 0 )
{
for ( i = 0LL; i != a2; ++i )
result = printf("link entry %d is %d", (unsigned int)i, *(unsigned int *)(a1 + 4 * i));
}
return result;
}

original_code:
void printLinkEnt(char* buf, int numLinks){
 int i;
 int* intArr = (int *)buf;
 for(i = 0; i < numLinks; i++){
  printf("link entry %d is %d",i,intArr[i]);
 }
}

canonical_original_code:
void printLinkEnt(char *buf, int numLinks){
 int i;
 int *intArr = (int *)buf;
 for(i = 0; i < numLinks; i++){
  printf("link entry %d is %d",i,intArr[i]);
 }
}

variable_types:
buf
char *

variable_types: i int

variable_types:
intArr
int *


printFileEnt

decompiled_code:
int __fastcall printFileEnt(const char *a1, int a2)
{
unsigned int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
result = printf("file entry %d is %s", i, a1);
a1 += 9;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(const char *a1, int a2)
{
unsigned int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
{
result = printf("file entry %d is %s", i, a1);
a1 += 9;
}
}
return result;
}

original_code:
void printFileEnt(char* buf, int numFiles){
 int i;
 for(i = 0; i < numFiles; i++){
  printf("file entry %d is %s",i,buf + 9*i);
 }
}

canonical_original_code:
void printFileEnt(char *buf, int numFiles){
 int i;
 for(i = 0; i < numFiles; i++){
  printf("file entry %d is %s",i,buf + 9*i);
 }
}


getFileEntry

decompiled_code:
const char **__fastcall getFileEntry(__int64 *a1, const char *a2)
{
__int64 v2; // rbx
const char **v3; // rbp

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !strcmp(**(const char ***)v2, a2) )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return v3;
}

canonical_decompiled_code:
const char **__fastcall func2(__int64 *a1, const char *a2)
{
__int64 v2; // rbx
const char **v3; // rbp

v2 = *a1;
if ( !*a1 )
return 0LL;
while ( 1 )
{
v3 = *(const char ***)v2;
if ( !strcmp(**(const char ***)v2, a2) )
break;
v2 = *(_QWORD *)(v2 + 8);
if ( !v2 )
return 0LL;
}
return v3;
}

original_code:
fileEntry* getFileEntry(linkedList* list, char* obj){
 node* curr;
 curr = list->head;
 while( curr != ((void *)0) ){
  fileEntry* fe = (fileEntry*)curr->data;
  if ( strcmp(fe->objectName, obj) == 0){
   return fe;
  }
  curr = curr->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct fe *getFileEntry(struct list *list, char *obj){
 struct node_s *curr;
 curr = list->head;
 while( curr != ((void *)0) ){
  struct fe *fe = (fileEntry*)curr->data;
  if ( strcmp(fe->objectName, obj) == 0){
   return fe;
  }
  curr = curr->next;
 }
 return ((void *)0);
}

variable_types: struct list { struct node_s { void *data; struct node_s *next; } *head; struct node_s *tail; } *

variable_types:
obj
char *

variable_types: struct fe { char *objectName; char *path; } *