decompiled_code:
__int64 process_mq_parent()
{
const char *v0; // rbx
__int64 result; // rax

mq_notify();
v0 = (const char *)calloc(0x2000uLL, 1uLL);
while ( 1 )
{
result = mq_receive();
if ( result < 0 )
break;
fprintf(stderr, "%s\n", v0);
while ( ll_next((__int64 *)mq_ll) )
mq_send();
}
return result;
}

canonical_decompiled_code:
__int64 func12()
{
const char *v0; // rbx
__int64 result; // rax

mq_notify();
v0 = (const char *)calloc(0x2000uLL, 1uLL);
while ( 1 )
{
result = mq_receive();
if ( result < 0 )
break;
fprintf(stderr, "%s\n", v0);
while ( func11((__int64 *)mq_ll) )
mq_send();
}
return result;
}

original_code:
void process_mq_parent() {
 struct sigevent sev;
 sev.sigev_notify = SIGEV_SIGNAL;
 sev.sigev_signo = 10;
 mq_notify(mqd_parent_incoming, &sev);
 mqd_t *mqd_child;
 Node *node = ((void *)0);
 char *msg = malloc(8192);
 memset(msg, 0, 8192);
 while (mq_receive(mqd_parent_incoming, msg, 8192, 0) >= 0) {
  fprintf(stderr, "%s\n", msg);
  while ((node = ll_next(mq_ll))) {
   mqd_child = node->data;
   mq_send(*mqd_child, msg, 8192, 0);
  }
 }
}

canonical_original_code:
void process_mq_parent() {
 struct sigevent sev;
 sev.sigev_notify = SIGEV_SIGNAL;
 sev.sigev_signo = 10;
 mq_notify(mqd_parent_incoming, &sev);
 int *mqd_child;
 struct Node *node = ((void *)0);
 char *msg = malloc(8192);
 memset(msg, 0, 8192);
 while (mq_receive(mqd_parent_incoming, msg, 8192, 0) >= 0) {
  fprintf(stderr, "%s\n", msg);
  while ((node = ll_next(mq_ll))) {
   mqd_child = node->data;
   mq_send(*mqd_child, msg, 8192, 0);
  }
 }
}

variable_types: struct Node { struct Node *next; void *data; unsigned long length; } *

user_defined_types: union sigval { int sival_int; void *sival_ptr; }

user_defined_types: union pthread_attr_t { char __size[56]; long __align; }


repo: poyannabati/charlando

decompiled_code:
void __fastcall ll_reset(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
}

canonical_decompiled_code:
void __fastcall func13(__int64 a1)
{
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void ll_reset(LinkedList *ll) {
 ll->cur = ((void *)0);
}

canonical_original_code:
void ll_reset(struct LinkedList *ll) {
 ll->cur = ((void *)0);
}

variable_types: struct LinkedList { struct Node { struct Node *next; void *data; unsigned long length; } *head; struct Node *tail; struct Node *cur; } *

return_type: void

user_defined_types: struct LinkedList { struct Node *head; struct Node *tail; struct Node *cur; }


decompiled_code:
size_t sigpipe_handler()
{
return fwrite("Sigpipe.\n", 1uLL, 9uLL, stderr);
}

canonical_decompiled_code:
size_t func14()
{
return fwrite("Sigpipe.\n", 1uLL, 9uLL, stderr);
}

original_code:
void sigpipe_handler(int status) {
 fprintf(stderr, "Sigpipe.\n");
}

variable_types: status int


strrev

decompiled_code:
void *__fastcall strrev(void *dest, __int64 a2)
{
size_t v2; // r12
_BYTE *v4; // rsi
_BYTE *v5; // rax
_BYTE *v6; // rdx
_BYTE *v7; // rcx

if ( *((char *)dest + a2 - 1) )
__assert_fail("*(string + length - 1) == '\\0'", "../server.c", 0x3Cu, "strrev");
v2 = a2 - 1;
v4 = malloc(a2 - 1);
v5 = (char *)dest + a2 - 2;
v6 = v4;
if ( v2 )
{
do
{
*v6++ = *v5;
v7 = v5--;
}
while ( v7 != dest );
}
return memcpy(dest, v4, v2);
}

canonical_decompiled_code:
void *__fastcall func15(void *dest, __int64 a2)
{
size_t v2; // r12
_BYTE *v4; // rsi
_BYTE *v5; // rax
_BYTE *v6; // rdx
_BYTE *v7; // rcx

if ( *((char *)dest + a2 - 1) )
__assert_fail("*(string + length - 1) == '\\0'", "../server.c", 0x3Cu, "strrev");
v2 = a2 - 1;
v4 = malloc(a2 - 1);
v5 = (char *)dest + a2 - 2;
v6 = v4;
if ( v2 )
{
do
{
*v6++ = *v5;
v7 = v5--;
}
while ( v7 != dest );
}
return memcpy(dest, v4, v2);
}

original_code:
void strrev(char *string, size_t length) {
 ((void) sizeof ((*(string + length - 1) == '\0') ? 1 : 0), __extension__ ({ if (*(string + length - 1) == '\0') ; else __assert_fail ("*(string + length - 1) == '\\0'", "../server.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 size_t content = length - 1;
 char *reversed = malloc(content);
 int i;
 for (i = 0; i < content; i++) {
  *(reversed + i) = *(string + content - i - 1);
 }
 memcpy(string, reversed, content);
}

canonical_original_code:
void strrev(char *string, unsigned long length) {
 ((void) sizeof ((*(string + length - 1) == '\0') ? 1 : 0), __extension__ ({ if (*(string + length - 1) == '\0') ; else __assert_fail ("*(string + length - 1) == '\\0'", "../server.c", 60, __extension__ __PRETTY_FUNCTION__); }));
 unsigned long content = length - 1;
 char *reversed = malloc(content);
 int i;
 for (i = 0; i < content; i++) {
  *(reversed + i) = *(string + content - i - 1);
 }
 memcpy(string, reversed, content);
}

variable_types:
string
char *

variable_types:
length
unsigned long

variable_types:
content
unsigned long

variable_types:
reversed
char *

variable_types: i int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
_DWORD *v4; // rbx
socklen_t v5; // edx
char *v6; // rbp
__int64 v7; // rax
_BYTE *v8; // r12
unsigned int v9; // er15
unsigned int v10; // er13
char *v11; // rbp
__int64 v12; // rcx
__sigset_t *v13; // rdi
_BYTE *v14; // rbp
int v15; // ebx
char v16; // al
char *v18; // rbp
int optval; // [rsp+8h] [rbp-F0h] BYREF
int buf; // [rsp+Ch] [rbp-ECh] BYREF
struct sockaddr v21; // [rsp+10h] [rbp-E8h] BYREF
struct sigaction v22; // [rsp+20h] [rbp-D8h] BYREF

mq_ll = ll_init(argc, argv, envp);
mqd_parent_incoming = mq_open();
fwrite("Server starting. \n", 1uLL, 0x12uLL, stderr);
v3 = socket(2, 1, 0);
optval = 1;
setsockopt(v3, 1, 2, &optval, 4u);
signal(13, (__sighandler_t)1);
v21 = 0LL;
v4 = malloc(0x20uLL);
inet_pton(2, "127.0.0.1", v4);
v21.sa_family = 2;
*(_DWORD *)&v21.sa_data[2] = *v4;
*(_WORD *)v21.sa_data = _bswap_16_constprop_0(v3, &v21, 16LL);
if ( bind(v3, &v21, v5) )
{
fwrite("Couldn't bind address. \n", 1uLL, 0x18uLL, stderr);
}
else
{
fwrite("Main>Successfully bound address. \n", 1uLL, 0x22uLL, stderr);
if ( !listen(v3, 10) )
{
fwrite("Main>Listening for connections.\n", 1uLL, 0x20uLL, stderr);
fwrite("Main>Accepting connections! Will block. \n", 1uLL, 0x29uLL, stderr);
while ( 1 )
{
v8 = malloc(0x2001uLL);
accepted_socket = accept(v3, 0LL, 0LL);
fwrite("Main>Accepted socket, forking \n", 1uLL, 0x1FuLL, stderr);
v9 = fork();
if ( !v9 )
break;
memset(&v22.sa_mask, 0, 0x90uLL);
v22.sa_handler = (__sighandler_t)sigchld_handler;
v22.sa_flags = 0x10000000;
sigaction(17, &v22, 0LL);
memset(&v22.sa_mask, 0, 0x90uLL);
v22.sa_handler = (__sighandler_t)process_mq_parent;
v22.sa_flags = 0x10000000;
sigaction(10, &v22, 0LL);
v6 = (char *)calloc(0x64uLL, 1uLL);
sprintf(v6, "/charlando_server_child_%d", v9);
fprintf(stderr, "%s\n", v6);
buf = mq_open();
v7 = node_init(&buf, 4uLL);
ll_add(mq_ll, v7);
free(v6);
process_mq_parent();
fprintf(stderr, "Main>Child created Server[%d]\n", v9);
}
v10 = getpid();
mq_open();
v11 = (char *)malloc(0x64uLL);
sprintf(v11, "/charlando_server_child_%d", v10);
incoming = mq_open();
free(v11);
v12 = 36LL;
v13 = &v22.sa_mask;
while ( v12 )
{
LODWORD(v13->__val[0]) = v9;
v13 = (__sigset_t *)((char *)v13 + 4);
--v12;
}
v22.sa_handler = (__sighandler_t)process_mq_child;
v22.sa_flags = 0x10000000;
sigaction(10, &v22, 0LL);
process_mq_child();
while ( 1 )
{
v14 = v8;
v15 = 0;
do
{
v15 += recv(accepted_socket, &buf, 1uLL, 0);
if ( v15 <= 0 )
{
free(v8);
fprintf(stderr, "Server[%d]>Client disconnected, exiting.\n", v10);
exit(0);
}
v16 = buf;
*v14++ = buf;
}
while ( v16 );
v18 = (char *)calloc(0x2000uLL, 1uLL);
sprintf(v18, "Client[%d]>%s\n", v10, v8);
strlen(v18);
mq_send();
free(v18);
}
}
fwrite("Couldn't listen. \n", 1uLL, 0x12uLL, stderr);
}
close(v3);
fwrite("Server shutting down. \n", 1uLL, 0x17uLL, stderr);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er13
_DWORD *v4; // rbx
socklen_t v5; // edx
char *v6; // rbp
__int64 v7; // rax
_BYTE *v8; // r12
unsigned int v9; // er15
unsigned int v10; // er13
char *v11; // rbp
__int64 v12; // rcx
__sigset_t *v13; // rdi
_BYTE *v14; // rbp
int v15; // ebx
char v16; // al
char *v18; // rbp
int optval; // [rsp+8h] [rbp-F0h] BYREF
int buf; // [rsp+Ch] [rbp-ECh] BYREF
struct sockaddr v21; // [rsp+10h] [rbp-E8h] BYREF
struct sigaction v22; // [rsp+20h] [rbp-D8h] BYREF

mq_ll = func10(argc, argv, envp);
mqd_parent_incoming = mq_open();
fwrite("Server starting. \n", 1uLL, 0x12uLL, stderr);
v3 = socket(2, 1, 0);
optval = 1;
setsockopt(v3, 1, 2, &optval, 4u);
signal(13, (__sighandler_t)1);
v21 = 0LL;
v4 = malloc(0x20uLL);
inet_pton(2, "127.0.0.1", v4);
v21.sa_family = 2;
*(_DWORD *)&v21.sa_data[2] = *v4;
*(_WORD *)v21.sa_data = func9(v3, &v21, 16LL);
if ( bind(v3, &v21, v5) )
{
fwrite("Couldn't bind address. \n", 1uLL, 0x18uLL, stderr);
}
else
{
fwrite("Main>Successfully bound address. \n", 1uLL, 0x22uLL, stderr);
if ( !listen(v3, 10) )
{
fwrite("Main>Listening for connections.\n", 1uLL, 0x20uLL, stderr);
fwrite("Main>Accepting connections! Will block. \n", 1uLL, 0x29uLL, stderr);
while ( 1 )
{
v8 = malloc(0x2001uLL);
accepted_socket = accept(v3, 0LL, 0LL);
fwrite("Main>Accepted socket, forking \n", 1uLL, 0x1FuLL, stderr);
v9 = fork();
if ( !v9 )
break;
memset(&v22.sa_mask, 0, 0x90uLL);
v22.sa_handler = (__sighandler_t)sigchld_handler;
v22.sa_flags = 0x10000000;
sigaction(17, &v22, 0LL);
memset(&v22.sa_mask, 0, 0x90uLL);
v22.sa_handler = (__sighandler_t)process_mq_parent;
v22.sa_flags = 0x10000000;
sigaction(10, &v22, 0LL);
v6 = (char *)calloc(0x64uLL, 1uLL);
sprintf(v6, "/charlando_server_child_%d", v9);
fprintf(stderr, "%s\n", v6);
buf = mq_open();
v7 = node_init(&buf, 4uLL);
ll_add(mq_ll, v7);
free(v6);
func12();
fprintf(stderr, "Main>Child created Server[%d]\n", v9);
}
v10 = getpid();
mq_open();
v11 = (char *)malloc(0x64uLL);
sprintf(v11, "/charlando_server_child_%d", v10);
incoming = mq_open();
free(v11);
v12 = 36LL;
v13 = &v22.sa_mask;
while ( v12 )
{
LODWORD(v13->__val[0]) = v9;
v13 = (__sigset_t *)((char *)v13 + 4);
--v12;
}
v22.sa_handler = (__sighandler_t)process_mq_child;
v22.sa_flags = 0x10000000;
sigaction(10, &v22, 0LL);
func8();
while ( 1 )
{
v14 = v8;
v15 = 0;
do
{
v15 += recv(accepted_socket, &buf, 1uLL, 0);
if ( v15 <= 0 )
{
free(v8);
fprintf(stderr, "Server[%d]>Client disconnected, exiting.\n", v10);
exit(0);
}
v16 = buf;
*v14++ = buf;
}
while ( v16 );
v18 = (char *)calloc(0x2000uLL, 1uLL);
sprintf(v18, "Client[%d]>%s\n", v10, v8);
strlen(v18);
mq_send();
free(v18);
}
}
fwrite("Couldn't listen. \n", 1uLL, 0x12uLL, stderr);
}
close(v3);
fwrite("Server shutting down. \n", 1uLL, 0x17uLL, stderr);
return 0;
}

original_code:
int main(int argc, char **argv) {
 mq_ll = ll_init();
 mqd_parent_incoming = mq_open("/charlando_server_parent",
 0100 | 00 | 04000,
 ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
 fprintf(stderr, "Server starting. \n");
 int sockfd = socket(2, SOCK_STREAM, 0);
 int optval = 1;
 setsockopt(sockfd, 1, 2, &optval, sizeof optval);
 signal(13, ((__sighandler_t) 1));
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 void *binaryLocalhost = malloc(32);
 inet_pton(2, "127.0.0.1", binaryLocalhost);
 addr.sin_family = 2;
 addr.sin_addr.s_addr = *(in_addr_t *) binaryLocalhost;
 addr.sin_port = htons(16999);
 if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))
   == 0) {
  fprintf(stderr, "Main>Successfully bound address. \n");
  if (listen(sockfd, 10) == 0) {
   fprintf(stderr, "Main>Listening for connections.\n");
   fprintf(stderr, "Main>Accepting connections! Will block. \n");
   while (1) {
    int bufsize = 8192;
    char *buf = malloc(bufsize + 1);
    char chr;
    accepted_socket = accept(sockfd, ((void *)0), 0);
    fprintf(stderr, "Main>Accepted socket, forking \n");
    pid_t child_pid = fork();
    switch (child_pid) {
    case 0: {
     pid_t process_pid = getpid();
     mqd_t outgoing = mq_open("/charlando_server_parent",
     0100 | 01, ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     char *queue_name = malloc(100);
     sprintf(queue_name, "/charlando_server_child_%d",
       process_pid);
     incoming = mq_open(queue_name,
     0100 | 00 | 04000,
     ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     free(queue_name);
     struct sigaction sa;
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &process_mq_child;
     sa.sa_flags = 0x10000000;
     sigaction(10, &sa, ((void *)0));
     process_mq_child();
     while (1) {
      int i;
      int bytes = 0;
      for (i = 0;
        (bytes += recv(accepted_socket, &chr, 1, 0)) > 0;
        i++) {
       buf[i] = chr;
       if (chr == '\0')
        break;
      }
      if (bytes > 0) {
       char *msg = malloc(8192);
       memset(msg, 0, 8192);
       sprintf(msg, "Client[%d]>%s\n", process_pid, buf);
       mq_send(outgoing, msg, strlen(msg), 0);
       free(msg);
      } else {
       break;
      }
     }
     free(buf);
     fprintf(stderr,
       "Server[%d]>Client disconnected, exiting.\n",
       process_pid);
     exit(0);
     break;
    }
    default: {
     struct sigaction sa;
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &sigchld_handler;
     sa.sa_flags = 0x10000000;
     sigaction(17, &sa, ((void *)0));
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &process_mq_parent;
     sa.sa_flags = 0x10000000;
     sigaction(10, &sa, ((void *)0));
     char *queue_name = malloc(100);
     memset(queue_name, 0, 100);
     sprintf(queue_name, "/charlando_server_child_%d",
       child_pid);
     fprintf(stderr, "%s\n", queue_name);
     mqd_t child_mqd = mq_open(queue_name, 0100 | 01,
     ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     ll_add(mq_ll, node_init(&child_mqd, sizeof(child_mqd)));
     free(queue_name);
     process_mq_parent();
     fprintf(stderr, "Main>Child created Server[%d]\n",
       child_pid);
     break;
    }
    }
   }
  } else {
   fprintf(stderr, "Couldn't listen. \n");
  }
 } else {
  fprintf(stderr, "Couldn't bind address. \n");
 }
 close(sockfd);
 fprintf(stderr, "Server shutting down. \n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 mq_ll = ll_init();
 mqd_parent_incoming = mq_open("/charlando_server_parent",
 0100 | 00 | 04000,
 ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
 fprintf(stderr, "Server starting. \n");
 int sockfd = socket(2, SOCK_STREAM, 0);
 int optval = 1;
 setsockopt(sockfd, 1, 2, &optval, sizeof optval);
 signal(13, ((void (*)(int)) 1));
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 void *binaryLocalhost = malloc(32);
 inet_pton(2, "127.0.0.1", binaryLocalhost);
 addr.sin_family = 2;
 addr.sin_addr.s_addr = *(unsigned int *) binaryLocalhost;
 addr.sin_port = htons(16999);
 if (bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in))
   == 0) {
  fprintf(stderr, "Main>Successfully bound address. \n");
  if (listen(sockfd, 10) == 0) {
   fprintf(stderr, "Main>Listening for connections.\n");
   fprintf(stderr, "Main>Accepting connections! Will block. \n");
   while (1) {
    int bufsize = 8192;
    char *buf = malloc(bufsize + 1);
    char chr;
    accepted_socket = accept(sockfd, ((void *)0), 0);
    fprintf(stderr, "Main>Accepted socket, forking \n");
    int child_pid = fork();
    switch (child_pid) {
    case 0: {
     int process_pid = getpid();
     int outgoing = mq_open("/charlando_server_parent",
     0100 | 01, ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     char *queue_name = malloc(100);
     sprintf(queue_name, "/charlando_server_child_%d",
       process_pid);
     incoming = mq_open(queue_name,
     0100 | 00 | 04000,
     ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     free(queue_name);
     struct sigaction sa;
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &process_mq_child;
     sa.sa_flags = 0x10000000;
     sigaction(10, &sa, ((void *)0));
     process_mq_child();
     while (1) {
      int i;
      int bytes = 0;
      for (i = 0;
        (bytes += recv(accepted_socket, &chr, 1, 0)) > 0;
        i++) {
       buf[i] = chr;
       if (chr == '\0')
        break;
      }
      if (bytes > 0) {
       char *msg = malloc(8192);
       memset(msg, 0, 8192);
       sprintf(msg, "Client[%d]>%s\n", process_pid, buf);
       mq_send(outgoing, msg, strlen(msg), 0);
       free(msg);
      } else {
       break;
      }
     }
     free(buf);
     fprintf(stderr,
       "Server[%d]>Client disconnected, exiting.\n",
       process_pid);
     exit(0);
     break;
    }
    default: {
     struct sigaction sa;
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &sigchld_handler;
     sa.sa_flags = 0x10000000;
     sigaction(17, &sa, ((void *)0));
     memset(&sa, 0, sizeof sa);
     sa.__sigaction_handler.sa_handler = &process_mq_parent;
     sa.sa_flags = 0x10000000;
     sigaction(10, &sa, ((void *)0));
     char *queue_name = malloc(100);
     memset(queue_name, 0, 100);
     sprintf(queue_name, "/charlando_server_child_%d",
       child_pid);
     fprintf(stderr, "%s\n", queue_name);
     int child_mqd = mq_open(queue_name, 0100 | 01,
     ((0400|0200|0100) >> 3) | (0400|0200|0100) | (((0400|0200|0100) >> 3) >> 3), ((void *)0));
     ll_add(mq_ll, node_init(&child_mqd, sizeof(child_mqd)));
     free(queue_name);
     process_mq_parent();
     fprintf(stderr, "Main>Child created Server[%d]\n",
       child_pid);
     break;
    }
    }
   }
  } else {
   fprintf(stderr, "Couldn't listen. \n");
  }
 } else {
  fprintf(stderr, "Couldn't bind address. \n");
 }
 close(sockfd);
 fprintf(stderr, "Server shutting down. \n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: sockfd int

variable_types: optval 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:
binaryLocalhost
void *

variable_types: bufsize int

variable_types:
buf
char *

variable_types: chr char

variable_types: outgoing 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: bytes int

variable_types:
msg
char *

return_type: int

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

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


original_code:
void trim_newlines(char *string, size_t length) {
 int i;
 for (i = 0; i < length; i++) {
  if (string[i] == '\n')
   string[i] = ' ';
 }
}

canonical_original_code:
void trim_newlines(char *string, unsigned long length) {
 int i;
 for (i = 0; i < length; i++) {
  if (string[i] == '\n')
   string[i] = ' ';
 }
}

variable_types:
string
char *

variable_types:
length
unsigned long


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
_DWORD *v4; // rbx
unsigned __int64 v5; // rax
size_t v6; // rdx
__int64 v7; // rbx
char v8; // al
char buf; // [rsp+Fh] [rbp-39h] BYREF
size_t n; // [rsp+10h] [rbp-38h] BYREF
char *lineptr; // [rsp+18h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

puts("Client starting. ");
addr = 0LL;
v3 = socket(2, 1, 0);
v4 = malloc(0x20uLL);
inet_pton(2, "127.0.0.1", v4);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = *v4;
*(_WORD *)addr.sa_data = _bswap_16_constprop_0("Attempting to connect. ");
puts("Attempting to connect. ");
if ( !connect(v3, &addr, 0x10u) )
{
puts("Connected! ");
buf = 0;
n = 0x2000LL;
for ( lineptr = (char *)calloc(0x2000uLL, 1uLL); ; printf("Server>%s\n", lineptr) )
{
do
{
while ( 1 )
{
printf("Client>");
v5 = getline(&lineptr, &n, stdin);
if ( v5 <= 1 )
break;
trim_newlines(lineptr, v5, v5 + 1);
write(v3, lineptr, v6);
}
}
while ( v5 != 1 );
v7 = 0LL;
memset(lineptr, 0, n);
do
{
if ( !(unsigned int)recv(v3, &buf, 1uLL, 0) )
break;
v8 = buf;
lineptr[v7++] = buf;
}
while ( v8 );
}
}
printf("Failed");
close(v3);
puts("Client shutting down. ");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
_DWORD *v4; // rbx
unsigned __int64 v5; // rax
size_t v6; // rdx
__int64 v7; // rbx
char v8; // al
char buf; // [rsp+Fh] [rbp-39h] BYREF
size_t n; // [rsp+10h] [rbp-38h] BYREF
char *lineptr; // [rsp+18h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

puts("Client starting. ");
addr = 0LL;
v3 = socket(2, 1, 0);
v4 = malloc(0x20uLL);
inet_pton(2, "127.0.0.1", v4);
addr.sa_family = 2;
*(_DWORD *)&addr.sa_data[2] = *v4;
*(_WORD *)addr.sa_data = func7("Attempting to connect. ");
puts("Attempting to connect. ");
if ( !connect(v3, &addr, 0x10u) )
{
puts("Connected! ");
buf = 0;
n = 0x2000LL;
for ( lineptr = (char *)calloc(0x2000uLL, 1uLL); ; printf("Server>%s\n", lineptr) )
{
do
{
while ( 1 )
{
printf("Client>");
v5 = getline(&lineptr, &n, stdin);
if ( v5 <= 1 )
break;
func8(lineptr, v5, v5 + 1);
write(v3, lineptr, v6);
}
}
while ( v5 != 1 );
v7 = 0LL;
memset(lineptr, 0, n);
do
{
if ( !(unsigned int)recv(v3, &buf, 1uLL, 0) )
break;
v8 = buf;
lineptr[v7++] = buf;
}
while ( v8 );
}
}
printf("Failed");
close(v3);
puts("Client shutting down. ");
return 0;
}

original_code:
int main(int argc, char **argv) {
 printf("Client starting. \n");
 int sockfd = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 void *binaryLocalhost = malloc(32);
 inet_pton(2, "127.0.0.1", binaryLocalhost);
 addr.sin_family = 2;
 addr.sin_addr.s_addr = *(in_addr_t *) binaryLocalhost;
 addr.sin_port = htons(16999);
 printf("Attempting to connect. \n");
 if (connect(sockfd, &addr, sizeof(addr)) == 0) {
  printf("Connected! \n");
  char chr = ((void *)0);
  size_t msg_size = 8192;
  char *msg = malloc(msg_size);
  memset(msg, 0, msg_size);
  size_t input_size = 0;
  while (1) {
   printf("Client>");
   input_size = getline(&msg, &msg_size, stdin);
   if (input_size > 1) {
    trim_newlines(msg, input_size);
    write(sockfd, msg, (input_size + 1));
   } else if (input_size == 1) {
    memset(msg, 0, msg_size);
    int i;
    int result;
    for (i = 0; (result = recv(sockfd, &chr, 1, 0)); i++) {
     msg[i]=chr;
     if (chr == '\0')
      break;
    }
    printf("Server>%s\n", msg);
   }
  }
 } else {
  printf("Failed");
 }
 close(sockfd);
 printf("Client shutting down. \n");
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 printf("Client starting. \n");
 int sockfd = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in addr;
 memset(&addr, 0, sizeof(struct sockaddr_in));
 void *binaryLocalhost = malloc(32);
 inet_pton(2, "127.0.0.1", binaryLocalhost);
 addr.sin_family = 2;
 addr.sin_addr.s_addr = *(unsigned int *) binaryLocalhost;
 addr.sin_port = htons(16999);
 printf("Attempting to connect. \n");
 if (connect(sockfd, &addr, sizeof(addr)) == 0) {
  printf("Connected! \n");
  char chr = ((void *)0);
  unsigned long msg_size = 8192;
  char *msg = malloc(msg_size);
  memset(msg, 0, msg_size);
  unsigned long input_size = 0;
  while (1) {
   printf("Client>");
   input_size = getline(&msg, &msg_size, stdin);
   if (input_size > 1) {
    trim_newlines(msg, input_size);
    write(sockfd, msg, (input_size + 1));
   } else if (input_size == 1) {
    memset(msg, 0, msg_size);
    int i;
    int result;
    for (i = 0; (result = recv(sockfd, &chr, 1, 0)); i++) {
     msg[i]=chr;
     if (chr == '\0')
      break;
    }
    printf("Server>%s\n", msg);
   }
  }
 } else {
  printf("Failed");
 }
 close(sockfd);
 printf("Client shutting down. \n");
 return 0;
}

variable_types: result int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
const char *v4; // r12
int v5; // eax
int result; // eax
unsigned int v7; // ebp
__int64 i; // rax

if ( argc == 4 )
{
while ( 1 )
{
v5 = getopt(4, (char *const *)argv, "n:");
if ( v5 == -1 )
{
for ( i = _bss_start; (int)i <= 3; ++i )
v4 = argv[i];
__sysv_signal(2, sig_handler);
__sysv_signal(1, sig_handler);
__sysv_signal(3, sig_handler);
__sysv_signal(15, sig_handler);
__sysv_signal(20, sig_handler);
extract_file(v3, v4);
return 0;
}
if ( v5 == 63 )
break;
if ( v5 != 110 )
return 1;
v3 = atoi(optarg);
}
v7 = optopt;
if ( optopt == 110 )
{
printf("Option -%c requires an argument.\n", 110LL);
result = 1;
}
else
{
if ( ((*__ctype_b_loc())[v7] & 0x4000) != 0 )
printf("Unknown option '-%c'.\n", v7);
else
printf("Unknown option character '\\x%x'.\n", v7);
result = 1;
}
}
else
{
puts("Wrong number of arguments");
result = 1;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
const char *v4; // r12
int v5; // eax
int result; // eax
unsigned int v7; // ebp
__int64 i; // rax

if ( argc == 4 )
{
while ( 1 )
{
v5 = getopt(4, (char *const *)argv, "n:");
if ( v5 == -1 )
{
for ( i = _bss_start; (int)i <= 3; ++i )
v4 = argv[i];
__sysv_signal(2, sig_handler);
__sysv_signal(1, sig_handler);
__sysv_signal(3, sig_handler);
__sysv_signal(15, sig_handler);
__sysv_signal(20, sig_handler);
func8(v3, v4);
return 0;
}
if ( v5 == 63 )
break;
if ( v5 != 110 )
return 1;
v3 = atoi(optarg);
}
v7 = optopt;
if ( optopt == 110 )
{
printf("Option -%c requires an argument.\n", 110LL);
result = 1;
}
else
{
if ( ((*__ctype_b_loc())[v7] & 0x4000) != 0 )
printf("Unknown option '-%c'.\n", v7);
else
printf("Unknown option character '\\x%x'.\n", v7);
result = 1;
}
}
else
{
puts("Wrong number of arguments");
result = 1;
}
return result;
}

original_code:
int main(int argc, char *argv[]) {
 if(argc==4) {
  char *archivename;
  int opt, index, indice;
  while((opt=getopt(argc,argv,"n:"))!=-1) {
   switch(opt) {
    case 'n':
     indice=atoi(optarg);
     break;
    case '?':
     if(optopt=='n')
      printf("Option -%c requires an argument.\n", optopt);
     else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short int) _ISprint))
      printf("Unknown option '-%c'.\n", optopt);
     else
      printf("Unknown option character '\\x%x'.\n", optopt);
     return 1;
    default:
     return 1;
   }
  }
  for(index=optind; index<argc; index++)
   archivename=argv[index];
  signal(2, sig_handler);
  signal(1, sig_handler);
  signal(3, sig_handler);
  signal(15, sig_handler);
  signal(20, sig_handler);
  extract_file(indice, archivename);
  return 0;
 }
 else {
  printf("Wrong number of arguments\n");
  return 1;
 }
}

canonical_original_code:
int main(int argc, char *argv[]) {
 if(argc==4) {
  char *archivename;
  int opt; int index; int indice;
  while((opt=getopt(argc,argv,"n:"))!=-1) {
   switch(opt) {
    case 'n':
     indice=atoi(optarg);
     break;
    case '?':
     if(optopt=='n')
      printf("Option -%c requires an argument.\n", optopt);
     else if (((*__ctype_b_loc ())[(int) ((optopt))] & (unsigned short) _ISprint))
      printf("Unknown option '-%c'.\n", optopt);
     else
      printf("Unknown option character '\\x%x'.\n", optopt);
     return 1;
    default:
     return 1;
   }
  }
  for(index=optind; index<argc; index++)
   archivename=argv[index];
  signal(2, sig_handler);
  signal(1, sig_handler);
  signal(3, sig_handler);
  signal(15, sig_handler);
  signal(20, sig_handler);
  extract_file(indice, archivename);
  return 0;
 }
 else {
  printf("Wrong number of arguments\n");
  return 1;
 }
}

variable_types:
argv
char *[]

variable_types:
archivename
char *

variable_types: opt int

variable_types: index int

variable_types: indice int


decompiled_code:
void __fastcall __noreturn sig_handler(int a1)
{
__sysv_signal(a1, (__sighandler_t)1);
puts("\nGoodbye");
close(a);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(int a1)
{
__sysv_signal(a1, (__sighandler_t)1);
puts("\nGoodbye");
close(a);
exit(1);
}

original_code:
void sig_handler(int signum) {
 signal(signum, ((__sighandler_t) 1));
 printf("\nGoodbye\n");
 close(a);
 exit(1);
}

canonical_original_code:
void sig_handler(int signum) {
 signal(signum, ((void (*)(int)) 1));
 printf("\nGoodbye\n");
 close(a);
 exit(1);
}

variable_types: signum int


decompiled_code:
int __fastcall extract_file(unsigned int a1, const char *a2)
{
void *v2; // rax
void *v3; // rbp
int v4; // er14
int i; // ebx
size_t v6; // r12
void *v7; // rax
void *v8; // rbp
size_t v9; // rax
int result; // eax
int buf[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = malloc(0x20uLL);
if ( !v2 )
LABEL_15:
exit(1);
v3 = v2;
a = open(a2, 0);
if ( a == -1 )
{
perror("open archive");
goto LABEL_15;
}
if ( read(a, v3, 0x20uLL) == -1 )
perror("read name");
puts((const char *)v3);
v4 = open((const char *)v3, 1217, 384LL);
if ( v4 == -1 )
{
perror("create temporary file");
exit(1);
}
if ( flock(a, 2) == -1 )
{
perror("flock - LOCK_EX");
exit(1);
}
for ( i = 0; ; ++i )
{
if ( (int)read(a, buf, 4uLL) <= 0 )
{
printf("File with indice %d doesn't exist in archive\n", a1);
unlink("README1");
if ( flock(a, 8) != -1 )
{
if ( close(a) != -1 )
goto LABEL_15;
LABEL_21:
perror("close archive");
exit(1);
}
LABEL_26:
perror("flock - LOCK_UN");
exit(1);
}
v6 = buf[0] - 1LL;
v7 = malloc(v6);
v8 = v7;
if ( !v7 )
goto LABEL_15;
if ( read(a, v7, v6) == -1 )
{
perror("read content");
exit(1);
}
if ( i == a1 )
break;
free(v8);
}
puts("EXTRACT");
v9 = strlen((const char *)v8);
if ( write(v4, v8, v9) == -1 )
{
perror("write content");
exit(1);
}
free(v8);
if ( flock(a, 8) == -1 )
goto LABEL_26;
if ( close(a) == -1 )
goto LABEL_21;
result = close(v4);
if ( result == -1 )
{
perror("close temporary");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(unsigned int a1, const char *a2)
{
void *v2; // rax
void *v3; // rbp
int v4; // er14
int i; // ebx
size_t v6; // r12
void *v7; // rax
void *v8; // rbp
size_t v9; // rax
int result; // eax
int buf[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = malloc(0x20uLL);
if ( !v2 )
LABEL_15:
exit(1);
v3 = v2;
a = open(a2, 0);
if ( a == -1 )
{
perror("open archive");
goto LABEL_15;
}
if ( read(a, v3, 0x20uLL) == -1 )
perror("read name");
puts((const char *)v3);
v4 = open((const char *)v3, 1217, 384LL);
if ( v4 == -1 )
{
perror("create temporary file");
exit(1);
}
if ( flock(a, 2) == -1 )
{
perror("flock - LOCK_EX");
exit(1);
}
for ( i = 0; ; ++i )
{
if ( (int)read(a, buf, 4uLL) <= 0 )
{
printf("File with indice %d doesn't exist in archive\n", a1);
unlink("README1");
if ( flock(a, 8) != -1 )
{
if ( close(a) != -1 )
goto LABEL_15;
LABEL_21:
perror("close archive");
exit(1);
}
LABEL_26:
perror("flock - LOCK_UN");
exit(1);
}
v6 = buf[0] - 1LL;
v7 = malloc(v6);
v8 = v7;
if ( !v7 )
goto LABEL_15;
if ( read(a, v7, v6) == -1 )
{
perror("read content");
exit(1);
}
if ( i == a1 )
break;
free(v8);
}
puts("EXTRACT");
v9 = strlen((const char *)v8);
if ( write(v4, v8, v9) == -1 )
{
perror("write content");
exit(1);
}
free(v8);
if ( flock(a, 8) == -1 )
goto LABEL_26;
if ( close(a) == -1 )
goto LABEL_21;
result = close(v4);
if ( result == -1 )
{
perror("close temporary");
exit(1);
}
return result;
}

original_code:
void extract_file(int indice, char *archivename) {
 int temporary;
 char *name;
 name=(char*)malloc(sizeof(char)*32);
 if(name==((void *)0)){
  free(name);
  exit(1);
 }
 a=open(archivename, 00);
 if(a==-1) {
  perror("open archive");
  exit(1);
 }
 if(read(a,(void*)name,(size_t)32)==-1){
  perror("read name");
 }
 printf("%s\n",name);
 temporary=open(name, 01|0100|0200|02000, 0400|0200);
 if(temporary==-1) {
  perror("create temporary file");
  exit(1);
 }
 if(flock(a,2)==-1) {
  perror("flock - LOCK_EX");
  exit(1);
 }
 int x,err;
 int flag = 0;
 int i = 0;
 while((err=read(a, (void *)&x, sizeof(int)))>0) {
  if(err==-1) {
   perror("read int");
   exit(1);
  }
  char *buffer;
  buffer=(char *)malloc((sizeof(char)*x)-1);
  if(buffer==((void *)0)) {
   free(buffer);
   exit(1);
  }
  if(read(a, (void *)buffer, (size_t)x-1)==-1) {
   perror("read content");
   exit(1);
  }
  if(i==indice) {
   flag=1;
   printf("EXTRACT\n");
   if(write(temporary, (void *)buffer, strlen(buffer))==-1) {
    perror("write content");
    exit(1);
   }
   free(buffer);
   break;
  }
  free(buffer);
  i++;
 }
 if(flag==0) {
  printf("File with indice %d doesn't exist in archive\n", indice);
  unlink("README1");
  if (flock(a,8)==-1) {
   perror("flock - LOCK_UN");
   exit(1);
  }
  if(close(a)==-1) {
   perror("close archive");
   exit(1);
  }
  exit(1);
 }
 if (flock(a,8)==-1) {
  perror("flock - LOCK_UN");
  exit(1);
 }
 if(close(a)==-1) {
  perror("close archive");
  exit(1);
 }
 if(close(temporary)==-1) {
  perror("close temporary");
  exit(1);
 }
}

canonical_original_code:
void extract_file(int indice, char *archivename) {
 int temporary;
 char *name;
 name=(char *)malloc(sizeof(char)*32);
 if(name==((void *)0)){
  free(name);
  exit(1);
 }
 a=open(archivename, 00);
 if(a==-1) {
  perror("open archive");
  exit(1);
 }
 if(read(a,(void *)name,(unsigned long)32)==-1){
  perror("read name");
 }
 printf("%s\n",name);
 temporary=open(name, 01|0100|0200|02000, 0400|0200);
 if(temporary==-1) {
  perror("create temporary file");
  exit(1);
 }
 if(flock(a,2)==-1) {
  perror("flock - LOCK_EX");
  exit(1);
 }
 int x; int err;
 int flag = 0;
 int i = 0;
 while((err=read(a, (void *)&x, sizeof(int)))>0) {
  if(err==-1) {
   perror("read int");
   exit(1);
  }
  char *buffer;
  buffer=(char *)malloc((sizeof(char)*x)-1);
  if(buffer==((void *)0)) {
   free(buffer);
   exit(1);
  }
  if(read(a, (void *)buffer, (unsigned long)x-1)==-1) {
   perror("read content");
   exit(1);
  }
  if(i==indice) {
   flag=1;
   printf("EXTRACT\n");
   if(write(temporary, (void *)buffer, strlen(buffer))==-1) {
    perror("write content");
    exit(1);
   }
   free(buffer);
   break;
  }
  free(buffer);
  i++;
 }
 if(flag==0) {
  printf("File with indice %d doesn't exist in archive\n", indice);
  unlink("README1");
  if (flock(a,8)==-1) {
   perror("flock - LOCK_UN");
   exit(1);
  }
  if(close(a)==-1) {
   perror("close archive");
   exit(1);
  }
  exit(1);
 }
 if (flock(a,8)==-1) {
  perror("flock - LOCK_UN");
  exit(1);
 }
 if(close(a)==-1) {
  perror("close archive");
  exit(1);
 }
 if(close(temporary)==-1) {
  perror("close temporary");
  exit(1);
 }
}

variable_types: temporary int

variable_types:
name
char *

variable_types: x int

variable_types: err int

variable_types: flag int

variable_types: i int

variable_types:
buffer
char *


decompiled_code:
__int64 __fastcall send_dns_reply(const char *a1, __int64 a2, __int64 a3, int a4, __int64 a5, signed int a6)
{
int v8; // edx

if ( (int)(strlen(a1) + 16) < a6 )
{
inet_addr("212.58.251.195");
inet_addr("74.125.226.212");
_bswap_16(49164);
_bswap_16(1);
_bswap_16(5);
if ( v8 == a4 )
{
_bswap_16(4);
if ( !malloc(a6 + 32) )
{
LABEL_8:
perror("Malloc Failure");
return 0LL;
}
}
else if ( (unsigned __int16)_bswap_16(2) == a4 )
{
_bswap_16(6);
if ( !malloc(a6 + 36) )
goto LABEL_8;
}
puts("\x1B[1;32mFINAL STEP : Ready to send ...\x1B[0m");
return 0LL;
}
puts("Failed to send DNS reply; DNS request packet appears to have an invalid length.");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, __int64 a2, __int64 a3, int a4, __int64 a5, signed int a6)
{
int v8; // edx

if ( (int)(strlen(a1) + 16) < a6 )
{
inet_addr("212.58.251.195");
inet_addr("74.125.226.212");
func0(49164);
func0(1);
func0(5);
if ( v8 == a4 )
{
func0(4);
if ( !malloc(a6 + 32) )
{
LABEL_8:
perror("Malloc Failure");
return 0LL;
}
}
else if ( (unsigned __int16)func0(2) == a4 )
{
func0(6);
if ( !malloc(a6 + 36) )
goto LABEL_8;
}
puts("\x1B[1;32mFINAL STEP : Ready to send ...\x1B[0m");
return 0LL;
}
puts("Failed to send DNS reply; DNS request packet appears to have an invalid length.");
return 0LL;
}

original_code:
int send_dns_reply(char *question_domain, int sock, struct sockaddr_in *clientaddr, int dns_type, char *request_packet, int request_packet_size)
{
 char *reply_packet = ((void *)0), *fqdn = ((void *)0);
 struct dns_header *header = ((void *)0);
 struct dns_answer_section answer;
 int reply_packet_size = 0;
 int answer_size = sizeof(struct dns_answer_section);
 int bytes_sent = 0;
 int memcpy_offset = 0;
 in_addr_t ip_address1 = {0};
 in_addr_t ip_address2 = {0};
 memset(&answer,0,sizeof(struct dns_answer_section));
 fqdn = "www.facebook.com";
 if(request_packet_size > ((int) (sizeof(struct dns_header) + sizeof(struct dns_question_section)) + (int) strlen(question_domain))){
   ip_address2 = inet_addr("212.58.251.195");
   ip_address1 = inet_addr("74.125.226.212");
  answer.name = htons(0xC00C);
  answer.type = dns_type;
  answer.class = htons(0x0001);
  answer.ttl = htons(0x0005);
  if(dns_type == htons(0x0001)){
   answer.data_len = htons(0x0004);
   reply_packet_size = request_packet_size + ((answer_size + 0x0004) * 0x0002);
   if((reply_packet = malloc(reply_packet_size)) != ((void *)0)){
    memcpy(reply_packet,request_packet,request_packet_size);
    memcpy_offset += request_packet_size;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,(void *) &ip_address1,0x0004);
    memcpy_offset += 0x0004;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,(void *) &ip_address2,0x0004);
   } else {
    perror("Malloc Failure");
    return 0;
   }
  } else if(dns_type == htons(0x0002)){
   answer.data_len = htons(0x0006);
   reply_packet_size = request_packet_size + ((answer_size + 0x0006) * 0x0002);
   if((reply_packet = malloc(reply_packet_size)) != ((void *)0)){
    memcpy(reply_packet,request_packet,request_packet_size);
    memcpy_offset += request_packet_size;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,"\x03ns1\xC0\x0C",0x0006);
    memcpy_offset += 0x0006;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,"\x03ns2\xC0\x0C",0x0006);
   } else {
    perror("Malloc Failure");
    return 0;
   }
  }
        header = (struct dns_header *) reply_packet;
        header->num_answers = htons(0x0002);
        header->flags = htons(0x8180);
  printf("\x1b[1;32m""FINAL STEP : Ready to send ...""\x1b[0m""\n");
 } else {
  printf("Failed to send DNS reply; DNS request packet appears to have an invalid length.\n");
 }
 return 0;
}

canonical_original_code:
int send_dns_reply(char *question_domain, int sock, struct sockaddr_in *clientaddr, int dns_type, char *request_packet, int request_packet_size)
{
 char *reply_packet = ((void *)0); char *fqdn = ((void *)0);
 struct dns_header *header = ((void *)0);
 struct dns_answer_section answer;
 int reply_packet_size = 0;
 int answer_size = sizeof(struct dns_answer_section);
 int bytes_sent = 0;
 int memcpy_offset = 0;
 unsigned int ip_address1 = {0};
 unsigned int ip_address2 = {0};
 memset(&answer,0,sizeof(struct dns_answer_section));
 fqdn = "www.facebook.com";
 if(request_packet_size > ((int) (sizeof(struct dns_header) + sizeof(struct dns_question_section)) + (int) strlen(question_domain))){
   ip_address2 = inet_addr("212.58.251.195");
   ip_address1 = inet_addr("74.125.226.212");
  answer.name = htons(0xC00C);
  answer.type = dns_type;
  answer.class = htons(0x0001);
  answer.ttl = htons(0x0005);
  if(dns_type == htons(0x0001)){
   answer.data_len = htons(0x0004);
   reply_packet_size = request_packet_size + ((answer_size + 0x0004) * 0x0002);
   if((reply_packet = malloc(reply_packet_size)) != ((void *)0)){
    memcpy(reply_packet,request_packet,request_packet_size);
    memcpy_offset += request_packet_size;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,(void *) &ip_address1,0x0004);
    memcpy_offset += 0x0004;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,(void *) &ip_address2,0x0004);
   } else {
    perror("Malloc Failure");
    return 0;
   }
  } else if(dns_type == htons(0x0002)){
   answer.data_len = htons(0x0006);
   reply_packet_size = request_packet_size + ((answer_size + 0x0006) * 0x0002);
   if((reply_packet = malloc(reply_packet_size)) != ((void *)0)){
    memcpy(reply_packet,request_packet,request_packet_size);
    memcpy_offset += request_packet_size;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,"\x03ns1\xC0\x0C",0x0006);
    memcpy_offset += 0x0006;
    memcpy(reply_packet+memcpy_offset,(void *) &answer,answer_size);
    memcpy_offset += answer_size;
    memcpy(reply_packet+memcpy_offset,"\x03ns2\xC0\x0C",0x0006);
   } else {
    perror("Malloc Failure");
    return 0;
   }
  }
        header = (struct dns_header *) reply_packet;
        header->num_answers = htons(0x0002);
        header->flags = htons(0x8180);
  printf("\x1b[1;32m""FINAL STEP : Ready to send ...""\x1b[0m""\n");
 } else {
  printf("Failed to send DNS reply; DNS request packet appears to have an invalid length.\n");
 }
 return 0;
}

variable_types: sock 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:
fqdn
char *

variable_types: struct dns_header { unsigned short xid; unsigned short flags; unsigned short num_questions; unsigned short num_answers; unsigned short num_authority; unsigned short num_additional; } *

variable_types: struct dns_answer_section { unsigned short name; unsigned short type; unsigned short class; unsigned short ttl_top; unsigned short ttl; unsigned short data_len; }

user_defined_types: struct dns_question_section { unsigned short type; unsigned short class; }


original_code:
char *get_domain_in_question(char *dns_packet, int packet_size)
{
 char *domain_name_pointer = ((void *)0);
 char *domain_name = ((void *)0);
 char *tmp_ptr = ((void *)0);
 int dns_header_len = sizeof(struct dns_header);
 int name_part_len = 0;
 int dn_len = 0;
 if(packet_size > dns_header_len){
  domain_name_pointer = (dns_packet + dns_header_len);
  do {
   name_part_len = (int) domain_name_pointer[0];
   if((name_part_len <= 0) || (name_part_len > (packet_size-dns_header_len))){
    printf("Ignoring : invalid name_part_len \n");
    break;
   }
   domain_name_pointer++;
   tmp_ptr = domain_name;
   domain_name = realloc(domain_name,(dn_len+name_part_len+1 +1));
   if(domain_name == ((void *)0)){
    if(tmp_ptr) free(tmp_ptr);
    perror("Realloc Failure");
    return ((void *)0);
   }
   memset(domain_name+dn_len,0,name_part_len+1 +1);
   strncat(domain_name,domain_name_pointer,name_part_len);
   strncat(domain_name,".",1);
   dn_len += name_part_len + 1 + 1;
   domain_name_pointer += name_part_len;
  } while(name_part_len > 0);
 }
 return domain_name;
}

return_type: char *


decompiled_code:
__int64 __fastcall create_socket(__int64 a1, __int64 a2, int a3)
{
int v4; // edx
int v5; // eax
unsigned int v6; // er12
int optval; // [rsp+0h] [rbp-1Ch] BYREF
__int128 v9; // [rsp+4h] [rbp-18h]

v4 = 6;
optval = 1;
v9 = 0LL;
if ( a3 != 1 )
v4 = (unsigned int)(a3 - 2) < 2 ? 0x11 : 0;
v5 = socket(2, a3, v4);
v6 = v5;
if ( v5 < 0 )
{
v6 = -1;
puts("Socklib: Failed to create socket");
}
else if ( setsockopt(v5, 1, 2, &optval, 4u) < 0 )
{
v6 = -1;
puts("Socklib: Failed to set socket option SO_REUSEADDR");
}
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
int v4; // edx
int v5; // eax
unsigned int v6; // er12
int optval; // [rsp+0h] [rbp-1Ch] BYREF
__int128 v9; // [rsp+4h] [rbp-18h]

v4 = 6;
optval = 1;
v9 = 0LL;
if ( a3 != 1 )
v4 = (unsigned int)(a3 - 2) < 2 ? 0x11 : 0;
v5 = socket(2, a3, v4);
v6 = v5;
if ( v5 < 0 )
{
v6 = -1;
puts("Socklib: Failed to create socket");
}
else if ( setsockopt(v5, 1, 2, &optval, 4u) < 0 )
{
v6 = -1;
puts("Socklib: Failed to set socket option SO_REUSEADDR");
}
return v6;
}

original_code:
int create_socket(char *ip, int port, int sock_type)
{
 int on = 1;
 int sock = 0;
 int proto = 0;
 int addrlen = sizeof(struct sockaddr_in);
 struct sockaddr_in serveraddr;
 memset((void *) &serveraddr,0,sizeof(struct sockaddr_in));
 if(sock_type == SOCK_STREAM){
  proto = IPPROTO_TCP;
 } else if(sock_type == SOCK_DGRAM){
  proto = IPPROTO_UDP;
 } else if(sock_type == SOCK_RAW) {
  proto = IPPROTO_UDP;
 }
    if((sock = socket(2,sock_type,proto)) < 0){
            printf("Socklib: Failed to create socket\n");
            return -1;
    }
    if(setsockopt(sock,1,2,&on,sizeof(int)) < 0){
        printf("Socklib: Failed to set socket option SO_REUSEADDR\n");
        return -1;
    }
 return sock;
}

variable_types:
ip
char *

variable_types: port int

variable_types: on int

variable_types: proto int

variable_types: addrlen 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]; }


receive

decompiled_code:
void *__fastcall receive(int fd, int a2, int *a3, __int64 a4, struct sockaddr *a5)
{
void *v5; // r12
void *v9; // rax
int v10; // eax
void *v11; // rdi
socklen_t addr_len[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = 0LL;
*a3 = 0;
addr_len[0] = 16;
if ( (unsigned int)(a2 - 2) <= 1 )
{
v9 = calloc(0x10001uLL, 1uLL);
v5 = v9;
if ( v9 )
{
v10 = recvfrom(fd, v9, 0x10000uLL, 0, a5, addr_len);
*a3 = v10;
if ( v10 < 0 )
{
puts("Socklib: Failed to read data from UDP socket");
v11 = v5;
v5 = 0LL;
free(v11);
}
}
else
{
perror("Malloc failed");
}
}
return v5;
}

canonical_decompiled_code:
void *__fastcall func4(int fd, int a2, int *a3, __int64 a4, struct sockaddr *a5)
{
void *v5; // r12
void *v9; // rax
int v10; // eax
void *v11; // rdi
socklen_t addr_len[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v5 = 0LL;
*a3 = 0;
addr_len[0] = 16;
if ( (unsigned int)(a2 - 2) <= 1 )
{
v9 = calloc(0x10001uLL, 1uLL);
v5 = v9;
if ( v9 )
{
v10 = recvfrom(fd, v9, 0x10000uLL, 0, a5, addr_len);
*a3 = v10;
if ( v10 < 0 )
{
puts("Socklib: Failed to read data from UDP socket");
v11 = v5;
v5 = 0LL;
free(v11);
}
}
else
{
perror("Malloc failed");
}
}
return v5;
}

original_code:
char *receive(int lsock, int sock_type, int *rx_bytes, int csock, struct sockaddr_in *clientaddr)
{
 int recv_size = 0;
 int clen = 0, header_offset = 0;
 int addrlen = sizeof(struct sockaddr_in);
 char *buffer = ((void *)0), *tmp_ptr = ((void *)0), *data_ptr = ((void *)0);
 char *clen_ptr = ((void *)0), *line_end_ptr = ((void *)0);
 *rx_bytes = 0;
 if(sock_type == SOCK_DGRAM || sock_type == SOCK_RAW) {
  if((buffer = malloc(65536 +1)) == ((void *)0)){
                 perror("Malloc failed");
                 return ((void *)0);
         }
         memset(buffer,0,65536 +1);
  if((*rx_bytes = recvfrom(lsock,buffer,65536,0,(struct sockaddr *) clientaddr, (socklen_t *) &addrlen)) < 0){
   printf("Socklib: Failed to read data from UDP socket\n");
   if(buffer) free(buffer);
   return ((void *)0);
  }
 }
 return buffer;
}

canonical_original_code:
char *receive(int lsock, int sock_type, int *rx_bytes, int csock, struct sockaddr_in *clientaddr)
{
 int recv_size = 0;
 int clen = 0; int header_offset = 0;
 int addrlen = sizeof(struct sockaddr_in);
 char *buffer = ((void *)0); char *tmp_ptr = ((void *)0); char *data_ptr = ((void *)0);
 char *clen_ptr = ((void *)0); char *line_end_ptr = ((void *)0);
 *rx_bytes = 0;
 if(sock_type == SOCK_DGRAM || sock_type == SOCK_RAW) {
  if((buffer = malloc(65536 +1)) == ((void *)0)){
                 perror("Malloc failed");
                 return ((void *)0);
         }
         memset(buffer,0,65536 +1);
  if((*rx_bytes = recvfrom(lsock,buffer,65536,0,(struct sockaddr *) clientaddr, (unsigned int *) &addrlen)) < 0){
   printf("Socklib: Failed to read data from UDP socket\n");
   if(buffer) free(buffer);
   return ((void *)0);
  }
 }
 return buffer;
}

variable_types: lsock int

variable_types: csock int

variable_types: clen int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int16 *v4; // rbx
unsigned __int16 v5; // ax
__int64 v6; // r13
unsigned __int16 v7; // ax
unsigned __int16 v8; // ax
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
char *v11; // r12
unsigned __int16 *v12; // rbx
__int16 v13; // ax
__int16 v14; // ax
__int16 v15; // dx
int v17; // [rsp+0h] [rbp-3Ch] BYREF
struct sockaddr v18[3]; // [rsp+4h] [rbp-38h] BYREF

v17 = 0;
v18[0] = 0LL;
v3 = create_socket((__int64)"mani", 2222LL, 3);
if ( v3 == -1 )
{
puts("Failed to create UDP socket for DNS server");
}
else
{
while ( 1 )
{
v4 = (__int16 *)receive(v3, 3, &v17, 0LL, v18);
if ( !v4 )
break;
printf("Packet size is %d\n", (unsigned int)v17);
if ( v17 <= 16 )
{
printf("Received invalid DNS packet; packet size too small");
}
else if ( v17 > 44 )
{
v5 = _bswap_16(v4[16]);
if ( v5 == 1 )
{
v6 = (__int64)(v4 + 14);
printf("------------ DNS QUERY -----------------");
v7 = _bswap_16(v4[16]);
printf("\n [%d QUS]", v7);
v8 = _bswap_16(v4[17]);
printf(" [%d ANW]", v8);
v9 = _bswap_16(v4[18]);
printf(" [%d AUT]", v9);
v10 = _bswap_16(v4[19]);
printf(" [%d ADD]\n\n", v10);
v11 = get_domain_in_question((__int64)(v4 + 14), v17);
printf("\x1B[1;34mDomain Name is %s\x1B[0m\n", v11);
if ( v11 && *v11 )
{
v12 = (unsigned __int16 *)(v6 + strlen(v11) + 13);
v13 = _bswap_16(1);
if ( v12[1] == v13 && (v13 == *v12 || (v14 = _bswap_16(2), v15 == v14)) )
{
puts("\x1B[33mDNS CLASS IN , TYPE A | NS\x1B[0m");
if ( !(unsigned int)send_dns_reply(v11, v3, (__int64)v18, *v12, v6, v17) )
puts("Failed to send DNS response packet");
}
else
{
puts(
"\x1B[1;31mReceived unsupported DNS query type or class. Only type A, NS and class IN queries are supported.\x1B[0m");
}
}
}
else
{
printf("DNS packet contained the wrong number of questions %d\n", v5);
}
}
}
puts("Failed to receive DNS request from client");
}
return 1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
__int16 *v4; // rbx
unsigned __int16 v5; // ax
__int64 v6; // r13
unsigned __int16 v7; // ax
unsigned __int16 v8; // ax
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
char *v11; // r12
unsigned __int16 *v12; // rbx
__int16 v13; // ax
__int16 v14; // ax
__int16 v15; // dx
int v17; // [rsp+0h] [rbp-3Ch] BYREF
struct sockaddr v18[3]; // [rsp+4h] [rbp-38h] BYREF

v17 = 0;
v18[0] = 0LL;
v3 = func3((__int64)"mani", 2222LL, 3);
if ( v3 == -1 )
{
puts("Failed to create UDP socket for DNS server");
}
else
{
while ( 1 )
{
v4 = (__int16 *)func4(v3, 3, &v17, 0LL, v18);
if ( !v4 )
break;
printf("Packet size is %d\n", (unsigned int)v17);
if ( v17 <= 16 )
{
printf("Received invalid DNS packet; packet size too small");
}
else if ( v17 > 44 )
{
v5 = func0(v4[16]);
if ( v5 == 1 )
{
v6 = (__int64)(v4 + 14);
printf("------------ DNS QUERY -----------------");
v7 = func0(v4[16]);
printf("\n [%d QUS]", v7);
v8 = func0(v4[17]);
printf(" [%d ANW]", v8);
v9 = func0(v4[18]);
printf(" [%d AUT]", v9);
v10 = func0(v4[19]);
printf(" [%d ADD]\n\n", v10);
v11 = func2((__int64)(v4 + 14), v17);
printf("\x1B[1;34mDomain Name is %s\x1B[0m\n", v11);
if ( v11 && *v11 )
{
v12 = (unsigned __int16 *)(v6 + strlen(v11) + 13);
v13 = func0(1);
if ( v12[1] == v13 && (v13 == *v12 || (v14 = func0(2), v15 == v14)) )
{
puts("\x1B[33mDNS CLASS IN , TYPE A | NS\x1B[0m");
if ( !(unsigned int)func1(v11, v3, (__int64)v18, *v12, v6, v17) )
puts("Failed to send DNS response packet");
}
else
{
puts(
"\x1B[1;31mReceived unsupported DNS query type or class. Only type A, NS and class IN queries are supported.\x1B[0m");
}
}
}
else
{
printf("DNS packet contained the wrong number of questions %d\n", v5);
}
}
}
puts("Failed to receive DNS request from client");
}
return 1;
}

original_code:
int main(int agrc, char *argv[]) {
 int sock = 0, csock = 0, packet_size = 0;
 struct sockaddr_in clientaddr;
 struct dns_header *header = ((void *)0);
 struct dns_question_section *query_info = ((void *)0);
 char *dns_packet = ((void *)0);
 char *question_domain = ((void *)0);
 char *message = ((void *)0);
 char *fqdn = ((void *)0);
 char *server_ip = ((void *)0);
 memset((void *) &clientaddr,0,sizeof(struct sockaddr_in));
 if((sock = create_socket("mani",2222,SOCK_RAW)) == -1){
  printf("Failed to create UDP socket for DNS server\n");
  return 1;
 }
 int count = 0;
 while(1){
  dns_packet = ((void *)0);
  if((dns_packet = receive(sock,SOCK_RAW,&packet_size,csock,&clientaddr)) == ((void *)0)){
   printf("Failed to receive DNS request from client\n");
   return 1;
  }
  printf("Packet size is %d\n", packet_size);
  if(packet_size <= (int) (sizeof(struct dns_header) + sizeof(struct dns_question_section))){
   printf("Received invalid DNS packet; packet size too small");
   continue;
  }
  if (packet_size <= (int) (sizeof(struct iphdr) + sizeof(struct udphdr) + sizeof(struct dns_header)+ sizeof(struct dns_question_section))) {
   continue;
  }
  dns_packet += sizeof(struct iphdr);
  dns_packet += sizeof(struct udphdr);
  header = (struct dns_header *) dns_packet;
  if(ntohs(header->num_questions) != 1){
   printf("DNS packet contained the wrong number of questions %d\n",ntohs(header->num_questions));
   continue;
  }
  printf("------------ DNS QUERY -----------------");
     printf("\n [%d QUS]",ntohs(header->num_questions));
     printf(" [%d ANW]",ntohs(header->num_answers));
     printf(" [%d AUT]",ntohs(header->num_authority));
     printf(" [%d ADD]\n\n",ntohs(header->num_additional));
  question_domain = get_domain_in_question(dns_packet,packet_size);
  printf("\x1b[1;34m""Domain Name is %s""\x1b[0m""\n", question_domain);
  if(question_domain != ((void *)0) && strlen(question_domain) > 0){
   query_info = (struct dns_question_section *) ((dns_packet) + sizeof(struct dns_header) + strlen(question_domain) + 1);
   if((query_info->class == htons(0x0001)) && ((query_info->type == htons(0x0001)) || (query_info->type == htons(0x0002)))){
     printf("\x1b[33m""DNS CLASS IN , TYPE A | NS""\x1b[0m""\n");
     if(!send_dns_reply(question_domain,sock,&clientaddr,query_info->type,dns_packet,packet_size)){
      printf("Failed to send DNS response packet\n");
     }
   } else {
    printf("\x1b[1;31m""Received unsupported DNS query type or class. Only type A, NS and class IN queries are supported.""\x1b[0m""\n");
   }
  }
 }
 return 0;
}

canonical_original_code:
int main(int agrc, char *argv[]) {
 int sock = 0; int csock = 0; int packet_size = 0;
 struct sockaddr_in clientaddr;
 struct dns_header *header = ((void *)0);
 struct dns_question_section *query_info = ((void *)0);
 char *dns_packet = ((void *)0);
 char *question_domain = ((void *)0);
 char *message = ((void *)0);
 char *fqdn = ((void *)0);
 char *server_ip = ((void *)0);
 memset((void *) &clientaddr,0,sizeof(struct sockaddr_in));
 if((sock = create_socket("mani",2222,SOCK_RAW)) == -1){
  printf("Failed to create UDP socket for DNS server\n");
  return 1;
 }
 int count = 0;
 while(1){
  dns_packet = ((void *)0);
  if((dns_packet = receive(sock,SOCK_RAW,&packet_size,csock,&clientaddr)) == ((void *)0)){
   printf("Failed to receive DNS request from client\n");
   return 1;
  }
  printf("Packet size is %d\n", packet_size);
  if(packet_size <= (int) (sizeof(struct dns_header) + sizeof(struct dns_question_section))){
   printf("Received invalid DNS packet; packet size too small");
   continue;
  }
  if (packet_size <= (int) (sizeof(struct iphdr) + sizeof(struct udphdr) + sizeof(struct dns_header)+ sizeof(struct dns_question_section))) {
   continue;
  }
  dns_packet += sizeof(struct iphdr);
  dns_packet += sizeof(struct udphdr);
  header = (struct dns_header *) dns_packet;
  if(ntohs(header->num_questions) != 1){
   printf("DNS packet contained the wrong number of questions %d\n",ntohs(header->num_questions));
   continue;
  }
  printf("------------ DNS QUERY -----------------");
     printf("\n [%d QUS]",ntohs(header->num_questions));
     printf(" [%d ANW]",ntohs(header->num_answers));
     printf(" [%d AUT]",ntohs(header->num_authority));
     printf(" [%d ADD]\n\n",ntohs(header->num_additional));
  question_domain = get_domain_in_question(dns_packet,packet_size);
  printf("\x1b[1;34m""Domain Name is %s""\x1b[0m""\n", question_domain);
  if(question_domain != ((void *)0) && strlen(question_domain) > 0){
   query_info = (struct dns_question_section *) ((dns_packet) + sizeof(struct dns_header) + strlen(question_domain) + 1);
   if((query_info->class == htons(0x0001)) && ((query_info->type == htons(0x0001)) || (query_info->type == htons(0x0002)))){
     printf("\x1b[33m""DNS CLASS IN , TYPE A | NS""\x1b[0m""\n");
     if(!send_dns_reply(question_domain,sock,&clientaddr,query_info->type,dns_packet,packet_size)){
      printf("Failed to send DNS response packet\n");
     }
   } else {
    printf("\x1b[1;31m""Received unsupported DNS query type or class. Only type A, NS and class IN queries are supported.""\x1b[0m""\n");
   }
  }
 }
 return 0;
}

variable_types: agrc int

variable_types:
argv
char *[]

variable_types: struct dns_question_section { unsigned short type; unsigned short class; } *

variable_types:
message
char *

variable_types: count int

user_defined_types: struct dns_header { unsigned short xid; unsigned short flags; unsigned short num_questions; unsigned short num_answers; unsigned short num_authority; unsigned short num_additional; }

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

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


repo: prajakta-pathak/digit-recognition

decompiled_code:
__int64 __fastcall largest_count(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = 0LL;
v2 = 0;
do
{
if ( *(_DWORD *)(a1 + 4 * v1) > *(_DWORD *)(a1 + 4LL * (int)v2) )
v2 = v1;
++v1;
}
while ( v1 != 10 );
return v2;
}

original_code:
int largest_count(int num[])
{
 int i,res=0;
 for(i=0;i<10;i++)
 {
  if(num[i]>num[res])
  {
   res=i;
  }
 }
 return res;
}

canonical_original_code:
int largest_count(int num[])
{
 int i; int res = 0;
 for(i=0;i<10;i++)
 {
  if(num[i]>num[res])
  {
   res=i;
  }
 }
 return res;
}

variable_types:
num
int []

variable_types: i int

variable_types: res int


digitrec

decompiled_code:
__int64 __fastcall digitrec(const char *a1)
{
unsigned int v1; // er12

v1 = 0;
if ( (unsigned int)ispresent("data/zero.txt", a1, 91) != 1 )
{
v1 = ispresent("data/one.txt", a1, 97);
if ( v1 != 1 )
{
if ( (unsigned int)ispresent("data/two.txt", a1, 94) == 1 )
{
v1 = 2;
}
else if ( (unsigned int)ispresent("data/three.txt", a1, 88) == 1 )
{
v1 = 3;
}
else if ( (unsigned int)ispresent("data/four.txt", a1, 98) == 1 )
{
v1 = 4;
}
else if ( (unsigned int)ispresent("data/five.txt", a1, 92) == 1 )
{
v1 = 5;
}
else if ( (unsigned int)ispresent("data/six.txt", a1, 98) == 1 )
{
v1 = 6;
}
else if ( (unsigned int)ispresent("data/seven.txt", a1, 98) == 1 )
{
v1 = 7;
}
else if ( (unsigned int)ispresent("data/eight.txt", a1, 89) == 1 )
{
v1 = 8;
}
else if ( (unsigned int)ispresent("data/nine.txt", a1, 96) == 1 )
{
v1 = 9;
}
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
unsigned int v1; // er12

v1 = 0;
if ( (unsigned int)func1("data/zero.txt", a1, 91) != 1 )
{
v1 = func1("data/one.txt", a1, 97);
if ( v1 != 1 )
{
if ( (unsigned int)func1("data/two.txt", a1, 94) == 1 )
{
v1 = 2;
}
else if ( (unsigned int)func1("data/three.txt", a1, 88) == 1 )
{
v1 = 3;
}
else if ( (unsigned int)func1("data/four.txt", a1, 98) == 1 )
{
v1 = 4;
}
else if ( (unsigned int)func1("data/five.txt", a1, 92) == 1 )
{
v1 = 5;
}
else if ( (unsigned int)func1("data/six.txt", a1, 98) == 1 )
{
v1 = 6;
}
else if ( (unsigned int)func1("data/seven.txt", a1, 98) == 1 )
{
v1 = 7;
}
else if ( (unsigned int)func1("data/eight.txt", a1, 89) == 1 )
{
v1 = 8;
}
else if ( (unsigned int)func1("data/nine.txt", a1, 96) == 1 )
{
v1 = 9;
}
}
}
return v1;
}

original_code:
int digitrec(char input[])
{
  int n;
  if(ispresent("data/zero.txt",input,91)==1)
  {
   n=0;
  }
  else if(ispresent("data/one.txt",input,97)==1)
  {
   n=1;
  }
  else if(ispresent("data/two.txt",input,94)==1)
  {
   n=2;
  }
  else if(ispresent("data/three.txt",input,88)==1)
  {
   n=3;
  }
  else if(ispresent("data/four.txt",input,98)==1)
  {
   n=4;
  }
  else if(ispresent("data/five.txt",input,92)==1)
  {
   n=5;
  }
  else if(ispresent("data/six.txt",input,98)==1)
  {
   n=6;
  }
  else if(ispresent("data/seven.txt",input,98)==1)
  {
   n=7;
  }
  else if(ispresent("data/eight.txt",input,89)==1)
  {
   n=8;
  }
  else if(ispresent("data/nine.txt",input,96)==1)
  {
   n=9;
  }
  return n;
 }

variable_types:
input
char []

variable_types: n int


predict

decompiled_code:
__int64 __fastcall predict(const char *a1)
{
unsigned int v1; // ebx
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
int v6; // eax
char v8[16]; // [rsp-10h] [rbp-58h] BYREF
__int128 v9[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v10; // [rsp+20h] [rbp-28h]

v1 = 0;
v10 = 0LL;
v9[0] = 0LL;
v9[1] = 0LL;
do
{
while ( 1 )
{
sprintf(v8, "data/%d.txt", v1);
if ( COERCE_FLOAT(distancesq(a1, v8, v2, v3, v4, v5)) < 130.0 )
break;
if ( ++v1 == 750 )
return largest_count((__int64)v9);
}
++v1;
v6 = digitrec(v8);
++*((_DWORD *)v9 + v6);
}
while ( v1 != 750 );
return largest_count((__int64)v9);
}

original_code:
int predict(char name[])
{
 int n=0,res;
 float dist;
 int i;
 int count[10];
 char fname[16];
 for(i=0;i<10;i++)
 count[i]=0;
 for(i=0;i<750;i++)
 {
  sprintf(fname,"data/%d.txt",i);
  dist=distancesq(name,fname);
  if(dist<130)
  {
   n=digitrec(fname);
   count[n]++;
  }
 }
 res=largest_count(count);
 return res;
}

canonical_original_code:
int predict(char name[])
{
 int n = 0; int res;
 float dist;
 int i;
 int count[10];
 char fname[16];
 for(i=0;i<10;i++)
 count[i]=0;
 for(i=0;i<750;i++)
 {
  sprintf(fname,"data/%d.txt",i);
  dist=distancesq(name,fname);
  if(dist<130)
  {
   n=digitrec(fname);
   count[n]++;
  }
 }
 res=largest_count(count);
 return res;
}

variable_types:
name
char []

variable_types: dist float

variable_types:
count
int [10]

variable_types:
fname
char [16]


decompiled_code:
__int64 accuracy_two()
{
unsigned int v0; // er12
unsigned int i; // ebx
int v2; // ebp
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = 0;
for ( i = 0; i != 1500; ++i )
{
sprintf(v4, "data/%d.txt", i);
v2 = predict(v4);
v0 += v2 == digitrec(v4);
printf("%d\n", v0);
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // er12
unsigned int i; // ebx
int v2; // ebp
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = 0;
for ( i = 0; i != 1500; ++i )
{
sprintf(v4, "data/%d.txt", i);
v2 = func3(v4);
v0 += v2 == func2(v4);
printf("%d\n", v0);
}
return v0;
}

original_code:
int accuracy_two()
{
 int count=0,i;
 float acc;
 int n1,n2;
 char fname[16];
 for(i=0;i<1500;i++)
  {
   sprintf(fname,"data/%d.txt",i);
   n1=predict(fname);
   n2=digitrec(fname);
   if(n1==n2)
   count++;
   printf("%d\n",count);
  }
 return count;
}

canonical_original_code:
int accuracy_two()
{
 int count = 0; int i;
 float acc;
 int n1; int n2;
 char fname[16];
 for(i=0;i<1500;i++)
  {
   sprintf(fname,"data/%d.txt",i);
   n1=predict(fname);
   n2=digitrec(fname);
   if(n1==n2)
   count++;
   printf("%d\n",count);
  }
 return count;
}

variable_types: acc float


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rbp
int v4; // er12
int v5; // er12
unsigned int i; // ebx
const char *v7; // r13
unsigned int v8; // eax
const char *v10; // rbp
unsigned int j; // ebx
const char *v12; // r13
unsigned int v13; // eax
unsigned int v14; // eax
unsigned int v15; // eax
char v16[56]; // [rsp+0h] [rbp-38h] BYREF

if ( argc != 2 )
{
if ( argc != 3 )
{
printf("check the number of arguments");
return 0;
}
v3 = argv[1];
v4 = strcmp(v3, "m1");
if ( v4 )
{
v5 = strcmp(v3, "m2");
if ( v5 )
{
puts("Check the name of method you wrote!!! ");
return 0;
}
printf("%s", argv[2]);
if ( !strcmp(argv[2], "acc") )
{
v15 = accuracy_two();
printf("accuracy for this method is %d/1500 \n", v15);
return 0;
}
for ( i = 0; i != 1499; ++i )
{
sprintf(v16, "data/%d.txt", i);
v7 = argv[2];
v5 += strcmp(v16, v7) == 0;
}
if ( v5 )
{
v8 = predict(v7);
printf("the predicted value by this method is %d \n", v8);
return 0;
}
}
else
{
if ( !strcmp(argv[2], "acc") )
{
v14 = accuracy_one();
printf("accuracy for this method is %d/1500 \n", v14);
return 0;
}
for ( j = 0; j != 1499; ++j )
{
sprintf(v16, "data/%d.txt", j);
v12 = argv[2];
v4 += strcmp(v16, v12) == 0;
}
if ( v4 )
{
v13 = prediction(v12);
printf("the predicted value by this method is %d \n", v13);
return 0;
}
}
puts("Such file does not exist ");
return 0;
}
v10 = argv[1];
if ( !strcmp(v10, "create_tr_data") )
{
create_training_data();
}
else if ( !strcmp(v10, "break_digitwise") )
{
data_set_divide();
}
else if ( !strcmp(v10, "break_samplewise") )
{
training_data_divide();
}
else if ( !strcmp(v10, "ave_construct") )
{
ave_construct();
}
else
{
printf("Read the instructions and write again :(");
}
return 0;
}

original_code:
int main(int argc,char *argv[])
{
 int n1=0,n2=0;
 int a1=0,a2=0;
 int i,chk=0;
 char fname[16];
 if(argc==2)
 {
  if(strcmp(argv[1],"create_tr_data")==0)
  create_training_data();
  else if(strcmp(argv[1],"break_digitwise")==0)
  data_set_divide();
  else if(strcmp(argv[1],"break_samplewise")==0)
  training_data_divide();
  else if(strcmp(argv[1],"ave_construct")==0)
  ave_construct();
  else
  printf("Read the instructions and write again :(");
 }
 else if(argc==3)
 {
  if(strcmp(argv[1],"m1")==0)
  {
   if(strcmp(argv[2],"acc")==0)
   {
    n1=accuracy_one();
    printf("accuracy for this method is %d/1500 \n",n1);
   }
   else
   {
    for(i=0;i<1499;i++)
    {
     sprintf(fname,"data/%d.txt",i);
     if(strcmp(fname,argv[2])==0)
     chk++;
    }
    if(chk!=0)
    {
    n1=prediction(argv[2]);
    printf("the predicted value by this method is %d \n",n1);
    }
    else
    printf("Such file does not exist \n");
   }
  }
  else if(strcmp(argv[1],"m2")==0)
  {
   printf("%s",argv[2]);
   if(strcmp(argv[2],"acc")==0)
   {
    a2=accuracy_two();
    printf("accuracy for this method is %d/1500  \n",a2);
   }
   else
   {
    for(i=0;i<1499;i++)
    {
     sprintf(fname,"data/%d.txt",i);
     if(strcmp(fname,argv[2])==0)
     chk++;
    }
    if(chk!=0)
    {
    n2=predict(argv[2]);
    printf("the predicted value by this method is %d \n",n2);
    }
    else
    printf("Such file does not exist \n");
   }
  }
  else
  {
   printf("Check the name of method you wrote!!! \n");
  }
 }
 else
 {
  printf("check the number of arguments");
 }
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int n1 = 0; int n2 = 0;
 int a1 = 0; int a2 = 0;
 int i; int chk = 0;
 char fname[16];
 if(argc==2)
 {
  if(strcmp(argv[1],"create_tr_data")==0)
  create_training_data();
  else if(strcmp(argv[1],"break_digitwise")==0)
  data_set_divide();
  else if(strcmp(argv[1],"break_samplewise")==0)
  training_data_divide();
  else if(strcmp(argv[1],"ave_construct")==0)
  ave_construct();
  else
  printf("Read the instructions and write again :(");
 }
 else if(argc==3)
 {
  if(strcmp(argv[1],"m1")==0)
  {
   if(strcmp(argv[2],"acc")==0)
   {
    n1=accuracy_one();
    printf("accuracy for this method is %d/1500 \n",n1);
   }
   else
   {
    for(i=0;i<1499;i++)
    {
     sprintf(fname,"data/%d.txt",i);
     if(strcmp(fname,argv[2])==0)
     chk++;
    }
    if(chk!=0)
    {
    n1=prediction(argv[2]);
    printf("the predicted value by this method is %d \n",n1);
    }
    else
    printf("Such file does not exist \n");
   }
  }
  else if(strcmp(argv[1],"m2")==0)
  {
   printf("%s",argv[2]);
   if(strcmp(argv[2],"acc")==0)
   {
    a2=accuracy_two();
    printf("accuracy for this method is %d/1500  \n",a2);
   }
   else
   {
    for(i=0;i<1499;i++)
    {
     sprintf(fname,"data/%d.txt",i);
     if(strcmp(fname,argv[2])==0)
     chk++;
    }
    if(chk!=0)
    {
    n2=predict(argv[2]);
    printf("the predicted value by this method is %d \n",n2);
    }
    else
    printf("Such file does not exist \n");
   }
  }
  else
  {
   printf("Check the name of method you wrote!!! \n");
  }
 }
 else
 {
  printf("check the number of arguments");
 }
}

variable_types: argc int

variable_types: chk int


smallest

decompiled_code:
__int64 __fastcall smallest(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // er8

v1 = 0LL;
v2 = 0;
do
{
if ( *(float *)(a1 + 4LL * (int)v2) > *(float *)(a1 + 4 * v1) )
v2 = v1;
++v1;
}
while ( v1 != 10 );
return v2;
}

original_code:
int smallest(float num[])
{
 int i,res=0;
 for(i=0;i<10;i++)
 {
  if(num[i]<num[res])
  {
   res=i;
  }
 }
 return res;
}

canonical_original_code:
int smallest(float num[])
{
 int i; int res = 0;
 for(i=0;i<10;i++)
 {
  if(num[i]<num[res])
  {
   res=i;
  }
 }
 return res;
}

variable_types:
num
float []


prediction

original_code:
int prediction(char name[])
{
 int n,i;
 float dist[10];
 dist[0]=distancesq1(name,"data/ave0.txt");
 dist[1]=distancesq1(name,"data/ave1.txt");
 dist[2]=distancesq1(name,"data/ave2.txt");
 dist[3]=distancesq1(name,"data/ave3.txt");
 dist[4]=distancesq1(name,"data/ave4.txt");
 dist[5]=distancesq1(name,"data/ave5.txt");
 dist[6]=distancesq1(name,"data/ave6.txt");
 dist[7]=distancesq1(name,"data/ave7.txt");
 dist[8]=distancesq1(name,"data/ave8.txt");
 dist[9]=distancesq1(name,"data/ave9.txt");
 n=smallest(dist);
 return n;
}

canonical_original_code:
int prediction(char name[])
{
 int n; int i;
 float dist[10];
 dist[0]=distancesq1(name,"data/ave0.txt");
 dist[1]=distancesq1(name,"data/ave1.txt");
 dist[2]=distancesq1(name,"data/ave2.txt");
 dist[3]=distancesq1(name,"data/ave3.txt");
 dist[4]=distancesq1(name,"data/ave4.txt");
 dist[5]=distancesq1(name,"data/ave5.txt");
 dist[6]=distancesq1(name,"data/ave6.txt");
 dist[7]=distancesq1(name,"data/ave7.txt");
 dist[8]=distancesq1(name,"data/ave8.txt");
 dist[9]=distancesq1(name,"data/ave9.txt");
 n=smallest(dist);
 return n;
}

variable_types:
dist
float [10]


decompiled_code:
__int64 accuracy_one()
{
unsigned int v0; // er12
unsigned int i; // ebx
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
int v6; // ebp
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = 0;
for ( i = 0; i != 1500; ++i )
{
sprintf(v8, "data/%d.txt", i);
v6 = prediction(v8, (__int64)"data/%d.txt", v2, v3, v4, v5);
v0 += v6 == digitrec(v8);
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // er12
unsigned int i; // ebx
__int64 v2; // rdx
__int64 v3; // rcx
__int64 v4; // r8
__int64 v5; // r9
int v6; // ebp
char v8[40]; // [rsp+0h] [rbp-28h] BYREF

v0 = 0;
for ( i = 0; i != 1500; ++i )
{
sprintf(v8, "data/%d.txt", i);
v6 = func1(v8, (__int64)"data/%d.txt", v2, v3, v4, v5);
v0 += v6 == digitrec(v8);
}
return v0;
}

original_code:
int accuracy_one()
{
 int count=0,i;
 float acc;
 int n1,n2;
 char fname[16];
 for(i=0;i<1500;i++)
  {
   sprintf(fname,"data/%d.txt",i);
   n1=prediction(fname);
   n2=digitrec(fname);
   if(n1==n2)
   count++;
  }
 return count;
}

canonical_original_code:
int accuracy_one()
{
 int count = 0; int i;
 float acc;
 int n1; int n2;
 char fname[16];
 for(i=0;i<1500;i++)
  {
   sprintf(fname,"data/%d.txt",i);
   n1=prediction(fname);
   n2=digitrec(fname);
   if(n1==n2)
   count++;
  }
 return count;
}


fail

repo: prasad-joshi/logfsprogs

decompiled_code:
void __fastcall __noreturn fail(const char *a1)
{
printf("mklogfs: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func2(const char *a1)
{
printf("mklogfs: %s\n", a1);
exit(1);
}

original_code:
void fail(const char *s)
{
 printf("mklogfs: %s\n", s);
 exit(1);
}

canonical_original_code:
void fail(char *s)
{
 printf("mklogfs: %s\n", s);
 exit(1);
}

variable_types:
s
char *


decompiled_code:
__int64 check_crc32()
{
__int64 result; // rax
int v1; // edx
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
logfs_crc32_constprop_0((__int64)v2);
result = _bswap_32(0xDEBB20E3);
if ( v1 != (_DWORD)result )
fail("crc32 returns bad results");
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 result; // rax
int v1; // edx
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2[0] = 0;
func1((__int64)v2);
result = func0(0xDEBB20E3);
if ( v1 != (_DWORD)result )
func2("crc32 returns bad results");
return result;
}

original_code:
void check_crc32(void)
{
 u32 c=0;
 if (logfs_crc32(&c, 4, 0) != (( __be32)(u32)(__bswap_32 (0xdebb20e3))))
  fail("crc32 returns bad results");
}

canonical_original_code:
void check_crc32()
{
 unsigned int c = 0;
 if (logfs_crc32(&c, 4, 0) != (( __be32)(u32)(__bswap_32 (0xdebb20e3))))
  fail("crc32 returns bad results");
}

variable_types:
c
unsigned int


maxbix

decompiled_code:
__int64 __fastcall maxbix(char a1)
{
return 1LL << (9 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(char a1)
{
return 1LL << (9 * a1);
}

original_code:
static inline u64 maxbix(u8 height)
{
 return 1ULL << ((9) * height);
}

canonical_original_code:
static inline unsigned long long maxbix(unsigned char height)
{
 return 1ULL << ((9) * height);
}

variable_types:
height
unsigned char

return_type: unsigned long long


decompiled_code:
void __fastcall grow_inode(__int64 a1, unsigned __int64 a2, char a3)
{
char i; // dl
__int64 v4; // r8

if ( !a3 )
{
for ( i = *(_BYTE *)(a1 + 98); maxbix(i) < a2; *(_BYTE *)(v4 + 98) = i )
;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, unsigned __int64 a2, char a3)
{
char i; // dl
__int64 v4; // r8

if ( !a3 )
{
for ( i = *(_BYTE *)(a1 + 98); func2(i) < a2; *(_BYTE *)(v4 + 98) = i )
;
}
}

original_code:
static void grow_inode(struct inode *inode, u64 bix, u8 level)
{
 if (level != 0)
  return;
 while (bix > maxbix(inode->di.di_height))
  inode->di.di_height++;
}

canonical_original_code:
static void grow_inode(struct inode *inode, unsigned long long bix, unsigned char level)
{
 if (level != 0)
  return;
 while (bix > maxbix(inode->di.di_height))
  inode->di.di_height++;
}

variable_types: struct inode { struct btree_head64 { struct btree_head { unsigned long *node; int height; } h; } block_tree[-1]; struct logfs_disk_inode { unsigned short di_mode; unsigned char di_height; unsigned char di_pad; unsigned int di_flags; unsigned int di_uid; unsigned int di_gid; unsigned long long di_ctime; unsigned long long di_mtime; unsigned long long di_atime; unsigned int di_refcount; unsigned int di_generation; unsigned long long di_used_bytes; unsigned long long di_size; unsigned long long di_data[-1]; } di; } *

variable_types:
bix
unsigned long long

variable_types:
level
unsigned char

user_defined_types: struct inode { struct btree_head64 block_tree[-1]; struct logfs_disk_inode di; }

user_defined_types: struct btree_head64 { struct btree_head h; }


decompiled_code:
__int64 __fastcall btree_lookup64(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return btree_lookup(a1, &btree_geo64, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return btree_lookup(a1, &btree_geo64, &v3);
}

original_code:
static inline void *btree_lookup64(struct btree_head64 *head, u64 key)
{
 return btree_lookup(&head->h, &btree_geo64, (unsigned long *)&key);
}

canonical_original_code:
static inline void *btree_lookup64(struct btree_head64 *head, unsigned long long key)
{
 return btree_lookup(&head->h, &btree_geo64, (unsigned long *)&key);
}

variable_types: struct btree_head64 { struct btree_head { unsigned long *node; int height; } h; } *

variable_types:
key
unsigned long long

return_type: void *


zalloc

decompiled_code:
void *__fastcall zalloc(size_t a1)
{
return calloc(a1, 1uLL);
}

canonical_decompiled_code:
void *__fastcall func5(size_t a1)
{
return calloc(a1, 1uLL);
}

original_code:
static inline void *zalloc(size_t bytes)
{
 void *p = malloc(bytes);
 memset(p, 0, bytes);
 return p;
}

canonical_original_code:
static inline void *zalloc(unsigned long bytes)
{
 void *p = malloc(bytes);
 memset(p, 0, bytes);
 return p;
}

variable_types:
bytes
unsigned long

variable_types:
p
void *


decompiled_code:
__int64 __fastcall btree_insert64(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a2;
return btree_insert(a1, &btree_geo64, &v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a2;
return btree_insert(a1, &btree_geo64, &v4, a3);
}

original_code:
static inline int btree_insert64(struct btree_head64 *head, u64 key,
  void *val)
{
 return btree_insert(&head->h, &btree_geo64, (unsigned long *)&key, val);
}

canonical_original_code:
static inline int btree_insert64(struct btree_head64 *head, unsigned long long key, void *val)
{
 return btree_insert(&head->h, &btree_geo64, (unsigned long *)&key, val);
}

variable_types:
val
void *

user_defined_types: struct btree_head { unsigned long *node; int height; }


decompiled_code:
__int64 __fastcall btree_last64(__int64 a1)
{
__int64 *v1; // rax
__int64 v2; // r8

v1 = (__int64 *)btree_last(a1, &btree_geo64);
v2 = 0LL;
if ( v1 )
v2 = *v1;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
__int64 *v1; // rax
__int64 v2; // r8

v1 = (__int64 *)btree_last(a1, &btree_geo64);
v2 = 0LL;
if ( v1 )
v2 = *v1;
return v2;
}

original_code:
static inline u64 btree_last64(struct btree_head64 *head)
{
 u64 *key;
 key = (u64 *)btree_last(&head->h, &btree_geo64);
 if (key)
  return *key;
 else
  return 0;
}

canonical_original_code:
static inline unsigned long long btree_last64(struct btree_head64 *head)
{
 unsigned long long *key;
 key = (unsigned long long *)btree_last(&head->h, &btree_geo64);
 if (key)
  return *key;
 else
  return 0;
}

variable_types:
key
unsigned long long *


decompiled_code:
__int64 __fastcall btree_remove64(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return btree_remove(a1, &btree_geo64, &v3);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v3; // [rsp+8h] [rbp-10h] BYREF

v3 = a2;
return btree_remove(a1, &btree_geo64, &v3);
}

original_code:
static inline void *btree_remove64(struct btree_head64 *head, u64 key)
{
 return btree_remove(&head->h, &btree_geo64, (unsigned long *)&key);
}

canonical_original_code:
static inline void *btree_remove64(struct btree_head64 *head, unsigned long long key)
{
 return btree_remove(&head->h, &btree_geo64, (unsigned long *)&key);
}


decompiled_code:
__int64 __fastcall logfs_crc32(__int64 a1, int a2, __int64 a3)
{
int v3; // eax

v3 = crc32(0LL, a1 + a3, (unsigned int)(a2 - a3));
return _bswap_32(~v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, int a2, __int64 a3)
{
int v3; // eax

v3 = crc32(0LL, a1 + a3, (unsigned int)(a2 - a3));
return func0(~v3);
}

original_code:
static inline __be32 logfs_crc32(void *data, size_t len, size_t skip)
{
 return (( __be32)(u32)(__bswap_32 (~crc32(0, data+skip, len-skip))));
}

canonical_original_code:
static inline unsigned int logfs_crc32(void *data, unsigned long len, unsigned long skip)
{
 return (( __be32)(u32)(__bswap_32 (~crc32(0, data+skip, len-skip))));
}

variable_types:
data
void *

variable_types:
len
unsigned long

variable_types:
skip
unsigned long

return_type: unsigned int


copybuf

decompiled_code:
void *__fastcall copybuf(__int64 a1, const void *a2, size_t a3)
{
int v3; // ebp
void *result; // rax

v3 = a3;
result = memcpy((void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 4)), a2, a3);
*(_DWORD *)(a1 + 4) += v3;
return result;
}

canonical_decompiled_code:
void *__fastcall func5(__int64 a1, const void *a2, size_t a3)
{
int v3; // ebp
void *result; // rax

v3 = a3;
result = memcpy((void *)(*(_QWORD *)(a1 + 8) + *(unsigned int *)(a1 + 4)), a2, a3);
*(_DWORD *)(a1 + 4) += v3;
return result;
}

original_code:
static void copybuf(struct logfs_area *area, void *buf, size_t len)
{
 memcpy(area->buf + area->used_bytes, buf, len);
 area->used_bytes += len;
}

canonical_original_code:
static void copybuf(struct logfs_area *area, void *buf, unsigned long len)
{
 memcpy(area->buf + area->used_bytes, buf, len);
 area->used_bytes += len;
}

variable_types: struct logfs_area { unsigned int segno; unsigned int used_bytes; void *buf; } *

variable_types:
buf
void *


decompiled_code:
__int64 __fastcall grow_inode(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rax
unsigned __int64 v6; // rax
__int64 v7; // rdx
__int64 result; // rax

v4 = find_or_create_inode();
if ( !v4 )
return 4294967284LL;
v5 = _bswap_64(*(_QWORD *)(v4 + 144));
v6 = _bswap_64(v5 + a3);
*(_QWORD *)(v7 + 144) = v6;
result = 0LL;
*(_QWORD *)(a1 + 104) += a3;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
__int64 v4; // rax
unsigned __int64 v5; // rax
unsigned __int64 v6; // rax
__int64 v7; // rdx
__int64 result; // rax

v4 = find_or_create_inode();
if ( !v4 )
return 4294967284LL;
v5 = func3(*(_QWORD *)(v4 + 144));
v6 = func3(v5 + a3);
*(_QWORD *)(v7 + 144) = v6;
result = 0LL;
*(_QWORD *)(a1 + 104) += a3;
return result;
}

user_defined_types: struct logfs_disk_inode { unsigned short di_mode; unsigned char di_height; unsigned char di_pad; unsigned int di_flags; unsigned int di_uid; unsigned int di_gid; unsigned long long di_ctime; unsigned long long di_mtime; unsigned long long di_atime; unsigned int di_refcount; unsigned int di_generation; unsigned long long di_used_bytes; unsigned long long di_size; unsigned long long di_data[-1]; }


usage

repo: prasad-joshi/skiena

decompiled_code:
int __fastcall usage(const char *a1)
{
return fprintf(stderr, "\nUsage:\n\t %s <#rows> <#cols>\n", a1);
}

canonical_decompiled_code:
int __fastcall func7(const char *a1)
{
return fprintf(stderr, "\nUsage:\n\t %s <#rows> <#cols>\n", a1);
}

original_code:
void usage(char *s)
{
 fprintf(stderr, "\nUsage:\n\t %s <#rows> <#cols>\n", s);
}

variable_types:
s
char *


decompiled_code:
void __fastcall free_board(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_board(unsigned long **board, int nrows, int ncols)
{
 free(board[0]);
 free(board);
}

variable_types:
board
unsigned long **

variable_types: nrows int

variable_types: ncols int


decompiled_code:
int __fastcall print_board_ulong(_QWORD *a1)
{
int v2; // er12
__int64 i; // rbx
__int64 v4; // rsi

puts("START");
if ( nrows > 0 )
{
v2 = 0;
do
{
for ( i = 0LL; ncols > (int)i; ++i )
{
v4 = *(_QWORD *)(*a1 + 8 * i);
printf(" %lu ", v4);
}
++v2;
++a1;
putchar(10);
}
while ( nrows > v2 );
}
return puts("END");
}

canonical_decompiled_code:
int __fastcall func9(_QWORD *a1)
{
int v2; // er12
__int64 i; // rbx
__int64 v4; // rsi

puts("START");
if ( nrows > 0 )
{
v2 = 0;
do
{
for ( i = 0LL; ncols > (int)i; ++i )
{
v4 = *(_QWORD *)(*a1 + 8 * i);
printf(" %lu ", v4);
}
++v2;
++a1;
putchar(10);
}
while ( nrows > v2 );
}
return puts("END");
}

original_code:
void print_board_ulong(unsigned long **b)
{
 int i;
 int j;
 printf("START\n");
 for (i = 0; i < nrows; i++) {
  for (j = 0; j < ncols; j++) {
   printf(" %lu ", b[i][j]);
  }
  printf("\n");
 }
 printf("END\n");
}

variable_types:
b
unsigned long **

variable_types: i int

variable_types: j int


decompiled_code:
int __fastcall print_board(_QWORD *a1)
{
int v2; // ebx
int v3; // er13
__int64 v4; // rbx
int v5; // eax
__int64 v6; // rsi
int v7; // ebx

v2 = 0;
if ( ncols >= -1 )
{
do
{
++v2;
putchar(61);
}
while ( 3 * ncols + 3 >= v2 );
}
putchar(10);
if ( nrows > 0 )
{
v3 = 0;
while ( 1 )
{
v4 = 0LL;
if ( ncols > 0 )
break;
LABEL_14:
++v3;
++a1;
putchar(10);
if ( nrows <= v3 )
goto LABEL_15;
}
while ( 1 )
{
if ( !v4 )
printf("| ");
v6 = *(_QWORD *)(*a1 + 8 * v4);
if ( v6 )
{
printf(" %c ", v6);
v5 = ncols;
if ( ncols - 1 != (_DWORD)v4 )
goto LABEL_8;
LABEL_13:
++v4;
printf(" |");
if ( ncols <= (int)v4 )
goto LABEL_14;
}
else
{
printf(" %lu ", 0LL);
v5 = ncols;
if ( ncols - 1 == (_DWORD)v4 )
goto LABEL_13;
LABEL_8:
if ( v5 <= (int)++v4 )
goto LABEL_14;
}
}
}
LABEL_15:
v7 = 0;
if ( ncols >= -1 )
{
do
{
++v7;
putchar(61);
}
while ( 3 * ncols + 3 >= v7 );
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func10(_QWORD *a1)
{
int v2; // ebx
int v3; // er13
__int64 v4; // rbx
int v5; // eax
__int64 v6; // rsi
int v7; // ebx

v2 = 0;
if ( ncols >= -1 )
{
do
{
++v2;
putchar(61);
}
while ( 3 * ncols + 3 >= v2 );
}
putchar(10);
if ( nrows > 0 )
{
v3 = 0;
while ( 1 )
{
v4 = 0LL;
if ( ncols > 0 )
break;
LABEL_14:
++v3;
++a1;
putchar(10);
if ( nrows <= v3 )
goto LABEL_15;
}
while ( 1 )
{
if ( !v4 )
printf("| ");
v6 = *(_QWORD *)(*a1 + 8 * v4);
if ( v6 )
{
printf(" %c ", v6);
v5 = ncols;
if ( ncols - 1 != (_DWORD)v4 )
goto LABEL_8;
LABEL_13:
++v4;
printf(" |");
if ( ncols <= (int)v4 )
goto LABEL_14;
}
else
{
printf(" %lu ", 0LL);
v5 = ncols;
if ( ncols - 1 == (_DWORD)v4 )
goto LABEL_13;
LABEL_8:
if ( v5 <= (int)++v4 )
goto LABEL_14;
}
}
}
LABEL_15:
v7 = 0;
if ( ncols >= -1 )
{
do
{
++v7;
putchar(61);
}
while ( 3 * ncols + 3 >= v7 );
}
return putchar(10);
}

original_code:
void print_board(unsigned long **board)
{
 int i;
 int j;
 for (i = 0; i < ncols * 3 + 4; i++) {
  printf("=");
 }
 printf("\n");
 for (i = 0; i < nrows; i++) {
  for (j = 0; j < ncols; j++) {
   if (j == 0) {
    printf("| ");
   }
   if (board[i][j] != 0) {
    printf(" %c ", (int) board[i][j]);
   } else {
    printf(" %lu ", board[i][j]);
   }
   if (j == ncols - 1) {
    printf(" |");
   }
  }
  printf("\n");
 }
 for (i = 0; i < ncols * 3 + 4; i++) {
  printf("=");
 }
 printf("\n");
}


decompiled_code:
__int64 __fastcall next_direction(int a1)
{
__int64 result; // rax

result = (unsigned int)(a1 + 1);
if ( a1 == 9 )
result = 9LL;
return result;
}

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

result = (unsigned int)(a1 + 1);
if ( a1 == 9 )
result = 9LL;
return result;
}

original_code:
DIRECTION next_direction(DIRECTION d)
{
 return ((d == INVAL) ? INVAL : ++d);
}

canonical_original_code:
enum DIRECTION next_direction(enum DIRECTION d)
{
 return ((d == INVAL) ? INVAL : ++d);
}

variable_types: enum DIRECTION { START=0, ULD=1, ULU=2, URU=3, URD=4, DLU=5, DLD=6, DRD=7, DRU=8, INVAL=9 }


decompiled_code:
__int64 __fastcall traverse_done(_QWORD **a1)
{
__int64 v1; // r8
_QWORD *v2; // rax

if ( nrows <= 0 )
return 1LL;
v1 = (__int64)&a1[(unsigned int)(nrows - 1) + 1];
while ( ncols <= 0 )
{
LABEL_8:
if ( ++a1 == (_QWORD **)v1 )
return 1LL;
}
v2 = *a1;
while ( *v2 )
{
if ( ++v2 == &(*a1)[(unsigned int)(ncols - 1) + 1] )
goto LABEL_8;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD **a1)
{
__int64 v1; // r8
_QWORD *v2; // rax

if ( nrows <= 0 )
return 1LL;
v1 = (__int64)&a1[(unsigned int)(nrows - 1) + 1];
while ( ncols <= 0 )
{
LABEL_8:
if ( ++a1 == (_QWORD **)v1 )
return 1LL;
}
v2 = *a1;
while ( *v2 )
{
if ( ++v2 == &(*a1)[(unsigned int)(ncols - 1) + 1] )
goto LABEL_8;
}
return 0LL;
}

original_code:
int traverse_done(unsigned long **board)
{
 int i;
 int j;
 for (i = 0; i < nrows; i++) {
  for (j = 0; j < ncols; j++) {
   if (board[i][j] == 0) {
    return (0);
   }
  }
 }
 return (1);
}


decompiled_code:
__int64 __fastcall set_board_position(__int64 a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8LL * a2);
*(_QWORD *)(result + 8LL * a3) = (a5 << 8) | (a4 << 16) | 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, int a2, int a3, int a4, int a5)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8LL * a2);
*(_QWORD *)(result + 8LL * a3) = (a5 << 8) | (a4 << 16) | 1;
return result;
}

original_code:
void set_board_position(unsigned long **board, int row, int col, int nr, int nc)
{
 board[row][col] = (nr << 16 | nc << 8 | 1);
}

variable_types: row int

variable_types: col int

variable_types: nr int

variable_types: nc int


decompiled_code:
__int64 __fastcall traverse_board(_QWORD **a1, int a2, int a3, int a4)
{
_QWORD *v4; // r15
__int64 v6; // r14
__int64 result; // rax
_QWORD *v9; // r9
int v10; // [rsp+8h] [rbp-40h] BYREF
int v11[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v4 = &a1[a2];
v6 = 8LL * a3;
*(_QWORD *)(v6 + *v4) = 1LL;
result = traverse_done(a1);
if ( (_DWORD)result == 1 )
{
++count;
}
else
{
*v9 = 0LL;
while ( 1 )
{
a4 = next_direction(a4);
if ( a4 == 9 )
break;
while ( 1 )
{
v10 = a2;
v11[0] = a3;
next_index(a4, &v10, v11);
if ( v10 < 0 || v10 >= nrows || v11[0] < 0 || v11[0] >= ncols || a1[v10][v11[0]] )
break;
set_board_position((__int64)a1, a2, a3, v10, v11[0]);
result = traverse_board(a1, (unsigned int)v10, (unsigned int)v11[0], 0LL);
if ( (_DWORD)result == 1 )
return result;
*(_QWORD *)(*v4 + v6) = 0LL;
a4 = next_direction(a4);
if ( a4 == 9 )
goto LABEL_11;
}
}
LABEL_11:
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(_QWORD **a1, int a2, int a3, int a4)
{
_QWORD *v4; // r15
__int64 v6; // r14
__int64 result; // rax
_QWORD *v9; // r9
int v10; // [rsp+8h] [rbp-40h] BYREF
int v11[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v4 = &a1[a2];
v6 = 8LL * a3;
*(_QWORD *)(v6 + *v4) = 1LL;
result = func13(a1);
if ( (_DWORD)result == 1 )
{
++count;
}
else
{
*v9 = 0LL;
while ( 1 )
{
a4 = func11(a4);
if ( a4 == 9 )
break;
while ( 1 )
{
v10 = a2;
v11[0] = a3;
func12(a4, &v10, v11);
if ( v10 < 0 || v10 >= nrows || v11[0] < 0 || v11[0] >= ncols || a1[v10][v11[0]] )
break;
func14((__int64)a1, a2, a3, v10, v11[0]);
result = func16(a1, (unsigned int)v10, (unsigned int)v11[0], 0LL);
if ( (_DWORD)result == 1 )
return result;
*(_QWORD *)(*v4 + v6) = 0LL;
a4 = func11(a4);
if ( a4 == 9 )
goto LABEL_11;
}
}
LABEL_11:
result = 0LL;
}
return result;
}

original_code:
int traverse_board(unsigned long **board, int row, int col, DIRECTION dir)
{
 int r;
 int c;
 board[row][col] = 1;
 if (traverse_done(board) == 1) {
  count++;
  return (1);
 }
 board[row][col] = 0;
 while ((dir = next_direction(dir)) != INVAL) {
  r = row;
  c = col;
  next_index(dir, &r, &c);
  if ((((r) >= 0 && (r) < (nrows) && (c) >= 0 && (c) < (ncols)) ? 1 : 0) == 0) {
   continue;
  }
  if (board[r][c] != 0) {
   continue;
  }
  set_board_position(board, row, col, r, c);
  if (traverse_board(board, r, c, START) == 1) {
   return (1);
  }
  board[row][col] = 0;
 }
 return (0);
}

canonical_original_code:
int traverse_board(unsigned long **board, int row, int col, enum DIRECTION dir)
{
 int r;
 int c;
 board[row][col] = 1;
 if (traverse_done(board) == 1) {
  count++;
  return (1);
 }
 board[row][col] = 0;
 while ((dir = next_direction(dir)) != INVAL) {
  r = row;
  c = col;
  next_index(dir, &r, &c);
  if ((((r) >= 0 && (r) < (nrows) && (c) >= 0 && (c) < (ncols)) ? 1 : 0) == 0) {
   continue;
  }
  if (board[r][c] != 0) {
   continue;
  }
  set_board_position(board, row, col, r, c);
  if (traverse_board(board, r, c, START) == 1) {
   return (1);
  }
  board[row][col] = 0;
 }
 return (0);
}

variable_types: r int

variable_types: c int

user_defined_types: enum DIRECTION { START=0, ULD=1, ULU=2, URU=3, URD=4, DLU=5, DLD=6, DRD=7, DRU=8, INVAL=9 }


decompiled_code:
void __fastcall knight_tour(__int64 a1, int a2, int a3)
{
int v3; // er12
_QWORD *v4; // rax
_QWORD *v5; // rbp
int v6; // edx
int v7; // ebx
int v9; // [rsp+18h] [rbp-30h] BYREF
int v10[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v3 = a2;
v4 = allocate_board(nrows, ncols);
if ( !v4 )
__assert_fail("b != NULL", "knight_tour.c", 0xEFu, "knight_tour");
v5 = v4;
*(_QWORD *)(v4[a2] + 8LL * a3) = 75LL;
print_board(v4);
if ( ncols * nrows > 1 )
{
v6 = a3;
v7 = 1;
do
{
get_board_position(a1, v3, v6, &v9, v10);
++v7;
*(_QWORD *)(v5[v9] + 8LL * v10[0]) = 75LL;
print_board(v5);
v3 = v9;
v6 = v10[0];
}
while ( ncols * nrows > v7 );
}
free_board(v5);
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, int a2, int a3)
{
int v3; // er12
_QWORD *v4; // rax
_QWORD *v5; // rbp
int v6; // edx
int v7; // ebx
int v9; // [rsp+18h] [rbp-30h] BYREF
int v10[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v3 = a2;
v4 = allocate_board(nrows, ncols);
if ( !v4 )
__assert_fail("b != NULL", "knight_tour.c", 0xEFu, "knight_tour");
v5 = v4;
*(_QWORD *)(v4[a2] + 8LL * a3) = 75LL;
func10(v4);
if ( ncols * nrows > 1 )
{
v6 = a3;
v7 = 1;
do
{
func15(a1, v3, v6, &v9, v10);
++v7;
*(_QWORD *)(v5[v9] + 8LL * v10[0]) = 75LL;
func10(v5);
v3 = v9;
v6 = v10[0];
}
while ( ncols * nrows > v7 );
}
func8(v5);
}

original_code:
void knight_tour(unsigned long **board, int r, int c)
{
 unsigned long **b;
 int n;
 int nr;
 int nc;
 b = allocate_board(nrows, ncols);
 ((void) sizeof ((b != ((void *)0)) ? 1 : 0), __extension__ ({ if (b != ((void *)0)) ; else __assert_fail ("b != NULL", "knight_tour.c", 239, __extension__ __PRETTY_FUNCTION__); }));
 b[r][c] = 'K';
 print_board(b);
 for (n = 1; n < nrows * ncols; n++) {
  get_board_position(board, r, c, &nr, &nc);
  b[nr][nc] = 'K';
  print_board(b);
  r = nr;
  c = nc;
 }
 free_board(b, nrows, ncols);
}

variable_types: n int


decompiled_code:
_BOOL8 __fastcall sll_is_empty(_QWORD *a1)
{
if ( !a1 )
__assert_fail("headp", "sll.c", 0xEu, "sll_is_empty");
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(_QWORD *a1)
{
if ( !a1 )
__assert_fail("headp", "sll.c", 0xEu, "sll_is_empty");
return *a1 == 0LL;
}

original_code:
int sll_is_empty(sll_t *headp)
{
 ((void) sizeof ((headp) ? 1 : 0), __extension__ ({ if (headp) ; else __assert_fail ("headp", "sll.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 return headp->next == ((void *)0);
}

canonical_original_code:
int sll_is_empty(struct sll *headp)
{
 ((void) sizeof ((headp) ? 1 : 0), __extension__ ({ if (headp) ; else __assert_fail ("headp", "sll.c", 14, __extension__ __PRETTY_FUNCTION__); }));
 return headp->next == ((void *)0);
}

variable_types:
headp
struct sll { struct sll *next; } *


decompiled_code:
__int64 __fastcall sll_next(__int64 a1)
{
if ( !a1 )
__assert_fail("nodep", "sll.c", 0x2Cu, "sll_next");
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( !a1 )
__assert_fail("nodep", "sll.c", 0x2Cu, "sll_next");
return *(_QWORD *)a1;
}

original_code:
sll_t *sll_next(sll_t *nodep)
{
 ((void) sizeof ((nodep) ? 1 : 0), __extension__ ({ if (nodep) ; else __assert_fail ("nodep", "sll.c", 44, __extension__ __PRETTY_FUNCTION__); }));
 return nodep->next;
}

canonical_original_code:
struct sll *sll_next(struct sll *nodep)
{
 ((void) sizeof ((nodep) ? 1 : 0), __extension__ ({ if (nodep) ; else __assert_fail ("nodep", "sll.c", 44, __extension__ __PRETTY_FUNCTION__); }));
 return nodep->next;
}

variable_types:
nodep
struct sll *

return_type: struct sll { struct sll *next; } *