original_code:
int
httprequest_parse(HttpRequest *p_http, char *p_buffer, int p_length)
{
 char *ptr = p_buffer;
 char *tmp;
 int ret = -1;
 if (p_length == 0)
  return 0;
 do
 {
  switch (p_http->m_state)
  {
   case E_ParseAction:
   {
    if (!strncmp(ptr, "GET ", 4))
    {
     p_http->m_state = E_ParseURL;
     p_http->m_cmd = E_Get;
     ptr += 4;
    }
    else if (!strncmp(ptr, "HEAD ", 5))
    {
     p_http->m_state = E_ParseHeader;
     p_http->m_cmd = E_Head;
     ptr += 5;
    }
    else if (!strncmp(ptr, "POST ", 5))
    {
     p_http->m_state = E_ParseURL;
     p_http->m_cmd = E_Post;
     ptr += 5;
    }
    else
     ret = ptr - p_buffer;
   break;
   case E_ParseURL:
    tmp = _endline(ptr);
    if (*tmp != 0)
    {
     while (*ptr++ != '/');
     ptr = strstore(&p_http->m_filepath, ptr, " ?\n\r");
     if (*ptr == '?')
     {
      ptr++;
      p_http->m_state = E_ParseGet;
     }
     else if (*ptr == ' ')
     {
      ptr = tmp;
      p_http->m_state = E_ParseHeader;
     }
     else if (*ptr == '\r'|| *ptr == '\n')
     {
      ptr = tmp;
      p_http->m_state = E_ParseHeader;
     }
    }
    else
     ret = ptr - p_buffer;
   }
   break;
   case E_ParseGet:
   {
    tmp = _endline(ptr);
    if (*tmp != 0)
    {
     char *equal;
     p_http->m_get[p_http->m_get_nb].name = ((void *)0);
     ptr = strstore(&(p_http->m_get[p_http->m_get_nb].name), ptr, " &\n\r");
     equal = strchrnul(p_http->m_get[p_http->m_get_nb].name, '=');
     if (*equal != '\0')
     {
      p_http->m_get[p_http->m_get_nb].value = equal + 1;
      *equal = '\0';
     }
     p_http->m_get_nb++;
     ptr = tmp;
     p_http->m_state = E_ParseHeader;
    }
    else
     ret = ptr - p_buffer;
   }
   break;
   case E_ParseHeader:
   {
    tmp = _endline(ptr);
    if (*tmp != 0)
    {
     if (!strncmp(ptr, "Host: ", 6))
     {
      ptr += 6;
      ptr = strstore(&p_http->m_host, ptr, " :\n\r");
      char *ddot = strchrnul(p_http->m_host, ':');
      if (*ddot == ':')
      {
       p_http->m_port = atoi(ddot + 1);
       *ddot = 0;
      }
      else
      {
       p_http->m_port = 80;
      }
     }
     else if (!strncmp(ptr, "User-Agent: ", 12))
     {
      ptr += 12;
      ptr = strstore(&p_http->m_useragent, ptr, "\n\r");
     }
     else if (!strncmp(ptr, "Content-Type: ", 14))
     {
      ptr += 14;
      if (!strncmp(ptr, "application/x-www-form-urlencoded", 32))
      {
       ptr += 32;
       p_http->m_content.type = E_Form;
      }
     }
     else if (!strncmp(ptr, "Content-Length: ", 16))
     {
      ptr += 16;
      p_http->m_content.length = atoi(ptr);
     }
     else if (*ptr == '\n' || *ptr == '\r')
     {
      p_http->m_state = E_ParseBody;
     }
     ptr = tmp;
    }
    else
     ret = ptr - p_buffer;
   }
   break;
   case E_ParseBody:
   {
    if (p_http->m_content.data)
    {
     p_http->m_content.data = malloc(p_http->m_content.length + 1);
     p_http->m_content.ptr = p_http->m_content.data;
    }
    memcpy(p_http->m_content.ptr, ptr, p_length);
    p_http->m_content.ptr += p_length;
    if (p_http->m_content.ptr - p_http->m_content.data == p_http->m_content.length)
     p_http->m_state = E_ParseEnd;
   }
   break;
   case E_ParseEnd:
    ret = 0;
   break;
  }
 } while (ret < 0);
 ptr = stpncpy(p_buffer, ptr, ret);
 return ret;
}

canonical_original_code:
int httprequest_parse(struct _httprequest *p_http, char *p_buffer, int p_length)
{
 char *ptr = p_buffer;
 char *tmp;
 int ret = -1;
 if (p_length == 0)
  return 0;
 do
 {
  switch (p_http->m_state)
  {
   case E_ParseAction:
   {
    if (!strncmp(ptr, "GET ", 4))
    {
     p_http->m_state = E_ParseURL;
     p_http->m_cmd = E_Get;
     ptr += 4;
    }
    else if (!strncmp(ptr, "HEAD ", 5))
    {
     p_http->m_state = E_ParseHeader;
     p_http->m_cmd = E_Head;
     ptr += 5;
    }
    else if (!strncmp(ptr, "POST ", 5))
    {
     p_http->m_state = E_ParseURL;
     p_http->m_cmd = E_Post;
     ptr += 5;
    }
    else
     ret = ptr - p_buffer;
   break;
   case E_ParseURL:
    tmp = _endline(ptr);
    if (*tmp != 0)
    {
     while (*ptr++ != '/');
     ptr = strstore(&p_http->m_filepath, ptr, " ?\n\r");
     if (*ptr == '?')
     {
      ptr++;
      p_http->m_state = E_ParseGet;
     }
     else if (*ptr == ' ')
     {
      ptr = tmp;
      p_http->m_state = E_ParseHeader;
     }
     else if (*ptr == '\r'|| *ptr == '\n')
     {
      ptr = tmp;
      p_http->m_state = E_ParseHeader;
     }
    }
    else
     ret = ptr - p_buffer;
   }
   break;
   case E_ParseGet:
   {
    tmp = _endline(ptr);
    if (*tmp != 0)
    {
     char *equal;
     p_http->m_get[p_http->m_get_nb].name = ((void *)0);
     ptr = strstore(&(p_http->m_get[p_http->m_get_nb].name), ptr, " &\n\r");
     equal = strchrnul(p_http->m_get[p_http->m_get_nb].name, '=');
     if (*equal != '\0')
     {
      p_http->m_get[p_http->m_get_nb].value = equal + 1;
      *equal = '\0';
     }
     p_http->m_get_nb++;
     ptr = tmp;
     p_http->m_state = E_ParseHeader;
    }
    else
     ret = ptr - p_buffer;
   }
   break;
   case E_ParseHeader:
   {
    tmp = _endline(ptr);
    if (*tmp != 0)
    {
     if (!strncmp(ptr, "Host: ", 6))
     {
      ptr += 6;
      ptr = strstore(&p_http->m_host, ptr, " :\n\r");
      char *ddot = strchrnul(p_http->m_host, ':');
      if (*ddot == ':')
      {
       p_http->m_port = atoi(ddot + 1);
       *ddot = 0;
      }
      else
      {
       p_http->m_port = 80;
      }
     }
     else if (!strncmp(ptr, "User-Agent: ", 12))
     {
      ptr += 12;
      ptr = strstore(&p_http->m_useragent, ptr, "\n\r");
     }
     else if (!strncmp(ptr, "Content-Type: ", 14))
     {
      ptr += 14;
      if (!strncmp(ptr, "application/x-www-form-urlencoded", 32))
      {
       ptr += 32;
       p_http->m_content.type = E_Form;
      }
     }
     else if (!strncmp(ptr, "Content-Length: ", 16))
     {
      ptr += 16;
      p_http->m_content.length = atoi(ptr);
     }
     else if (*ptr == '\n' || *ptr == '\r')
     {
      p_http->m_state = E_ParseBody;
     }
     ptr = tmp;
    }
    else
     ret = ptr - p_buffer;
   }
   break;
   case E_ParseBody:
   {
    if (p_http->m_content.data)
    {
     p_http->m_content.data = malloc(p_http->m_content.length + 1);
     p_http->m_content.ptr = p_http->m_content.data;
    }
    memcpy(p_http->m_content.ptr, ptr, p_length);
    p_http->m_content.ptr += p_length;
    if (p_http->m_content.ptr - p_http->m_content.data == p_http->m_content.length)
     p_http->m_state = E_ParseEnd;
   }
   break;
   case E_ParseEnd:
    ret = 0;
   break;
  }
 } while (ret < 0);
 ptr = stpncpy(p_buffer, ptr, ret);
 return ret;
}

variable_types:
tmp
char *

variable_types:
equal
char *

variable_types:
ddot
char *


strstore

decompiled_code:
char *__fastcall strstore(char **a1, const char *a2, const char *a3)
{
char *v4; // r12
char *v5; // rdi
size_t v6; // rdx
char *v8; // rax

v4 = strpbrk(a2, a3);
if ( !v4 )
{
v4 = (char *)a2;
do
++v4;
while ( *(v4 - 1) );
}
if ( a1 )
{
v5 = *a1;
v6 = v4 - a2;
if ( !*a1 )
{
v8 = (char *)malloc(v6 + 1);
v6 = v4 - a2;
*a1 = v8;
v5 = v8;
}
*stpncpy(v5, a2, v6) = 0;
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func0(char **a1, const char *a2, const char *a3)
{
char *v4; // r12
char *v5; // rdi
size_t v6; // rdx
char *v8; // rax

v4 = strpbrk(a2, a3);
if ( !v4 )
{
v4 = (char *)a2;
do
++v4;
while ( *(v4 - 1) );
}
if ( a1 )
{
v5 = *a1;
v6 = v4 - a2;
if ( !*a1 )
{
v8 = (char *)malloc(v6 + 1);
v6 = v4 - a2;
*a1 = v8;
v5 = v8;
}
*stpncpy(v5, a2, v6) = 0;
}
return v4;
}

original_code:
char *strstore(char **p_output, char *p_input, char *p_tags)
{
 char *last;
 char *end = strpbrk(p_input, p_tags);
 if (!end)
 {
  end = p_input;
  while (*end++) ;
 }
 if (p_output)
 {
  if (!*p_output)
  {
   *p_output = malloc(end - p_input + 1);
  }
  last = stpncpy(*p_output, p_input, end - p_input) - 1;
  *(last+1) = 0;
 }
 return end;
}

variable_types:
last
char *

variable_types:
end
char *

return_type: char *


decompiled_code:
char *__fastcall utf8parsing(char *s)
{
char *v1; // r12
char *v2; // r14
char *i; // rbp
void *v4; // rdi
char *v5; // rbx
char *v6; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v1 = s;
if ( s )
{
v2 = s;
for ( i = &s[strlen(s)]; ; *i = 0 )
{
v6 = index(v2, 37);
if ( !v6 )
break;
v2 = v6 + 1;
v4 = v6 + 1;
*v6 = strtol(v6 + 1, &endptr, 16);
v5 = (char *)(endptr - v2);
memmove(v4, endptr, i - endptr);
i -= (__int64)v5;
}
}
return v1;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
char *v1; // r12
char *v2; // r14
char *i; // rbp
void *v4; // rdi
char *v5; // rbx
char *v6; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v1 = s;
if ( s )
{
v2 = s;
for ( i = &s[strlen(s)]; ; *i = 0 )
{
v6 = index(v2, 37);
if ( !v6 )
break;
v2 = v6 + 1;
v4 = v6 + 1;
*v6 = strtol(v6 + 1, &endptr, 16);
v5 = (char *)(endptr - v2);
memmove(v4, endptr, i - endptr);
i -= (__int64)v5;
}
}
return v1;
}

original_code:
char *utf8parsing(char *p_buffer)
{
 char *ptr = p_buffer;
 char *end = p_buffer;
 if (!p_buffer)
  return p_buffer;
 end += strlen(p_buffer);
 while ((ptr = index(ptr,'%')) != ((void *)0))
 {
  char value;
  char *next;
  value = strtol(ptr + 1, &next, 16);
  *ptr = value;
  ptr++;
  memmove(ptr, next, end - next);
  end -= next - ptr;
  *end = 0;
 }
 return p_buffer;
}

variable_types:
ptr
char *

variable_types: value char

variable_types:
next
char *


main

canonical_name: main

repo: mikeyhc/byter

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rdx
int v4; // eax
__int64 v5; // rcx
int v6; // edx
__int64 v7; // rax

if ( argc <= 2 )
{
fwrite("require at least two files\n", 1uLL, 0x1BuLL, _bss_start);
print_usage(*argv, 1LL);
}
process_cmd_args(argc, argv, envp);
v3 = argv + 1;
v4 = 1;
while ( 1 )
{
v5 = v4++;
if ( **v3 != 45 )
break;
++v3;
if ( argc == v4 )
{
v5 = argc;
break;
}
}
v6 = v5 + 1;
if ( argc > (int)v5 + 1 )
{
v7 = v6;
do
{
v6 = v7;
if ( *argv[v7] != 45 )
break;
v6 = ++v7;
}
while ( argc > (int)v7 );
}
if ( argc == v6 )
{
fwrite("requires at least 2 files\n", 1uLL, 0x1AuLL, _bss_start);
print_usage(*argv, 1LL);
}
return compare_files(argv[v5], argv[v6]);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rdx
int v4; // eax
__int64 v5; // rcx
int v6; // edx
__int64 v7; // rax

if ( argc <= 2 )
{
fwrite("require at least two files\n", 1uLL, 0x1BuLL, _bss_start);
func7(*argv, 1LL);
}
func8(argc, argv, envp);
v3 = argv + 1;
v4 = 1;
while ( 1 )
{
v5 = v4++;
if ( **v3 != 45 )
break;
++v3;
if ( argc == v4 )
{
v5 = argc;
break;
}
}
v6 = v5 + 1;
if ( argc > (int)v5 + 1 )
{
v7 = v6;
do
{
v6 = v7;
if ( *argv[v7] != 45 )
break;
v6 = ++v7;
}
while ( argc > (int)v7 );
}
if ( argc == v6 )
{
fwrite("requires at least 2 files\n", 1uLL, 0x1AuLL, _bss_start);
func7(*argv, 1LL);
}
return func11(argv[v5], argv[v6]);
}

original_code:
int main(int argc, char **argv)
{
 int f1, f2;
 if(argc<3){
  fprintf(stderr, "require at least two files\n");
  print_usage(argv[0], 1);
 }
 process_cmd_args(argc, argv);
 for(f1=1; f1<argc; f1++)
  if(argv[f1][0]!='-')
   break;
 for(f2=f1+1; f2<argc; f2++)
  if(argv[f2][0]!='-')
   break;
 if(f2==argc){
  fprintf(stderr, "requires at least 2 files\n");
  print_usage(argv[0], 1);
 }
 return compare_files(argv[f1], argv[f2]);
}

canonical_original_code:
int main(int argc, char **argv)
{
 int f1; int f2;
 if(argc<3){
  fprintf(stderr, "require at least two files\n");
  print_usage(argv[0], 1);
 }
 process_cmd_args(argc, argv);
 for(f1=1; f1<argc; f1++)
  if(argv[f1][0]!='-')
   break;
 for(f2=f1+1; f2<argc; f2++)
  if(argv[f2][0]!='-')
   break;
 if(f2==argc){
  fprintf(stderr, "requires at least 2 files\n");
  print_usage(argv[0], 1);
 }
 return compare_files(argv[f1], argv[f2]);
}

variable_types: argc int

variable_types:
argv
char **

return_type: int


decompiled_code:
void __fastcall __noreturn print_usage(const char *a1, int a2)
{
fwrite("usage:\n", 1uLL, 7uLL, _bss_start);
fprintf(_bss_start, "\t%s [args] file1 file2\n\n", a1);
fwrite("Will do a bytewise compare between file1 and file2\n", 1uLL, 0x33uLL, _bss_start);
fwrite("args:\n", 1uLL, 6uLL, _bss_start);
fwrite("\t-h, --help: show this dialog\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("\t-c, --color: use colored output\n", 1uLL, 0x21uLL, _bss_start);
exit(a2);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1, int a2)
{
fwrite("usage:\n", 1uLL, 7uLL, _bss_start);
fprintf(_bss_start, "\t%s [args] file1 file2\n\n", a1);
fwrite("Will do a bytewise compare between file1 and file2\n", 1uLL, 0x33uLL, _bss_start);
fwrite("args:\n", 1uLL, 6uLL, _bss_start);
fwrite("\t-h, --help: show this dialog\n", 1uLL, 0x1FuLL, _bss_start);
fwrite("\t-c, --color: use colored output\n", 1uLL, 0x21uLL, _bss_start);
exit(a2);
}

original_code:
void print_usage(char *name, int ret)
{
 fprintf(stderr, "usage:\n");
 fprintf(stderr, "\t%s [args] file1 file2\n\n", name);
 fprintf(stderr, "Will do a bytewise compare between file1 and file2\n");
 fprintf(stderr, "args:\n");
 fprintf(stderr, "\t-h, --help:  show this dialog\n");
 fprintf(stderr, "\t-c, --color: use colored output\n");
 exit(ret);
}

variable_types:
name
char *

variable_types: ret int

return_type: void


decompiled_code:
void __fastcall process_cmd_args(int a1, const char **a2)
{
const char **v2; // rax
const char *v3; // rdx
int v4; // er8

if ( a1 > 1 )
{
v2 = a2 + 1;
do
{
v3 = *v2;
v4 = *(unsigned __int8 *)*v2;
if ( v4 == 45 && v3[1] == 104 && !v3[2] || !strcmp(*v2, "--help") )
print_usage(*a2, 0);
if ( v4 == 45 && v3[1] == 99 && !v3[2] || !strcmp(*v2, "--color") )
{
color = 1;
}
else if ( *v3 == 45 )
{
fprintf(_bss_start, "unknown option: %s\n", v3);
print_usage(*a2, 1);
}
++v2;
}
while ( v2 != &a2[(unsigned int)(a1 - 2) + 2] );
}
}

original_code:
void process_cmd_args(int argc, char **argv)
{
 int i;
 for(i=1; i<argc; i++)
  if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help"))
   print_usage(argv[0], 0);
  else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--color"))
   color = 1;
  else if(argv[i][0]=='-'){
   fprintf(stderr, "unknown option: %s\n", argv[i]);
   print_usage(argv[0], 1);
  }
}

variable_types: i int


decompiled_code:
int __fastcall print_hex_row(_BYTE *a1, _BYTE *a2, unsigned int a3)
{
_BYTE *v3; // r13
_BYTE *v4; // r12
_BYTE *v5; // rbp
_BYTE *v6; // rbx
char i; // al
const char *v8; // rcx
const char *v9; // rsi
char *v10; // r13
char j; // al
const char *v12; // rcx
const char *v13; // rsi

v3 = a2;
v4 = a1;
v5 = a2;
v6 = a1;
printf(" %06d", a3);
for ( i = *a1; i; ++v5 )
{
while ( 1 )
{
if ( color )
{
v8 = "\x1B[m";
v9 = "\x1B[1;31;40m";
if ( *v5 == i )
v8 = "\t%s [args] file1 file2\n\n" + 24;
if ( *v5 == i )
v9 = "\t%s [args] file1 file2\n\n" + 24;
}
else
{
v8 = "\t%s [args] file1 file2\n\n" + 24;
v9 = "\t%s [args] file1 file2\n\n" + 24;
}
printf("%s %02X%s", v9, (unsigned int)i, v8);
if ( *v6 == *v5 )
break;
i = *++v6;
++wrong;
++v5;
if ( !i )
goto LABEL_12;
}
i = *++v6;
++right;
}
LABEL_12:
v10 = v3 + 1;
printf("\n ");
for ( j = *(v10 - 1); j; ++v10 )
{
if ( color )
{
v12 = "\x1B[m";
v13 = "\x1B[1;31;40m";
if ( *v4 == j )
v12 = "\t%s [args] file1 file2\n\n" + 24;
if ( *v4 == j )
v13 = "\t%s [args] file1 file2\n\n" + 24;
}
else
{
v12 = "\t%s [args] file1 file2\n\n" + 24;
v13 = "\t%s [args] file1 file2\n\n" + 24;
}
printf("%s %02X%s", v13, (unsigned int)j, v12);
j = *v10;
++v4;
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func9(_BYTE *a1, _BYTE *a2, unsigned int a3)
{
_BYTE *v3; // r13
_BYTE *v4; // r12
_BYTE *v5; // rbp
_BYTE *v6; // rbx
char i; // al
const char *v8; // rcx
const char *v9; // rsi
char *v10; // r13
char j; // al
const char *v12; // rcx
const char *v13; // rsi

v3 = a2;
v4 = a1;
v5 = a2;
v6 = a1;
printf(" %06d", a3);
for ( i = *a1; i; ++v5 )
{
while ( 1 )
{
if ( color )
{
v8 = "\x1B[m";
v9 = "\x1B[1;31;40m";
if ( *v5 == i )
v8 = "\t%s [args] file1 file2\n\n" + 24;
if ( *v5 == i )
v9 = "\t%s [args] file1 file2\n\n" + 24;
}
else
{
v8 = "\t%s [args] file1 file2\n\n" + 24;
v9 = "\t%s [args] file1 file2\n\n" + 24;
}
printf("%s %02X%s", v9, (unsigned int)i, v8);
if ( *v6 == *v5 )
break;
i = *++v6;
++wrong;
++v5;
if ( !i )
goto LABEL_12;
}
i = *++v6;
++right;
}
LABEL_12:
v10 = v3 + 1;
printf("\n ");
for ( j = *(v10 - 1); j; ++v10 )
{
if ( color )
{
v12 = "\x1B[m";
v13 = "\x1B[1;31;40m";
if ( *v4 == j )
v12 = "\t%s [args] file1 file2\n\n" + 24;
if ( *v4 == j )
v13 = "\t%s [args] file1 file2\n\n" + 24;
}
else
{
v12 = "\t%s [args] file1 file2\n\n" + 24;
v13 = "\t%s [args] file1 file2\n\n" + 24;
}
printf("%s %02X%s", v13, (unsigned int)j, v12);
j = *v10;
++v4;
}
return putchar(10);
}

original_code:
void print_hex_row(char *str, char *other, int offset)
{
 int i;
 printf(" %06d", offset);
 for(i=0; str[i]!='\0'; i++){
  printf("%s"" %02X""%s", color && str[i]!=other[i] ? "\033[1;31;40m" : "", str[i], color && str[i]!=other[i] ? "\033[m" : "");
  if(str[i]==other[i])
   right++;
  else
   wrong++;
 }
 printf("\n       ");
 for(i=0; other[i]!='\0'; i++)
  printf("%s"" %02X""%s", color && other[i]!=str[i] ? "\033[1;31;40m" : "", other[i], color && other[i]!=str[i] ? "\033[m" : "");
 printf("\n");
}

variable_types:
str
char *

variable_types:
other
char *

variable_types: offset int


variable_types: c char


decompiled_code:
__int64 __fastcall compare_files(const char *a1, const char *a2)
{
int v2; // eax
int v3; // er12
unsigned int v4; // ebp
int v5; // er13
int v6; // eax
unsigned int v7; // edx
int v8; // eax
__int64 v9; // rbx
int *v10; // rax
char *v11; // rax
int v12; // ebx
unsigned int v13; // ebp
int v14; // ebx
unsigned int v15; // er12
int *v17; // rax
char *v18; // rax
int *v19; // rax
char *v20; // rax
int *v21; // rax
char *v22; // rax
const char *v23; // rdx
const char *v24; // rcx
unsigned int v25; // [rsp+Ch] [rbp-7Ch]
char v26[32]; // [rsp+10h] [rbp-78h] BYREF
char buf[88]; // [rsp+30h] [rbp-58h] BYREF

v2 = open(a1, 0, 0LL);
if ( v2 == -1 )
{
v19 = __errno_location();
v20 = strerror(*v19);
v23 = a1;
v24 = v20;
goto LABEL_16;
}
v3 = v2;
v4 = 0;
v5 = open(a2, 0, 0LL);
if ( v5 == -1 )
{
close(v3);
v21 = __errno_location();
v22 = strerror(*v21);
v23 = a2;
v24 = v22;
LABEL_16:
v15 = 1;
fprintf(_bss_start, "could not read %s - %s\n", v23, v24);
return v15;
}
while ( 1 )
{
v8 = read(v3, v26, 0x14uLL);
v9 = v8;
if ( v8 <= 0 )
{
if ( v8 == -1 )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(_bss_start, "Error reading from %s - %s\n", a1, v11);
}
goto LABEL_9;
}
v6 = read(v5, buf, 0x14uLL);
if ( v6 <= 0 )
break;
v7 = v4;
v26[v9] = 0;
buf[v6] = 0;
v4 += 20;
print_hex_row(v26, buf, v7);
print_char_row(v26, buf);
putchar(10);
}
if ( v6 == -1 )
{
v17 = __errno_location();
v18 = strerror(*v17);
fprintf(_bss_start, "Error reading from %s - %s\n", a2, v18);
}
LABEL_9:
v12 = lseek(v3, 0LL, 1);
v13 = lseek(v3, 0LL, 2) - v12;
v14 = lseek(v5, 0LL, 1);
v25 = lseek(v5, 0LL, 2) - v14;
close(v3);
close(v5);
v15 = color;
if ( color )
{
v15 = 0;
printf(
"\t\x1B[1;36;40m%6d\x1B[m %s unread\n"
"\t\x1B[1;36;40m%6d\x1B[m %s unread\n"
"\t\x1B[1;33;40m%6d\x1B[m total\n"
"\t\x1B[1;32;40m%6d\x1B[m matched\n"
"\t\x1B[1;31;40m%6d\x1B[m no match\n",
v13,
a1,
v25,
a2,
(unsigned int)(wrong + right),
(unsigned int)right,
(unsigned int)wrong);
}
else
{
printf(
"\t%6d %s unread\n\t%6d %s unread\n\t%6d total\n\t%6d matched\n\t%6d no match\n",
v13,
a1,
v25,
a2,
(unsigned int)(wrong + right),
(unsigned int)right,
(unsigned int)wrong);
}
return v15;
}

canonical_decompiled_code:
__int64 __fastcall func11(const char *a1, const char *a2)
{
int v2; // eax
int v3; // er12
unsigned int v4; // ebp
int v5; // er13
int v6; // eax
unsigned int v7; // edx
int v8; // eax
__int64 v9; // rbx
int *v10; // rax
char *v11; // rax
int v12; // ebx
unsigned int v13; // ebp
int v14; // ebx
unsigned int v15; // er12
int *v17; // rax
char *v18; // rax
int *v19; // rax
char *v20; // rax
int *v21; // rax
char *v22; // rax
const char *v23; // rdx
const char *v24; // rcx
unsigned int v25; // [rsp+Ch] [rbp-7Ch]
char v26[32]; // [rsp+10h] [rbp-78h] BYREF
char buf[88]; // [rsp+30h] [rbp-58h] BYREF

v2 = open(a1, 0, 0LL);
if ( v2 == -1 )
{
v19 = __errno_location();
v20 = strerror(*v19);
v23 = a1;
v24 = v20;
goto LABEL_16;
}
v3 = v2;
v4 = 0;
v5 = open(a2, 0, 0LL);
if ( v5 == -1 )
{
close(v3);
v21 = __errno_location();
v22 = strerror(*v21);
v23 = a2;
v24 = v22;
LABEL_16:
v15 = 1;
fprintf(_bss_start, "could not read %s - %s\n", v23, v24);
return v15;
}
while ( 1 )
{
v8 = read(v3, v26, 0x14uLL);
v9 = v8;
if ( v8 <= 0 )
{
if ( v8 == -1 )
{
v10 = __errno_location();
v11 = strerror(*v10);
fprintf(_bss_start, "Error reading from %s - %s\n", a1, v11);
}
goto LABEL_9;
}
v6 = read(v5, buf, 0x14uLL);
if ( v6 <= 0 )
break;
v7 = v4;
v26[v9] = 0;
buf[v6] = 0;
v4 += 20;
func9(v26, buf, v7);
func10(v26, buf);
putchar(10);
}
if ( v6 == -1 )
{
v17 = __errno_location();
v18 = strerror(*v17);
fprintf(_bss_start, "Error reading from %s - %s\n", a2, v18);
}
LABEL_9:
v12 = lseek(v3, 0LL, 1);
v13 = lseek(v3, 0LL, 2) - v12;
v14 = lseek(v5, 0LL, 1);
v25 = lseek(v5, 0LL, 2) - v14;
close(v3);
close(v5);
v15 = color;
if ( color )
{
v15 = 0;
printf(
"\t\x1B[1;36;40m%6d\x1B[m %s unread\n"
"\t\x1B[1;36;40m%6d\x1B[m %s unread\n"
"\t\x1B[1;33;40m%6d\x1B[m total\n"
"\t\x1B[1;32;40m%6d\x1B[m matched\n"
"\t\x1B[1;31;40m%6d\x1B[m no match\n",
v13,
a1,
v25,
a2,
(unsigned int)(wrong + right),
(unsigned int)right,
(unsigned int)wrong);
}
else
{
printf(
"\t%6d %s unread\n\t%6d %s unread\n\t%6d total\n\t%6d matched\n\t%6d no match\n",
v13,
a1,
v25,
a2,
(unsigned int)(wrong + right),
(unsigned int)right,
(unsigned int)wrong);
}
return v15;
}

original_code:
int compare_files(char *file1, char *file2)
{
 int fh1, fh2, r1, r2;
 unsigned ur1, ur2;
 char buf1[20 + 1], buf2[20 + 1];
 int i, pos;
 fh1 = open(file1, 0, 00);
 if(fh1==-1){
  fprintf(stderr, "could not read %s - %s\n", file1,
   strerror((*__errno_location ())));
  return 1;
 }
 fh2 = open(file2, 0, 00);
 if(fh2==-1){
  close(fh1);
  fprintf(stderr, "could not read %s - %s\n", file2,
   strerror((*__errno_location ())));
  return 1;
 }
 pos = 0;
 while((r1 = read(fh1, buf1, 20))>0){
  if((r2 = read(fh2, buf2, 20))<=0)
   break;
  buf1[r1] = '\0';
  buf2[r2] = '\0';
  print_hex_row(buf1, buf2, pos*20);
  print_char_row(buf1, buf2);
  printf("\n");
  pos++;
 }
 if(r1==-1)
  fprintf(stderr, "Error reading from %s - %s\n",
   file1, strerror((*__errno_location ())));
 else if(r2==-1)
  fprintf(stderr, "Error reading from %s - %s\n",
   file2, strerror((*__errno_location ())));
 i = lseek(fh1, 0, 1);
 ur1 = lseek(fh1, 0, 2) - i;
 i = lseek(fh2, 0, 1);
 ur2 = lseek(fh2, 0, 2) - i;
 close(fh1);
 close(fh2);
 if(color)
  printf("\t\033[1;36;40m%6d\033[m %s unread\n\t\033[1;36;40m"
   "%6d\033[m %s unread\n\t\033[1;33;40m%6d\033[m "
   "total\n\t\033[1;32;40m%6d\033[m matched\n\t"
   "\033[1;31;40m%6d\033[m no match\n", ur1, file1, ur2,
   file2, right + wrong, right, wrong);
 else
  printf("\t%6d %s unread\n\t%6d %s unread\n\t%6d total\n\t%6d "
   "matched\n\t%6d no match\n", ur1, file1, ur2, file2,
   right+wrong, right, wrong);
 return 0;
}

canonical_original_code:
int compare_files(char *file1, char *file2)
{
 int fh1; int fh2; int r1; int r2;
 unsigned int ur1; unsigned int ur2;
 char buf1[-1]; char buf2[-1];
 int i; int pos;
 fh1 = open(file1, 0, 00);
 if(fh1==-1){
  fprintf(stderr, "could not read %s - %s\n", file1,
   strerror((*__errno_location ())));
  return 1;
 }
 fh2 = open(file2, 0, 00);
 if(fh2==-1){
  close(fh1);
  fprintf(stderr, "could not read %s - %s\n", file2,
   strerror((*__errno_location ())));
  return 1;
 }
 pos = 0;
 while((r1 = read(fh1, buf1, 20))>0){
  if((r2 = read(fh2, buf2, 20))<=0)
   break;
  buf1[r1] = '\0';
  buf2[r2] = '\0';
  print_hex_row(buf1, buf2, pos*20);
  print_char_row(buf1, buf2);
  printf("\n");
  pos++;
 }
 if(r1==-1)
  fprintf(stderr, "Error reading from %s - %s\n",
   file1, strerror((*__errno_location ())));
 else if(r2==-1)
  fprintf(stderr, "Error reading from %s - %s\n",
   file2, strerror((*__errno_location ())));
 i = lseek(fh1, 0, 1);
 ur1 = lseek(fh1, 0, 2) - i;
 i = lseek(fh2, 0, 1);
 ur2 = lseek(fh2, 0, 2) - i;
 close(fh1);
 close(fh2);
 if(color)
  printf("\t\033[1;36;40m%6d\033[m %s unread\n\t\033[1;36;40m"
   "%6d\033[m %s unread\n\t\033[1;33;40m%6d\033[m "
   "total\n\t\033[1;32;40m%6d\033[m matched\n\t"
   "\033[1;31;40m%6d\033[m no match\n", ur1, file1, ur2,
   file2, right + wrong, right, wrong);
 else
  printf("\t%6d %s unread\n\t%6d %s unread\n\t%6d total\n\t%6d "
   "matched\n\t%6d no match\n", ur1, file1, ur2, file2,
   right+wrong, right, wrong);
 return 0;
}

variable_types: pos int


repo: mitchellwrosen/rsa-crack-cuda

decompiled_code:
__int64 __fastcall mpz_primality(__int64 a1)
{
return _gmpz_probab_prime_p(a1, 25LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return _gmpz_probab_prime_p(a1, 25LL);
}

original_code:
Primality mpz_primality(mpz_t n) {
  return __gmpz_probab_prime_p(n, 25);
}

canonical_original_code:
enum Primality mpz_primality(struct __mpz_struct n[1]) {
  return __gmpz_probab_prime_p(n, 25);
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

return_type: enum Primality { COMPOSITE=0, PROB_PRIME=1, PRIME=2 }


decompiled_code:
__int64 __fastcall mpz_printb(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = _gmpz_out_str(stdout, a2, a1);
fputc(10, stdout);
return v2 + 1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = _gmpz_out_str(stdout, a2, a1);
fputc(10, stdout);
return v2 + 1;
}

original_code:
size_t mpz_printb(const mpz_t n, int base) {
  size_t nbytes = __gmpz_out_str(stdout, base, n);
  fprintf(stdout, "\n");
  return nbytes+1;
}

canonical_original_code:
unsigned long mpz_printb(struct __mpz_struct n[1], int base) {
  unsigned long nbytes = __gmpz_out_str(stdout, base, n);
  fprintf(stdout, "\n");
  return nbytes+1;
}

variable_types: base int

variable_types:
nbytes
unsigned long

return_type: unsigned long

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


decompiled_code:
__int64 __fastcall mpz_print(__int64 a1)
{
return mpz_printb(a1, 10LL);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return func6(a1, 10LL);
}

original_code:
size_t mpz_print(const mpz_t n) {
  return mpz_printb(n, 10);
}

canonical_original_code:
unsigned long mpz_print(struct __mpz_struct n[1]) {
  return mpz_printb(n, 10);
}


decompiled_code:
__int64 __fastcall gmp_rand_init_seed(__int64 a1, __int64 a2)
{
_gmp_randinit_default();
return _gmp_randseed_ui(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
_gmp_randinit_default();
return _gmp_randseed_ui(a1, a2);
}

original_code:
void gmp_rand_init_seed(gmp_randstate_t rstate, unsigned long int seed) {
  __gmp_randinit_default(rstate);
  __gmp_randseed_ui(rstate, seed);
}

canonical_original_code:
void gmp_rand_init_seed(struct __gmp_randstate_struct rstate[1], unsigned long seed) {
  __gmp_randinit_default(rstate);
  __gmp_randseed_ui(rstate, seed);
}

variable_types: struct __gmp_randstate_struct { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types:
seed
unsigned long

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


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

do
{
_gmpz_urandomb(a1, a2, a3);
result = mpz_primality(a1);
}
while ( (_DWORD)result != 2 );
return result;
}

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

do
{
_gmpz_urandomb(a1, a2, a3);
result = func0(a1);
}
while ( (_DWORD)result != 2 );
return result;
}

original_code:
void gmp_genprime(mpz_t n, gmp_randstate_t rstate, mp_bitcnt_t bitcount) {
  do {
    __gmpz_urandomb(n, rstate, bitcount);
  } while (mpz_primality(n) != PRIME);
}

canonical_original_code:
void gmp_genprime(struct __mpz_struct n[1], struct __gmp_randstate_struct rstate[1], unsigned long bitcount) {
  do {
    __gmpz_urandomb(n, rstate, bitcount);
  } while (mpz_primality(n) != PRIME);
}

variable_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } [1]

variable_types:
bitcount
unsigned long


decompiled_code:
__int64 __fastcall rsa_generate_npq(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
time_t v6; // rax
_BYTE v8[72]; // [rsp+0h] [rbp-48h] BYREF

v6 = time(0LL);
gmp_rand_init_seed(v8, v6);
gmp_genprime(a2, v8, a4);
gmp_genprime(a3, v8, a4);
return _gmpz_mul(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
time_t v6; // rax
_BYTE v8[72]; // [rsp+0h] [rbp-48h] BYREF

v6 = time(0LL);
gmp_rand_init_seed(v8, v6);
gmp_genprime(a2, v8, a4);
gmp_genprime(a3, v8, a4);
return _gmpz_mul(a1, a2, a3);
}

original_code:
void rsa_generate_npq(mpz_t n, mpz_t p, mpz_t q, mp_bitcnt_t bitcount) {
  gmp_randstate_t rstate;
  gmp_rand_init_seed(rstate, time(((void *)0)));
  gmp_genprime(p, rstate, bitcount);
  gmp_genprime(q, rstate, bitcount);
  __gmpz_mul(n, p, q);
}

canonical_original_code:
void rsa_generate_npq(struct __mpz_struct n[1], struct __mpz_struct p[1], struct __mpz_struct q[1], unsigned long bitcount) {
  struct __gmp_randstate_struct rstate[1];
  gmp_rand_init_seed(rstate, time(((void *)0)));
  gmp_genprime(p, rstate, bitcount);
  gmp_genprime(q, rstate, bitcount);
  __gmpz_mul(n, p, q);
}

variable_types:
p
struct __mpz_struct [1]

variable_types:
q
struct __mpz_struct [1]

user_defined_types: enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr }


decompiled_code:
__int64 __fastcall rsa_phi(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_inits(v5, v6, 0LL);
_gmpz_sub_ui(v5, a2, 1LL);
_gmpz_sub_ui(v6, a3, 1LL);
_gmpz_mul(a1, v5, v6);
return _gmpz_clears(v5, v6, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3)
{
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_inits(v5, v6, 0LL);
_gmpz_sub_ui(v5, a2, 1LL);
_gmpz_sub_ui(v6, a3, 1LL);
_gmpz_mul(a1, v5, v6);
return _gmpz_clears(v5, v6, 0LL);
}

original_code:
void rsa_phi(mpz_t phi_n, const mpz_t p, const mpz_t q) {
  mpz_t p_minus_one, q_minus_one;
  __gmpz_inits(p_minus_one, q_minus_one, '\0');
  __gmpz_sub_ui(p_minus_one, p, 1);
  __gmpz_sub_ui(q_minus_one, q, 1);
  __gmpz_mul(phi_n, p_minus_one, q_minus_one);
  __gmpz_clears(p_minus_one, q_minus_one, '\0');
}

canonical_original_code:
void rsa_phi(struct __mpz_struct phi_n[1], struct __mpz_struct p[1], struct __mpz_struct q[1]) {
  struct __mpz_struct p_minus_one[1]; struct __mpz_struct q_minus_one[1];
  __gmpz_inits(p_minus_one, q_minus_one, '\0');
  __gmpz_sub_ui(p_minus_one, p, 1);
  __gmpz_sub_ui(q_minus_one, q, 1);
  __gmpz_mul(phi_n, p_minus_one, q_minus_one);
  __gmpz_clears(p_minus_one, q_minus_one, '\0');
}


decompiled_code:
__int64 __fastcall rsa_compute_d(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BYTE v7[16]; // [rsp+0h] [rbp-48h] BYREF
char v8[16]; // [rsp+10h] [rbp-38h] BYREF
char v9[40]; // [rsp+20h] [rbp-28h] BYREF

_gmpz_inits(v7, v8, v9);
rsa_phi((__int64)v8, a3, a4);
_gmpz_set_ui(v7, 65537LL);
if ( !(unsigned int)_gmpz_invert(a1, v7, v8) )
exit(1);
_gmpz_clears(v8, v9, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BYTE v7[16]; // [rsp+0h] [rbp-48h] BYREF
char v8[16]; // [rsp+10h] [rbp-38h] BYREF
char v9[40]; // [rsp+20h] [rbp-28h] BYREF

_gmpz_inits(v7, v8, v9);
func1((__int64)v8, a3, a4);
_gmpz_set_ui(v7, 65537LL);
if ( !(unsigned int)_gmpz_invert(a1, v7, v8) )
exit(1);
_gmpz_clears(v8, v9, 0LL);
return 0LL;
}

original_code:
int rsa_compute_d(mpz_t d, const mpz_t n, const mpz_t p, const mpz_t q) {
  mpz_t e, phi_n, gcd;
  __gmpz_inits(e, phi_n, gcd, '\0');
  rsa_phi(phi_n, p, q);
  __gmpz_set_ui(e, 65537);
  if (__gmpz_invert(d, e, phi_n) == 0)
    exit(1);
  __gmpz_clears(phi_n, gcd, '\0');
  return 0;
}

canonical_original_code:
int rsa_compute_d(struct __mpz_struct d[1], struct __mpz_struct n[1], struct __mpz_struct p[1], struct __mpz_struct q[1]) {
  struct __mpz_struct e[1]; struct __mpz_struct phi_n[1]; struct __mpz_struct gcd[1];
  __gmpz_inits(e, phi_n, gcd, '\0');
  rsa_phi(phi_n, p, q);
  __gmpz_set_ui(e, 65537);
  if (__gmpz_invert(d, e, phi_n) == 0)
    exit(1);
  __gmpz_clears(phi_n, gcd, '\0');
  return 0;
}

variable_types:
n
struct __mpz_struct [1]


decompiled_code:
__int64 __fastcall rsa_compute_keys(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v8; // er12
_BYTE v10[16]; // [rsp+0h] [rbp-48h] BYREF
char v11[56]; // [rsp+10h] [rbp-38h] BYREF

_gmpz_inits(v10, v11, 0LL);
rsa_phi((__int64)v10, a4, a5);
_gmpz_set_ui(a1, 65537LL);
while ( 1 )
{
if ( (int)_gmpz_cmp(a1, v10) >= 0 )
{
_gmpz_clears(v10, v11, 0LL);
return 0xFFFFFFFFLL;
}
_gmpz_gcd(v11, a1, a3);
v8 = _gmpz_cmp_ui(v11, 1LL);
if ( !v8 )
break;
_gmpz_nextprime(a1, a1);
}
if ( !(unsigned int)_gmpz_invert(a2, a1, v10) )
exit(1);
_gmpz_clears(v10, v11, 0LL);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v8; // er12
_BYTE v10[16]; // [rsp+0h] [rbp-48h] BYREF
char v11[56]; // [rsp+10h] [rbp-38h] BYREF

_gmpz_inits(v10, v11, 0LL);
func1((__int64)v10, a4, a5);
_gmpz_set_ui(a1, 65537LL);
while ( 1 )
{
if ( (int)_gmpz_cmp(a1, v10) >= 0 )
{
_gmpz_clears(v10, v11, 0LL);
return 0xFFFFFFFFLL;
}
_gmpz_gcd(v11, a1, a3);
v8 = _gmpz_cmp_ui(v11, 1LL);
if ( !v8 )
break;
_gmpz_nextprime(a1, a1);
}
if ( !(unsigned int)_gmpz_invert(a2, a1, v10) )
exit(1);
_gmpz_clears(v10, v11, 0LL);
return v8;
}

original_code:
int rsa_compute_keys(mpz_t e, mpz_t d, const mpz_t n, const mpz_t p, const mpz_t q) {
  mpz_t phi_n, gcd;
  __gmpz_inits(phi_n, gcd, '\0');
  rsa_phi(phi_n, p, q);
  __gmpz_set_ui(e, 65537);
  while (1) {
    if (__gmpz_cmp(e, phi_n) >= 0) {
      __gmpz_clears(phi_n, gcd, '\0');
      return -1;
    }
    __gmpz_gcd(gcd, e, n);
    if ((__builtin_constant_p (1) && (1) == 0 ? ((gcd)->_mp_size < 0 ? -1 : (gcd)->_mp_size > 0) : __gmpz_cmp_ui (gcd,1)) == 0)
      break;
    __gmpz_nextprime(e, e);
  }
  if (__gmpz_invert(d, e, phi_n) == 0)
    exit(1);
  __gmpz_clears(phi_n, gcd, '\0');
  return 0;
}

canonical_original_code:
int rsa_compute_keys(struct __mpz_struct e[1], struct __mpz_struct d[1], struct __mpz_struct n[1], struct __mpz_struct p[1], struct __mpz_struct q[1]) {
  struct __mpz_struct phi_n[1]; struct __mpz_struct gcd[1];
  __gmpz_inits(phi_n, gcd, '\0');
  rsa_phi(phi_n, p, q);
  __gmpz_set_ui(e, 65537);
  while (1) {
    if (__gmpz_cmp(e, phi_n) >= 0) {
      __gmpz_clears(phi_n, gcd, '\0');
      return -1;
    }
    __gmpz_gcd(gcd, e, n);
    if ((__builtin_constant_p (1) && (1) == 0 ? ((gcd)->_mp_size < 0 ? -1 : (gcd)->_mp_size > 0) : __gmpz_cmp_ui (gcd,1)) == 0)
      break;
    __gmpz_nextprime(e, e);
  }
  if (__gmpz_invert(d, e, phi_n) == 0)
    exit(1);
  __gmpz_clears(phi_n, gcd, '\0');
  return 0;
}

variable_types:
d
struct __mpz_struct [1]


decompiled_code:
__int64 __fastcall rsa_keygen(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
unsigned int v6; // er12
_BYTE v8[16]; // [rsp+0h] [rbp-48h] BYREF
char v9[56]; // [rsp+10h] [rbp-38h] BYREF

_gmpz_inits(v8, v9, 0LL);
rsa_generate_npq(a1, (__int64)v8, (__int64)v9, a4);
v6 = rsa_compute_keys(a2, a3, a1, (__int64)v8, (__int64)v9);
_gmpz_clears(v8, v9, 0LL);
return v6;
}

original_code:
int rsa_keygen(mpz_t n, mpz_t e, mpz_t d, mp_bitcnt_t bitcount) {
  mpz_t p, q;
  __gmpz_inits(p, q, '\0');
  rsa_generate_npq(n, p, q, bitcount);
  int ret = rsa_compute_keys(e, d, n, p, q);
  __gmpz_clears(p, q, '\0');
  return ret;
}

canonical_original_code:
int rsa_keygen(struct __mpz_struct n[1], struct __mpz_struct e[1], struct __mpz_struct d[1], unsigned long bitcount) {
  struct __mpz_struct p[1]; struct __mpz_struct q[1];
  __gmpz_inits(p, q, '\0');
  rsa_generate_npq(n, p, q, bitcount);
  int ret = rsa_compute_keys(e, d, n, p, q);
  __gmpz_clears(p, q, '\0');
  return ret;
}

variable_types:
e
struct __mpz_struct [1]

variable_types: ret int


decompiled_code:
__int64 __fastcall rsa_keygen512(__int64 a1, __int64 a2, __int64 a3)
{
return rsa_keygen(a1, a2, a3, 512LL);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
return func4(a1, a2, a3, 512LL);
}

original_code:
int rsa_keygen512(mpz_t n, mpz_t e, mpz_t d) {
  return rsa_keygen(n, e, d, 512);
}

canonical_original_code:
int rsa_keygen512(struct __mpz_struct n[1], struct __mpz_struct e[1], struct __mpz_struct d[1]) {
  return rsa_keygen(n, e, d, 512);
}


decompiled_code:
// attributes: thunk
__int64 rsa_encrypt()
{
return _gmpz_powm();
}

canonical_decompiled_code:
__int64 func6()
{
return _gmpz_powm();
}

original_code:
void rsa_encrypt(mpz_t c, const mpz_t m, const mpz_t e, const mpz_t n) {
  __gmpz_powm(c, m, e, n);
}

canonical_original_code:
void rsa_encrypt(struct __mpz_struct c[1], struct __mpz_struct m[1], struct __mpz_struct e[1], struct __mpz_struct n[1]) {
  __gmpz_powm(c, m, e, n);
}

variable_types:
m
struct __mpz_struct [1]


decompiled_code:
// attributes: thunk
__int64 rsa_decrypt()
{
return rsa_encrypt();
}

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

original_code:
void rsa_decrypt(mpz_t m, const mpz_t c, const mpz_t d, const mpz_t n) {
  __gmpz_powm(m, c, d, n);
}

canonical_original_code:
void rsa_decrypt(struct __mpz_struct m[1], struct __mpz_struct c[1], struct __mpz_struct d[1], struct __mpz_struct n[1]) {
  __gmpz_powm(m, c, d, n);
}

variable_types:
c
struct __mpz_struct [1]


checkIfCrackedAlready

decompiled_code:
__int64 __fastcall checkIfCrackedAlready(int a1)
{
_DWORD *v1; // rax

if ( crackedLen <= 0 )
return 0LL;
v1 = cracked;
while ( *v1 != a1 )
{
if ( ++v1 == (_DWORD *)((char *)cracked + 4 * (unsigned int)(crackedLen - 1) + 4) )
return 0LL;
}
return 1LL;
}

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

if ( crackedLen <= 0 )
return 0LL;
v1 = cracked;
while ( *v1 != a1 )
{
if ( ++v1 == (_DWORD *)((char *)cracked + 4 * (unsigned int)(crackedLen - 1) + 4) )
return 0LL;
}
return 1LL;
}

original_code:
int checkIfCrackedAlready(int n) {
  for (int i = 0; i < crackedLen; ++i) {
    if (n == cracked[i])
      return 1;
  }
  return 0;
}

variable_types: n int

variable_types: i int


printUsage

decompiled_code:
void __fastcall __noreturn printUsage(const char *a1)
{
fprintf(stderr, "Usage: %s keyfile numkeys [outputfile]\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fprintf(stderr, "Usage: %s keyfile numkeys [outputfile]\n", a1);
exit(1);
}

original_code:
void printUsage(char* progname) {
  fprintf(stderr, "Usage: %s keyfile numkeys [outputfile]\n", progname);
  exit(1);
}

canonical_original_code:
void printUsage(char *progname) {
  fprintf(stderr, "Usage: %s keyfile numkeys [outputfile]\n", progname);
  exit(1);
}

variable_types:
progname
char *


decompiled_code:
__int64 __fastcall rsa_compute_d(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rcx
_BYTE v8[16]; // [rsp+0h] [rbp-68h] BYREF
char v9[16]; // [rsp+10h] [rbp-58h] BYREF
char v10[16]; // [rsp+20h] [rbp-48h] BYREF
char v11[16]; // [rsp+30h] [rbp-38h] BYREF
char v12[40]; // [rsp+40h] [rbp-28h] BYREF

_gmpz_inits(v8, v9, v10, 0LL);
_gmpz_inits(v11, v12, 0LL, v6);
_gmpz_sub_ui(v11, a3, 1LL);
_gmpz_sub_ui(v12, a4, 1LL);
_gmpz_mul(v9, v11, v12);
_gmpz_clears(v11, v12, 0LL);
_gmpz_set_ui(v8, 65537LL);
if ( !(unsigned int)_gmpz_invert(a1, v8, v9) )
exit(1);
_gmpz_clears(v9, v10, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v6; // rcx
_BYTE v8[16]; // [rsp+0h] [rbp-68h] BYREF
char v9[16]; // [rsp+10h] [rbp-58h] BYREF
char v10[16]; // [rsp+20h] [rbp-48h] BYREF
char v11[16]; // [rsp+30h] [rbp-38h] BYREF
char v12[40]; // [rsp+40h] [rbp-28h] BYREF

_gmpz_inits(v8, v9, v10, 0LL);
_gmpz_inits(v11, v12, 0LL, v6);
_gmpz_sub_ui(v11, a3, 1LL);
_gmpz_sub_ui(v12, a4, 1LL);
_gmpz_mul(v9, v11, v12);
_gmpz_clears(v11, v12, 0LL);
_gmpz_set_ui(v8, 65537LL);
if ( !(unsigned int)_gmpz_invert(a1, v8, v9) )
exit(1);
_gmpz_clears(v9, v10, 0LL);
return 0LL;
}

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]


decompiled_code:
__int64 __fastcall rsa_phi(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BYTE v6[16]; // [rsp+0h] [rbp-38h] BYREF
char v7[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_inits(v6, v7, 0LL, a4);
_gmpz_sub_ui(v6, a2, 1LL);
_gmpz_sub_ui(v7, a3, 1LL);
_gmpz_mul(a1, v6, v7);
return _gmpz_clears(v6, v7, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
_BYTE v6[16]; // [rsp+0h] [rbp-38h] BYREF
char v7[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_inits(v6, v7, 0LL, a4);
_gmpz_sub_ui(v6, a2, 1LL);
_gmpz_sub_ui(v7, a3, 1LL);
_gmpz_mul(a1, v6, v7);
return _gmpz_clears(v6, v7, 0LL);
}


repo: mohammadul/meshlib

decompiled_code:
void __fastcall __noreturn mesh_error(int a1)
{
if ( a1 == 2 )
{
fwrite("mesh: can not open file\n", 1uLL, 0x18uLL, stderr);
goto LABEL_6;
}
if ( a1 > 2 )
{
if ( a1 == 3 )
{
fwrite("mesh: incompatible data\n", 1uLL, 0x18uLL, stderr);
goto LABEL_6;
}
}
else
{
if ( !a1 )
{
fwrite("mesh: malloc error\n", 1uLL, 0x13uLL, stderr);
LABEL_6:
exit(-1);
}
if ( a1 == 1 )
{
fwrite("mesh: dimension size mismatch\n", 1uLL, 0x1EuLL, stderr);
goto LABEL_6;
}
}
fwrite("mesh: unknown error\n", 1uLL, 0x14uLL, stderr);
goto LABEL_6;
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
if ( a1 == 2 )
{
fwrite("mesh: can not open file\n", 1uLL, 0x18uLL, stderr);
goto LABEL_6;
}
if ( a1 > 2 )
{
if ( a1 == 3 )
{
fwrite("mesh: incompatible data\n", 1uLL, 0x18uLL, stderr);
goto LABEL_6;
}
}
else
{
if ( !a1 )
{
fwrite("mesh: malloc error\n", 1uLL, 0x13uLL, stderr);
LABEL_6:
exit(-1);
}
if ( a1 == 1 )
{
fwrite("mesh: dimension size mismatch\n", 1uLL, 0x1EuLL, stderr);
goto LABEL_6;
}
}
fwrite("mesh: unknown error\n", 1uLL, 0x14uLL, stderr);
goto LABEL_6;
}

original_code:
void mesh_error(int type)
{
    switch(type)
    {
    case 0:
        fprintf(stderr, "mesh: malloc error\n");
        break;
    case 1:
        fprintf(stderr, "mesh: dimension size mismatch\n");
        break;
    case 2:
        fprintf(stderr, "mesh: can not open file\n");
        break;
    case 3:
        fprintf(stderr, "mesh: incompatible data\n");
        break;
    default:
        fprintf(stderr, "mesh: unknown error\n");
        break;
    }
    exit(-1);
}

variable_types: type int


main

repo: msuriar/fabler

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
err(10, "Usage: fabler <prefix>/<len> <healthcheck_cmd> [<healtcheck_args>...]", envp);
run_loop(argv);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
if ( argc <= 2 )
err(10, "Usage: fabler <prefix>/<len> <healthcheck_cmd> [<healtcheck_args>...]", envp);
func16(argv);
}

original_code:
int main(int argc, char *argv[])
{
  if (argc < 3) {
    err(10, "Usage: fabler <prefix>/<len> <healthcheck_cmd> [<healtcheck_args>...]");
  }
  run_loop(argv);
  exit(0);
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
void catch_child()
{
kill_child = 0;
}

canonical_decompiled_code:
void func7()
{
kill_child = 0;
}

original_code:
static void catch_child(int sig) {
  (void)sig;
  kill_child = 0;
}

variable_types: sig int


decompiled_code:
__int64 __fastcall prefix_len_to_subnet_mask(char a1)
{
return (unsigned int)(-1 << (32 - a1));
}

canonical_decompiled_code:
__int64 __fastcall func8(char a1)
{
return (unsigned int)(-1 << (32 - a1));
}

original_code:
static uint32_t prefix_len_to_subnet_mask(int prefix_len) {
    uint32_t netmask = (4294967295U);
    netmask <<= 32 - prefix_len;
    return netmask;
}

canonical_original_code:
static unsigned int prefix_len_to_subnet_mask(int prefix_len) {
    unsigned int netmask = (4294967295U);
    netmask <<= 32 - prefix_len;
    return netmask;
}

variable_types:
netmask
unsigned int

return_type: unsigned int


decompiled_code:
char *__fastcall get_net_from_prefix(char *string)
{
char *v1; // rax

v1 = strchr(string, 47);
return strndup(string, v1 - string);
}

canonical_decompiled_code:
char *__fastcall func10(char *string)
{
char *v1; // rax

v1 = strchr(string, 47);
return strndup(string, v1 - string);
}

original_code:
static char *get_net_from_prefix(const char *prefix) {
  char *loc = strchr(prefix, '/');
  char *network = strndup(prefix, loc-prefix);
  return network;
}

canonical_original_code:
static char *get_net_from_prefix(char *prefix) {
  char *loc = strchr(prefix, '/');
  char *network = strndup(prefix, loc-prefix);
  return network;
}

variable_types:
prefix
char *

variable_types:
loc
char *

variable_types:
network
char *


decompiled_code:
__int64 get_prefix_len_from_prefix()
{
unsigned int v1; // [rsp+24h] [rbp-Ch]

__isoc99_sscanf();
return v1;
}

canonical_decompiled_code:
__int64 func11()
{
unsigned int v1; // [rsp+24h] [rbp-Ch]

__isoc99_sscanf();
return v1;
}

original_code:
static int get_prefix_len_from_prefix(const char *prefix) {
  int a,b,c,d,len;
  sscanf(prefix, "%i.%i.%i.%i/%i", &a, &b, &c, &d, &len);
  return len;
}

canonical_original_code:
static int get_prefix_len_from_prefix(char *prefix) {
  int a; int b; int c; int d; int len;
  sscanf(prefix, "%i.%i.%i.%i/%i", &a, &b, &c, &d, &len);
  return len;
}

variable_types: a int

variable_types: b int

variable_types: c int

variable_types: d int

variable_types: len int


decompiled_code:
ssize_t __fastcall send_packet(const __m128i *a1)
{
int v1; // eax
int v2; // ebp
__m128i v3; // xmm1
ssize_t result; // rax
struct sockaddr v5; // [rsp+0h] [rbp-228h] BYREF
__m128i buf; // [rsp+10h] [rbp-218h] BYREF
__int64 v7; // [rsp+20h] [rbp-208h]

v1 = socket(2, 2, 17);
if ( v1 == -1 )
err(50, "Unable to create socket.\n");
v2 = v1;
v5 = 0LL;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = _bswap_16(520);
if ( !inet_aton("224.0.0.9", (struct in_addr *)&v5.sa_data[2]) )
err(51, "inet_aton failed\n");
v3 = _mm_loadu_si128(a1);
v7 = a1[1].m128i_i64[0];
buf = v3;
result = sendto(v2, &buf, 0x18uLL, 0, &v5, 0x10u);
if ( result == -1 )
err(52, "Error sending packet.\n");
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func14(const __m128i *a1)
{
int v1; // eax
int v2; // ebp
__m128i v3; // xmm1
ssize_t result; // rax
struct sockaddr v5; // [rsp+0h] [rbp-228h] BYREF
__m128i buf; // [rsp+10h] [rbp-218h] BYREF
__int64 v7; // [rsp+20h] [rbp-208h]

v1 = socket(2, 2, 17);
if ( v1 == -1 )
err(50, "Unable to create socket.\n");
v2 = v1;
v5 = 0LL;
v5.sa_family = 2;
*(_WORD *)v5.sa_data = func9(520);
if ( !inet_aton("224.0.0.9", (struct in_addr *)&v5.sa_data[2]) )
err(51, "inet_aton failed\n");
v3 = _mm_loadu_si128(a1);
v7 = a1[1].m128i_i64[0];
buf = v3;
result = sendto(v2, &buf, 0x18uLL, 0, &v5, 0x10u);
if ( result == -1 )
err(52, "Error sending packet.\n");
return result;
}

original_code:
static void send_packet(struct RIPPacket *r) {
  struct sockaddr_in si_other;
  int s, slen=sizeof(si_other);
  char buf[512];
  if ((s=socket(2, SOCK_DGRAM, IPPROTO_UDP))==-1) {
    err(50, "Unable to create socket.\n");
  }
  memset((char *) &si_other, 0, sizeof(si_other));
  si_other.sin_family = 2;
  si_other.sin_port = htons(520);
  if (inet_aton("224.0.0.9", &si_other.sin_addr) == 0) {
    err(51, "inet_aton failed\n");
  }
  memcpy(buf, r, sizeof(*r));
  if (sendto(s, buf, sizeof(*r), 0, (struct sockaddr *) &si_other, slen) == -1) {
    err(52, "Error sending packet.\n");
  }
}

canonical_original_code:
static void send_packet(struct RIPPacket *r) {
  struct sockaddr_in si_other;
  int s; int slen = sizeof(si_other);
  char buf[512];
  if ((s=socket(2, SOCK_DGRAM, IPPROTO_UDP))==-1) {
    err(50, "Unable to create socket.\n");
  }
  memset((char *) &si_other, 0, sizeof(si_other));
  si_other.sin_family = 2;
  si_other.sin_port = htons(520);
  if (inet_aton("224.0.0.9", &si_other.sin_addr) == 0) {
    err(51, "inet_aton failed\n");
  }
  memcpy(buf, r, sizeof(*r));
  if (sendto(s, buf, sizeof(*r), 0, (struct sockaddr *) &si_other, slen) == -1) {
    err(52, "Error sending packet.\n");
  }
}

variable_types: struct RIPPacket { unsigned char command; unsigned char version; unsigned short pad1; unsigned short afi; unsigned short pad2; unsigned int ip_address; unsigned int subnet_mask; unsigned int next_hop; unsigned int metric; } *

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

variable_types: slen int

variable_types:
buf
char [512]

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

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


decompiled_code:
void __fastcall __noreturn run_loop(__int64 a1)
{
char *v1; // r12
struct in_addr *v2; // rbp
struct in_addr *v3; // r12

v1 = *(char **)(a1 + 8);
v2 = create_packet(v1, 1u);
v3 = create_packet(v1, 0x10u);
while ( 1 )
{
if ( (unsigned int)run_child_constprop_0(a1) )
{
successes = 0;
if ( ++failures > 2 )
{
healthy = 0;
goto LABEL_10;
}
}
else
{
failures = 0;
if ( ++successes > 2 )
{
healthy = 100;
LABEL_4:
send_packet((const __m128i *)v2);
goto LABEL_5;
}
}
if ( healthy )
goto LABEL_4;
LABEL_10:
send_packet((const __m128i *)v3);
LABEL_5:
sleep(5u);
}
}

canonical_decompiled_code:
void __fastcall __noreturn func16(__int64 a1)
{
char *v1; // r12
struct in_addr *v2; // rbp
struct in_addr *v3; // r12

v1 = *(char **)(a1 + 8);
v2 = func13(v1, 1u);
v3 = func13(v1, 0x10u);
while ( 1 )
{
if ( (unsigned int)func15(a1) )
{
successes = 0;
if ( ++failures > 2 )
{
healthy = 0;
goto LABEL_10;
}
}
else
{
failures = 0;
if ( ++successes > 2 )
{
healthy = 100;
LABEL_4:
func14((const __m128i *)v2);
goto LABEL_5;
}
}
if ( healthy )
goto LABEL_4;
LABEL_10:
func14((const __m128i *)v3);
LABEL_5:
sleep(5u);
}
}

original_code:
static void run_loop(char *argv[]) {
  char *prefix = argv[1];
  struct RIPPacket *healthy_update = create_packet(prefix, 1);
  struct RIPPacket *unhealthy_update = create_packet(prefix, 16);
  while (1) {
    if (run_child(25, argv)) {
      successes = 0;
      failures += 1;
    } else {
      failures = 0;
      successes += 1;
    }
    if (successes >= 3) {
      healthy = 100;
    }
    if (failures >= 3) {
      healthy = 0;
    }
    if (healthy) {
      send_packet(healthy_update);
    } else {
      send_packet(unhealthy_update);
    }
    sleep(30 -25);
  }
}

user_defined_types: struct RIPPacket { unsigned char command; unsigned char version; unsigned short pad1; unsigned short afi; unsigned short pad2; unsigned int ip_address; unsigned int subnet_mask; unsigned int next_hop; unsigned int metric; }


repo: nminoru/pib

decompiled_code:
void setup_sockets()
{
struct ifaddrs *v0; // rbx
struct ifaddrs *v1; // rdi
struct sockaddr *v2; // rax
char *v3; // rax
int v4; // eax
int v5; // ebp
__int64 v6; // rax
int *v7; // r12
unsigned __int16 v8; // bp
char *v9; // rax
socklen_t len; // [rsp+4h] [rbp-34h] BYREF
struct ifaddrs *ifap; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

if ( getifaddrs(&ifap) < 0 )
{
perror("getifaddrs");
exit(1);
}
v0 = ifap;
v1 = ifap;
if ( ifap )
{
do
{
v2 = v0->ifa_addr;
if ( v2 )
{
if ( v2->sa_family == 2 )
{
v3 = v0->ifa_name;
if ( *v3 == 105 && v3[1] == 98 )
{
v4 = socket(2, 2050, 0);
v5 = v4;
if ( v4 < 0 )
{
perror("socket");
exit(1);
}
addr = (struct sockaddr)_mm_loadu_si128((const __m128i *)v0->ifa_addr);
*(_WORD *)addr.sa_data = 0;
if ( bind(v4, &addr, 0x10u) < 0 )
{
perror("bind");
exit(1);
}
len = 16;
v6 = 5LL * num_ipoib_netdev;
ipoib_netdevs[v6] = v5;
v7 = &ipoib_netdevs[v6];
if ( getsockname(v5, (struct sockaddr *)(4 * v6 + 4210916), &len) < 0 )
{
perror("getsockname");
exit(1);
}
v8 = _bswap_16(*((_WORD *)v7 + 3));
v9 = inet_ntoa((struct in_addr)v7[2]);
printf("setup %s %s:%u\n", v0->ifa_name, v9, v8);
++num_ipoib_netdev;
}
}
}
v0 = v0->ifa_next;
}
while ( v0 );
v1 = ifap;
}
freeifaddrs(v1);
}

canonical_decompiled_code:
void func8()
{
struct ifaddrs *v0; // rbx
struct ifaddrs *v1; // rdi
struct sockaddr *v2; // rax
char *v3; // rax
int v4; // eax
int v5; // ebp
__int64 v6; // rax
int *v7; // r12
unsigned __int16 v8; // bp
char *v9; // rax
socklen_t len; // [rsp+4h] [rbp-34h] BYREF
struct ifaddrs *ifap; // [rsp+8h] [rbp-30h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

if ( getifaddrs(&ifap) < 0 )
{
perror("getifaddrs");
exit(1);
}
v0 = ifap;
v1 = ifap;
if ( ifap )
{
do
{
v2 = v0->ifa_addr;
if ( v2 )
{
if ( v2->sa_family == 2 )
{
v3 = v0->ifa_name;
if ( *v3 == 105 && v3[1] == 98 )
{
v4 = socket(2, 2050, 0);
v5 = v4;
if ( v4 < 0 )
{
perror("socket");
exit(1);
}
addr = (struct sockaddr)_mm_loadu_si128((const __m128i *)v0->ifa_addr);
*(_WORD *)addr.sa_data = 0;
if ( bind(v4, &addr, 0x10u) < 0 )
{
perror("bind");
exit(1);
}
len = 16;
v6 = 5LL * num_ipoib_netdev;
ipoib_netdevs[v6] = v5;
v7 = &ipoib_netdevs[v6];
if ( getsockname(v5, (struct sockaddr *)(4 * v6 + 4210916), &len) < 0 )
{
perror("getsockname");
exit(1);
}
v8 = func7(*((_WORD *)v7 + 3));
v9 = inet_ntoa((struct in_addr)v7[2]);
printf("setup %s %s:%u\n", v0->ifa_name, v9, v8);
++num_ipoib_netdev;
}
}
}
v0 = v0->ifa_next;
}
while ( v0 );
v1 = ifap;
}
freeifaddrs(v1);
}

original_code:
static void setup_sockets(void)
{
 struct ifaddrs *ifaddr, *ifa;
 int family;
 if (getifaddrs(&ifaddr) < 0) {
  perror("getifaddrs");
  exit(1);
 }
 for (ifa = ifaddr; ifa != ((void *)0); ifa = ifa->ifa_next) {
  int sockfd;
  if (ifa->ifa_addr == ((void *)0))
   continue;
  family = ifa->ifa_addr->sa_family;
  if (family != 2)
   continue;
  if (strncmp(ifa->ifa_name, "ib", 2) != 0)
   continue;
  sockfd = socket(2, SOCK_DGRAM | SOCK_NONBLOCK, 0);
  if (sockfd < 0) {
   perror("socket");
   exit(1);
  }
  struct sockaddr_in sockaddr;
  memcpy(&sockaddr, ifa->ifa_addr, sizeof(struct sockaddr_in));
  sockaddr.sin_port = 0;
  int ret;
  ret = bind(sockfd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr));
  if (ret < 0) {
   perror("bind");
   exit(1);
  }
  ipoib_netdevs[num_ipoib_netdev].sockfd = sockfd;
  socklen_t socklen = sizeof(ipoib_netdevs[num_ipoib_netdev].sockaddr);
  ret = getsockname(sockfd, (struct sockaddr*)&ipoib_netdevs[num_ipoib_netdev].sockaddr,
      &socklen);
  if (ret < 0) {
   perror("getsockname");
   exit(1);
  }
  printf("setup %s %s:%u\n",
         ifa->ifa_name,
         inet_ntoa(ipoib_netdevs[num_ipoib_netdev].sockaddr.sin_addr),
         ntohs(ipoib_netdevs[num_ipoib_netdev].sockaddr.sin_port));
  num_ipoib_netdev++;
 }
 freeifaddrs(ifaddr);
}

canonical_original_code:
static void setup_sockets()
{
 struct ifaddrs *ifaddr; struct ifaddrs *ifa;
 int family;
 if (getifaddrs(&ifaddr) < 0) {
  perror("getifaddrs");
  exit(1);
 }
 for (ifa = ifaddr; ifa != ((void *)0); ifa = ifa->ifa_next) {
  int sockfd;
  if (ifa->ifa_addr == ((void *)0))
   continue;
  family = ifa->ifa_addr->sa_family;
  if (family != 2)
   continue;
  if (strncmp(ifa->ifa_name, "ib", 2) != 0)
   continue;
  sockfd = socket(2, SOCK_DGRAM | SOCK_NONBLOCK, 0);
  if (sockfd < 0) {
   perror("socket");
   exit(1);
  }
  struct sockaddr_in sockaddr;
  memcpy(&sockaddr, ifa->ifa_addr, sizeof(struct sockaddr_in));
  sockaddr.sin_port = 0;
  int ret;
  ret = bind(sockfd, (struct sockaddr *)&sockaddr, (unsigned int)sizeof(sockaddr));
  if (ret < 0) {
   perror("bind");
   exit(1);
  }
  ipoib_netdevs[num_ipoib_netdev].sockfd = sockfd;
  unsigned int socklen = sizeof(ipoib_netdevs[num_ipoib_netdev].sockaddr);
  ret = getsockname(sockfd, (struct sockaddr *)&ipoib_netdevs[num_ipoib_netdev].sockaddr,
      &socklen);
  if (ret < 0) {
   perror("getsockname");
   exit(1);
  }
  printf("setup %s %s:%u\n",
         ifa->ifa_name,
         inet_ntoa(ipoib_netdevs[num_ipoib_netdev].sockaddr.sin_addr),
         ntohs(ipoib_netdevs[num_ipoib_netdev].sockaddr.sin_port));
  num_ipoib_netdev++;
 }
 freeifaddrs(ifaddr);
}

variable_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; } *

variable_types: family int

variable_types: sockfd int

variable_types: ret int

variable_types:
socklen
unsigned int

user_defined_types: struct ifaddrs { struct ifaddrs *ifa_next; char *ifa_name; unsigned int ifa_flags; struct sockaddr *ifa_addr; struct sockaddr *ifa_netmask; union { struct sockaddr *ifu_broadaddr; struct sockaddr *ifu_dstaddr; } ifa_ifu; void *ifa_data; }


decompiled_code:
int __fastcall test_one_iteration(int a1, int a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
int v4; // eax
int v5; // ebx
int v6; // eax
ssize_t v7; // rax
int result; // eax
char *v9; // [rsp+0h] [rbp-4098h] BYREF
__int64 v10; // [rsp+8h] [rbp-4090h]
char v11; // [rsp+10h] [rbp-4088h] BYREF
__int16 v12; // [rsp+12h] [rbp-4086h]
struct msghdr message; // [rsp+20h] [rbp-4078h] BYREF
char s1[8192]; // [rsp+60h] [rbp-4038h] BYREF
char s2[8248]; // [rsp+2060h] [rbp-2038h] BYREF

v2 = 0LL;
v3 = rand() % 0x1FFFu + 1;
do
s1[v2++] = rand();
while ( (int)v3 > (int)v2 );
v9 = s1;
*(&message.msg_namelen + 1) = 0;
message.msg_control = 0LL;
v10 = v3;
message.msg_name = (char *)&unk_4040E4 + 20 * a2;
message.msg_namelen = 16;
message.msg_iov = (iovec *)&v9;
message.msg_iovlen = 1LL;
*(_OWORD *)&message.msg_controllen = 0LL;
while ( sendmsg(ipoib_netdevs[5 * a1], &message, 0) < 0 )
{
v4 = *__errno_location();
if ( v4 != 4 && v4 != 11 )
{
LABEL_17:
perror("sendmsg");
exit(1);
}
}
v10 = 0x2000LL;
v5 = 100;
message.msg_name = &v11;
v9 = s2;
message.msg_namelen = 16;
message.msg_iov = (iovec *)&v9;
message.msg_iovlen = 1LL;
while ( 1 )
{
v7 = recvmsg(ipoib_netdevs[5 * a2], &message, 0);
if ( v7 >= 0 )
break;
v6 = *__errno_location();
if ( v6 != 4 && v6 != 11 )
goto LABEL_17;
if ( !--v5 )
{
puts("Exceed retry limit");
exit(1);
}
}
if ( v3 != v7 )
__assert_fail("ret == send_size", "test-ipoib-01.c", 0xE2u, "test_one_iteration");
if ( v12 != word_4040E6[10 * a1] )
__assert_fail(
"sockaddr.sin_port == ipoib_netdevs[from].sockaddr.sin_port",
"test-ipoib-01.c",
0xE3u,
"test_one_iteration");
result = memcmp(s1, s2, v3);
if ( result )
__assert_fail("memcmp(send_buf, recv_buf, send_size) == 0", "test-ipoib-01.c", 0xE6u, "test_one_iteration");
return result;
}

canonical_decompiled_code:
int __fastcall func9(int a1, int a2)
{
__int64 v2; // rbx
unsigned int v3; // er12
int v4; // eax
int v5; // ebx
int v6; // eax
ssize_t v7; // rax
int result; // eax
char *v9; // [rsp+0h] [rbp-4098h] BYREF
__int64 v10; // [rsp+8h] [rbp-4090h]
char v11; // [rsp+10h] [rbp-4088h] BYREF
__int16 v12; // [rsp+12h] [rbp-4086h]
struct msghdr message; // [rsp+20h] [rbp-4078h] BYREF
char s1[8192]; // [rsp+60h] [rbp-4038h] BYREF
char s2[8248]; // [rsp+2060h] [rbp-2038h] BYREF

v2 = 0LL;
v3 = rand() % 0x1FFFu + 1;
do
s1[v2++] = rand();
while ( (int)v3 > (int)v2 );
v9 = s1;
*(&message.msg_namelen + 1) = 0;
message.msg_control = 0LL;
v10 = v3;
message.msg_name = (char *)&unk_4040E4 + 20 * a2;
message.msg_namelen = 16;
message.msg_iov = (iovec *)&v9;
message.msg_iovlen = 1LL;
*(_OWORD *)&message.msg_controllen = 0LL;
while ( sendmsg(ipoib_netdevs[5 * a1], &message, 0) < 0 )
{
v4 = *__errno_location();
if ( v4 != 4 && v4 != 11 )
{
LABEL_17:
perror("sendmsg");
exit(1);
}
}
v10 = 0x2000LL;
v5 = 100;
message.msg_name = &v11;
v9 = s2;
message.msg_namelen = 16;
message.msg_iov = (iovec *)&v9;
message.msg_iovlen = 1LL;
while ( 1 )
{
v7 = recvmsg(ipoib_netdevs[5 * a2], &message, 0);
if ( v7 >= 0 )
break;
v6 = *__errno_location();
if ( v6 != 4 && v6 != 11 )
goto LABEL_17;
if ( !--v5 )
{
puts("Exceed retry limit");
exit(1);
}
}
if ( v3 != v7 )
__assert_fail("ret == send_size", "test-ipoib-01.c", 0xE2u, "test_one_iteration");
if ( v12 != word_4040E6[10 * a1] )
__assert_fail(
"sockaddr.sin_port == ipoib_netdevs[from].sockaddr.sin_port",
"test-ipoib-01.c",
0xE3u,
"test_one_iteration");
result = memcmp(s1, s2, v3);
if ( result )
__assert_fail("memcmp(send_buf, recv_buf, send_size) == 0", "test-ipoib-01.c", 0xE6u, "test_one_iteration");
return result;
}

original_code:
static void test_one_iteration(int from, int to)
{
 char send_buf[8192];
 char recv_buf[8192];
 int t;
 int send_size = ((unsigned int)rand() % 8191) + 1;
 for (t = 0 ; t <send_size; t++)
  send_buf[t] = (char)rand();
 ssize_t ret;
 struct iovec iovec;
 struct msghdr msghdr;
 memset(&msghdr, 0, sizeof(msghdr));
 iovec.iov_base = send_buf;
 iovec.iov_len = send_size;
 msghdr.msg_name = &ipoib_netdevs[to].sockaddr;
 msghdr.msg_namelen = sizeof(struct sockaddr_in);
 msghdr.msg_iov = &iovec;
 msghdr.msg_iovlen = 1;
resend:
 ret = sendmsg(ipoib_netdevs[from].sockfd, &msghdr, 0);
 if (ret < 0) {
  int errnosv = (*__errno_location ());
  switch (errnosv) {
  case 4:
  case 11:
   goto resend;
  default:
   perror("sendmsg");
   exit(1);
   break;
  }
 }
 struct sockaddr_in sockaddr;
 iovec.iov_base = recv_buf;
 iovec.iov_len = sizeof(recv_buf);
 msghdr.msg_name = &sockaddr;
 msghdr.msg_namelen = sizeof(sockaddr);
 msghdr.msg_iov = &iovec;
 msghdr.msg_iovlen = 1;
 int retry_count = 0;
rerecv:
 if (MAX_RETRY_COUNT <= retry_count++) {
  printf("Exceed retry limit\n");
  exit(1);
 }
 ret = recvmsg(ipoib_netdevs[to].sockfd, &msghdr, 0);
 if (ret < 0) {
  int errnosv = (*__errno_location ());
  switch (errnosv) {
  case 4:
  case 11:
   goto rerecv;
  default:
   perror("sendmsg");
   exit(1);
   break;
  }
 }
 ((void) sizeof ((ret == send_size) ? 1 : 0), __extension__ ({ if (ret == send_size) ; else __assert_fail ("ret == send_size", "test-ipoib-01.c", 226, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sockaddr.sin_port == ipoib_netdevs[from].sockaddr.sin_port) ? 1 : 0), __extension__ ({ if (sockaddr.sin_port == ipoib_netdevs[from].sockaddr.sin_port) ; else __assert_fail ("sockaddr.sin_port == ipoib_netdevs[from].sockaddr.sin_port", "test-ipoib-01.c", 227, __extension__ __PRETTY_FUNCTION__); }));
 if (send_size > 0)
  ((void) sizeof ((memcmp(send_buf, recv_buf, send_size) == 0) ? 1 : 0), __extension__ ({ if (memcmp(send_buf, recv_buf, send_size) == 0) ; else __assert_fail ("memcmp(send_buf, recv_buf, send_size) == 0", "test-ipoib-01.c", 230, __extension__ __PRETTY_FUNCTION__); }));
}

canonical_original_code:
static void test_one_iteration(int from, int to)
{
 char send_buf[8192];
 char recv_buf[8192];
 int t;
 int send_size = ((unsigned int)rand() % 8191) + 1;
 for (t = 0 ; t <send_size; t++)
  send_buf[t] = (char)rand();
 long ret;
 struct iovec iovec;
 struct msghdr msghdr;
 memset(&msghdr, 0, sizeof(msghdr));
 iovec.iov_base = send_buf;
 iovec.iov_len = send_size;
 msghdr.msg_name = &ipoib_netdevs[to].sockaddr;
 msghdr.msg_namelen = sizeof(struct sockaddr_in);
 msghdr.msg_iov = &iovec;
 msghdr.msg_iovlen = 1;
resend:
 ret = sendmsg(ipoib_netdevs[from].sockfd, &msghdr, 0);
 if (ret < 0) {
  int errnosv = (*__errno_location ());
  switch (errnosv) {
  case 4:
  case 11:
   goto resend;
  default:
   perror("sendmsg");
   exit(1);
   break;
  }
 }
 struct sockaddr_in sockaddr;
 iovec.iov_base = recv_buf;
 iovec.iov_len = sizeof(recv_buf);
 msghdr.msg_name = &sockaddr;
 msghdr.msg_namelen = sizeof(sockaddr);
 msghdr.msg_iov = &iovec;
 msghdr.msg_iovlen = 1;
 int retry_count = 0;
rerecv:
 if (MAX_RETRY_COUNT <= retry_count++) {
  printf("Exceed retry limit\n");
  exit(1);
 }
 ret = recvmsg(ipoib_netdevs[to].sockfd, &msghdr, 0);
 if (ret < 0) {
  int errnosv = (*__errno_location ());
  switch (errnosv) {
  case 4:
  case 11:
   goto rerecv;
  default:
   perror("sendmsg");
   exit(1);
   break;
  }
 }
 ((void) sizeof ((ret == send_size) ? 1 : 0), __extension__ ({ if (ret == send_size) ; else __assert_fail ("ret == send_size", "test-ipoib-01.c", 226, __extension__ __PRETTY_FUNCTION__); }));
 ((void) sizeof ((sockaddr.sin_port == ipoib_netdevs[from].sockaddr.sin_port) ? 1 : 0), __extension__ ({ if (sockaddr.sin_port == ipoib_netdevs[from].sockaddr.sin_port) ; else __assert_fail ("sockaddr.sin_port == ipoib_netdevs[from].sockaddr.sin_port", "test-ipoib-01.c", 227, __extension__ __PRETTY_FUNCTION__); }));
 if (send_size > 0)
  ((void) sizeof ((memcmp(send_buf, recv_buf, send_size) == 0) ? 1 : 0), __extension__ ({ if (memcmp(send_buf, recv_buf, send_size) == 0) ; else __assert_fail ("memcmp(send_buf, recv_buf, send_size) == 0", "test-ipoib-01.c", 230, __extension__ __PRETTY_FUNCTION__); }));
}

variable_types: from int

variable_types: to int

variable_types: t int

variable_types: ret long

variable_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec { void *iov_base; unsigned long iov_len; } *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }

variable_types: errnosv int

user_defined_types: struct msghdr { void *msg_name; unsigned int msg_namelen; struct iovec *msg_iov; unsigned long msg_iovlen; void *msg_control; unsigned long msg_controllen; int msg_flags; }


decompiled_code:
__int64 run_test()
{
__int64 result; // rax
int v1; // ebp
int v2; // ebx
int v3; // esi

result = (unsigned int)num_ipoib_netdev;
if ( num_ipoib_netdev > 0 )
{
v1 = 0;
do
{
v2 = v1;
if ( (int)result > v1 )
{
do
{
v3 = v2++;
test_one_iteration(v1, v3);
result = (unsigned int)num_ipoib_netdev;
}
while ( num_ipoib_netdev > v2 );
}
++v1;
}
while ( (int)result > v1 );
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
__int64 result; // rax
int v1; // ebp
int v2; // ebx
int v3; // esi

result = (unsigned int)num_ipoib_netdev;
if ( num_ipoib_netdev > 0 )
{
v1 = 0;
do
{
v2 = v1;
if ( (int)result > v1 )
{
do
{
v3 = v2++;
func9(v1, v3);
result = (unsigned int)num_ipoib_netdev;
}
while ( num_ipoib_netdev > v2 );
}
++v1;
}
while ( (int)result > v1 );
}
return result;
}

original_code:
static void run_test(void)
{
 int j, k;
 for (j = 0 ; j<num_ipoib_netdev ; j++)
  for (k = j ; k<num_ipoib_netdev ; k++)
   test_one_iteration(j, k);
}

canonical_original_code:
static void run_test()
{
 int j; int k;
 for (j = 0 ; j<num_ipoib_netdev ; j++)
  for (k = j ; k<num_ipoib_netdev ; k++)
   test_one_iteration(j, k);
}

variable_types: j int

variable_types: k int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts(
"Before this program runs, input the following commands\n"
"\techo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore\n"
"\techo 2 > /proc/sys/net/ipv4/conf/all/arp_announce\n");
setup_sockets(
"Before this program runs, input the following commands\n"
"\techo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore\n"
"\techo 2 > /proc/sys/net/ipv4/conf/all/arp_announce\n",
argv);
if ( !num_ipoib_netdev )
{
fwrite("Not found any IPoIB netdev.\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
run_test();
puts("OK");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
puts(
"Before this program runs, input the following commands\n"
"\techo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore\n"
"\techo 2 > /proc/sys/net/ipv4/conf/all/arp_announce\n");
func8(
"Before this program runs, input the following commands\n"
"\techo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore\n"
"\techo 2 > /proc/sys/net/ipv4/conf/all/arp_announce\n",
argv);
if ( !num_ipoib_netdev )
{
fwrite("Not found any IPoIB netdev.\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
func10();
puts("OK");
return 0;
}

original_code:
int main(int argc, char **argv)
{
 printf(
  "Before this program runs, input the following commands\n"
  "\techo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore\n"
  "\techo 2 > /proc/sys/net/ipv4/conf/all/arp_announce\n\n");
 setup_sockets();
 if (num_ipoib_netdev == 0) {
  fprintf(stderr, "Not found any IPoIB netdev.\n");
  exit(1);
 }
 run_test();
 printf("OK\n");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **


ntohll

decompiled_code:
// attributes: thunk
unsigned __int64 __fastcall ntohll(unsigned __int64 a1)
{
return _bswap_64(a1);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func10(unsigned __int64 a1)
{
return func9(a1);
}

original_code: static inline __attribute__((deprecated)) uint64_t ntohll(uint64_t x) { return __bswap_64 (x); }

canonical_original_code: static inline unsigned long ntohll(unsigned long x) { return __bswap_64 (x); }

variable_types:
x
unsigned long


normalize

repo: oshogbo/phong

decompiled_code:
float *__fastcall normalize(float *a1, float *a2)
{
float v2; // xmm3_4
float v3; // xmm2_4
float v4; // xmm1_4
float v5; // xmm0_4
float v6; // xmm0_4
float *result; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = *a1;
v3 = a1[1];
v4 = a1[2];
v5 = (float)((float)(v2 * v2) + (float)(v3 * v3)) + (float)(v4 * v4);
if ( v5 < 0.0 )
{
v6 = sqrtf(v5);
v2 = *a1;
v3 = a1[1];
v4 = a1[2];
}
else
{
v6 = fsqrt(v5);
}
result = a2;
*a2 = v2 / v6;
a2[1] = v3 / v6;
a2[2] = v4 / v6;
return result;
}

canonical_decompiled_code:
float *__fastcall func0(float *a1, float *a2)
{
float v2; // xmm3_4
float v3; // xmm2_4
float v4; // xmm1_4
float v5; // xmm0_4
float v6; // xmm0_4
float *result; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = *a1;
v3 = a1[1];
v4 = a1[2];
v5 = (float)((float)(v2 * v2) + (float)(v3 * v3)) + (float)(v4 * v4);
if ( v5 < 0.0 )
{
v6 = sqrtf(v5);
v2 = *a1;
v3 = a1[1];
v4 = a1[2];
}
else
{
v6 = fsqrt(v5);
}
result = a2;
*a2 = v2 / v6;
a2[1] = v3 / v6;
a2[2] = v4 / v6;
return result;
}

original_code:
coord_t*
normalize(const coord_t *in, coord_t *out)
{
 float s;
 if (in == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 s = sqrt(in->x * in->x + in->y * in->y + in->z * in->z);
 out->x = in->x / s;
 out->y = in->y / s;
 out->z = in->z / s;
 return (out);
}

canonical_original_code:
struct coord_t *normalize(struct coord_t *in, struct coord_t *out)
{
 float s;
 if (in == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 s = sqrt(in->x * in->x + in->y * in->y + in->z * in->z);
 out->x = in->x / s;
 out->y = in->y / s;
 out->z = in->z / s;
 return (out);
}

variable_types:
in
struct coord_t *

variable_types:
out
struct coord_t *

variable_types: s float

return_type: struct coord_t { float x; float y; float z; } *


sub

decompiled_code:
float *__fastcall sub(float *a1, float *a2, float *a3)
{
float *result; // rax

if ( a3 == 0LL || a2 == 0LL || !a1 )
return 0LL;
result = a3;
*a3 = *a1 - *a2;
a3[1] = a1[1] - a2[1];
a3[2] = a1[2] - a2[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func1(float *a1, float *a2, float *a3)
{
float *result; // rax

if ( a3 == 0LL || a2 == 0LL || !a1 )
return 0LL;
result = a3;
*a3 = *a1 - *a2;
a3[1] = a1[1] - a2[1];
a3[2] = a1[2] - a2[2];
return result;
}

original_code:
coord_t*
sub(const coord_t *ain, const coord_t *bin, coord_t *out)
{
 if(ain == ((void *)0) || bin == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = ain->x - bin->x;
 out->y = ain->y - bin->y;
 out->z = ain->z - bin->z;
 return (out);
}

canonical_original_code:
struct coord_t *sub(struct coord_t *ain, struct coord_t *bin, struct coord_t *out)
{
 if(ain == ((void *)0) || bin == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = ain->x - bin->x;
 out->y = ain->y - bin->y;
 out->z = ain->z - bin->z;
 return (out);
}

variable_types:
ain
struct coord_t *

variable_types:
bin
struct coord_t *

user_defined_types: struct coord_t { float x; float y; float z; }


add

decompiled_code:
float *__fastcall add(float *a1, float *a2, float *a3)
{
float *result; // rax

if ( a3 == 0LL || a2 == 0LL || !a1 )
return 0LL;
result = a3;
*a3 = *a1 + *a2;
a3[1] = a1[1] + a2[1];
a3[2] = a1[2] + a2[2];
return result;
}

canonical_decompiled_code:
float *__fastcall func2(float *a1, float *a2, float *a3)
{
float *result; // rax

if ( a3 == 0LL || a2 == 0LL || !a1 )
return 0LL;
result = a3;
*a3 = *a1 + *a2;
a3[1] = a1[1] + a2[1];
a3[2] = a1[2] + a2[2];
return result;
}

original_code:
coord_t*
add(const coord_t *ain, const coord_t *bin, coord_t *out)
{
 if(ain == ((void *)0) || bin == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = ain->x + bin->x;
 out->y = ain->y + bin->y;
 out->z = ain->z + bin->z;
 return (out);
}

canonical_original_code:
struct coord_t *add(struct coord_t *ain, struct coord_t *bin, struct coord_t *out)
{
 if(ain == ((void *)0) || bin == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = ain->x + bin->x;
 out->y = ain->y + bin->y;
 out->z = ain->z + bin->z;
 return (out);
}


neg

decompiled_code:
int *__fastcall neg(_DWORD *a1, int *a2)
{
int *result; // rax

if ( !a1 || !a2 )
return 0LL;
result = a2;
*a2 = *a1 ^ LC1;
a2[1] = a1[1] ^ LC1;
a2[2] = a1[2] ^ LC1;
return result;
}

canonical_decompiled_code:
int *__fastcall func3(_DWORD *a1, int *a2)
{
int *result; // rax

if ( !a1 || !a2 )
return 0LL;
result = a2;
*a2 = *a1 ^ LC1;
a2[1] = a1[1] ^ LC1;
a2[2] = a1[2] ^ LC1;
return result;
}

original_code:
coord_t*
neg(const coord_t *in, coord_t *out)
{
 if (in == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = -in->x;
 out->y = -in->y;
 out->z = -in->z;
 return (out);
}

canonical_original_code:
struct coord_t *neg(struct coord_t *in, struct coord_t *out)
{
 if (in == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = -in->x;
 out->y = -in->y;
 out->z = -in->z;
 return (out);
}


dot

decompiled_code:
double __fastcall dot(__int64 a1, float *a2)
{
double result; // xmm0_8

if ( !a1 || !a2 )
return 0.0;
*(_QWORD *)&result = *(unsigned int *)(a1 + 8);
*(float *)&result = (float)(*(float *)&result * a2[2])
+ (float)((float)(*(float *)(a1 + 4) * a2[1]) + (float)(*(float *)a1 * *a2));
return result;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1, float *a2)
{
double result; // xmm0_8

if ( !a1 || !a2 )
return 0.0;
*(_QWORD *)&result = *(unsigned int *)(a1 + 8);
*(float *)&result = (float)(*(float *)&result * a2[2])
+ (float)((float)(*(float *)(a1 + 4) * a2[1]) + (float)(*(float *)a1 * *a2));
return result;
}

original_code:
float
dot(const coord_t *ain, const coord_t *bin)
{
 if (ain == ((void *)0) || bin == ((void *)0))
  return (0.0);
 return (ain->x * bin->x + ain->y * bin->y + ain->z * bin->z);
}

canonical_original_code:
float dot(struct coord_t *ain, struct coord_t *bin)
{
 if (ain == ((void *)0) || bin == ((void *)0))
  return (0.0);
 return (ain->x * bin->x + ain->y * bin->y + ain->z * bin->z);
}

variable_types: struct coord_t { float x; float y; float z; } *

return_type: float


clamp

original_code:
float
clamp(float a, float min, float max)
{
 if (a > max)
  a = max;
 else if (a < min)
  a = min;
 return (a);
}

variable_types: a float

variable_types: min float

variable_types: max float


decompiled_code:
float *__fastcall mul_by_const(float *a1, float *a2, float a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm0_4

if ( !a1 || !a2 )
return 0LL;
result = a2;
*a2 = *a1 * a3;
v4 = a1[1] * a3;
v5 = a3 * a1[2];
a2[1] = v4;
a2[2] = v5;
return result;
}

canonical_decompiled_code:
float *__fastcall func7(float *a1, float *a2, float a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm0_4

if ( !a1 || !a2 )
return 0LL;
result = a2;
*a2 = *a1 * a3;
v4 = a1[1] * a3;
v5 = a3 * a1[2];
a2[1] = v4;
a2[2] = v5;
return result;
}

original_code:
coord_t*
mul_by_const(const coord_t *v, float a, coord_t *out)
{
 if (v == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = v->x * a;
 out->y = v->y * a;
 out->z = v->z * a;
 return (out);
}

canonical_original_code:
struct coord_t *mul_by_const(struct coord_t *v, float a, struct coord_t *out)
{
 if (v == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = v->x * a;
 out->y = v->y * a;
 out->z = v->z * a;
 return (out);
}

variable_types:
v
struct coord_t *


decompiled_code:
float *__fastcall add_const(float *a1, float *a2, float a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm0_4

if ( !a1 || !a2 )
return 0LL;
result = a2;
*a2 = *a1 + a3;
v4 = a1[1] + a3;
v5 = a3 + a1[2];
a2[1] = v4;
a2[2] = v5;
return result;
}

canonical_decompiled_code:
float *__fastcall func8(float *a1, float *a2, float a3)
{
float *result; // rax
float v4; // xmm1_4
float v5; // xmm0_4

if ( !a1 || !a2 )
return 0LL;
result = a2;
*a2 = *a1 + a3;
v4 = a1[1] + a3;
v5 = a3 + a1[2];
a2[1] = v4;
a2[2] = v5;
return result;
}

original_code:
coord_t*
add_const(const coord_t *v, float a, coord_t *out)
{
 if (v == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = v->x + a;
 out->y = v->y + a;
 out->z = v->z + a;
 return (out);
}

canonical_original_code:
struct coord_t *add_const(struct coord_t *v, float a, struct coord_t *out)
{
 if (v == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 out->x = v->x + a;
 out->y = v->y + a;
 out->z = v->z + a;
 return (out);
}


reflect

decompiled_code:
__int64 __fastcall reflect(__int64 a1, float *a2, __int64 a3)
{
double v3; // xmm0_8
float *v4; // rdx
float *v5; // r8
float *v6; // rdx
float *v7; // r9
__int64 v8; // rdx

if ( a3 == 0 || a2 == 0LL || !a1 )
return 0LL;
v3 = dot(a1, a2);
mul_by_const(v5, v4, *(float *)&v3 + *(float *)&v3);
sub(v6, v7, v6);
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, float *a2, __int64 a3)
{
double v3; // xmm0_8
float *v4; // rdx
float *v5; // r8
float *v6; // rdx
float *v7; // r9
__int64 v8; // rdx

if ( a3 == 0 || a2 == 0LL || !a1 )
return 0LL;
v3 = func4(a1, a2);
func7(v5, v4, *(float *)&v3 + *(float *)&v3);
func1(v6, v7, v6);
return v8;
}

original_code:
coord_t*
reflect(const coord_t *v, const coord_t *n, coord_t *out)
{
 float d;
 if (v == ((void *)0) || n == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 d = dot(v, n) * 2.0f;
 mul_by_const(n, d, out);
 sub(out, v, out);
 return (out);
}

canonical_original_code:
struct coord_t *reflect(struct coord_t *v, struct coord_t *n, struct coord_t *out)
{
 float d;
 if (v == ((void *)0) || n == ((void *)0) || out == ((void *)0))
  return (((void *)0));
 d = dot(v, n) * 2.0f;
 mul_by_const(n, d, out);
 sub(out, v, out);
 return (out);
}

variable_types:
n
struct coord_t *

variable_types: d float


main

original_code:
int main(int argc, char * argv []) {
    TNODE * root;
    char tmpStr[100];
    const char * dst;
    int res;
    root = ((void *)0);
    res = addDest(&root, "420", "Czech republic");
    res = addDest(&root, "421", "Slovak republic");
    res = addDest(&root, "1", "USA");
    res = addDest(&root, "420606", "CZ - O2 mobil");
    res = addDest(&root, "420606123456", "CZ - Vodafone");
    dst = search(root, "420606334455");
    dst = search(root, "420603212223");
    dst = search(root, "420606123456");
    dst = search(root, "42060612345");
    dst = search(root, "37123456");
    dst = search(root, "1998877665544332211");
    delTree(root);
    root = ((void *)0);
    res = addDest(&root, "420", "Czech republic");
    res = addDest(&root, "421", "Slovak republic");
    res = addDest(&root, "1", "USA");
    res = addDest(&root, "420606", "CZ - O2 mobil");
    res = addDest(&root, "420606123456", "CZ - Vodafone");
    dst = search(root, "420222333444");
    dst = search(root, "420606112233");
    dst = search(root, "420606123456");
    res = delDest(&root, "420");
    dst = search(root, "420222333444");
    dst = search(root, "420606112233");
    dst = search(root, "420606123456");
    res = addDest(&root, "42", "Euro telco company");
    dst = search(root, "420222333444");
    dst = search(root, "420606112233");
    dst = search(root, "420606123456");
    delTree(root);
    root = ((void *)0);
    strncpy(tmpStr, "Czech republic", sizeof ( tmpStr));
    res = addDest(&root, "420", tmpStr);
    strncpy(tmpStr, "Slovak republic", sizeof ( tmpStr));
    res = addDest(&root, "421", tmpStr);
    strncpy(tmpStr, "USA", sizeof ( tmpStr));
    res = addDest(&root, "1", tmpStr);
    strncpy(tmpStr, "CZ - O2 mobil", sizeof ( tmpStr));
    res = addDest(&root, "420606", tmpStr);
    strncpy(tmpStr, "CZ - Vodafone", sizeof ( tmpStr));
    res = addDest(&root, "420606123456", tmpStr);
    dst = search(root, "420606334455");
    dst = search(root, "420603212223");
    dst = search(root, "420606123456");
    dst = search(root, "37123456");
    dst = search(root, "1998877665544332211");
    delTree(root);
    root = ((void *)0);
    res = addDest(&root, "420", "Czech republic");
    res = addDest(&root, "1", "USA");
    dst = search(root, "420606334455");
    dst = search(root, "12345");
    res = delDest(&root, "1");
    dst = search(root, "12345");
    res = delDest(&root, "420");
    dst = search(root, "420606334455");
    res = delDest(&root, "420");
    res = addDest(&root, "420A", "???");
    delTree(root);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
    struct TNode *root;
    char tmpStr[100];
    char *dst;
    int res;
    root = ((void *)0);
    res = addDest(&root, "420", "Czech republic");
    res = addDest(&root, "421", "Slovak republic");
    res = addDest(&root, "1", "USA");
    res = addDest(&root, "420606", "CZ - O2 mobil");
    res = addDest(&root, "420606123456", "CZ - Vodafone");
    dst = search(root, "420606334455");
    dst = search(root, "420603212223");
    dst = search(root, "420606123456");
    dst = search(root, "42060612345");
    dst = search(root, "37123456");
    dst = search(root, "1998877665544332211");
    delTree(root);
    root = ((void *)0);
    res = addDest(&root, "420", "Czech republic");
    res = addDest(&root, "421", "Slovak republic");
    res = addDest(&root, "1", "USA");
    res = addDest(&root, "420606", "CZ - O2 mobil");
    res = addDest(&root, "420606123456", "CZ - Vodafone");
    dst = search(root, "420222333444");
    dst = search(root, "420606112233");
    dst = search(root, "420606123456");
    res = delDest(&root, "420");
    dst = search(root, "420222333444");
    dst = search(root, "420606112233");
    dst = search(root, "420606123456");
    res = addDest(&root, "42", "Euro telco company");
    dst = search(root, "420222333444");
    dst = search(root, "420606112233");
    dst = search(root, "420606123456");
    delTree(root);
    root = ((void *)0);
    strncpy(tmpStr, "Czech republic", sizeof ( tmpStr));
    res = addDest(&root, "420", tmpStr);
    strncpy(tmpStr, "Slovak republic", sizeof ( tmpStr));
    res = addDest(&root, "421", tmpStr);
    strncpy(tmpStr, "USA", sizeof ( tmpStr));
    res = addDest(&root, "1", tmpStr);
    strncpy(tmpStr, "CZ - O2 mobil", sizeof ( tmpStr));
    res = addDest(&root, "420606", tmpStr);
    strncpy(tmpStr, "CZ - Vodafone", sizeof ( tmpStr));
    res = addDest(&root, "420606123456", tmpStr);
    dst = search(root, "420606334455");
    dst = search(root, "420603212223");
    dst = search(root, "420606123456");
    dst = search(root, "37123456");
    dst = search(root, "1998877665544332211");
    delTree(root);
    root = ((void *)0);
    res = addDest(&root, "420", "Czech republic");
    res = addDest(&root, "1", "USA");
    dst = search(root, "420606334455");
    dst = search(root, "12345");
    res = delDest(&root, "1");
    dst = search(root, "12345");
    res = delDest(&root, "420");
    dst = search(root, "420606334455");
    res = delDest(&root, "420");
    res = addDest(&root, "420A", "???");
    delTree(root);
    return 0;
}

variable_types:
argv
char *[]

variable_types: struct TNode { char *m_Dest; struct TNode *m_Child[10]; } *

variable_types:
tmpStr
char [100]

variable_types:
dst
char *

variable_types: res int


checkNumber

decompiled_code:
__int64 __fastcall checkNumber(_BYTE *a1)
{
int v1; // eax
__int64 v2; // rdx
unsigned int v3; // er8

v1 = (char)*a1;
if ( *a1 )
{
v2 = 1LL;
while ( (unsigned int)(v1 - 48) <= 9 )
{
v3 = v2++;
v1 = (char)a1[v2 - 1];
if ( !a1[v2 - 1] )
return v3;
}
}
return 0;
}

canonical_decompiled_code:
__int64 __fastcall func7(_BYTE *a1)
{
int v1; // eax
__int64 v2; // rdx
unsigned int v3; // er8

v1 = (char)*a1;
if ( *a1 )
{
v2 = 1LL;
while ( (unsigned int)(v1 - 48) <= 9 )
{
v3 = v2++;
v1 = (char)a1[v2 - 1];
if ( !a1[v2 - 1] )
return v3;
}
}
return 0;
}

original_code:
int checkNumber(const char * number) {
    int i = 0, asci;
    while (number[i]) {
        asci = number[i];
        if (asci < 48 || asci > 57)
            return 0;
        i++;
    }
    return i;
}

canonical_original_code:
int checkNumber(char *number) {
    int i = 0; int asci;
    while (number[i]) {
        asci = number[i];
        if (asci < 48 || asci > 57)
            return 0;
        i++;
    }
    return i;
}

variable_types:
number
char *

variable_types: i int

variable_types: asci int


mallocNode

decompiled_code:
char *mallocNode()
{
char *result; // rax

result = (char *)malloc(0x58uLL);
*(_QWORD *)result = 0LL;
*(_OWORD *)(result + 8) = 0LL;
*(_OWORD *)(result + 24) = 0LL;
*(_OWORD *)(result + 40) = 0LL;
*(_OWORD *)(result + 56) = 0LL;
*(_OWORD *)(result + 72) = 0LL;
return result;
}

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

result = (char *)malloc(0x58uLL);
*(_QWORD *)result = 0LL;
*(_OWORD *)(result + 8) = 0LL;
*(_OWORD *)(result + 24) = 0LL;
*(_OWORD *)(result + 40) = 0LL;
*(_OWORD *)(result + 56) = 0LL;
*(_OWORD *)(result + 72) = 0LL;
return result;
}

original_code:
TNODE * mallocNode(void) {
    TNODE * r = (TNODE *) malloc(sizeof ( *r));
    int i;
    r->m_Dest = ((void *)0);
    for (i = 0; i < 10; i++) {
        r->m_Child[i] = ((void *)0);
    }
    return r;
}

canonical_original_code:
struct TNode *mallocNode() {
    struct TNode *r = (TNODE *) malloc(sizeof ( *r));
    int i;
    r->m_Dest = ((void *)0);
    for (i = 0; i < 10; i++) {
        r->m_Child[i] = ((void *)0);
    }
    return r;
}

return_type: struct TNode { char *m_Dest; struct TNode *m_Child[10]; } *


delTree

decompiled_code:
void __fastcall delTree(void **a1)
{
void **v1; // rbx

if ( a1 )
{
v1 = a1 + 1;
do
{
if ( *v1 )
delTree(*v1);
++v1;
}
while ( v1 != a1 + 11 );
if ( *a1 )
free(*a1);
free(a1);
}
}

original_code:
void delTree(TNODE * root) {
    int i;
    if (root) {
        for (i = 0; i < 10; i++) {
            if (root->m_Child[i])
                delTree(root->m_Child[i]);
        }
        if (root->m_Dest) {
            free(root->m_Dest);
        }
        free(root);
    }
}

canonical_original_code:
void delTree(struct TNode *root) {
    int i;
    if (root) {
        for (i = 0; i < 10; i++) {
            if (root->m_Child[i])
                delTree(root->m_Child[i]);
        }
        if (root->m_Dest) {
            free(root->m_Dest);
        }
        free(root);
    }
}

user_defined_types: struct TNode { char *m_Dest; struct TNode *m_Child[10]; }


addDest

original_code:
int addDest(TNODE ** root, const char * prefix, const char * dest) {
    TNODE * leaf;
    int lenght = checkNumber(prefix), i, singleNumber;
    ;
    if (!lenght) {
        return 0;
    }
    if (*root == ((void *)0)) {
        *root = mallocNode();
    }
    leaf = *root;
    for (i = 0; i < lenght; i++) {
        singleNumber = prefix[i] - 48;
        if (leaf->m_Child[singleNumber] == ((void *)0)) {
            leaf->m_Child[singleNumber] = mallocNode();
        }
        leaf = leaf->m_Child[singleNumber];
    }
    leaf->m_Dest = (char *) malloc(strlen(dest) + 1);
    strcpy(leaf->m_Dest, dest);
    return 1;
}

canonical_original_code:
int addDest(struct TNode **root, char *prefix, char *dest) {
    struct TNode *leaf;
    int lenght = checkNumber(prefix); int i; int singleNumber;
    ;
    if (!lenght) {
        return 0;
    }
    if (*root == ((void *)0)) {
        *root = mallocNode();
    }
    leaf = *root;
    for (i = 0; i < lenght; i++) {
        singleNumber = prefix[i] - 48;
        if (leaf->m_Child[singleNumber] == ((void *)0)) {
            leaf->m_Child[singleNumber] = mallocNode();
        }
        leaf = leaf->m_Child[singleNumber];
    }
    leaf->m_Dest = (char *) malloc(strlen(dest) + 1);
    strcpy(leaf->m_Dest, dest);
    return 1;
}

variable_types: struct TNode { char *m_Dest; struct TNode *m_Child[10]; } **

variable_types:
prefix
char *

variable_types:
dest
char *

variable_types: lenght int

variable_types: singleNumber int


delUn

decompiled_code:
__int64 __fastcall delUn(void *ptr)
{
int v1; // er12
void **v2; // rbp
void **v3; // rbx

v1 = 0;
v2 = (void **)((char *)ptr + 88);
v3 = (void **)((char *)ptr + 8);
do
{
while ( 1 )
{
if ( !*v3 )
goto LABEL_3;
if ( (unsigned int)delUn(*v3) )
break;
++v1;
LABEL_3:
if ( ++v3 == v2 )
goto LABEL_7;
}
*v3++ = 0LL;
}
while ( v3 != v2 );
LABEL_7:
if ( *(_QWORD *)ptr || v1 )
return 0LL;
free(ptr);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(void *ptr)
{
int v1; // er12
void **v2; // rbp
void **v3; // rbx

v1 = 0;
v2 = (void **)((char *)ptr + 88);
v3 = (void **)((char *)ptr + 8);
do
{
while ( 1 )
{
if ( !*v3 )
goto LABEL_3;
if ( (unsigned int)func11(*v3) )
break;
++v1;
LABEL_3:
if ( ++v3 == v2 )
goto LABEL_7;
}
*v3++ = 0LL;
}
while ( v3 != v2 );
LABEL_7:
if ( *(_QWORD *)ptr || v1 )
return 0LL;
free(ptr);
return 1LL;
}

original_code:
int delUn(TNODE * root) {
    int i, childrens = 0;
    for (i = 0; i < 10; i++) {
        if (root->m_Child[i]) {
            childrens++;
            if (delUn(root->m_Child[i])) {
                root->m_Child[i] = ((void *)0);
                childrens--;
            }
        }
    }
    if (!root->m_Dest && !childrens) {
        free(root);
        return 1;
    }
    return 0;
}

canonical_original_code:
int delUn(struct TNode *root) {
    int i; int childrens = 0;
    for (i = 0; i < 10; i++) {
        if (root->m_Child[i]) {
            childrens++;
            if (delUn(root->m_Child[i])) {
                root->m_Child[i] = ((void *)0);
                childrens--;
            }
        }
    }
    if (!root->m_Dest && !childrens) {
        free(root);
        return 1;
    }
    return 0;
}

variable_types: childrens int


delDest

decompiled_code:
__int64 __fastcall delDest(void **a1, _BYTE *a2)
{
__int64 result; // rax
void **v3; // rbp
__int64 v4; // rdx
_QWORD *v5; // rax
void **v6; // rbp

result = checkNumber(a2);
if ( (_DWORD)result )
{
v3 = (void **)*a1;
if ( !*a1 )
return 0LL;
if ( (int)result > 0 )
{
v4 = (__int64)&a2[(unsigned int)(result - 1) + 1];
do
{
v3 = (void **)v3[(char)*a2 - 47];
if ( !v3 )
return 0LL;
}
while ( ++a2 != (_BYTE *)v4 );
}
free(*v3);
*v3 = 0LL;
v5 = v3 + 1;
v6 = v3 + 11;
while ( !*v5 )
{
if ( ++v5 == v6 )
{
if ( (unsigned int)delUn(*a1) )
*a1 = 0LL;
break;
}
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(void **a1, _BYTE *a2)
{
__int64 result; // rax
void **v3; // rbp
__int64 v4; // rdx
_QWORD *v5; // rax
void **v6; // rbp

result = func7(a2);
if ( (_DWORD)result )
{
v3 = (void **)*a1;
if ( !*a1 )
return 0LL;
if ( (int)result > 0 )
{
v4 = (__int64)&a2[(unsigned int)(result - 1) + 1];
do
{
v3 = (void **)v3[(char)*a2 - 47];
if ( !v3 )
return 0LL;
}
while ( ++a2 != (_BYTE *)v4 );
}
free(*v3);
*v3 = 0LL;
v5 = v3 + 1;
v6 = v3 + 11;
while ( !*v5 )
{
if ( ++v5 == v6 )
{
if ( (unsigned int)func11(*a1) )
*a1 = 0LL;
break;
}
}
result = 1LL;
}
return result;
}

original_code:
int delDest(TNODE ** root, const char * prefix) {
    TNODE * leaf;
    TNODE * del;
    int lenght = checkNumber(prefix), i, singleNumber;
    if (!lenght || !*root) {
        return 0;
    }
    leaf = *root;
    for (i = 0; i < lenght; i++) {
        singleNumber = prefix[i] - 48;
        leaf = leaf->m_Child[singleNumber];
        if (leaf == ((void *)0)) {
            return 0;
        }
    }
    free(leaf->m_Dest);
    leaf->m_Dest = ((void *)0);
    for (i = 0; i < 10; i++) {
        if (leaf->m_Child[i])
            return 1;
    }
    del = *root;
    if (delUn(del))
        * root = ((void *)0);
    return 1;
}

canonical_original_code:
int delDest(struct TNode **root, char *prefix) {
    struct TNode *leaf;
    struct TNode *del;
    int lenght = checkNumber(prefix); int i; int singleNumber;
    if (!lenght || !*root) {
        return 0;
    }
    leaf = *root;
    for (i = 0; i < lenght; i++) {
        singleNumber = prefix[i] - 48;
        leaf = leaf->m_Child[singleNumber];
        if (leaf == ((void *)0)) {
            return 0;
        }
    }
    free(leaf->m_Dest);
    leaf->m_Dest = ((void *)0);
    for (i = 0; i < 10; i++) {
        if (leaf->m_Child[i])
            return 1;
    }
    del = *root;
    if (delUn(del))
        * root = ((void *)0);
    return 1;
}


search

original_code:
const char * search(TNODE * root, const char * number) {
    char * destination;
    int lenght, i, singleNumber;
    ;
    destination = ((void *)0);
    lenght = checkNumber(number);
    if (!lenght || !root)
        return ((void *)0);
    for (i = 0; i < lenght; i++) {
        singleNumber = number[i] - 48;
        root = root->m_Child[singleNumber];
        if (root == ((void *)0)) {
            return destination;
        }
        if (root->m_Dest) {
            destination = root->m_Dest;
        }
    }
    return destination;
}

canonical_original_code:
char *search(struct TNode *root, char *number) {
    char *destination;
    int lenght; int i; int singleNumber;
    ;
    destination = ((void *)0);
    lenght = checkNumber(number);
    if (!lenght || !root)
        return ((void *)0);
    for (i = 0; i < lenght; i++) {
        singleNumber = number[i] - 48;
        root = root->m_Child[singleNumber];
        if (root == ((void *)0)) {
            return destination;
        }
        if (root->m_Dest) {
            destination = root->m_Dest;
        }
    }
    return destination;
}

variable_types:
destination
char *


repo: phrack-lp/miniComplier

decompiled_code:
__int64 __fastcall get_hashcode(_BYTE *a1)
{
int v1; // eax
int v2; // ecx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 31 * v2;
v1 = (char)*a1;
}
while ( *a1 );
return (unsigned int)(v2 % 131);
}

canonical_decompiled_code:
__int64 __fastcall func0(_BYTE *a1)
{
int v1; // eax
int v2; // ecx

v1 = (char)*a1;
if ( !*a1 )
return 0LL;
v2 = 0;
do
{
++a1;
v2 = v1 + 31 * v2;
v1 = (char)*a1;
}
while ( *a1 );
return (unsigned int)(v2 % 131);
}

original_code:
static int get_hashcode(char* str){
 int h = 0;
 while(*str){
  h = h * 31 + *str;
  str++;
 }
 return h%131;
}

canonical_original_code:
static int get_hashcode(char *str){
 int h = 0;
 while(*str){
  h = h * 31 + *str;
  str++;
 }
 return h%131;
}

variable_types:
str
char *

variable_types: h int


release

decompiled_code:
void __fastcall release(void *ptr)
{
if ( !ptr )
_assert_fail("e!=NULL", "hash.c", 0x39u, "release");
free(*(void **)(*(_QWORD *)ptr + 8LL));
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( !ptr )
_assert_fail("e!=NULL", "hash.c", 0x39u, "release");
free(*(void **)(*(_QWORD *)ptr + 8LL));
free(*(void **)ptr);
free(ptr);
}

original_code:
static void release(entry e){
 ((void) sizeof ((e!=((void *)0)) ? 1 : 0), __extension__ ({ if (e!=((void *)0)) ; else __assert_fail ("e!=NULL", "hash.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 free(e->t->detail.word);
 free(e->t);
 free(e);
}

canonical_original_code:
static void release(struct _entry *e){
 ((void) sizeof ((e!=((void *)0)) ? 1 : 0), __extension__ ({ if (e!=((void *)0)) ; else __assert_fail ("e!=NULL", "hash.c", 57, __extension__ __PRETTY_FUNCTION__); }));
 free(e->t->detail.word);
 free(e->t);
 free(e);
}

variable_types: struct _entry { struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *t; struct _entry *next; } *

user_defined_types: struct _entry { struct _token *t; struct _entry *next; }


decompiled_code:
void *init_hashtable()
{
return calloc(0x418uLL, 1uLL);
}

canonical_decompiled_code:
void *func2()
{
return calloc(0x418uLL, 1uLL);
}

original_code:
hashtable init_hashtable(){
 int i;
 hashtable ht = (hashtable)malloc(sizeof(entry) * 131);
 for(i=0;i<131;i++)
  ht[i] = ((void *)0);
 return ht;
}

canonical_original_code:
struct _entry **init_hashtable(){
 int i;
 struct _entry **ht = (hashtable)malloc(sizeof(entry) * 131);
 for(i=0;i<131;i++)
  ht[i] = ((void *)0);
 return ht;
}

variable_types: struct _entry { struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *t; struct _entry *next; } **


decompiled_code:
__int64 __fastcall get_from_hashtable(__int64 a1, char *a2)
{
int v2; // eax
__int64 v3; // r8
_QWORD *v4; // rbx
__int64 v5; // r12

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, char *a2)
{
int v2; // eax
__int64 v3; // r8
_QWORD *v4; // rbx
__int64 v5; // r12

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

original_code:
token get_from_hashtable(hashtable ht,char* str){
 int h = get_hashcode(str);
 entry e = ht[h];
 while(e){
  if(!strcmp(e->t->detail.word,str))
   return e->t;
  e = e->next;
 }
 return ((void *)0);
}

canonical_original_code:
struct _token *get_from_hashtable(struct _entry **ht, char *str){
 int h = get_hashcode(str);
 struct _entry *e = ht[h];
 while(e){
  if(!strcmp(e->t->detail.word,str))
   return e->t;
  e = e->next;
 }
 return ((void *)0);
}

variable_types: struct _entry { struct _token *t; struct _entry *next; } **

return_type: struct _token { int tag; union { int num; float real; char *word; char dummy; struct { char *name; int width; } type; } detail; } *