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

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

original_code:
token_list *html_token_list_nil(void)
{
 return ((void *)0);
}

canonical_original_code:
struct token_list_s *html_token_list_nil()
{
 return ((void *)0);
}

return_type: struct token_list_s { struct token_s { enum token_type { TOKEN_DOCTYPE=0, TOKEN_START_TAG=1, TOKEN_END_TAG=2, TOKEN_COMMENT=3, TOKEN_MULTI_CHAR=4, TOKEN_EOF=5 } type; struct doctype_token_s { unsigned char *doctype_name; unsigned char *doctype_public_identifier; unsigned char *doctype_system_identifier; enum force_quirks_flag_type { ON=0, OFF=1 } force_quirks_flag; } dt; struct start_tag_token_s { unsigned char *tag_name; enum self_closing_flag_type { SET=0, UNSET=1 } self_closing_flag; struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *attributes; } stt; struct end_tag_token_s { unsigned char *tag_name; } ett; struct comment_token_s { unsigned char *comment; } cmt; struct multi_char_token_s { unsigned char *mch; long char_count; } mcht; } *tk; struct token_list_s *tail; } *

user_defined_types: struct token_list_s { struct token_s *tk; struct token_list_s *tail; }


repo: yeslogic/prince-html

decompiled_code:
__int64 __fastcall html_token_list_get_first_token(__int64 *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
token *html_token_list_get_first_token(token_list *tk_list)
{
 if(tk_list != ((void *)0))
 {
  return tk_list->tk;
 }
 else
 {
  return ((void *)0);
 }
}

canonical_original_code:
struct token_s *html_token_list_get_first_token(struct token_list_s *tk_list)
{
 if(tk_list != ((void *)0))
 {
  return tk_list->tk;
 }
 else
 {
  return ((void *)0);
 }
}

variable_types: struct token_list_s { struct token_s *tk; struct token_list_s *tail; } *

return_type: struct token_s { enum token_type { TOKEN_DOCTYPE=0, TOKEN_START_TAG=1, TOKEN_END_TAG=2, TOKEN_COMMENT=3, TOKEN_MULTI_CHAR=4, TOKEN_EOF=5 } type; struct doctype_token_s { unsigned char *doctype_name; unsigned char *doctype_public_identifier; unsigned char *doctype_system_identifier; enum force_quirks_flag_type { ON=0, OFF=1 } force_quirks_flag; } dt; struct start_tag_token_s { unsigned char *tag_name; enum self_closing_flag_type { SET=0, UNSET=1 } self_closing_flag; struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *attributes; } stt; struct end_tag_token_s { unsigned char *tag_name; } ett; struct comment_token_s { unsigned char *comment; } cmt; struct multi_char_token_s { unsigned char *mch; long char_count; } mcht; } *

user_defined_types: struct token_s { enum token_type type; struct doctype_token_s dt; struct start_tag_token_s stt; struct end_tag_token_s ett; struct comment_token_s cmt; struct multi_char_token_s mcht; }

user_defined_types: struct doctype_token_s { unsigned char *doctype_name; unsigned char *doctype_public_identifier; unsigned char *doctype_system_identifier; enum force_quirks_flag_type force_quirks_flag; }

user_defined_types: struct start_tag_token_s { unsigned char *tag_name; enum self_closing_flag_type self_closing_flag; struct attribute_list_s *attributes; }

user_defined_types: struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type attr_ns; struct attribute_list_s *tail; }


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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
token_list *html_token_list_get_tail(token_list *tk_list)
{
 if(tk_list != ((void *)0))
 {
  return tk_list->tail;
 }
 else
 {
   return ((void *)0);
 }
}

canonical_original_code:
struct token_list_s *html_token_list_get_tail(struct token_list_s *tk_list)
{
 if(tk_list != ((void *)0))
 {
  return tk_list->tail;
 }
 else
 {
   return ((void *)0);
 }
}

user_defined_types: enum token_type { TOKEN_DOCTYPE=0, TOKEN_START_TAG=1, TOKEN_END_TAG=2, TOKEN_COMMENT=3, TOKEN_MULTI_CHAR=4, TOKEN_EOF=5 }

user_defined_types: struct end_tag_token_s { unsigned char *tag_name; }

user_defined_types: struct comment_token_s { unsigned char *comment; }

user_defined_types: struct multi_char_token_s { unsigned char *mch; long char_count; }

user_defined_types: enum force_quirks_flag_type { ON=0, OFF=1 }

user_defined_types: enum self_closing_flag_type { SET=0, UNSET=1 }

user_defined_types: enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 }


decompiled_code:
int __fastcall html_print_force_quirks_flag(int a1)
{
if ( !a1 )
return puts("Force quirks flag: on");
if ( a1 == 1 )
return puts("Force quirks flag: off");
return puts("Invalid force quirks flag value.");
}

canonical_decompiled_code:
int __fastcall func12(int a1)
{
if ( !a1 )
return puts("Force quirks flag: on");
if ( a1 == 1 )
return puts("Force quirks flag: off");
return puts("Invalid force quirks flag value.");
}

original_code:
void html_print_force_quirks_flag(force_quirks_flag_type flag)
{
 if(flag == ON)
 {
  printf("Force quirks flag: on\n");
 }
 else if(flag == OFF)
 {
  printf("Force quirks flag: off\n");
 }
 else
 {
  printf("Invalid force quirks flag value.\n");
 }
}

canonical_original_code:
void html_print_force_quirks_flag(enum force_quirks_flag_type flag)
{
 if(flag == ON)
 {
  printf("Force quirks flag: on\n");
 }
 else if(flag == OFF)
 {
  printf("Force quirks flag: off\n");
 }
 else
 {
  printf("Invalid force quirks flag value.\n");
 }
}

variable_types: enum force_quirks_flag_type { ON=0, OFF=1 }

return_type: void


decompiled_code:
int __fastcall html_print_attribute_list(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
printf("Attributes: [");
if ( a1 )
{
do
{
printf("%s=%s", *(const char **)v1, *(const char **)(v1 + 8));
switch ( *(_DWORD *)(v1 + 16) )
{
case 0:
printf("(ns-html)");
break;
case 1:
printf("(ns-mathml)");
break;
case 2:
printf("(ns-svg)");
break;
case 3:
printf("(ns-xlink)");
break;
case 4:
printf("(ns-xml)");
break;
case 5:
printf("(ns-xmlns)");
break;
case 6:
printf("(ns-default)");
break;
default:
break;
}
if ( !*(_QWORD *)(v1 + 24) )
break;
printf(", ");
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
putchar(93);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
__int64 v1; // rbx

v1 = a1;
printf("Attributes: [");
if ( a1 )
{
do
{
printf("%s=%s", *(const char **)v1, *(const char **)(v1 + 8));
switch ( *(_DWORD *)(v1 + 16) )
{
case 0:
printf("(ns-html)");
break;
case 1:
printf("(ns-mathml)");
break;
case 2:
printf("(ns-svg)");
break;
case 3:
printf("(ns-xlink)");
break;
case 4:
printf("(ns-xml)");
break;
case 5:
printf("(ns-xmlns)");
break;
case 6:
printf("(ns-default)");
break;
default:
break;
}
if ( !*(_QWORD *)(v1 + 24) )
break;
printf(", ");
v1 = *(_QWORD *)(v1 + 24);
}
while ( v1 );
}
putchar(93);
return putchar(10);
}

original_code:
void html_print_attribute_list(attribute_list *attributes)
{
 printf("Attributes: [");
    while (attributes != ((void *)0))
    {
  printf("%s=%s", attributes->name, attributes->value);
  switch (attributes->attr_ns)
  {
   case HTML:
    printf("(ns-html)");
    break;
   case MATHML:
    printf("(ns-mathml)");
    break;
   case SVG:
    printf("(ns-svg)");
    break;
   case XLINK:
    printf("(ns-xlink)");
    break;
   case XML:
    printf("(ns-xml)");
    break;
   case XMLNS:
    printf("(ns-xmlns)");
    break;
   case DEFAULT:
    printf("(ns-default)");
    break;
   default:
    break;
  }
  if (attributes->tail != ((void *)0))
  {
   printf(", ");
  }
  attributes = attributes->tail;
    }
    putchar(']');
 printf("\n");
}

canonical_original_code:
void html_print_attribute_list(struct attribute_list_s *attributes)
{
 printf("Attributes: [");
    while (attributes != ((void *)0))
    {
  printf("%s=%s", attributes->name, attributes->value);
  switch (attributes->attr_ns)
  {
   case HTML:
    printf("(ns-html)");
    break;
   case MATHML:
    printf("(ns-mathml)");
    break;
   case SVG:
    printf("(ns-svg)");
    break;
   case XLINK:
    printf("(ns-xlink)");
    break;
   case XML:
    printf("(ns-xml)");
    break;
   case XMLNS:
    printf("(ns-xmlns)");
    break;
   case DEFAULT:
    printf("(ns-default)");
    break;
   default:
    break;
  }
  if (attributes->tail != ((void *)0))
  {
   printf(", ");
  }
  attributes = attributes->tail;
    }
    putchar(']');
 printf("\n");
}

variable_types: struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *


decompiled_code:
int __fastcall html_print_self_closing_flag(int a1)
{
if ( !a1 )
return puts("Self closing flag: set");
if ( a1 == 1 )
return puts("Self closing flag: unset");
return puts("Invalid self closing flag value.");
}

canonical_decompiled_code:
int __fastcall func14(int a1)
{
if ( !a1 )
return puts("Self closing flag: set");
if ( a1 == 1 )
return puts("Self closing flag: unset");
return puts("Invalid self closing flag value.");
}

original_code:
void html_print_self_closing_flag(self_closing_flag_type flag)
{
 if(flag == SET)
 {
  printf("Self closing flag: set\n");
 }
 else if(flag == UNSET)
 {
  printf("Self closing flag: unset\n");
 }
 else
 {
  printf("Invalid self closing flag value.\n");
 }
}

canonical_original_code:
void html_print_self_closing_flag(enum self_closing_flag_type flag)
{
 if(flag == SET)
 {
  printf("Self closing flag: set\n");
 }
 else if(flag == UNSET)
 {
  printf("Self closing flag: unset\n");
 }
 else
 {
  printf("Invalid self closing flag value.\n");
 }
}

variable_types: enum self_closing_flag_type { SET=0, UNSET=1 }


decompiled_code:
int __fastcall html_print_token(__int64 a1)
{
switch ( *(_DWORD *)a1 )
{
case 0:
puts("Token type: DOCTYPE.");
printf("Doctype name: %s\n", *(const char **)(a1 + 8));
printf("Public identifier: %s\n", *(const char **)(a1 + 16));
printf("System identifier: %s\n", *(const char **)(a1 + 24));
html_print_force_quirks_flag(*(_DWORD *)(a1 + 32));
break;
case 1:
puts("Token type: START TAG.");
printf("Start tag name: %s\n", *(const char **)(a1 + 40));
html_print_self_closing_flag(*(_DWORD *)(a1 + 48));
html_print_attribute_list(*(_QWORD *)(a1 + 56));
break;
case 2:
puts("Token type: END TAG.");
printf("End tag name: %s\n", *(const char **)(a1 + 64));
break;
case 3:
puts("Token type: COMMENT.");
printf("Comment: %s\n", *(const char **)(a1 + 72));
break;
case 4:
puts("Token type: MULTI_CHAR.");
printf("First character: %c\n", **(unsigned __int8 **)(a1 + 80));
printf("Character count: %d\n", *(_QWORD *)(a1 + 88));
break;
case 5:
puts("Token type: END OF FILE.");
break;
default:
return putchar(10);
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
switch ( *(_DWORD *)a1 )
{
case 0:
puts("Token type: DOCTYPE.");
printf("Doctype name: %s\n", *(const char **)(a1 + 8));
printf("Public identifier: %s\n", *(const char **)(a1 + 16));
printf("System identifier: %s\n", *(const char **)(a1 + 24));
func12(*(_DWORD *)(a1 + 32));
break;
case 1:
puts("Token type: START TAG.");
printf("Start tag name: %s\n", *(const char **)(a1 + 40));
func14(*(_DWORD *)(a1 + 48));
func13(*(_QWORD *)(a1 + 56));
break;
case 2:
puts("Token type: END TAG.");
printf("End tag name: %s\n", *(const char **)(a1 + 64));
break;
case 3:
puts("Token type: COMMENT.");
printf("Comment: %s\n", *(const char **)(a1 + 72));
break;
case 4:
puts("Token type: MULTI_CHAR.");
printf("First character: %c\n", **(unsigned __int8 **)(a1 + 80));
printf("Character count: %d\n", *(_QWORD *)(a1 + 88));
break;
case 5:
puts("Token type: END OF FILE.");
break;
default:
return putchar(10);
}
return putchar(10);
}

original_code:
void html_print_token(token *tk)
{
 switch (tk->type)
 {
  case TOKEN_DOCTYPE:
   printf("Token type: DOCTYPE.\n");
   printf("Doctype name: %s\n", tk->dt.doctype_name);
   printf("Public identifier: %s\n", tk->dt.doctype_public_identifier);
   printf("System identifier: %s\n", tk->dt.doctype_system_identifier);
   html_print_force_quirks_flag(tk->dt.force_quirks_flag);
   break;
  case TOKEN_START_TAG:
   printf("Token type: START TAG.\n");
   printf("Start tag name: %s\n", tk->stt.tag_name);
   html_print_self_closing_flag(tk->stt.self_closing_flag);
   html_print_attribute_list(tk->stt.attributes);
   break;
  case TOKEN_END_TAG:
   printf("Token type: END TAG.\n");
   printf("End tag name: %s\n", tk->ett.tag_name);
   break;
  case TOKEN_COMMENT:
   printf("Token type: COMMENT.\n");
   printf("Comment: %s\n", tk->cmt.comment);
   break;
  case TOKEN_MULTI_CHAR:
   printf("Token type: MULTI_CHAR.\n");
   printf("First character: %c\n", *(tk->mcht.mch));
   printf("Character count: %d\n", tk->mcht.char_count);
   break;
  case TOKEN_EOF:
   printf("Token type: END OF FILE.\n");
   break;
  default:
   break;
 }
 printf("\n");
}

canonical_original_code:
void html_print_token(struct token_s *tk)
{
 switch (tk->type)
 {
  case TOKEN_DOCTYPE:
   printf("Token type: DOCTYPE.\n");
   printf("Doctype name: %s\n", tk->dt.doctype_name);
   printf("Public identifier: %s\n", tk->dt.doctype_public_identifier);
   printf("System identifier: %s\n", tk->dt.doctype_system_identifier);
   html_print_force_quirks_flag(tk->dt.force_quirks_flag);
   break;
  case TOKEN_START_TAG:
   printf("Token type: START TAG.\n");
   printf("Start tag name: %s\n", tk->stt.tag_name);
   html_print_self_closing_flag(tk->stt.self_closing_flag);
   html_print_attribute_list(tk->stt.attributes);
   break;
  case TOKEN_END_TAG:
   printf("Token type: END TAG.\n");
   printf("End tag name: %s\n", tk->ett.tag_name);
   break;
  case TOKEN_COMMENT:
   printf("Token type: COMMENT.\n");
   printf("Comment: %s\n", tk->cmt.comment);
   break;
  case TOKEN_MULTI_CHAR:
   printf("Token type: MULTI_CHAR.\n");
   printf("First character: %c\n", *(tk->mcht.mch));
   printf("Character count: %d\n", tk->mcht.char_count);
   break;
  case TOKEN_EOF:
   printf("Token type: END OF FILE.\n");
   break;
  default:
   break;
 }
 printf("\n");
}

variable_types: struct token_s { enum token_type { TOKEN_DOCTYPE=0, TOKEN_START_TAG=1, TOKEN_END_TAG=2, TOKEN_COMMENT=3, TOKEN_MULTI_CHAR=4, TOKEN_EOF=5 } type; struct doctype_token_s { unsigned char *doctype_name; unsigned char *doctype_public_identifier; unsigned char *doctype_system_identifier; enum force_quirks_flag_type { ON=0, OFF=1 } force_quirks_flag; } dt; struct start_tag_token_s { unsigned char *tag_name; enum self_closing_flag_type { SET=0, UNSET=1 } self_closing_flag; struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *attributes; } stt; struct end_tag_token_s { unsigned char *tag_name; } ett; struct comment_token_s { unsigned char *comment; } cmt; struct multi_char_token_s { unsigned char *mch; long char_count; } mcht; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int result; // eax
const char *v4; // rax
char *v5; // rbx

if ( argc == 2 )
{
v4 = (const char *)get_file_encoding(argv[1]);
v5 = (char *)v4;
if ( v4 )
{
printf("The character encoding for the file is: %s\n", v4);
free(v5);
}
else
{
puts("No encoding found.");
}
result = 0;
}
else
{
printf("usage: %s FILENAME\n", *argv);
result = 1;
}
return result;
}

original_code:
int main(int argc, char* argv[])
{
 unsigned char *file_name;
 unsigned char *encoding;
 if (argc != 2)
 {
  printf("usage: %s FILENAME\n", argv[0]);
  return 1;
 }
 file_name = argv[1];
 encoding = get_file_encoding(file_name);
 if(encoding != ((void *)0))
 {
  printf("The character encoding for the file is: %s\n", encoding);
  free(encoding);
 }
 else
 {
  printf("No encoding found.\n");
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned char *file_name;
 unsigned char *encoding;
 if (argc != 2)
 {
  printf("usage: %s FILENAME\n", argv[0]);
  return 1;
 }
 file_name = argv[1];
 encoding = get_file_encoding(file_name);
 if(encoding != ((void *)0))
 {
  printf("The character encoding for the file is: %s\n", encoding);
  free(encoding);
 }
 else
 {
  printf("No encoding found.\n");
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
encoding
unsigned char *

return_type: int


decompiled_code:
_BOOL8 __fastcall html_element_stack_is_empty(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(__int64 a1)
{
return a1 == 0;
}

original_code:
int html_element_stack_is_empty(element_stack *st)
{
 if(st == ((void *)0))
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

canonical_original_code:
int html_element_stack_is_empty(struct element_stack_s *st)
{
 if(st == ((void *)0))
 {
  return 1;
 }
 else
 {
  return 0;
 }
}

variable_types: struct element_stack_s { struct element_node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; } *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *name; struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *attributes; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } name_space; } *e; struct element_stack_s *tail; } *

user_defined_types: struct element_stack_s { struct element_node_s *e; struct element_stack_s *tail; }

user_defined_types: struct element_node_s { enum node_type type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *name; struct attribute_list_s *attributes; enum namespace_type name_space; }

user_defined_types: struct node_s { enum node_type type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; }


decompiled_code:
__int64 __fastcall open_element_stack_pop(_QWORD **a1)
{
_QWORD *v2; // rdi
__int64 result; // rax
_QWORD *v4; // r12

v2 = *a1;
result = 0LL;
if ( v2 )
{
v4 = (_QWORD *)v2[1];
free(v2);
*a1 = v4;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD **a1)
{
_QWORD *v2; // rdi
__int64 result; // rax
_QWORD *v4; // r12

v2 = *a1;
result = 0LL;
if ( v2 )
{
v4 = (_QWORD *)v2[1];
free(v2);
*a1 = v4;
result = 1LL;
}
return result;
}

original_code:
int open_element_stack_pop(element_stack **st)
{
 element_stack *temp_st_ptr;
 if(*st != ((void *)0))
 {
  temp_st_ptr = (*st)->tail;
  free(*st);
  *st = temp_st_ptr;
  return 1;
 }
 else
 {
  return 0;
 }
}

canonical_original_code:
int open_element_stack_pop(struct element_stack_s **st)
{
 struct element_stack_s *temp_st_ptr;
 if(*st != ((void *)0))
 {
  temp_st_ptr = (*st)->tail;
  free(*st);
  *st = temp_st_ptr;
  return 1;
 }
 else
 {
  return 0;
 }
}

variable_types: struct element_stack_s { struct element_node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; } *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *name; struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *attributes; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } name_space; } *e; struct element_stack_s *tail; } **


decompiled_code:
void __fastcall free_element_stack(void *ptr)
{
void *v1; // rbx
void *v2; // rdi

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v2);
}
}

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

v1 = ptr;
while ( v1 )
{
v2 = v1;
v1 = (void *)*((_QWORD *)v1 + 1);
free(v2);
}
}

original_code:
void free_element_stack(element_stack *st)
{
 element_stack *temp_ptr;
 while(st != ((void *)0))
 {
  temp_ptr = st;
  st = st->tail;
  free(temp_ptr);
 }
}

canonical_original_code:
void free_element_stack(struct element_stack_s *st)
{
 struct element_stack_s *temp_ptr;
 while(st != ((void *)0))
 {
  temp_ptr = st;
  st = st->tail;
  free(temp_ptr);
 }
}

user_defined_types: enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 }


decompiled_code:
__int64 __fastcall open_element_stack_top(__int64 *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
element_node *open_element_stack_top(element_stack *st)
{
 if(st != ((void *)0))
 {
  return st->e;
 }
 else
 {
  return ((void *)0);
 }
}

canonical_original_code:
struct element_node_s *open_element_stack_top(struct element_stack_s *st)
{
 if(st != ((void *)0))
 {
  return st->e;
 }
 else
 {
  return ((void *)0);
 }
}

variable_types: struct element_stack_s { struct element_node_s *e; struct element_stack_s *tail; } *

return_type: struct element_node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; } *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *name; struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *attributes; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } name_space; } *


decompiled_code:
void __fastcall pop_elements_up_to(__int64 **a1, const char *a2)
{
__int64 v2; // rax

if ( !a2 )
_assert_fail("element_name != NULL", "stack.c", 0x4Fu, "pop_elements_up_to");
while ( *a1 )
{
v2 = open_element_stack_top(*a1);
if ( !strcmp(*(const char **)(v2 + 48), a2) )
{
open_element_stack_pop(a1);
return;
}
open_element_stack_pop(a1);
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 **a1, const char *a2)
{
__int64 v2; // rax

if ( !a2 )
_assert_fail("element_name != NULL", "stack.c", 0x4Fu, "pop_elements_up_to");
while ( *a1 )
{
v2 = func3(*a1);
if ( !strcmp(*(const char **)(v2 + 48), a2) )
{
func1(a1);
return;
}
func1(a1);
}
}

original_code:
void pop_elements_up_to(element_stack **st, unsigned char *element_name)
{
 element_node *curr_element;
 int found_element = 0;
 ((void) sizeof ((element_name != ((void *)0)) ? 1 : 0), __extension__ ({ if (element_name != ((void *)0)) ; else __assert_fail ("element_name != NULL", "stack.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 while(*st != ((void *)0))
 {
  curr_element = open_element_stack_top(*st);
  if(strcmp(curr_element->name, element_name) == 0)
  {
   found_element = 1;
  }
  open_element_stack_pop(st);
  if(found_element == 1)
  {
   break;
  }
 }
}

canonical_original_code:
void pop_elements_up_to(struct element_stack_s **st, unsigned char *element_name)
{
 struct element_node_s *curr_element;
 int found_element = 0;
 ((void) sizeof ((element_name != ((void *)0)) ? 1 : 0), __extension__ ({ if (element_name != ((void *)0)) ; else __assert_fail ("element_name != NULL", "stack.c", 79, __extension__ __PRETTY_FUNCTION__); }));
 while(*st != ((void *)0))
 {
  curr_element = open_element_stack_top(*st);
  if(strcmp(curr_element->name, element_name) == 0)
  {
   found_element = 1;
  }
  open_element_stack_pop(st);
  if(found_element == 1)
  {
   break;
  }
 }
}

variable_types: struct element_node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; } *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *name; struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *attributes; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } name_space; } *


decompiled_code:
void __fastcall pop_ele_up_to(__int64 **a1, __int64 a2)
{
if ( !a2 )
_assert_fail("e != NULL", "stack.c", 0x6Cu, "pop_ele_up_to");
while ( *a1 )
{
if ( a2 == open_element_stack_top(*a1) )
{
open_element_stack_pop(a1);
return;
}
open_element_stack_pop(a1);
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 **a1, __int64 a2)
{
if ( !a2 )
_assert_fail("e != NULL", "stack.c", 0x6Cu, "pop_ele_up_to");
while ( *a1 )
{
if ( a2 == func3(*a1) )
{
func1(a1);
return;
}
func1(a1);
}
}

original_code:
void pop_ele_up_to(element_stack **st, element_node *e)
{
 element_node *curr_element;
 int found_element = 0;
 ((void) sizeof ((e != ((void *)0)) ? 1 : 0), __extension__ ({ if (e != ((void *)0)) ; else __assert_fail ("e != NULL", "stack.c", 108, __extension__ __PRETTY_FUNCTION__); }));
 while(*st != ((void *)0))
 {
  curr_element = open_element_stack_top(*st);
  if(curr_element == e)
  {
   found_element = 1;
  }
  open_element_stack_pop(st);
  if(found_element == 1)
  {
   break;
  }
 }
}

canonical_original_code:
void pop_ele_up_to(struct element_stack_s **st, struct element_node_s *e)
{
 struct element_node_s *curr_element;
 int found_element = 0;
 ((void) sizeof ((e != ((void *)0)) ? 1 : 0), __extension__ ({ if (e != ((void *)0)) ; else __assert_fail ("e != NULL", "stack.c", 108, __extension__ __PRETTY_FUNCTION__); }));
 while(*st != ((void *)0))
 {
  curr_element = open_element_stack_top(*st);
  if(curr_element == e)
  {
   found_element = 1;
  }
  open_element_stack_pop(st);
  if(found_element == 1)
  {
   break;
  }
 }
}

variable_types:
e
struct element_node_s *


decompiled_code:
__int64 __fastcall is_last_element_in_stack(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a2 )
_assert_fail("e != NULL", "stack.c", 0x93u, "is_last_element_in_stack");
result = 0LL;
if ( a1 )
{
do
{
while ( *a1 != a2 )
{
a1 = (_QWORD *)a1[1];
if ( !a1 )
return 0LL;
}
a1 = (_QWORD *)a1[1];
}
while ( a1 );
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a2 )
_assert_fail("e != NULL", "stack.c", 0x93u, "is_last_element_in_stack");
result = 0LL;
if ( a1 )
{
do
{
while ( *a1 != a2 )
{
a1 = (_QWORD *)a1[1];
if ( !a1 )
return 0LL;
}
a1 = (_QWORD *)a1[1];
}
while ( a1 );
result = 1LL;
}
return result;
}

original_code:
int is_last_element_in_stack(element_stack *st, element_node *e)
{
 ((void) sizeof ((e != ((void *)0)) ? 1 : 0), __extension__ ({ if (e != ((void *)0)) ; else __assert_fail ("e != NULL", "stack.c", 147, __extension__ __PRETTY_FUNCTION__); }));
 while(st != ((void *)0))
 {
  if((st->e == e) && (st->tail == ((void *)0)))
  {
   return 1;
  }
  st = st->tail;
 }
 return 0;
}

canonical_original_code:
int is_last_element_in_stack(struct element_stack_s *st, struct element_node_s *e)
{
 ((void) sizeof ((e != ((void *)0)) ? 1 : 0), __extension__ ({ if (e != ((void *)0)) ; else __assert_fail ("e != NULL", "stack.c", 147, __extension__ __PRETTY_FUNCTION__); }));
 while(st != ((void *)0))
 {
  if((st->e == e) && (st->tail == ((void *)0)))
  {
   return 1;
  }
  st = st->tail;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall is_on_element_stack(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a2 )
_assert_fail("e != NULL", "stack.c", 0xA6u, "is_on_element_stack");
result = 0LL;
if ( a1 )
{
while ( *a1 != a2 )
{
a1 = (_QWORD *)a1[1];
if ( !a1 )
return 0LL;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, __int64 a2)
{
__int64 result; // rax

if ( !a2 )
_assert_fail("e != NULL", "stack.c", 0xA6u, "is_on_element_stack");
result = 0LL;
if ( a1 )
{
while ( *a1 != a2 )
{
a1 = (_QWORD *)a1[1];
if ( !a1 )
return 0LL;
}
result = 1LL;
}
return result;
}

original_code:
int is_on_element_stack(element_stack *st, element_node *e)
{
 ((void) sizeof ((e != ((void *)0)) ? 1 : 0), __extension__ ({ if (e != ((void *)0)) ; else __assert_fail ("e != NULL", "stack.c", 166, __extension__ __PRETTY_FUNCTION__); }));
 while(st != ((void *)0))
 {
  if(st->e == e)
  {
   return 1;
  }
  st = st->tail;
 }
 return 0;
}

canonical_original_code:
int is_on_element_stack(struct element_stack_s *st, struct element_node_s *e)
{
 ((void) sizeof ((e != ((void *)0)) ? 1 : 0), __extension__ ({ if (e != ((void *)0)) ; else __assert_fail ("e != NULL", "stack.c", 166, __extension__ __PRETTY_FUNCTION__); }));
 while(st != ((void *)0))
 {
  if(st->e == e)
  {
   return 1;
  }
  st = st->tail;
 }
 return 0;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
element_stack *previous_stack_node(element_stack *st)
{
 if(st != ((void *)0))
 {
  return st->tail;
 }
 else
 {
  return ((void *)0);
 }
}

canonical_original_code:
struct element_stack_s *previous_stack_node(struct element_stack_s *st)
{
 if(st != ((void *)0))
 {
  return st->tail;
 }
 else
 {
  return ((void *)0);
 }
}

variable_types:
st
struct element_stack_s *

return_type: struct element_stack_s { struct element_node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; } *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *name; struct attribute_list_s { unsigned char *name; unsigned char *value; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } attr_ns; struct attribute_list_s *tail; } *attributes; enum namespace_type { HTML=0, MATHML=1, SVG=2, XLINK=3, XML=4, XMLNS=5, DEFAULT=6 } name_space; } *e; struct element_stack_s *tail; } *


decompiled_code:
void __fastcall remove_element_from_stack(_QWORD **a1, __int64 a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rbx
__int64 v5; // rax

if ( !a2 )
_assert_fail("e != NULL", "stack.c", 0xDDu, "remove_element_from_stack");
v3 = *a1;
if ( *v3 == a2 )
{
*a1 = (_QWORD *)v3[1];
free(v3);
}
else
{
v4 = (_QWORD *)v3[1];
if ( v4 )
{
while ( *v4 != a2 )
{
v5 = previous_stack_node((__int64)v4);
v3 = v4;
if ( !v5 )
return;
v4 = (_QWORD *)v5;
}
v3[1] = v4[1];
free(v4);
}
}
}

canonical_decompiled_code:
void __fastcall func9(_QWORD **a1, __int64 a2)
{
_QWORD *v3; // rdi
_QWORD *v4; // rbx
__int64 v5; // rax

if ( !a2 )
_assert_fail("e != NULL", "stack.c", 0xDDu, "remove_element_from_stack");
v3 = *a1;
if ( *v3 == a2 )
{
*a1 = (_QWORD *)v3[1];
free(v3);
}
else
{
v4 = (_QWORD *)v3[1];
if ( v4 )
{
while ( *v4 != a2 )
{
v5 = func8((__int64)v4);
v3 = v4;
if ( !v5 )
return;
v4 = (_QWORD *)v5;
}
v3[1] = v4[1];
free(v4);
}
}
}

original_code:
void remove_element_from_stack(element_stack **st, element_node *e)
{
 element_stack *temp_stack_node, *last_node;
 ((void) sizeof ((e != ((void *)0)) ? 1 : 0), __extension__ ({ if (e != ((void *)0)) ; else __assert_fail ("e != NULL", "stack.c", 221, __extension__ __PRETTY_FUNCTION__); }));
 if((*st)->e == e)
 {
  temp_stack_node = *st;
  *st = (*st)->tail;
  free(temp_stack_node);
 }
 else
 {
  temp_stack_node = (*st)->tail;
  last_node = *st;
  while(temp_stack_node != ((void *)0))
  {
   if(temp_stack_node->e == e)
   {
    last_node->tail = temp_stack_node->tail;
    free(temp_stack_node);
    break;
   }
   last_node = temp_stack_node;
   temp_stack_node = previous_stack_node(temp_stack_node);
  }
 }
}

canonical_original_code:
void remove_element_from_stack(struct element_stack_s **st, struct element_node_s *e)
{
 struct element_stack_s *temp_stack_node; struct element_stack_s *last_node;
 ((void) sizeof ((e != ((void *)0)) ? 1 : 0), __extension__ ({ if (e != ((void *)0)) ; else __assert_fail ("e != NULL", "stack.c", 221, __extension__ __PRETTY_FUNCTION__); }));
 if((*st)->e == e)
 {
  temp_stack_node = *st;
  *st = (*st)->tail;
  free(temp_stack_node);
 }
 else
 {
  temp_stack_node = (*st)->tail;
  last_node = *st;
  while(temp_stack_node != ((void *)0))
  {
   if(temp_stack_node->e == e)
   {
    last_node->tail = temp_stack_node->tail;
    free(temp_stack_node);
    break;
   }
   last_node = temp_stack_node;
   temp_stack_node = previous_stack_node(temp_stack_node);
  }
 }
}


decompiled_code:
_QWORD *create_text_node()
{
_QWORD *v0; // rbx

v0 = malloc(0x38uLL);
*(_DWORD *)v0 = 1;
v0[6] = string_append(0LL, 0LL);
v0[1] = 0LL;
v0[4] = 0LL;
v0[5] = 0LL;
v0[2] = 0LL;
v0[3] = 0LL;
return v0;
}

original_code:
text_node *create_text_node(void)
{
 text_node *t = (text_node *)malloc(sizeof(text_node));
 t->type = TEXT_N;
 t->text_data = string_append(((void *)0), '\0');
 t->parent = ((void *)0);
 t->first_child = ((void *)0);
 t->last_child = ((void *)0);
 t->previous_sibling = ((void *)0);
 t->next_sibling = ((void *)0);
 return t;
}

canonical_original_code:
struct text_node_s *create_text_node()
{
 struct text_node_s *t = (text_node *)malloc(sizeof(text_node));
 t->type = TEXT_N;
 t->text_data = string_append(((void *)0), '\0');
 t->parent = ((void *)0);
 t->first_child = ((void *)0);
 t->last_child = ((void *)0);
 t->previous_sibling = ((void *)0);
 t->next_sibling = ((void *)0);
 return t;
}

variable_types: struct text_node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; } *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *text_data; } *

user_defined_types: struct text_node_s { enum node_type type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *text_data; }


original_code:
void insert_child_node(node *parent, node *child_node, node *child_2)
{
 ((void) sizeof (((parent != ((void *)0)) && (child_node != ((void *)0)) && (child_2 != ((void *)0)) && (child_2->parent == parent)) ? 1 : 0), __extension__ ({ if ((parent != ((void *)0)) && (child_node != ((void *)0)) && (child_2 != ((void *)0)) && (child_2->parent == parent)) ; else __assert_fail ("(parent != NULL) && (child_node != NULL) && (child_2 != NULL) && (child_2->parent == parent)", "tree.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 if(parent->first_child == child_2)
 {
  parent->first_child = child_node;
  child_node->previous_sibling = ((void *)0);
 }
 else
 {
  child_node->previous_sibling = child_2->previous_sibling;
  child_2->previous_sibling->next_sibling = child_node;
 }
 child_node->parent = parent;
 child_node->next_sibling = child_2;
 child_2->previous_sibling = child_node;
}

canonical_original_code:
void insert_child_node(struct node_s *parent, struct node_s *child_node, struct node_s *child_2)
{
 ((void) sizeof (((parent != ((void *)0)) && (child_node != ((void *)0)) && (child_2 != ((void *)0)) && (child_2->parent == parent)) ? 1 : 0), __extension__ ({ if ((parent != ((void *)0)) && (child_node != ((void *)0)) && (child_2 != ((void *)0)) && (child_2->parent == parent)) ; else __assert_fail ("(parent != NULL) && (child_node != NULL) && (child_2 != NULL) && (child_2->parent == parent)", "tree.c", 92, __extension__ __PRETTY_FUNCTION__); }));
 if(parent->first_child == child_2)
 {
  parent->first_child = child_node;
  child_node->previous_sibling = ((void *)0);
 }
 else
 {
  child_node->previous_sibling = child_2->previous_sibling;
  child_2->previous_sibling->next_sibling = child_node;
 }
 child_node->parent = parent;
 child_node->next_sibling = child_2;
 child_2->previous_sibling = child_node;
}

variable_types: struct node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; } *


decompiled_code:
void __fastcall free_node(void *ptr)
{
int v2; // eax
__int64 v3; // rbx
void *v4; // rdi

if ( ptr )
{
v2 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 1 || v2 == 2 )
{
free(*((void **)ptr + 6));
free(ptr);
}
else if ( !v2 )
{
v3 = *((_QWORD *)ptr + 7);
while ( v3 )
{
free(*(void **)v3);
free(*(void **)(v3 + 8));
v4 = (void *)v3;
v3 = *(_QWORD *)(v3 + 24);
free(v4);
}
free(*((void **)ptr + 6));
free(ptr);
}
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
int v2; // eax
__int64 v3; // rbx
void *v4; // rdi

if ( ptr )
{
v2 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 1 || v2 == 2 )
{
free(*((void **)ptr + 6));
free(ptr);
}
else if ( !v2 )
{
v3 = *((_QWORD *)ptr + 7);
while ( v3 )
{
free(*(void **)v3);
free(*(void **)(v3 + 8));
v4 = (void *)v3;
v3 = *(_QWORD *)(v3 + 24);
free(v4);
}
free(*((void **)ptr + 6));
free(ptr);
}
}
}

original_code:
void free_node(node *n)
{
 if(n != ((void *)0))
 {
  switch (n->type)
  {
   case ELEMENT_N:
    {
     element_node *e = (element_node *)n;
     attribute_list *attrs = e->attributes;
     attribute_list *temp_ptr;
     while(attrs != ((void *)0))
     {
      free(attrs->name);
      free(attrs->value);
      temp_ptr = attrs;
      attrs = attrs->tail;
      free(temp_ptr);
     }
     free(e->name);
     free(e);
    }
    break;
   case TEXT_N:
    {
     text_node *t = (text_node *)n;
     free(t->text_data);
     free(t);
    }
    break;
   case COMMENT_N:
    {
     comment_node *c = (comment_node *)n;
     free(c->comment_data);
     free(c);
    }
    break;
   default:
    break;
  }
 }
}

canonical_original_code:
void free_node(struct node_s *n)
{
 if(n != ((void *)0))
 {
  switch (n->type)
  {
   case ELEMENT_N:
    {
     struct element_node_s *e = (element_node *)n;
     struct attribute_list_s *attrs = e->attributes;
     struct attribute_list_s *temp_ptr;
     while(attrs != ((void *)0))
     {
      free(attrs->name);
      free(attrs->value);
      temp_ptr = attrs;
      attrs = attrs->tail;
      free(temp_ptr);
     }
     free(e->name);
     free(e);
    }
    break;
   case TEXT_N:
    {
     struct text_node_s *t = (text_node *)n;
     free(t->text_data);
     free(t);
    }
    break;
   case COMMENT_N:
    {
     struct comment_node_s *c = (comment_node *)n;
     free(c->comment_data);
     free(c);
    }
    break;
   default:
    break;
  }
 }
}

variable_types: struct comment_node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s { enum node_type { ELEMENT_N=0, TEXT_N=1, COMMENT_N=2 } type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; } *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *comment_data; } *

user_defined_types: struct comment_node_s { enum node_type type; struct node_s *parent; struct node_s *previous_sibling; struct node_s *next_sibling; struct node_s *first_child; struct node_s *last_child; unsigned char *comment_data; }


decompiled_code:
void __fastcall print_parent_node(__int64 a1)
{
__int64 v1; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
printf("Parent node name: %s\n", *(const char **)(v1 + 48));
}
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
__int64 v1; // rax

if ( a1 )
{
v1 = *(_QWORD *)(a1 + 8);
if ( v1 )
printf("Parent node name: %s\n", *(const char **)(v1 + 48));
}
}

original_code:
void print_parent_node(node *n)
{
 if((n != ((void *)0)) && (n->parent != ((void *)0)))
 {
  element_node *e = (element_node *)(n->parent);
  printf("Parent node name: %s\n", e->name);
 }
}

canonical_original_code:
void print_parent_node(struct node_s *n)
{
 if((n != ((void *)0)) && (n->parent != ((void *)0)))
 {
  struct element_node_s *e = (element_node *)(n->parent);
  printf("Parent node name: %s\n", e->name);
 }
}


decompiled_code:
void __fastcall print_child_nodes(__int64 a1)
{
const char **v1; // rbx
int v2; // eax

if ( !a1 )
_assert_fail("n != NULL", "tree.c", 0x12Au, "print_child_nodes");
v1 = *(const char ***)(a1 + 32);
if ( v1 )
{
printf("Child nodes: ");
do
{
v2 = *(_DWORD *)v1;
if ( *(_DWORD *)v1 )
{
if ( v2 == 1 )
{
printf("text node; ");
}
else if ( v2 == 2 )
{
printf("comment node; ");
}
}
else
{
printf("element node[%s]; ", v1[6]);
}
v1 = (const char **)v1[3];
}
while ( v1 );
puts("\n");
}
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
const char **v1; // rbx
int v2; // eax

if ( !a1 )
_assert_fail("n != NULL", "tree.c", 0x12Au, "print_child_nodes");
v1 = *(const char ***)(a1 + 32);
if ( v1 )
{
printf("Child nodes: ");
do
{
v2 = *(_DWORD *)v1;
if ( *(_DWORD *)v1 )
{
if ( v2 == 1 )
{
printf("text node; ");
}
else if ( v2 == 2 )
{
printf("comment node; ");
}
}
else
{
printf("element node[%s]; ", v1[6]);
}
v1 = (const char **)v1[3];
}
while ( v1 );
puts("\n");
}
}

original_code:
void print_child_nodes(node *n)
{
 node *temp_node;
 ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "tree.c", 298, __extension__ __PRETTY_FUNCTION__); }));
 temp_node = n->first_child;
 if(temp_node != ((void *)0))
 {
  printf("Child nodes: ");
  while(temp_node != ((void *)0))
  {
   if(temp_node->type == ELEMENT_N)
   {
    element_node *e = (element_node *)temp_node;
    printf("element node[%s]; ", e->name);
   }
   else if(temp_node->type == TEXT_N)
   {
    printf("text node; ");
   }
   else if(temp_node->type == COMMENT_N)
   {
    printf("comment node; ");
   }
   else
   {
    ;
   }
   temp_node = temp_node->next_sibling;
  }
  printf("\n\n");
 }
}

canonical_original_code:
void print_child_nodes(struct node_s *n)
{
 struct node_s *temp_node;
 ((void) sizeof ((n != ((void *)0)) ? 1 : 0), __extension__ ({ if (n != ((void *)0)) ; else __assert_fail ("n != NULL", "tree.c", 298, __extension__ __PRETTY_FUNCTION__); }));
 temp_node = n->first_child;
 if(temp_node != ((void *)0))
 {
  printf("Child nodes: ");
  while(temp_node != ((void *)0))
  {
   if(temp_node->type == ELEMENT_N)
   {
    struct element_node_s *e = (element_node *)temp_node;
    printf("element node[%s]; ", e->name);
   }
   else if(temp_node->type == TEXT_N)
   {
    printf("text node; ");
   }
   else if(temp_node->type == COMMENT_N)
   {
    printf("comment node; ");
   }
   else
   {
    ;
   }
   temp_node = temp_node->next_sibling;
  }
  printf("\n\n");
 }
}


decompiled_code:
void __fastcall print_node(__int64 a1)
{
int v1; // eax
int v2; // eax

if ( a1 )
{
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 1 )
{
puts("Node type: TEXT.");
printf("Text data: %s\n", *(const char **)(a1 + 48));
print_parent_node(a1);
}
else if ( v1 == 2 )
{
puts("Node type: COMMENT.");
printf("Comment data: %s\n", *(const char **)(a1 + 48));
print_parent_node(a1);
}
else if ( !v1 )
{
puts("Node type: ELEMENT.");
printf("Element name: %s\n", *(const char **)(a1 + 48));
printf("Element name space: ---------------------------------------------------- ");
v2 = *(_DWORD *)(a1 + 64);
if ( v2 )
{
switch ( v2 )
{
case 1:
puts("MATHML");
break;
case 2:
puts("SVG");
break;
case 3:
puts("XLINK");
break;
case 4:
puts("XML");
break;
case 5:
puts("XMLNS");
break;
}
}
else
{
puts("HTML");
}
html_print_attribute_list(*(_QWORD *)(a1 + 56));
print_parent_node(a1);
print_child_nodes(a1);
}
puts("-----------------------------------------------------------------------------------------");
}
}

original_code:
void print_node(node *n)
{
 if(n != ((void *)0))
 {
  switch (n->type)
  {
   case ELEMENT_N:
    {
     element_node *e = (element_node *)n;
     printf("Node type: ELEMENT.\n");
     printf("Element name: %s\n", e->name);
     printf("Element name space: ---------------------------------------------------- ");
     if(e->name_space == HTML)
     {
      printf("HTML\n");
     }
     else if(e->name_space == MATHML)
     {
      printf("MATHML\n");
     }
     else if(e->name_space == SVG)
     {
      printf("SVG\n");
     }
     else if(e->name_space == XLINK)
     {
      printf("XLINK\n");
     }
     else if(e->name_space == XML)
     {
      printf("XML\n");
     }
     else if(e->name_space == XMLNS)
     {
      printf("XMLNS\n");
     }
     else
     {
      ;
     }
     html_print_attribute_list(e->attributes);
     print_parent_node(n);
     print_child_nodes(n);
    }
    break;
   case TEXT_N:
    {
     text_node *t = (text_node *)n;
     printf("Node type: TEXT.\n");
     printf("Text data: %s\n", t->text_data);
     print_parent_node(n);
    }
    break;
   case COMMENT_N:
    {
     comment_node *c = (comment_node *)n;
     printf("Node type: COMMENT.\n");
     printf("Comment data: %s\n", c->comment_data);
     print_parent_node(n);
    }
    break;
   default:
    break;
  }
  printf("-----------------------------------------------------------------------------------------\n");
 }
}

canonical_original_code:
void print_node(struct node_s *n)
{
 if(n != ((void *)0))
 {
  switch (n->type)
  {
   case ELEMENT_N:
    {
     struct element_node_s *e = (element_node *)n;
     printf("Node type: ELEMENT.\n");
     printf("Element name: %s\n", e->name);
     printf("Element name space: ---------------------------------------------------- ");
     if(e->name_space == HTML)
     {
      printf("HTML\n");
     }
     else if(e->name_space == MATHML)
     {
      printf("MATHML\n");
     }
     else if(e->name_space == SVG)
     {
      printf("SVG\n");
     }
     else if(e->name_space == XLINK)
     {
      printf("XLINK\n");
     }
     else if(e->name_space == XML)
     {
      printf("XML\n");
     }
     else if(e->name_space == XMLNS)
     {
      printf("XMLNS\n");
     }
     else
     {
      ;
     }
     html_print_attribute_list(e->attributes);
     print_parent_node(n);
     print_child_nodes(n);
    }
    break;
   case TEXT_N:
    {
     struct text_node_s *t = (text_node *)n;
     printf("Node type: TEXT.\n");
     printf("Text data: %s\n", t->text_data);
     print_parent_node(n);
    }
    break;
   case COMMENT_N:
    {
     struct comment_node_s *c = (comment_node *)n;
     printf("Node type: COMMENT.\n");
     printf("Comment data: %s\n", c->comment_data);
     print_parent_node(n);
    }
    break;
   default:
    break;
  }
  printf("-----------------------------------------------------------------------------------------\n");
 }
}


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

if ( a1 )
{
print_node(a1);
for ( i = *(_QWORD *)(a1 + 32); i; i = *(_QWORD *)(i + 24) )
print_tree(i);
}
}

original_code:
void print_tree(node *root)
{
 node *temp_node;
 if(root != ((void *)0))
 {
  print_node(root);
  temp_node = root->first_child;
  while(temp_node != ((void *)0))
  {
   print_tree(temp_node);
   temp_node = temp_node->next_sibling;
  }
 }
}

canonical_original_code:
void print_tree(struct node_s *root)
{
 struct node_s *temp_node;
 if(root != ((void *)0))
 {
  print_node(root);
  temp_node = root->first_child;
  while(temp_node != ((void *)0))
  {
   print_tree(temp_node);
   temp_node = temp_node->next_sibling;
  }
 }
}


decompiled_code:
void __fastcall free_tree(_QWORD *a1)
{
__int64 v2; // rbx
__int64 v3; // rdi

if ( a1 )
{
v2 = a1[4];
while ( v2 )
{
v3 = v2;
v2 = *(_QWORD *)(v2 + 24);
free_tree(v3);
}
free_node(a1);
}
}

original_code:
void free_tree(node *root)
{
 node *child_node, *next_sibling;
 if(root != ((void *)0))
 {
  child_node = root->first_child;
  while(child_node != ((void *)0))
  {
   next_sibling = child_node->next_sibling;
   free_tree(child_node);
   child_node = next_sibling;
  }
  free_node(root);
 }
}

canonical_original_code:
void free_tree(struct node_s *root)
{
 struct node_s *child_node; struct node_s *next_sibling;
 if(root != ((void *)0))
 {
  child_node = root->first_child;
  while(child_node != ((void *)0))
  {
   next_sibling = child_node->next_sibling;
   free_tree(child_node);
   child_node = next_sibling;
  }
  free_node(root);
 }
}


decompiled_code:
void __fastcall remove_last_child_node(__int64 a1)
{
_QWORD *v2; // rdi
_QWORD *v3; // rax

if ( !a1 )
_assert_fail("parent != NULL", "tree.c", 0x75u, "remove_last_child_node");
v2 = *(_QWORD **)(a1 + 32);
if ( v2 )
{
v3 = *(_QWORD **)(a1 + 40);
if ( v2 == v3 )
{
free_tree(v2);
*(_QWORD *)(a1 + 32) = 0LL;
*(_QWORD *)(a1 + 40) = 0LL;
}
else
{
*(_QWORD *)(v3[2] + 24LL) = 0LL;
*(_QWORD *)(a1 + 40) = *(_QWORD *)(*(_QWORD *)(a1 + 40) + 16LL);
free_tree(v3);
}
}
}

original_code:
void remove_last_child_node(node *parent)
{
 ((void) sizeof ((parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (parent != ((void *)0)) ; else __assert_fail ("parent != NULL", "tree.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 if(parent->first_child != ((void *)0))
 {
  if(parent->first_child == parent->last_child)
  {
   free_tree(parent->first_child);
   parent->first_child = ((void *)0);
   parent->last_child = ((void *)0);
  }
  else
  {
   node *node_to_delete = parent->last_child;
   parent->last_child->previous_sibling->next_sibling = ((void *)0);
   parent->last_child = parent->last_child->previous_sibling;
   free_tree(node_to_delete);
  }
 }
}

canonical_original_code:
void remove_last_child_node(struct node_s *parent)
{
 ((void) sizeof ((parent != ((void *)0)) ? 1 : 0), __extension__ ({ if (parent != ((void *)0)) ; else __assert_fail ("parent != NULL", "tree.c", 117, __extension__ __PRETTY_FUNCTION__); }));
 if(parent->first_child != ((void *)0))
 {
  if(parent->first_child == parent->last_child)
  {
   free_tree(parent->first_child);
   parent->first_child = ((void *)0);
   parent->last_child = ((void *)0);
  }
  else
  {
   struct node_s *node_to_delete = parent->last_child;
   parent->last_child->previous_sibling->next_sibling = ((void *)0);
   parent->last_child = parent->last_child->previous_sibling;
   free_tree(node_to_delete);
  }
 }
}


decompiled_code:
__int64 __fastcall replacement_for_disallowed_char(int a1, _DWORD *a2)
{
__int64 v2; // rax

v2 = 0LL;
while ( disallowed_chars[2 * v2] != a1 )
{
if ( ++v2 == 34 )
return 0LL;
}
*a2 = disallowed_chars[2 * (int)v2 + 1];
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, _DWORD *a2)
{
__int64 v2; // rax

v2 = 0LL;
while ( disallowed_chars[2 * v2] != a1 )
{
if ( ++v2 == 34 )
return 0LL;
}
*a2 = disallowed_chars[2 * (int)v2 + 1];
return 1LL;
}

original_code:
int replacement_for_disallowed_char(unsigned int char_to_check, unsigned int *replacement_char)
{
 int i;
 for(i = 0; i < 34; i++)
 {
  if(disallowed_chars[i][0] == char_to_check)
  {
   *replacement_char = disallowed_chars[i][1];
   return 1;
  }
 }
 return 0;
}

variable_types: i int


decompiled_code:
char *__fastcall string_n_append(void *ptr, char *src, signed __int64 a3)
{
char *v3; // rbx
size_t v5; // rax
char *v6; // r14

v3 = (char *)ptr;
if ( src && a3 > 0 )
{
if ( ptr )
{
v5 = strlen((const char *)ptr);
v6 = (char *)malloc(a3 + v5 + 1);
strcpy(v6, (const char *)ptr);
free(ptr);
strncat(v6, src, a3);
v3 = v6;
}
else
{
v3 = (char *)malloc(a3 + 1);
strncpy(v3, src, a3);
v3[a3] = 0;
}
}
return v3;
}

canonical_decompiled_code:
char *__fastcall func3(void *ptr, char *src, signed __int64 a3)
{
char *v3; // rbx
size_t v5; // rax
char *v6; // r14

v3 = (char *)ptr;
if ( src && a3 > 0 )
{
if ( ptr )
{
v5 = strlen((const char *)ptr);
v6 = (char *)malloc(a3 + v5 + 1);
strcpy(v6, (const char *)ptr);
free(ptr);
strncat(v6, src, a3);
v3 = v6;
}
else
{
v3 = (char *)malloc(a3 + 1);
strncpy(v3, src, a3);
v3[a3] = 0;
}
}
return v3;
}

original_code:
unsigned char *string_n_append(unsigned char *str1, unsigned char *str2, long num)
{
 if((str2 != ((void *)0)) && (num > 0))
 {
  unsigned char *str;
  if(str1 == ((void *)0))
  {
   str = malloc(num + 1);
   strncpy(str, str2, num);
   str[num] = '\0';
  }
  else
  {
   str = malloc(strlen(str1) + num + 1);
   strcpy(str, str1);
   free(str1);
   strncat(str, str2, num);
  }
  return str;
 }
 else
 {
  return str1;
 }
}

variable_types: num long

variable_types:
str
unsigned char *

return_type: unsigned char *


decompiled_code:
void __fastcall string_lower(const char *a1)
{
signed __int64 v1; // rax
char *v2; // rbx
const char *v3; // r13

if ( a1 )
{
v1 = strlen(a1);
if ( v1 > 0 )
{
v2 = (char *)a1;
v3 = &a1[v1];
do
{
*v2 = tolower((unsigned __int8)*v2);
++v2;
}
while ( v2 != v3 );
}
}
}

canonical_decompiled_code:
void __fastcall func4(const char *a1)
{
signed __int64 v1; // rax
char *v2; // rbx
const char *v3; // r13

if ( a1 )
{
v1 = strlen(a1);
if ( v1 > 0 )
{
v2 = (char *)a1;
v3 = &a1[v1];
do
{
*v2 = tolower((unsigned __int8)*v2);
++v2;
}
while ( v2 != v3 );
}
}
}

original_code:
void string_lower(unsigned char *str)
{
 long i, len;
 if(str != ((void *)0))
 {
  len = strlen(str);
  for(i = 0; i < len; i++)
  {
   str[i] = tolower(str[i]);
  }
 }
}

canonical_original_code:
void string_lower(unsigned char *str)
{
 long i; long len;
 if(str != ((void *)0))
 {
  len = strlen(str);
  for(i = 0; i < len; i++)
  {
   str[i] = tolower(str[i]);
  }
 }
}

variable_types: i long

variable_types: len long


decompiled_code:
__int64 __fastcall is_hex_digit(char a1)
{
return ((unsigned __int8)(a1 - 48) <= 9u) | (unsigned __int8)((unsigned __int8)((a1 & 0xDF) - 65) <= 5u);
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1)
{
return ((unsigned __int8)(a1 - 48) <= 9u) | (unsigned __int8)((unsigned __int8)((a1 & 0xDF) - 65) <= 5u);
}

variable_types:
ch
unsigned char


decompiled_code:
_BOOL8 __fastcall is_dec_digit(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(char a1)
{
return (unsigned __int8)(a1 - 48) <= 9u;
}

original_code:
int is_dec_digit(unsigned char ch)
{
 if((ch >= 48) && (ch <= 57))
 {
  return 1;
 }
 else
 {
  return 0;
 }
}


original_code:
unsigned char *html_character_reference(unsigned char *ch, int is_attr, int has_additional_allowed_char,
          unsigned char additional_allowed_char, int *chars_consumed,
          long curr_buf_index, long buf_len)
{
 unsigned char c = *ch;
 unsigned char *ref_char_bytes;
 unsigned char *following_char;
 unsigned long code_point, second_code_point;
 unsigned int replacement_char;
 int i;
 if((c == 0x09) || (c == 0x0A) || (c == 0x0C) || (c == 0x20)
  || (c == 0x3C) || (c == 0x26) || ((has_additional_allowed_char == 1) && (c == additional_allowed_char)))
 {
  *chars_consumed = 0;
  return ((void *)0);
 }
 else if(c == 0x23)
 {
  if(((curr_buf_index + 1) < buf_len) && ((*(ch + 1) == 'x') || (*(ch + 1) == 'X')))
  {
   int num_hex_digits;
   unsigned char *hex_string;
   num_hex_digits = 0;
   while(((curr_buf_index + 1 + num_hex_digits + 1) < buf_len) &&
      (is_hex_digit(*(ch + 1 + num_hex_digits + 1))))
   {
    num_hex_digits += 1;
   }
   if(num_hex_digits == 0)
   {
    *chars_consumed = 0;
    return ((void *)0);
   }
   else
   {
    hex_string = malloc(num_hex_digits + 1);
    for(i = 0; i < num_hex_digits; i++)
    {
     hex_string[i] = *(ch + 2 + i);
    }
    hex_string[num_hex_digits] = '\0';
    code_point = strtol(hex_string, &following_char, 16);
    free(hex_string);
    if(((curr_buf_index + 1 + num_hex_digits + 1) < buf_len) &&
       (*(ch + 1 + num_hex_digits + 1) == ';'))
    {
     *chars_consumed = num_hex_digits + 3;
    }
    else
    {
     *chars_consumed = num_hex_digits + 2;
    }
   }
  }
  else
  {
   int num_dec_digits;
   unsigned char *dec_string;
   num_dec_digits = 0;
   while(((curr_buf_index + num_dec_digits + 1) < buf_len) &&
      (is_dec_digit(*(ch + num_dec_digits + 1))))
   {
    num_dec_digits += 1;
   }
   if(num_dec_digits == 0)
   {
    *chars_consumed = 0;
    return ((void *)0);
   }
   else
   {
    dec_string = malloc(num_dec_digits + 1);
    for(i = 0; i < num_dec_digits; i++)
    {
     dec_string[i] = *(ch + 1 + i);
    }
    dec_string[num_dec_digits] = '\0';
    code_point = strtol(dec_string, &following_char, 10);
    free(dec_string);
    if(((curr_buf_index + num_dec_digits + 1) < buf_len) &&
       (*(ch + num_dec_digits + 1) == ';'))
    {
     *chars_consumed = num_dec_digits + 2;
    }
    else
    {
     *chars_consumed = num_dec_digits + 1;
    }
   }
  }
  if(((code_point >= 0xD800) && (code_point <= 0xDFFF)) || (code_point > 0x10FFFF))
  {
   code_point = 0xFFFD;
  }
  if(replacement_for_disallowed_char(code_point, &replacement_char) == 1)
  {
   code_point = replacement_char;
  }
  if(code_point_disallowed(code_point) == 1)
  {
   *chars_consumed = 0;
   return ((void *)0);
  }
  ref_char_bytes = malloc(10);
  utf8_byte_sequence(code_point, ref_char_bytes);
  return ref_char_bytes;
 }
 else
 {
  int max_name_len = 31, initial_str_len, matched_str_len;
  unsigned char *initial_str;
  initial_str_len = max_name_len;
  for(i = 0; i <= max_name_len; i++)
  {
   if((curr_buf_index + i) == (buf_len - 1))
   {
    initial_str_len = i + 1;
    break;
   }
   if(*(ch + i) == 0x3B)
   {
    initial_str_len = i;
    break;
   }
  }
  if(initial_str_len == 0)
  {
   *chars_consumed = 0;
   return ((void *)0);
  }
  else
  {
   initial_str = malloc(initial_str_len + 1);
   for(i = 0; i < initial_str_len; i++)
   {
    initial_str[i] = *(ch + i);
   }
   initial_str[initial_str_len] = '\0';
   matched_str_len = 0;
   for(i = initial_str_len; i > 0; i--)
   {
    initial_str[i] = '\0';
    if(is_named_char_ref(initial_str, &code_point) == 1)
    {
     matched_str_len = i;
     break;
    }
   }
   if((matched_str_len == initial_str_len) && ((curr_buf_index + initial_str_len - 1) == (buf_len - 1)))
   {
    *chars_consumed = initial_str_len;
   }
   else if((matched_str_len == initial_str_len) && (*(ch + initial_str_len) == 0x3B))
   {
    *chars_consumed = initial_str_len + 1;
   }
   else
   {
    *chars_consumed = matched_str_len;
    if(is_attr == 1)
    {
     if((*(ch + matched_str_len) == 0x3D) ||
        ((*(ch + matched_str_len) >= 0x30) && (*(ch + matched_str_len) <= 0x39)) ||
        ((*(ch + matched_str_len) >= 0x41) && (*(ch + matched_str_len) <= 0x5A)) ||
        ((*(ch + matched_str_len) >= 0x61) && (*(ch + matched_str_len) <= 0x7A)))
     {
      *chars_consumed = 0;
      free(initial_str);
      return ((void *)0);
     }
    }
   }
   if(matched_str_len == 0)
   {
    free(initial_str);
    return ((void *)0);
   }
   else
   {
    ref_char_bytes = malloc(10);
    utf8_byte_sequence(code_point, ref_char_bytes);
    if(has_second_code_point(initial_str, &second_code_point) == 1)
    {
     unsigned char more_char_bytes[5];
     utf8_byte_sequence(second_code_point, more_char_bytes);
     strcat(ref_char_bytes, more_char_bytes);
    }
    free(initial_str);
    return ref_char_bytes;
   }
  }
 }
}

canonical_original_code:
unsigned char *html_character_reference(unsigned char *ch, int is_attr, int has_additional_allowed_char, unsigned char additional_allowed_char, int *chars_consumed, long curr_buf_index, long buf_len)
{
 unsigned char c = *ch;
 unsigned char *ref_char_bytes;
 unsigned char *following_char;
 unsigned long code_point; unsigned long second_code_point;
 unsigned int replacement_char;
 int i;
 if((c == 0x09) || (c == 0x0A) || (c == 0x0C) || (c == 0x20)
  || (c == 0x3C) || (c == 0x26) || ((has_additional_allowed_char == 1) && (c == additional_allowed_char)))
 {
  *chars_consumed = 0;
  return ((void *)0);
 }
 else if(c == 0x23)
 {
  if(((curr_buf_index + 1) < buf_len) && ((*(ch + 1) == 'x') || (*(ch + 1) == 'X')))
  {
   int num_hex_digits;
   unsigned char *hex_string;
   num_hex_digits = 0;
   while(((curr_buf_index + 1 + num_hex_digits + 1) < buf_len) &&
      (is_hex_digit(*(ch + 1 + num_hex_digits + 1))))
   {
    num_hex_digits += 1;
   }
   if(num_hex_digits == 0)
   {
    *chars_consumed = 0;
    return ((void *)0);
   }
   else
   {
    hex_string = malloc(num_hex_digits + 1);
    for(i = 0; i < num_hex_digits; i++)
    {
     hex_string[i] = *(ch + 2 + i);
    }
    hex_string[num_hex_digits] = '\0';
    code_point = strtol(hex_string, &following_char, 16);
    free(hex_string);
    if(((curr_buf_index + 1 + num_hex_digits + 1) < buf_len) &&
       (*(ch + 1 + num_hex_digits + 1) == ';'))
    {
     *chars_consumed = num_hex_digits + 3;
    }
    else
    {
     *chars_consumed = num_hex_digits + 2;
    }
   }
  }
  else
  {
   int num_dec_digits;
   unsigned char *dec_string;
   num_dec_digits = 0;
   while(((curr_buf_index + num_dec_digits + 1) < buf_len) &&
      (is_dec_digit(*(ch + num_dec_digits + 1))))
   {
    num_dec_digits += 1;
   }
   if(num_dec_digits == 0)
   {
    *chars_consumed = 0;
    return ((void *)0);
   }
   else
   {
    dec_string = malloc(num_dec_digits + 1);
    for(i = 0; i < num_dec_digits; i++)
    {
     dec_string[i] = *(ch + 1 + i);
    }
    dec_string[num_dec_digits] = '\0';
    code_point = strtol(dec_string, &following_char, 10);
    free(dec_string);
    if(((curr_buf_index + num_dec_digits + 1) < buf_len) &&
       (*(ch + num_dec_digits + 1) == ';'))
    {
     *chars_consumed = num_dec_digits + 2;
    }
    else
    {
     *chars_consumed = num_dec_digits + 1;
    }
   }
  }
  if(((code_point >= 0xD800) && (code_point <= 0xDFFF)) || (code_point > 0x10FFFF))
  {
   code_point = 0xFFFD;
  }
  if(replacement_for_disallowed_char(code_point, &replacement_char) == 1)
  {
   code_point = replacement_char;
  }
  if(code_point_disallowed(code_point) == 1)
  {
   *chars_consumed = 0;
   return ((void *)0);
  }
  ref_char_bytes = malloc(10);
  utf8_byte_sequence(code_point, ref_char_bytes);
  return ref_char_bytes;
 }
 else
 {
  int max_name_len = 31; int initial_str_len; int matched_str_len;
  unsigned char *initial_str;
  initial_str_len = max_name_len;
  for(i = 0; i <= max_name_len; i++)
  {
   if((curr_buf_index + i) == (buf_len - 1))
   {
    initial_str_len = i + 1;
    break;
   }
   if(*(ch + i) == 0x3B)
   {
    initial_str_len = i;
    break;
   }
  }
  if(initial_str_len == 0)
  {
   *chars_consumed = 0;
   return ((void *)0);
  }
  else
  {
   initial_str = malloc(initial_str_len + 1);
   for(i = 0; i < initial_str_len; i++)
   {
    initial_str[i] = *(ch + i);
   }
   initial_str[initial_str_len] = '\0';
   matched_str_len = 0;
   for(i = initial_str_len; i > 0; i--)
   {
    initial_str[i] = '\0';
    if(is_named_char_ref(initial_str, &code_point) == 1)
    {
     matched_str_len = i;
     break;
    }
   }
   if((matched_str_len == initial_str_len) && ((curr_buf_index + initial_str_len - 1) == (buf_len - 1)))
   {
    *chars_consumed = initial_str_len;
   }
   else if((matched_str_len == initial_str_len) && (*(ch + initial_str_len) == 0x3B))
   {
    *chars_consumed = initial_str_len + 1;
   }
   else
   {
    *chars_consumed = matched_str_len;
    if(is_attr == 1)
    {
     if((*(ch + matched_str_len) == 0x3D) ||
        ((*(ch + matched_str_len) >= 0x30) && (*(ch + matched_str_len) <= 0x39)) ||
        ((*(ch + matched_str_len) >= 0x41) && (*(ch + matched_str_len) <= 0x5A)) ||
        ((*(ch + matched_str_len) >= 0x61) && (*(ch + matched_str_len) <= 0x7A)))
     {
      *chars_consumed = 0;
      free(initial_str);
      return ((void *)0);
     }
    }
   }
   if(matched_str_len == 0)
   {
    free(initial_str);
    return ((void *)0);
   }
   else
   {
    ref_char_bytes = malloc(10);
    utf8_byte_sequence(code_point, ref_char_bytes);
    if(has_second_code_point(initial_str, &second_code_point) == 1)
    {
     unsigned char more_char_bytes[5];
     utf8_byte_sequence(second_code_point, more_char_bytes);
     strcat(ref_char_bytes, more_char_bytes);
    }
    free(initial_str);
    return ref_char_bytes;
   }
  }
 }
}

variable_types:
ch
unsigned char *

variable_types:
c
unsigned char


decompiled_code:
__int64 __fastcall is_named_char_ref(char *s1, __int64 *a2)
{
__int64 v2; // rbx
char *endptr; // [rsp+8h] [rbp-28h] BYREF

v2 = 0LL;
while ( strcmp(s1, (&named_chars)[2 * v2]) )
{
if ( ++v2 == 2231 )
return 0LL;
}
*a2 = strtol((&named_chars)[2 * (int)v2 + 1], &endptr, 16);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *s1, __int64 *a2)
{
__int64 v2; // rbx
char *endptr; // [rsp+8h] [rbp-28h] BYREF

v2 = 0LL;
while ( strcmp(s1, (&named_chars)[2 * v2]) )
{
if ( ++v2 == 2231 )
return 0LL;
}
*a2 = strtol((&named_chars)[2 * (int)v2 + 1], &endptr, 16);
return 1LL;
}

original_code:
int is_named_char_ref(unsigned char *char_to_check, unsigned long *code_point)
{
 int i;
 unsigned char *following_char;
 for(i = 0; i < 2231; i++)
 {
  if(strcmp(char_to_check, named_chars[i][0]) == 0)
  {
   *code_point =strtol(named_chars[i][1], &following_char, 16);
   return 1;
  }
 }
 return 0;
}


decompiled_code:
__int64 __fastcall has_second_code_point(char *s1, __int64 *a2)
{
__int64 v2; // rbx
char *endptr; // [rsp+8h] [rbp-28h] BYREF

v2 = 0LL;
while ( strcmp(s1, second_code_points[2 * v2]) )
{
if ( ++v2 == 93 )
return 0LL;
}
*a2 = strtol(second_code_points[2 * (int)v2 + 1], &endptr, 16);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1, __int64 *a2)
{
__int64 v2; // rbx
char *endptr; // [rsp+8h] [rbp-28h] BYREF

v2 = 0LL;
while ( strcmp(s1, second_code_points[2 * v2]) )
{
if ( ++v2 == 93 )
return 0LL;
}
*a2 = strtol(second_code_points[2 * (int)v2 + 1], &endptr, 16);
return 1LL;
}

original_code:
int has_second_code_point(unsigned char *char_to_check, unsigned long *code_point)
{
 int i;
 unsigned char *following_char;
 for(i = 0; i < 93; i++)
 {
  if(strcmp(char_to_check, second_code_points[i][0]) == 0)
  {
   *code_point = strtol(second_code_points[i][1], &following_char, 16);
   return 1;
  }
 }
 return 0;
}


decompiled_code:
_BOOL8 __fastcall code_point_disallowed(unsigned __int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rdx

if ( a1 > 0x1F )
{
result = 1LL;
if ( a1 - 127 <= 0x20 )
return result;
}
else
{
result = 1LL;
v2 = 4294953470LL;
if ( _bittest64(&v2, a1) )
return result;
}
result = 1LL;
if ( a1 - 64976 > 0x1F )
{
v3 = a1 & 0xFFFFFFFFFFFEFFFELL;
if ( (a1 & 0xFFFFFFFFFFFEFFFELL) != 65534
&& v3 != 196606
&& v3 != 327678
&& v3 != 458750
&& v3 != 589822
&& v3 != 720894
&& v3 != 851966 )
{
if ( v3 == 983038 )
result = 1LL;
else
result = a1 - 1114110 <= 1;
}
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(unsigned __int64 a1)
{
_BOOL8 result; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rdx

if ( a1 > 0x1F )
{
result = 1LL;
if ( a1 - 127 <= 0x20 )
return result;
}
else
{
result = 1LL;
v2 = 4294953470LL;
if ( _bittest64(&v2, a1) )
return result;
}
result = 1LL;
if ( a1 - 64976 > 0x1F )
{
v3 = a1 & 0xFFFFFFFFFFFEFFFELL;
if ( (a1 & 0xFFFFFFFFFFFEFFFELL) != 65534
&& v3 != 196606
&& v3 != 327678
&& v3 != 458750
&& v3 != 589822
&& v3 != 720894
&& v3 != 851966 )
{
if ( v3 == 983038 )
result = 1LL;
else
result = a1 - 1114110 <= 1;
}
}
return result;
}

original_code:
int code_point_disallowed(unsigned long code_point)
{
 if(((code_point >= 0x0001) && (code_point <= 0x0008)) ||
    ((code_point >= 0x000E) && (code_point <= 0x001F)) ||
    ((code_point >= 0x007F) && (code_point <= 0x009F)) ||
    ((code_point >= 0xFDD0) && (code_point <= 0xFDEF)) ||
  (code_point == 0x000B) ||
  (code_point == 0xFFFE) ||
  (code_point == 0xFFFF) ||
  (code_point == 0x1FFFE) ||
  (code_point == 0x1FFFF) ||
  (code_point == 0x2FFFE) ||
  (code_point == 0x2FFFF) ||
  (code_point == 0x3FFFE) ||
  (code_point == 0x3FFFF) ||
  (code_point == 0x4FFFE) ||
  (code_point == 0x4FFFF) ||
  (code_point == 0x5FFFE) ||
  (code_point == 0x5FFFF) ||
  (code_point == 0x6FFFE) ||
  (code_point == 0x6FFFF) ||
  (code_point == 0x7FFFE) ||
  (code_point == 0x7FFFF) ||
  (code_point == 0x8FFFE) ||
  (code_point == 0x8FFFF) ||
  (code_point == 0x9FFFE) ||
  (code_point == 0x9FFFF) ||
  (code_point == 0xAFFFE) ||
  (code_point == 0xAFFFF) ||
  (code_point == 0xBFFFE) ||
  (code_point == 0xBFFFF) ||
  (code_point == 0xCFFFE) ||
  (code_point == 0xCFFFF) ||
  (code_point == 0xDFFFE) ||
  (code_point == 0xDFFFF) ||
  (code_point == 0xEFFFE) ||
  (code_point == 0xEFFFF) ||
  (code_point == 0xFFFFE) ||
  (code_point == 0xFFFFF) ||
  (code_point == 0x10FFFE) ||
  (code_point == 0x10FFFF) )
 {
  return 1;
 }
 else
 {
  return 0;
 }
}


debug

repo: yfyf/idris-concstate-effect

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

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

original_code:
int debug(char* str) {
    return 0;
}

canonical_original_code:
int debug(char *str) {
    return 0;
}

variable_types:
str
char *


decompiled_code:
__int64 __fastcall get_path(char *a1, unsigned int a2)
{
sprintf(a1, "/tmp/idris-resource-%d", a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1, unsigned int a2)
{
sprintf(a1, "/tmp/idris-resource-%d", a2);
return 0LL;
}

original_code:
int get_path(char* buff, int id) {
    sprintf(buff, "/tmp/idris-resource-%d", id);
    return 0;
}

canonical_original_code:
int get_path(char *buff, int id) {
    sprintf(buff, "/tmp/idris-resource-%d", id);
    return 0;
}

variable_types:
buff
char *

variable_types: id int


decompiled_code:
int __fastcall open_file(unsigned int a1)
{
int result; // eax
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

get_path(v2, a1);
result = open(v2, 66, 438LL);
if ( result < 0 )
{
printf("Failed to open file");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1)
{
int result; // eax
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

func1(v2, a1);
result = open(v2, 66, 438LL);
if ( result < 0 )
{
printf("Failed to open file");
exit(1);
}
return result;
}

original_code:
int open_file(int id) {
    int fd;
    char path[100];
    get_path(path, id);
    if ((fd = open(path, 0100 | 02, 0666)) < 0) {
        printf("Failed to open file");
        exit(1);
    }
    return fd;
}

variable_types: fd int

variable_types:
path
char [100]


decompiled_code:
__int64 __fastcall init_lock(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

get_path(v2, a1);
remove(v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
char v2[120]; // [rsp+0h] [rbp-78h] BYREF

func1(v2, a1);
remove(v2);
return 0LL;
}

original_code:
int init_lock(int id) {
    char path[100];
    get_path(path, id);
    remove(path);
    return 0;
}


decompiled_code:
__int64 __fastcall get_lock(unsigned int a1)
{
unsigned int v1; // ebx

v1 = open_file(a1);
if ( flock(v1, 2) < 0 )
{
printf("Locking failed");
exit(1);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
unsigned int v1; // ebx

v1 = func2(a1);
if ( flock(v1, 2) < 0 )
{
printf("Locking failed");
exit(1);
}
return v1;
}

original_code:
int get_lock(int id) {
    int fd;
    fd = open_file(id);
    if (flock (fd, 2) < 0) {
        printf("Locking failed");
        exit(1);
    }
    debug("Got lock");
    return fd;
}


decompiled_code:
__int64 __fastcall release_lock(int fd)
{
flock(fd, 8);
close(fd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd)
{
flock(fd, 8);
close(fd);
return 0LL;
}

original_code:
int release_lock(int fd) {
    debug("Released lock");
    flock(fd, 8);
    close(fd);
    return 0;
}


decompiled_code:
__int64 __fastcall empty_file(int fd)
{
ftruncate(fd, 0LL);
lseek(fd, 0LL, 0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(int fd)
{
ftruncate(fd, 0LL);
lseek(fd, 0LL, 0);
return 0LL;
}

original_code:
int empty_file(int fd) {
    ftruncate(fd, 0);
    lseek(fd, 0, 0);
    return 0;
}


decompiled_code:
__int64 __fastcall write_locked(int fd, unsigned int a2)
{
size_t v2; // rax
char v4[136]; // [rsp+0h] [rbp-88h] BYREF

empty_file(fd);
sprintf(v4, "%d", a2);
v2 = strlen(v4);
write(fd, v4, v2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(int fd, unsigned int a2)
{
size_t v2; // rax
char v4[136]; // [rsp+0h] [rbp-88h] BYREF

func6(fd);
sprintf(v4, "%d", a2);
v2 = strlen(v4);
write(fd, v4, v2);
return 0LL;
}

original_code:
int write_locked(int fd, int val) {
    debug("Writing...");
    empty_file(fd);
    char buf[100];
    sprintf(buf, "%d", val);
    debug(buf);
    write(fd, buf, strlen(buf));
    return 0;
}

variable_types: val int

variable_types:
buf
char [100]


decompiled_code:
__int64 __fastcall read_locked(int fd)
{
__off_t v1; // r12
void *v2; // rbp
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = lseek(fd, 0LL, 2);
lseek(fd, 0LL, 0);
v2 = malloc(v1 + 1);
read(fd, v2, v1);
_isoc99_sscanf(v2, "%d", &v4);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(int fd)
{
__off_t v1; // r12
void *v2; // rbp
unsigned int v4; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = lseek(fd, 0LL, 2);
lseek(fd, 0LL, 0);
v2 = malloc(v1 + 1);
read(fd, v2, v1);
_isoc99_sscanf(v2, "%d", &v4);
return v4;
}

original_code:
int read_locked(int fd) {
    debug("Reading...");
    off_t size = lseek(fd, 0, 2);
    lseek(fd, 0, 0);
    char *buff = malloc(size + 1);
    read(fd, buff, size);
    int ret;
    sscanf(buff, "%d", &ret);
    return ret;
}

canonical_original_code:
int read_locked(int fd) {
    debug("Reading...");
    long size = lseek(fd, 0, 2);
    lseek(fd, 0, 0);
    char *buff = malloc(size + 1);
    read(fd, buff, size);
    int ret;
    sscanf(buff, "%d", &ret);
    return ret;
}

variable_types: size long

variable_types: ret int


myhashfunc

repo: ygarbage/compilation

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

original_code:
hsize myhashfunc(const char * key){
  hsize hash=0;
  return hash;
}

canonical_original_code:
unsigned long myhashfunc(char *key){
  unsigned long hash = 0;
  return hash;
}

variable_types:
key
char *

variable_types:
hash
unsigned long

return_type: unsigned long


decompiled_code:
__int64 test_create__destroy()
{
__int64 v0; // rax

v0 = htable_create(101LL, 0LL);
htable_destroy(v0);
return 1LL;
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax

v0 = htable_create(101LL, 0LL);
htable_destroy(v0);
return 1LL;
}

original_code:
int test_create__destroy(){
  hashtable* myhtable;
  hsize size=101;
  myhtable=htable_create(size,((void *)0));
  htable_destroy(myhtable);
  myhtable=((void *)0);
  return 1;
}

canonical_original_code:
int test_create__destroy(){
  struct hashtable_ *myhtable;
  unsigned long size = 101;
  myhtable=htable_create(size,((void *)0));
  htable_destroy(myhtable);
  myhtable=((void *)0);
  return 1;
}

variable_types: struct hashtable_ { unsigned long size; struct hashnode { char *key; void *data; struct hashnode *next; } **nodes; unsigned long (*hashfunc)(char *); } *

variable_types:
size
unsigned long

user_defined_types: struct hashtable_ { unsigned long size; struct hashnode **nodes; unsigned long (*hashfunc)(char *); }


decompiled_code:
__int64 test_add_element_and_find_it()
{
__int64 v0; // rbx

v0 = htable_create(101LL, 0LL);
htable_insert(v0, "Hugo", "Yvaon");
if ( strcmp("Yvaon", (const char *)htable_get(v0, "Hugo")) )
_assert_fail(
"!strcmp(\"Yvaon\",htable_get(myhtable,\"Hugo\"))",
"htable_test.c",
0x1Bu,
"test_add_element_and_find_it");
htable_destroy(v0);
return 1LL;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rbx

v0 = htable_create(101LL, 0LL);
htable_insert(v0, "Hugo", "Yvaon");
if ( strcmp("Yvaon", (const char *)htable_get(v0, "Hugo")) )
_assert_fail(
"!strcmp(\"Yvaon\",htable_get(myhtable,\"Hugo\"))",
"htable_test.c",
0x1Bu,
"test_add_element_and_find_it");
htable_destroy(v0);
return 1LL;
}

original_code:
int test_add_element_and_find_it(){
  hashtable* myhtable;
  hsize size=101;
  myhtable=htable_create(size,((void *)0));
  htable_insert(myhtable,"Hugo","Yvaon");
  ((void) sizeof ((!strcmp("Yvaon",htable_get(myhtable,"Hugo"))) ? 1 : 0), __extension__ ({ if (!strcmp("Yvaon",htable_get(myhtable,"Hugo"))) ; else __assert_fail ("!strcmp(\"Yvaon\",htable_get(myhtable,\"Hugo\"))", "htable_test.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  htable_destroy(myhtable);
  myhtable=((void *)0);
  return 1;
}

canonical_original_code:
int test_add_element_and_find_it(){
  struct hashtable_ *myhtable;
  unsigned long size = 101;
  myhtable=htable_create(size,((void *)0));
  htable_insert(myhtable,"Hugo","Yvaon");
  ((void) sizeof ((!strcmp("Yvaon",htable_get(myhtable,"Hugo"))) ? 1 : 0), __extension__ ({ if (!strcmp("Yvaon",htable_get(myhtable,"Hugo"))) ; else __assert_fail ("!strcmp(\"Yvaon\",htable_get(myhtable,\"Hugo\"))", "htable_test.c", 27, __extension__ __PRETTY_FUNCTION__); }));
  htable_destroy(myhtable);
  myhtable=((void *)0);
  return 1;
}

user_defined_types: struct hashnode { char *key; void *data; struct hashnode *next; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)test_create__destroy(argc, argv, envp) )
puts("OK");
else
printf("test create destroy failed");
if ( (unsigned int)test_add_element_and_find_it() )
puts("OK");
else
printf("test add element and find it failed");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
if ( (unsigned int)func1(argc, argv, envp) )
puts("OK");
else
printf("test create destroy failed");
if ( (unsigned int)func2() )
puts("OK");
else
printf("test add element and find it failed");
return 0;
}

original_code:
int main(int argc, char* argv[]){
  if(test_create__destroy()) printf("OK\n");
  else printf("test create destroy failed");
  if(test_add_element_and_find_it()) printf("OK\n");
  else printf("test add element and find it failed");
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
  if(test_create__destroy()) printf("OK\n");
  else printf("test create destroy failed");
  if(test_add_element_and_find_it()) printf("OK\n");
  else printf("test add element and find it failed");
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 __fastcall def_hashfunc(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
do
{
v2 += (char)v1 + 8 * v1;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1)
{
unsigned __int8 v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
do
{
v2 += (char)v1 + 8 * v1;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

original_code:
hsize def_hashfunc(const char * key){
  hsize hash=0;
  while(*key!='\0'){
    hash+= *key+8* (unsigned char)*key;
    (unsigned char) *key++;
  }
  return hash;
}

canonical_original_code:
unsigned long def_hashfunc(char *key){
  unsigned long hash = 0;
  while(*key!='\0'){
    hash+= *key+8* (unsigned char)*key;
    (unsigned char) *key++;
  }
  return hash;
}


decompiled_code:
void __fastcall htable_destroy(void *ptr)
{
unsigned __int64 v2; // rbp
__int64 v3; // rbx
void *v4; // rdi

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

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
unsigned __int64 v2; // rbp
__int64 v3; // rbx
void *v4; // rdi

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

original_code:
void htable_destroy(struct hashtable *h){
  hsize n;
  struct hashnode * node, *oldnode;
  for(n=0;n<h->size;n++){
    node=h->nodes[n];
    while(node){
      free(node->key);
      oldnode=node;
      node=node->next;
      free(oldnode);
    }
  }
  free(h->nodes);
  free(h);
}

canonical_original_code:
void htable_destroy(struct hashtable *h){
  unsigned long n;
  struct hashnode *node; struct hashnode *oldnode;
  for(n=0;n<h->size;n++){
    node=h->nodes[n];
    while(node){
      free(node->key);
      oldnode=node;
      node=node->next;
      free(oldnode);
    }
  }
  free(h->nodes);
  free(h);
}

variable_types: struct hashtable { unsigned long size; struct hashnode { char *key; void *data; struct hashnode *next; } **nodes; unsigned long (*hashfunc)(char *); } *

variable_types:
n
unsigned long

user_defined_types: struct hashtable { unsigned long size; struct hashnode **nodes; unsigned long (*hashfunc)(char *); }


decompiled_code:
int __fastcall htable_insert(__int64 a1, const char *a2, __int64 a3)
{
__int64 *v4; // r13
__int64 v5; // rbx
int result; // eax
_QWORD *v7; // rbx
char *v8; // rax

v4 = (__int64 *)(*(_QWORD *)(a1 + 8)
+ 8 * ((unsigned __int64)(*(__int64 (__fastcall **)(const char *))(a1 + 16))(a2) % *(_QWORD *)a1));
v5 = *v4;
if ( *v4 )
{
while ( 1 )
{
result = strcmp(*(const char **)v5, a2);
if ( !result )
break;
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_4;
}
*(_QWORD *)(v5 + 8) = a3;
}
else
{
LABEL_4:
v7 = malloc(0x18uLL);
if ( v7 )
{
v8 = strdup(a2);
*v7 = v8;
if ( v8 )
{
v7[1] = a3;
v7[2] = *v4;
*v4 = (__int64)v7;
result = 0;
}
else
{
free(v7);
result = -1;
}
}
else
{
result = -1;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, const char *a2, __int64 a3)
{
__int64 *v4; // r13
__int64 v5; // rbx
int result; // eax
_QWORD *v7; // rbx
char *v8; // rax

v4 = (__int64 *)(*(_QWORD *)(a1 + 8)
+ 8 * ((unsigned __int64)(*(__int64 (__fastcall **)(const char *))(a1 + 16))(a2) % *(_QWORD *)a1));
v5 = *v4;
if ( *v4 )
{
while ( 1 )
{
result = strcmp(*(const char **)v5, a2);
if ( !result )
break;
v5 = *(_QWORD *)(v5 + 16);
if ( !v5 )
goto LABEL_4;
}
*(_QWORD *)(v5 + 8) = a3;
}
else
{
LABEL_4:
v7 = malloc(0x18uLL);
if ( v7 )
{
v8 = strdup(a2);
*v7 = v8;
if ( v8 )
{
v7[1] = a3;
v7[2] = *v4;
*v4 = (__int64)v7;
result = 0;
}
else
{
free(v7);
result = -1;
}
}
else
{
result = -1;
}
}
return result;
}

original_code:
int htable_insert(struct hashtable *h, const char *key, void* data){
  struct hashnode *node;
  hsize hash=h->hashfunc(key)%h->size;
  node=h->nodes[hash];
  while(node){
    if(!(strcmp(node->key,key))){
      node->data=data;
      return 0;
    }
    node=node->next;
  }
  if(!(node=malloc(sizeof(struct hashnode)))) return -1;
  if(!(node->key=strdup(key))){
    free(node);
    return -1;
  }
  node->data=data;
  node->next=h->nodes[hash];
  h->nodes[hash]=node;
  return 0;
}

canonical_original_code:
int htable_insert(struct hashtable *h, char *key, void *data){
  struct hashnode *node;
  unsigned long hash = h->hashfunc(key)%h->size;
  node=h->nodes[hash];
  while(node){
    if(!(strcmp(node->key,key))){
      node->data=data;
      return 0;
    }
    node=node->next;
  }
  if(!(node=malloc(sizeof(struct hashnode)))) return -1;
  if(!(node->key=strdup(key))){
    free(node);
    return -1;
  }
  node->data=data;
  node->next=h->nodes[hash];
  h->nodes[hash]=node;
  return 0;
}

variable_types:
data
void *

variable_types: struct hashnode { char *key; void *data; struct hashnode *next; } *


decompiled_code:
int __fastcall htable_insert_type(__int64 a1, const char *a2, int a3)
{
_DWORD *v4; // rax

v4 = malloc(0x820uLL);
*v4 = a3;
return htable_insert(a1, a2, (__int64)v4);
}

canonical_decompiled_code:
int __fastcall func3(__int64 a1, const char *a2, int a3)
{
_DWORD *v4; // rax

v4 = malloc(0x820uLL);
*v4 = a3;
return func2(a1, a2, (__int64)v4);
}

original_code:
void *htable_insert_type(struct hashtable* h, const char*key, enum Type type){
  struct Variable* data=malloc(sizeof(struct Variable));
  data->type=type;
  htable_insert(h,key,data);
}

canonical_original_code:
void *htable_insert_type(struct hashtable *h, char *key, enum Type type){
  struct Variable *data = malloc(sizeof(struct Variable));
  data->type=type;
  htable_insert(h,key,data);
}

variable_types: struct Variable { enum Type { INTEGER=0, INTPOINTER=1, REAL=2, REALPOINTER=3, EMPTY=4, STRING=5, OPERATOREQUAL=6, STRUCTURE=7 } type; enum Comportement { VAR=0, CST=1, FUNCTION=2 } cmpt; char *name; char *llvm_name; char code[2048]; float value; } *

return_type: void *

user_defined_types: struct Variable { enum Type type; enum Comportement cmpt; char *name; char *llvm_name; char code[2048]; float value; }


decompiled_code:
__int64 __fastcall htable_remove(__int64 a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // r14
char *v4; // r12
unsigned int v5; // ebx
unsigned __int64 v7; // [rsp+8h] [rbp-40h]

v7 = (unsigned __int64)(*(__int64 (__fastcall **)(const char *))(a1 + 16))(a2) % *(_QWORD *)a1;
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7);
if ( v2 )
{
v3 = 0LL;
while ( 1 )
{
v4 = *(char **)v2;
v5 = strcmp(*(const char **)v2, a2);
if ( !v5 )
break;
v3 = v2;
if ( !*(_QWORD *)(v2 + 16) )
goto LABEL_6;
v2 = *(_QWORD *)(v2 + 16);
}
free(v4);
if ( v3 )
*(_QWORD *)(v3 + 16) = *(_QWORD *)(v2 + 16);
else
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7) = *(_QWORD *)(v2 + 16);
free((void *)v2);
}
else
{
LABEL_6:
perror("htable_remove() : element not found");
v5 = -1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, const char *a2)
{
__int64 v2; // rbp
__int64 v3; // r14
char *v4; // r12
unsigned int v5; // ebx
unsigned __int64 v7; // [rsp+8h] [rbp-40h]

v7 = (unsigned __int64)(*(__int64 (__fastcall **)(const char *))(a1 + 16))(a2) % *(_QWORD *)a1;
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7);
if ( v2 )
{
v3 = 0LL;
while ( 1 )
{
v4 = *(char **)v2;
v5 = strcmp(*(const char **)v2, a2);
if ( !v5 )
break;
v3 = v2;
if ( !*(_QWORD *)(v2 + 16) )
goto LABEL_6;
v2 = *(_QWORD *)(v2 + 16);
}
free(v4);
if ( v3 )
*(_QWORD *)(v3 + 16) = *(_QWORD *)(v2 + 16);
else
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v7) = *(_QWORD *)(v2 + 16);
free((void *)v2);
}
else
{
LABEL_6:
perror("htable_remove() : element not found");
v5 = -1;
}
return v5;
}

original_code:
int htable_remove(struct hashtable* h, const char *key){
  struct hashnode *node,*prevnode=((void *)0);
  hsize hash=h->hashfunc(key)%h->size;
  node=h->nodes[hash];
  while(node){
    if(!strcmp(node->key,key)){
      free(node->key);
      if(((void *)0)==prevnode) h->nodes[hash]=node->next;
      else prevnode->next=node->next;
      free(node);
      return 0;
    }
    prevnode=node;
    node=node->next;
  }
  perror("htable_remove() : element not found");
  return -1;
}

canonical_original_code:
int htable_remove(struct hashtable *h, char *key){
  struct hashnode *node; struct hashnode *prevnode = ((void *)0);
  unsigned long hash = h->hashfunc(key)%h->size;
  node=h->nodes[hash];
  while(node){
    if(!strcmp(node->key,key)){
      free(node->key);
      if(((void *)0)==prevnode) h->nodes[hash]=node->next;
      else prevnode->next=node->next;
      free(node);
      return 0;
    }
    prevnode=node;
    node=node->next;
  }
  perror("htable_remove() : element not found");
  return -1;
}


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

v2 = *(_QWORD *)(*(_QWORD *)(a1 + 8)
+ 8 * ((unsigned __int64)(*(__int64 (__fastcall **)(const char *))(a1 + 16))(a2) % *(_QWORD *)a1));
if ( v2 )
{
while ( strcmp(*(const char **)v2, a2) )
{
v2 = *(_QWORD *)(v2 + 16);
if ( !v2 )
return v2;
}
v2 = *(_QWORD *)(v2 + 8);
}
return v2;
}

original_code:
void* htable_get(struct hashtable* h, const char *key){
  struct hashnode* node;
  hsize hash=h->hashfunc(key)%h->size;
  node=h->nodes[hash];
  while(node){
    if(!strcmp(node->key,key)) return node->data;
    node=node->next;
  }
  return ((void *)0);
}

canonical_original_code:
void *htable_get(struct hashtable *h, char *key){
  struct hashnode *node;
  unsigned long hash = h->hashfunc(key)%h->size;
  node=h->nodes[hash];
  while(node){
    if(!strcmp(node->key,key)) return node->data;
    node=node->next;
  }
  return ((void *)0);
}


decompiled_code:
__int64 __fastcall htable_resize(__int64 a1, size_t a2)
{
unsigned __int64 v2; // r12
__int64 i; // rbx
size_t v5; // [rsp+0h] [rbp-38h] BYREF
void *v6; // [rsp+8h] [rbp-30h]
__int64 v7; // [rsp+10h] [rbp-28h]

v5 = a2;
v7 = *(_QWORD *)(a1 + 16);
v6 = calloc(a2, 8uLL);
if ( !v6 )
return 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 )
{
v2 = 0LL;
do
{
for ( i = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8 * v2); i; i = *(_QWORD *)(i + 16) )
{
htable_insert((__int64)&v5, *(const char **)i, *(_QWORD *)(i + 8));
htable_remove(a1, *(const char **)i);
}
++v2;
}
while ( *(_QWORD *)a1 > v2 );
}
free(*(void **)(a1 + 8));
*(_QWORD *)a1 = v5;
*(_QWORD *)(a1 + 8) = v6;
return 0LL;
}

original_code:
int htable_resize(struct hashtable *h, hsize size){
  struct hashtable newtbl;
  hsize n;
  struct hashnode *node;
  newtbl.size=size;
  newtbl.hashfunc=h->hashfunc;
  if(!(newtbl.nodes=calloc(size, sizeof(struct hashnode*)))) return -1;
  for(n=0; n<h->size; ++n) {
    for(node=h->nodes[n]; node; node=node->next) {
      htable_insert(&newtbl, node->key, node->data);
      htable_remove(h, node->key);
    }
  }
  free(h->nodes);
  h->size=newtbl.size;
  h->nodes=newtbl.nodes;
  return 0;
}

canonical_original_code:
int htable_resize(struct hashtable *h, unsigned long size){
  struct hashtable newtbl;
  unsigned long n;
  struct hashnode *node;
  newtbl.size=size;
  newtbl.hashfunc=h->hashfunc;
  if(!(newtbl.nodes=calloc(size, sizeof(struct hashnode *)))) return -1;
  for(n=0; n<h->size; ++n) {
    for(node=h->nodes[n]; node; node=node->next) {
      htable_insert(&newtbl, node->key, node->data);
      htable_remove(h, node->key);
    }
  }
  free(h->nodes);
  h->size=newtbl.size;
  h->nodes=newtbl.nodes;
  return 0;
}

variable_types: struct hashtable { unsigned long size; struct hashnode { char *key; void *data; struct hashnode *next; } **nodes; unsigned long (*hashfunc)(char *); }


decompiled_code:
int __fastcall htable_insert_list(__int64 a1, int a2, char *a3)
{
char *v4; // rbp
char v5; // al
char *v6; // rbx
int v7; // edx

v4 = (char *)malloc(0x64uLL);
v5 = *a3;
if ( *a3 != 59 )
{
v6 = a3 + 1;
v7 = 0;
do
{
if ( v5 == 44 )
{
v4[v7 + 1] = 0;
htable_insert_type(a1, v4, a2);
free(v4);
v4 = (char *)malloc(0x64uLL);
v7 = 0;
}
else
{
v4[v7++] = v5;
}
v5 = *v6++;
}
while ( v5 != 59 );
}
return htable_insert_type(a1, v4, a2);
}

original_code:
void *htable_insert_list(struct hashtable * h, enum Type t, char code[2048]) {
  int i = 0;
  int j = 0;
  char * buf = malloc(sizeof(char) * 100);
  while (code[i] != ';') {
    if (code[i] != ',') {
      buf[j] = code[i];
      ++j;
    }
    else {
      ++j;
      buf[j] = 0;
      htable_insert_type(h, buf, t);
      free(buf);
      buf = ((void *)0);
      buf = malloc(sizeof(char) * 100);
      j = 0;
    }
    ++i;
  }
  htable_insert_type(h, buf, t);
}

canonical_original_code:
void *htable_insert_list(struct hashtable *h, enum Type t, char code[2048]) {
  int i = 0;
  int j = 0;
  char *buf = malloc(sizeof(char) * 100);
  while (code[i] != ';') {
    if (code[i] != ',') {
      buf[j] = code[i];
      ++j;
    }
    else {
      ++j;
      buf[j] = 0;
      htable_insert_type(h, buf, t);
      free(buf);
      buf = ((void *)0);
      buf = malloc(sizeof(char) * 100);
      j = 0;
    }
    ++i;
  }
  htable_insert_type(h, buf, t);
}

variable_types: enum Type { INTEGER=0, INTPOINTER=1, REAL=2, REALPOINTER=3, EMPTY=4, STRING=5, OPERATOREQUAL=6, STRUCTURE=7 }

variable_types:
code
char [2048]

variable_types: i int

variable_types: j int

variable_types:
buf
char *


decompiled_code:
_BOOL8 __fastcall tools_are_types_compatible(int a1, int a2)
{
_BOOL8 result; // rax

switch ( a1 )
{
case 2:
return a2 == 2;
case 0:
return a2 == 0;
case 3:
return a2 == 2;
case 1:
result = a2 == 0;
break;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, int a2)
{
_BOOL8 result; // rax

switch ( a1 )
{
case 2:
return a2 == 2;
case 0:
return a2 == 0;
case 3:
return a2 == 2;
case 1:
result = a2 == 0;
break;
}
return result;
}

original_code:
int tools_are_types_compatible(enum Type left, enum Type right) {
  if (left == REAL)
    return (right == REAL);
  else if (left == INTEGER)
    return (right == INTEGER);
  else if (left == REALPOINTER)
    return (right == REAL);
  else if (left == INTPOINTER)
    return (right == INTEGER);
  else ;
}

user_defined_types: enum Type { INTEGER=0, INTPOINTER=1, REAL=2, REALPOINTER=3, EMPTY=4, STRING=5, OPERATOREQUAL=6, STRUCTURE=7 }


decompiled_code:
_BOOL8 __fastcall htable_replace_llvm_name(__int64 a1, const char *a2, __int64 a3)
{
__int64 v3; // rbp

v3 = htable_get(a1, a3);
strcpy(*(char **)(v3 + 16), a2);
return strcmp(a2, *(const char **)(v3 + 16)) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, const char *a2, __int64 a3)
{
__int64 v3; // rbp

v3 = htable_get(a1, a3);
strcpy(*(char **)(v3 + 16), a2);
return strcmp(a2, *(const char **)(v3 + 16)) == 0;
}

original_code:
int htable_replace_llvm_name(struct hashtable * h,char * llvm_name, const char *key){
  struct Variable * var=(struct Variable *)htable_get(h,key);
  strcpy(var->llvm_name,llvm_name);
  return !(strcmp(llvm_name,var->llvm_name));
}

canonical_original_code:
int htable_replace_llvm_name(struct hashtable *h, char *llvm_name, char *key){
  struct Variable *var = (struct Variable *)htable_get(h,key);
  strcpy(var->llvm_name,llvm_name);
  return !(strcmp(llvm_name,var->llvm_name));
}

variable_types:
key
char *

user_defined_types: enum Comportement { VAR=0, CST=1, FUNCTION=2 }


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

strcpy((char *)&special_variables_types, "%steerCmd");
*((_DWORD *)&special_variables_types + 8) = 3;
strcpy((char *)&special_variables_types + 36, "%accelCmd");
*((_DWORD *)&special_variables_types + 17) = 3;
strcpy((char *)&special_variables_types + 72, "%brakeCmd");
*((_DWORD *)&special_variables_types + 26) = 3;
strcpy((char *)&special_variables_types + 108, "%clutchCmd");
*((_DWORD *)&special_variables_types + 35) = 3;
result = 0x646D437261656725LL;
strcpy((char *)&special_variables_types + 144, "%gearCmd");
*((_DWORD *)&special_variables_types + 44) = 1;
return result;
}

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

strcpy((char *)&special_variables_types, "%steerCmd");
*((_DWORD *)&special_variables_types + 8) = 3;
strcpy((char *)&special_variables_types + 36, "%accelCmd");
*((_DWORD *)&special_variables_types + 17) = 3;
strcpy((char *)&special_variables_types + 72, "%brakeCmd");
*((_DWORD *)&special_variables_types + 26) = 3;
strcpy((char *)&special_variables_types + 108, "%clutchCmd");
*((_DWORD *)&special_variables_types + 35) = 3;
result = 0x646D437261656725LL;
strcpy((char *)&special_variables_types + 144, "%gearCmd");
*((_DWORD *)&special_variables_types + 44) = 1;
return result;
}

original_code:
void special_init() {
  strcpy(special_variables_types[0].name, "%steerCmd");
  special_variables_types[0].type = REALPOINTER;
  strcpy(special_variables_types[1].name, "%accelCmd");
  special_variables_types[1].type = REALPOINTER;
  strcpy(special_variables_types[2].name, "%brakeCmd");
  special_variables_types[2].type = REALPOINTER;
  strcpy(special_variables_types[3].name, "%clutchCmd");
  special_variables_types[3].type = REALPOINTER;
  strcpy(special_variables_types[4].name, "%gearCmd");
  special_variables_types[4].type = INTPOINTER;
}


decompiled_code:
__int64 __fastcall special_get_type(char *s2)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcmp((const char *)&special_variables_types + 36 * v1, s2) )
{
if ( ++v1 == 10 )
return 4LL;
}
return *((unsigned int *)&special_variables_types + 9 * (int)v1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s2)
{
__int64 v1; // rbx

v1 = 0LL;
while ( strcmp((const char *)&special_variables_types + 36 * v1, s2) )
{
if ( ++v1 == 10 )
return 4LL;
}
return *((unsigned int *)&special_variables_types + 9 * (int)v1 + 8);
}

original_code:
enum Type special_get_type(const char * name) {
  int i;
  for (i = 0; i < 10; ++i) {
    if ( strcmp(special_variables_types[i].name, name) == 0)
      return special_variables_types[i].type;
  }
  return EMPTY;
}

canonical_original_code:
enum Type special_get_type(char *name) {
  int i;
  for (i = 0; i < 10; ++i) {
    if ( strcmp(special_variables_types[i].name, name) == 0)
      return special_variables_types[i].type;
  }
  return EMPTY;
}

variable_types:
name
char *

return_type: enum Type { INTEGER=0, INTPOINTER=1, REAL=2, REALPOINTER=3, EMPTY=4, STRING=5, OPERATOREQUAL=6, STRUCTURE=7 }