decompiled_code:
void __noreturn dump_form()
{
printf("<TITLE>Form for Submarine Order</TITLE>%c", 10LL);
printf("
Jimmy John's Submarine Order Form
%c", 10LL);
printf("This form will send a faxed order to Jimmy John's in Champaign. Proper password is requred%c", 10LL);
printf("for order to be submitted, otherwise a copy of the order that would have been submitted will%c", 10LL);
printf("will be displayed.
%c", 10LL);
printf("
%c", 10LL);
printf("<FORM ACTION=\"http://hoohoo.ncsa.uiuc.edu:80/htbin/jj\">%c", 10LL);
printf("Password: <INPUT TYPE=\"text\" NAME=\"pwd\" MAXLENGTH=\"20\">
%c", 10LL);
printf("
Sub Type
%c", 10LL);
printf("Select which you would like of the following:
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"0\">%s:%c", sublist, 10LL);
printf("Smoked virginia ham and provolone cheese topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"1\">%s:%c", *(&sublist + 1), 10LL);
printf("Medium rare shaved roast beef topped with mayo, lettuce, and tomato.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"2\">%s:%c", *(&sublist + 2), 10LL);
printf("Tuna, mixed with celery, onions, and sauce, topped with lettuce,%c", 10LL);
printf("tomato, and alfalfa sprouts.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"3\">%s:%c", *(&sublist + 3), 10LL);
printf("Turkey breast topped with lettuce, mayo, alfalfa sprouts, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"4\">%s:%c", *(&sublist + 4), 10LL);
printf(
"Genoa salami and provolone cheese topped with capacola, onion, lettuce, tomato, and Italian sauce.
%c",
10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"5\">%s:%c", *(&sublist + 5), 10LL);
printf("Layers of provolone cheese, separated by avocado, sprouts, lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"6\">%s:%c", *(&sublist + 6), 10LL);
printf("1/4 pound of smoked ham, provolone cheese, topped with lettuce,%c", 10LL);
printf("tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"7\">%s:%c", *(&sublist + 7), 10LL);
printf("Shaved roast beef, provolone cheese, french dijon mustard, topped with shaved ham, lettuce,%c", 10LL);
printf("tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"8\">%s:%c", *(&sublist + 8), 10LL);
printf("Genoa salami, Italian capacola, smoked ham, and provolone cheese topped with lettuce,%c", 10LL);
printf("tomato, onions, mayo, and Italian sauce.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"9\">%s:%c", *(&sublist + 9), 10LL);
printf("1/4 pound of sliced roast beef, provolone cheese, topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"10\">%s:%c", *(&sublist + 10), 10LL);
printf("Turkey breast, smoked ham, and provolonecheese topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"11\">%s:%c", *(&sublist + 11), 10LL);
printf("Turkey breast, avocado, and cheese topped with lettuce, mayo, alfalfa, and tomato.
%c", 10LL);
printf("
Slim Jim Subs
%c", 10LL);
printf("Subs without veggies or sauce.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"0\">%s
%c", slimlist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"1\">%s
%c", slimlist[1], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"2\">%s
%c", slimlist[2], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"3\">%s
%c", slimlist[3], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"4\">%s
%c", slimlist[4], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"5\">%s
%c", slimlist[5], 10LL);
printf("
Side orders
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"0\">%s
%c", sidelist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"1\">%s
%c", sidelist[1], 10LL);
printf("
Drinks
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"0\">%s
%c", poplist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"1\">%s
%c", poplist[1], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"2\">%s
%c", poplist[2], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"3\">%s
%c", poplist[3], 10LL);
printf("
Your Address, Phone Number, and Name
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"32\">Name
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"adr\" MAXLENGTH=\"64\">Address
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"phone\" MAXLENGTH=\"10\">Phone Number
%c", 10LL);
printf("<INPUT type=\"submit\">%c", 10LL);
printf("</FORM>%c", 10LL);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
printf("<TITLE>Form for Submarine Order</TITLE>%c", 10LL);
printf("
Jimmy John's Submarine Order Form
%c", 10LL);
printf("This form will send a faxed order to Jimmy John's in Champaign. Proper password is requred%c", 10LL);
printf("for order to be submitted, otherwise a copy of the order that would have been submitted will%c", 10LL);
printf("will be displayed.
%c", 10LL);
printf("
%c", 10LL);
printf("<FORM ACTION=\"http://hoohoo.ncsa.uiuc.edu:80/htbin/jj\">%c", 10LL);
printf("Password: <INPUT TYPE=\"text\" NAME=\"pwd\" MAXLENGTH=\"20\">
%c", 10LL);
printf("
Sub Type
%c", 10LL);
printf("Select which you would like of the following:
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"0\">%s:%c", sublist, 10LL);
printf("Smoked virginia ham and provolone cheese topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"1\">%s:%c", *(&sublist + 1), 10LL);
printf("Medium rare shaved roast beef topped with mayo, lettuce, and tomato.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"2\">%s:%c", *(&sublist + 2), 10LL);
printf("Tuna, mixed with celery, onions, and sauce, topped with lettuce,%c", 10LL);
printf("tomato, and alfalfa sprouts.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"3\">%s:%c", *(&sublist + 3), 10LL);
printf("Turkey breast topped with lettuce, mayo, alfalfa sprouts, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"4\">%s:%c", *(&sublist + 4), 10LL);
printf(
"Genoa salami and provolone cheese topped with capacola, onion, lettuce, tomato, and Italian sauce.
%c",
10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"5\">%s:%c", *(&sublist + 5), 10LL);
printf("Layers of provolone cheese, separated by avocado, sprouts, lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"6\">%s:%c", *(&sublist + 6), 10LL);
printf("1/4 pound of smoked ham, provolone cheese, topped with lettuce,%c", 10LL);
printf("tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"7\">%s:%c", *(&sublist + 7), 10LL);
printf("Shaved roast beef, provolone cheese, french dijon mustard, topped with shaved ham, lettuce,%c", 10LL);
printf("tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"8\">%s:%c", *(&sublist + 8), 10LL);
printf("Genoa salami, Italian capacola, smoked ham, and provolone cheese topped with lettuce,%c", 10LL);
printf("tomato, onions, mayo, and Italian sauce.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"9\">%s:%c", *(&sublist + 9), 10LL);
printf("1/4 pound of sliced roast beef, provolone cheese, topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"10\">%s:%c", *(&sublist + 10), 10LL);
printf("Turkey breast, smoked ham, and provolonecheese topped with lettuce, tomato, and mayo.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"11\">%s:%c", *(&sublist + 11), 10LL);
printf("Turkey breast, avocado, and cheese topped with lettuce, mayo, alfalfa, and tomato.
%c", 10LL);
printf("
Slim Jim Subs
%c", 10LL);
printf("Subs without veggies or sauce.
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"0\">%s
%c", slimlist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"1\">%s
%c", slimlist[1], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"2\">%s
%c", slimlist[2], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"3\">%s
%c", slimlist[3], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"4\">%s
%c", slimlist[4], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"5\">%s
%c", slimlist[5], 10LL);
printf("
Side orders
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"0\">%s
%c", sidelist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"1\">%s
%c", sidelist[1], 10LL);
printf("
Drinks
%c", 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"0\">%s
%c", poplist[0], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"1\">%s
%c", poplist[1], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"2\">%s
%c", poplist[2], 10LL);
printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"3\">%s
%c", poplist[3], 10LL);
printf("
Your Address, Phone Number, and Name
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"32\">Name
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"adr\" MAXLENGTH=\"64\">Address
%c", 10LL);
printf("<INPUT TYPE=\"text\" NAME=\"phone\" MAXLENGTH=\"10\">Phone Number
%c", 10LL);
printf("<INPUT type=\"submit\">%c", 10LL);
printf("</FORM>%c", 10LL);
exit(0);
}

original_code:
void dump_form() {
    printf("<TITLE>Form for Submarine Order</TITLE>%c",10);
    printf("
Jimmy John's Submarine Order Form
%c",10);
    printf("This form will send a faxed order to Jimmy John's in Champaign. Proper password is requred%c",10);
    printf("for order to be submitted, otherwise a copy of the order that would have been submitted will%c",10);
    printf("will be displayed.
%c",10);
    printf("
%c",10);
    printf("<FORM ACTION=\"http://hoohoo.ncsa.uiuc.edu:80/htbin/jj\">%c",10);
    printf("Password: <INPUT TYPE=\"text\" NAME=\"pwd\" MAXLENGTH=\"20\">
%c",10);
    printf("
Sub Type
%c",10);
    printf("Select which you would like of the following:
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"0\">%s:%c",sublist[0],10);
    printf("Smoked virginia ham and provolone cheese topped with lettuce, tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"1\">%s:%c",sublist[1],10);
    printf("Medium rare shaved roast beef topped with mayo, lettuce, and tomato.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"2\">%s:%c",sublist[2],10);
    printf("Tuna, mixed with celery, onions, and sauce, topped with lettuce,%c",10);
    printf("tomato, and alfalfa sprouts.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"3\">%s:%c",sublist[3],10);
    printf("Turkey breast topped with lettuce, mayo, alfalfa sprouts, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"4\">%s:%c",sublist[4],10);
    printf("Genoa salami and provolone cheese topped with capacola, onion, lettuce, tomato, and Italian sauce.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"5\">%s:%c",sublist[5],10);
    printf("Layers of provolone cheese, separated by avocado, sprouts, lettuce, tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"6\">%s:%c",sublist[6],10);
    printf("1/4 pound of smoked ham, provolone cheese, topped with lettuce,%c",10);
    printf("tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"7\">%s:%c",sublist[7],10);
    printf("Shaved roast beef, provolone cheese, french dijon mustard, topped with shaved ham, lettuce,%c",10);
    printf("tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"8\">%s:%c",sublist[8],10);
    printf("Genoa salami, Italian capacola, smoked ham, and provolone cheese topped with lettuce,%c",10);
    printf("tomato, onions, mayo, and Italian sauce.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"9\">%s:%c",sublist[9],10);
    printf("1/4 pound of sliced roast beef, provolone cheese, topped with lettuce, tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"10\">%s:%c",sublist[10],10);
    printf("Turkey breast, smoked ham, and provolonecheese topped with lettuce, tomato, and mayo.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sub\" VALUE=\"11\">%s:%c",sublist[11],10);
    printf("Turkey breast, avocado, and cheese topped with lettuce, mayo, alfalfa, and tomato.
%c",10);
    printf("
Slim Jim Subs
%c",10);
    printf("Subs without veggies or sauce.
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"0\">%s
%c",slimlist[0],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"1\">%s
%c",slimlist[1],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"2\">%s
%c",slimlist[2],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"3\">%s
%c",slimlist[3],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"4\">%s
%c",slimlist[4],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"slj\" VALUE=\"5\">%s
%c",slimlist[5],10);
    printf("
Side orders
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"0\">%s
%c",sidelist[0],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"sde\" VALUE=\"1\">%s
%c",sidelist[1],10);
    printf("
Drinks
%c",10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"0\">%s
%c",poplist[0],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"1\">%s
%c",poplist[1],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"2\">%s
%c",poplist[2],10);
    printf("<INPUT TYPE=\"checkbox\" NAME=\"pop\" VALUE=\"3\">%s
%c",poplist[3],10);
    printf("
Your Address, Phone Number, and Name
%c",10);
    printf("<INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"32\">Name
%c",10);
    printf("<INPUT TYPE=\"text\" NAME=\"adr\" MAXLENGTH=\"64\">Address
%c",10);
    printf("<INPUT TYPE=\"text\" NAME=\"phone\" MAXLENGTH=\"10\">Phone Number
%c",10);
    printf("<INPUT type=\"submit\">%c",10);
    printf("</FORM>%c",10);
    exit(0);
}


repo: TooDumbForAName/ncsa-httpd

decompiled_code:
void __fastcall __noreturn print_error(const char *a1)
{
printf("<TITLE>Order Not Submitted</TITLE>%c", 10LL);
printf("
Order Not Submitted
%c", 10LL);
printf("Your order has not been submitted, because %s.
%c", a1, 10LL);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
printf("<TITLE>Order Not Submitted</TITLE>%c", 10LL);
printf("
Order Not Submitted
%c", 10LL);
printf("Your order has not been submitted, because %s.
%c", a1, 10LL);
exit(1);
}

original_code:
void print_error(char *reason) {
    printf("<TITLE>Order Not Submitted</TITLE>%c",10);
    printf("
Order Not Submitted
%c",10);
    printf("Your order has not been submitted, because %s.
%c",reason,10);
    exit(1);
}

variable_types:
reason
char *

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbp
_BOOL4 v5; // er14
int v6; // er15
int v7; // er13
int v8; // er12
FILE *v9; // rbp
__int64 v10; // rbx
__int64 v11; // rbx
__int64 v12; // rbx
int v13; // [rsp+Ch] [rbp-2CCh]
char command[256]; // [rsp+10h] [rbp-2C8h] BYREF
char dest[70]; // [rsp+110h] [rbp-1C8h] BYREF
char v16[10]; // [rsp+156h] [rbp-182h] BYREF
char v17[32]; // [rsp+160h] [rbp-178h] BYREF
char s[32]; // [rsp+180h] [rbp-158h] BYREF
char s1[312]; // [rsp+1A0h] [rbp-138h] BYREF

printf("Content-type: text/html%c%c", 10LL, 10LL);
v3 = getenv("QUERY_STRING");
if ( !v3 || (v4 = v3, !*v3) )
dump_form();
tmpnam(s);
if ( fopen(s, "w") )
{
v17[0] = 0;
v16[0] = 0;
dest[0] = 0;
if ( *v4 )
{
v5 = 0;
v6 = 0;
v13 = 0;
v7 = 0;
v8 = 0;
do
{
getword(s1, v4, 61LL);
plustospace(s1);
unescape_url(s1);
if ( !strcmp(s1, "pwd") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v5 = strcmp(s1, "HTTPdRocKs") == 0;
}
if ( !strcmp(s1, "sub") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v8 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "slj") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v7 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "sde") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v13 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "pop") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v6 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "name") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(v17, s1);
}
else if ( !strcmp(s1, "phone") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(v16, s1);
}
else if ( !strcmp(s1, "adr") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(dest, s1);
}
}
while ( *v4 );
if ( v17[0] )
{
if ( dest[0] )
{
if ( v16[0] )
{
if ( v6 | v13 | v8 | v7 )
{
if ( v5 )
{
sprintf(command, "/bin/mail %s", "JIMMY_JOHNS_5555680@fax.uiuc.edu");
v9 = popen(command, "w");
if ( !v9 )
print_error("the server was unable to open a pipe to mail");
printf("<TITLE>Order Sent</TITLE>%c", 10LL);
printf("
Order Sent
%c", 10LL);
printf("Your order has been sent to the UIUC e-mail to FAX gateway.
%c", 10LL);
}
else
{
printf("<TITLE>Your Order</TITLE>%c", 10LL);
printf("
Your Order
%c", 10LL);
printf("This is how your order would have looked if it had been sent.
<PLAINTEXT>%c", 10LL);
v9 = stdout;
}
fprintf(v9, "My name is %s, and I would like to have the following%c", v17, 10LL);
fprintf(v9, "order delivered to %s:%c%c", dest, 10LL, 10LL);
v10 = 0LL;
while ( 1 )
{
if ( ((v8 >> v10) & 1) != 0 )
fprintf(v9, "\t(1) %s%c", (&sublist)[v10], 10LL);
if ( ++v10 == 12 )
{
v11 = 0LL;
while ( 1 )
{
if ( ((v7 >> v11) & 1) != 0 )
fprintf(v9, "\t(1) %s Slim Jim%c", slimlist[v11], 10LL);
if ( ++v11 == 6 )
{
if ( (v13 & 1) != 0 )
fprintf(v9, "\t(1) %s%c", sidelist[0], 10LL);
if ( (v13 & 2) != 0 )
fprintf(v9, "\t(1) %s%c", sidelist[1], 10LL);
v12 = 0LL;
while ( 1 )
{
if ( ((v6 >> v12) & 1) != 0 )
fprintf(v9, "\t(1) %s%c", poplist[v12], 10LL);
if ( ++v12 == 4 )
{
fprintf(v9, "%cPlease feel free to call me at %s if there is any%c", 10LL, v16, 10LL);
fprintf(v9, "problem. Thank you.%c%c.%c", 10LL, 10LL, 10LL);
fclose(v9);
exit(0);
}
}
}
}
}
}
}
print_error("you didn't order anything");
}
print_error("you didn't give your phone number");
}
print_error("you didn't give your address");
}
}
print_error("you didn't give your name");
}
printf("<TITLE>Server Error</TITLE>%c", 10LL);
printf("
Server Error
%c", 10LL);
printf("Server unable to get a temporary file. Please try again later.
%c", 10LL);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
char *v4; // rbp
_BOOL4 v5; // er14
int v6; // er15
int v7; // er13
int v8; // er12
FILE *v9; // rbp
__int64 v10; // rbx
__int64 v11; // rbx
__int64 v12; // rbx
int v13; // [rsp+Ch] [rbp-2CCh]
char command[256]; // [rsp+10h] [rbp-2C8h] BYREF
char dest[70]; // [rsp+110h] [rbp-1C8h] BYREF
char v16[10]; // [rsp+156h] [rbp-182h] BYREF
char v17[32]; // [rsp+160h] [rbp-178h] BYREF
char s[32]; // [rsp+180h] [rbp-158h] BYREF
char s1[312]; // [rsp+1A0h] [rbp-138h] BYREF

printf("Content-type: text/html%c%c", 10LL, 10LL);
v3 = getenv("QUERY_STRING");
if ( !v3 || (v4 = v3, !*v3) )
func0();
tmpnam(s);
if ( fopen(s, "w") )
{
v17[0] = 0;
v16[0] = 0;
dest[0] = 0;
if ( *v4 )
{
v5 = 0;
v6 = 0;
v13 = 0;
v7 = 0;
v8 = 0;
do
{
getword(s1, v4, 61LL);
plustospace(s1);
unescape_url(s1);
if ( !strcmp(s1, "pwd") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v5 = strcmp(s1, "HTTPdRocKs") == 0;
}
if ( !strcmp(s1, "sub") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v8 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "slj") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v7 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "sde") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v13 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "pop") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
v6 |= 1 << atoi(s1);
}
else if ( !strcmp(s1, "name") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(v17, s1);
}
else if ( !strcmp(s1, "phone") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(v16, s1);
}
else if ( !strcmp(s1, "adr") )
{
getword(s1, v4, 38LL);
plustospace(s1);
unescape_url(s1);
strcpy(dest, s1);
}
}
while ( *v4 );
if ( v17[0] )
{
if ( dest[0] )
{
if ( v16[0] )
{
if ( v6 | v13 | v8 | v7 )
{
if ( v5 )
{
sprintf(command, "/bin/mail %s", "JIMMY_JOHNS_5555680@fax.uiuc.edu");
v9 = popen(command, "w");
if ( !v9 )
func1("the server was unable to open a pipe to mail");
printf("<TITLE>Order Sent</TITLE>%c", 10LL);
printf("
Order Sent
%c", 10LL);
printf("Your order has been sent to the UIUC e-mail to FAX gateway.
%c", 10LL);
}
else
{
printf("<TITLE>Your Order</TITLE>%c", 10LL);
printf("
Your Order
%c", 10LL);
printf("This is how your order would have looked if it had been sent.
<PLAINTEXT>%c", 10LL);
v9 = stdout;
}
fprintf(v9, "My name is %s, and I would like to have the following%c", v17, 10LL);
fprintf(v9, "order delivered to %s:%c%c", dest, 10LL, 10LL);
v10 = 0LL;
while ( 1 )
{
if ( ((v8 >> v10) & 1) != 0 )
fprintf(v9, "\t(1) %s%c", (&sublist)[v10], 10LL);
if ( ++v10 == 12 )
{
v11 = 0LL;
while ( 1 )
{
if ( ((v7 >> v11) & 1) != 0 )
fprintf(v9, "\t(1) %s Slim Jim%c", slimlist[v11], 10LL);
if ( ++v11 == 6 )
{
if ( (v13 & 1) != 0 )
fprintf(v9, "\t(1) %s%c", sidelist[0], 10LL);
if ( (v13 & 2) != 0 )
fprintf(v9, "\t(1) %s%c", sidelist[1], 10LL);
v12 = 0LL;
while ( 1 )
{
if ( ((v6 >> v12) & 1) != 0 )
fprintf(v9, "\t(1) %s%c", poplist[v12], 10LL);
if ( ++v12 == 4 )
{
fprintf(v9, "%cPlease feel free to call me at %s if there is any%c", 10LL, v16, 10LL);
fprintf(v9, "problem. Thank you.%c%c.%c", 10LL, 10LL, 10LL);
fclose(v9);
exit(0);
}
}
}
}
}
}
}
func1("you didn't order anything");
}
func1("you didn't give your phone number");
}
func1("you didn't give your address");
}
}
func1("you didn't give your name");
}
printf("<TITLE>Server Error</TITLE>%c", 10LL);
printf("
Server Error
%c", 10LL);
printf("Server unable to get a temporary file. Please try again later.
%c", 10LL);
exit(1);
}

original_code:
int main(int argc, char **argv)
{
 char pre_digest[2048];
 char digest[33];
 if (argc != 4)
 {
  fprintf(stderr, "\n%s is useful for generating the digest entries for\n", argv[0]);
  fprintf(stderr, "your .htdigest file\n\n");
  fprintf(stderr, "Usage: %s username realm password\n", argv[0]);
  exit(-1);
 }
 sprintf(pre_digest, "%s:%s:%s", argv[1], argv[2], argv[3]);
 md5(pre_digest, digest);
 printf("%s:%s:%s\n", argv[1], argv[2], digest);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
digest
char [33]

return_type: int


strd

decompiled_code:
char *__fastcall strd(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

canonical_decompiled_code:
char *__fastcall func8(char *src)
{
size_t v1; // rax
char *v2; // rax

v1 = strlen(src);
v2 = (char *)malloc(v1 + 1);
return strcpy(v2, src);
}

original_code:
char *strd(char *s) {
    char *d;
    d=(char *)malloc(strlen(s) + 1);
    strcpy(d,s);
    return(d);
}

variable_types:
s
char *

variable_types:
d
char *

return_type: char *


parseURL

variable_types:
url
char *

variable_types:
host
char **

variable_types:
path
char **

variable_types:
p
char *

variable_types:
pp
char *

variable_types: port int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
char v4; // dl
int v5; // er12
int v6; // ebx
int v7; // ebp
int v8; // eax
int v9; // eax
__int16 v10; // r13
char v11; // dl
char *v12; // rax
struct hostent *v13; // r14
int v14; // edi
int v15; // eax
int v16; // er14
FILE *v17; // r15
FILE *v18; // r13
const char *v19; // rdx
int v20; // eax
int v21; // eax
char *name; // [rsp+0h] [rbp-458h] BYREF
char *v23; // [rsp+8h] [rbp-450h] BYREF
char ptr[1024]; // [rsp+10h] [rbp-448h] BYREF
struct sockaddr dest[4]; // [rsp+410h] [rbp-48h] BYREF

if ( argc > 1 )
{
v3 = argv[1];
v4 = *v3;
if ( argc > 2 || v4 != 45 )
{
if ( v4 == 45 )
{
v23 = (char *)(v3 + 1);
v11 = v3[1];
if ( v11 )
{
v12 = (char *)(v3 + 2);
v5 = 0;
v6 = 0;
v7 = 0;
do
{
switch ( v11 )
{
case 'r':
v5 = 1;
break;
case 's':
v7 = 1;
break;
case 'h':
v6 = 1;
break;
}
v23 = v12++;
v11 = *(v12 - 1);
}
while ( v11 );
v8 = 2;
}
else
{
v5 = 0;
v6 = 0;
v7 = 0;
v8 = 2;
}
}
else
{
v5 = 0;
v6 = 0;
v7 = 0;
v8 = 1;
}
v9 = parseURL(argv[v8], &name, &v23);
v10 = v9;
if ( !v9 )
{
fwrite("error: invalid url\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
v13 = gethostbyname(name);
if ( v13 )
{
*(_QWORD *)&dest[0].sa_family = 0LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
*(_WORD *)dest[0].sa_data = _bswap_16(v10);
memcpy(&dest[0].sa_data[2], *(const void **)v13->h_addr_list, v13->h_length);
v14 = v13->h_addrtype;
dest[0].sa_family = v14;
v15 = socket(v14, 1, 0);
v16 = v15;
if ( v15 >= 0 )
{
if ( connect(v15, dest, 0x10u) >= 0 )
{
v17 = fdopen(v16, "w");
v18 = fdopen(v16, "r");
v19 = "HEAD";
if ( !v6 )
v19 = "GET";
fprintf(v17, "%s %s HTTP/1.0\r\n", v19, v23);
if ( v5 )
{
do
{
if ( feof(stdin) )
break;
v20 = fread(ptr, 1uLL, 0x400uLL, stdin);
if ( v20 )
fwrite(ptr, 1uLL, v20, v17);
}
while ( !feof(stdin) );
}
else
{
fwrite("User-Agent: WebGrab/1.2 (commandline forever)\r\n", 1uLL, 0x2FuLL, v17);
}
fwrite("\r\n", 1uLL, 2uLL, v17);
fflush(v17);
do
{
if ( feof(v18) )
break;
fgets(ptr, 1024, v18);
if ( !v7 )
fputs(ptr, stdout);
}
while ( !feof(v18) && ptr[0] > 31 );
do
{
if ( feof(v18) )
break;
v21 = fread(ptr, 1uLL, 0x400uLL, v18);
if ( v21 )
fwrite(ptr, 1uLL, v21, stdout);
}
while ( !feof(v18) );
close(v16);
exit(0);
}
close(v16);
fwrite("error: can't connect\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
fwrite("error: can't get socket\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
fprintf(stderr, "error: can't get host %s.\n", name);
exit(1);
}
}
usage(*argv);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
char v4; // dl
int v5; // er12
int v6; // ebx
int v7; // ebp
int v8; // eax
int v9; // eax
__int16 v10; // r13
char v11; // dl
char *v12; // rax
struct hostent *v13; // r14
int v14; // edi
int v15; // eax
int v16; // er14
FILE *v17; // r15
FILE *v18; // r13
const char *v19; // rdx
int v20; // eax
int v21; // eax
char *name; // [rsp+0h] [rbp-458h] BYREF
char *v23; // [rsp+8h] [rbp-450h] BYREF
char ptr[1024]; // [rsp+10h] [rbp-448h] BYREF
struct sockaddr dest[4]; // [rsp+410h] [rbp-48h] BYREF

if ( argc > 1 )
{
v3 = argv[1];
v4 = *v3;
if ( argc > 2 || v4 != 45 )
{
if ( v4 == 45 )
{
v23 = (char *)(v3 + 1);
v11 = v3[1];
if ( v11 )
{
v12 = (char *)(v3 + 2);
v5 = 0;
v6 = 0;
v7 = 0;
do
{
switch ( v11 )
{
case 'r':
v5 = 1;
break;
case 's':
v7 = 1;
break;
case 'h':
v6 = 1;
break;
}
v23 = v12++;
v11 = *(v12 - 1);
}
while ( v11 );
v8 = 2;
}
else
{
v5 = 0;
v6 = 0;
v7 = 0;
v8 = 2;
}
}
else
{
v5 = 0;
v6 = 0;
v7 = 0;
v8 = 1;
}
v9 = func9(argv[v8], &name, &v23);
v10 = v9;
if ( !v9 )
{
fwrite("error: invalid url\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
v13 = gethostbyname(name);
if ( v13 )
{
*(_QWORD *)&dest[0].sa_family = 0LL;
*(_QWORD *)&dest[0].sa_data[6] = 0LL;
*(_WORD *)dest[0].sa_data = func7(v10);
memcpy(&dest[0].sa_data[2], *(const void **)v13->h_addr_list, v13->h_length);
v14 = v13->h_addrtype;
dest[0].sa_family = v14;
v15 = socket(v14, 1, 0);
v16 = v15;
if ( v15 >= 0 )
{
if ( connect(v15, dest, 0x10u) >= 0 )
{
v17 = fdopen(v16, "w");
v18 = fdopen(v16, "r");
v19 = "HEAD";
if ( !v6 )
v19 = "GET";
fprintf(v17, "%s %s HTTP/1.0\r\n", v19, v23);
if ( v5 )
{
do
{
if ( feof(stdin) )
break;
v20 = fread(ptr, 1uLL, 0x400uLL, stdin);
if ( v20 )
fwrite(ptr, 1uLL, v20, v17);
}
while ( !feof(stdin) );
}
else
{
fwrite("User-Agent: WebGrab/1.2 (commandline forever)\r\n", 1uLL, 0x2FuLL, v17);
}
fwrite("\r\n", 1uLL, 2uLL, v17);
fflush(v17);
do
{
if ( feof(v18) )
break;
fgets(ptr, 1024, v18);
if ( !v7 )
fputs(ptr, stdout);
}
while ( !feof(v18) && ptr[0] > 31 );
do
{
if ( feof(v18) )
break;
v21 = fread(ptr, 1uLL, 0x400uLL, v18);
if ( v21 )
fwrite(ptr, 1uLL, v21, stdout);
}
while ( !feof(v18) );
close(v16);
exit(0);
}
close(v16);
fwrite("error: can't connect\n", 1uLL, 0x15uLL, stderr);
exit(1);
}
fwrite("error: can't get socket\n", 1uLL, 0x18uLL, stderr);
exit(1);
}
fprintf(stderr, "error: can't get host %s.\n", name);
exit(1);
}
}
func10(*argv);
}

canonical_original_code:
int main(int argc, char **argv)
{
 char pre_digest[2048];
 char digest[33];
 if (argc != 4)
 {
  fprintf(stderr, "\n%s is useful for generating the digest entries for\n", argv[0]);
  fprintf(stderr, "your .htdigest file\n\n");
  fprintf(stderr, "Usage: %s username realm password\n", argv[0]);
  exit(-1);
 }
 sprintf(pre_digest, "%s:%s:%s", argv[1], argv[2], argv[3]);
 md5(pre_digest, digest);
 printf("%s:%s:%s\n", argv[1], argv[2], digest);
 return 0;
}


decompiled_code:
int __fastcall md5(char *s, char *a2)
{
size_t v2; // rax
char *v3; // rbx
char *v4; // rbp
int result; // eax
_BYTE v6[16]; // [rsp+0h] [rbp-A8h] BYREF
char v7[152]; // [rsp+10h] [rbp-98h] BYREF

MD5Init(v7);
v2 = strlen(s);
MD5Update(v7, s, v2);
MD5Final(v6, v7);
v3 = v6;
v4 = a2;
do
{
result = sprintf(v4, "%02x", (unsigned __int8)*v3);
v4 += 2;
++v3;
}
while ( v3 != v7 );
a2[32] = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func0(char *s, char *a2)
{
size_t v2; // rax
char *v3; // rbx
char *v4; // rbp
int result; // eax
_BYTE v6[16]; // [rsp+0h] [rbp-A8h] BYREF
char v7[152]; // [rsp+10h] [rbp-98h] BYREF

MD5Init(v7);
v2 = strlen(s);
MD5Update(v7, s, v2);
MD5Final(v6, v7);
v3 = v6;
v4 = a2;
do
{
result = sprintf(v4, "%02x", (unsigned __int8)*v3);
v4 += 2;
++v3;
}
while ( v3 != v7 );
a2[32] = 0;
return result;
}

original_code:
void md5 (unsigned char *string, char result[33])
{
    MD5_CTX my_md5;
    unsigned char hash[16];
    char *p;
    int i;
    MD5Init(&my_md5);
    MD5Update(&my_md5, string, strlen((const char *)string));
    MD5Final(hash, &my_md5);
    for (i=0, p=result; i<16; i++, p+=2)
        sprintf(p, "%02x", hash[i]);
    *p = '\0';
 return;
}

canonical_original_code:
void md5(unsigned char *string, char result[33])
{
    struct MD5_CTX my_md5;
    unsigned char hash[16];
    char *p;
    int i;
    MD5Init(&my_md5);
    MD5Update(&my_md5, string, strlen((char *)string));
    MD5Final(hash, &my_md5);
    for (i=0, p=result; i<16; i++, p+=2)
        sprintf(p, "%02x", hash[i]);
    *p = '\0';
 return;
}

variable_types:
string
unsigned char *

variable_types:
result
char [33]

variable_types: struct MD5_CTX { unsigned long state[4]; unsigned long count[2]; unsigned char buffer[64]; }

variable_types:
hash
unsigned char [16]

variable_types: i int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int v4; // er12
const char *v5; // rbx
__int64 v6; // r12
int v7; // eax
__int32_t v8; // ebx
char v9; // r13
int v10; // eax
__int64 v11; // rbx
char v12[296]; // [rsp+0h] [rbp-128h] BYREF

if ( argc == 1 )
{
v3 = stdin;
}
else
{
if ( argc != 2 )
usage(*argv);
v3 = fopen(argv[1], "r");
if ( !v3 )
{
perror("fopen");
exit(1);
}
}
v4 = 0;
while ( 1 )
{
v7 = fgetc(v3);
v8 = v7;
if ( v7 == -1 )
break;
v9 = v7;
if ( ((*__ctype_b_loc())[(char)v7] & 0x400) != 0 )
v8 = (*__ctype_tolower_loc())[(char)v8];
if ( v8 == aIncSrv[v4] )
{
if ( !aIncSrv[++v4] )
{
v10 = fgetc(v3);
v11 = 0LL;
while ( v10 != 62 )
{
v12[v11] = v10;
v10 = fgetc(v3);
++v11;
if ( v10 == -1 )
{
fwrite("<inc srv ", 1uLL, 9uLL, _bss_start);
fputs(v12, _bss_start);
fflush(_bss_start);
exit(1);
}
}
v12[(int)v11] = 0;
translate_tag(v12, _bss_start);
v4 = 0;
}
}
else
{
if ( v4 > 0 )
{
v5 = "<inc srv";
v6 = (unsigned int)(v4 - 1) + 4202605LL;
do
fputc(*v5++, _bss_start);
while ( v5 != (const char *)v6 );
}
fputc(v9, _bss_start);
v4 = 0;
}
}
fflush(_bss_start);
exit(0);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int v4; // er12
const char *v5; // rbx
__int64 v6; // r12
int v7; // eax
__int32_t v8; // ebx
char v9; // r13
int v10; // eax
__int64 v11; // rbx
char v12[296]; // [rsp+0h] [rbp-128h] BYREF

if ( argc == 1 )
{
v3 = stdin;
}
else
{
if ( argc != 2 )
func7(*argv);
v3 = fopen(argv[1], "r");
if ( !v3 )
{
perror("fopen");
exit(1);
}
}
v4 = 0;
while ( 1 )
{
v7 = fgetc(v3);
v8 = v7;
if ( v7 == -1 )
break;
v9 = v7;
if ( ((*__ctype_b_loc())[(char)v7] & 0x400) != 0 )
v8 = (*__ctype_tolower_loc())[(char)v8];
if ( v8 == aIncSrv[v4] )
{
if ( !aIncSrv[++v4] )
{
v10 = fgetc(v3);
v11 = 0LL;
while ( v10 != 62 )
{
v12[v11] = v10;
v10 = fgetc(v3);
++v11;
if ( v10 == -1 )
{
fwrite("<inc srv ", 1uLL, 9uLL, _bss_start);
fputs(v12, _bss_start);
fflush(_bss_start);
exit(1);
}
}
v12[(int)v11] = 0;
func8(v12, _bss_start);
v4 = 0;
}
}
else
{
if ( v4 > 0 )
{
v5 = "<inc srv";
v6 = (unsigned int)(v4 - 1) + 4202605LL;
do
fputc(*v5++, _bss_start);
while ( v5 != (const char *)v6 );
}
fputc(v9, _bss_start);
v4 = 0;
}
}
fflush(_bss_start);
exit(0);
}


repo: TorinCooperBennun/sdlbrot

decompiled_code:
long double *__fastcall c_add(long double *a1, long double a2, long double a3, long double a4, long double a5)
{
long double *result; // rax

result = a1;
*a1 = a2 + a4;
a1[1] = a3 + a5;
return result;
}

canonical_decompiled_code:
long double *__fastcall func1(long double *a1, long double a2, long double a3, long double a4, long double a5)
{
long double *result; // rax

result = a1;
*a1 = a2 + a4;
a1[1] = a3 + a5;
return result;
}

original_code:
cmp_num c_add(cmp_num a, cmp_num b)
{
    cmp_num c;
    c.re = a.re + b.re;
    c.im = a.im + b.im;
    return c;
}

canonical_original_code:
struct cmp_num c_add(struct cmp_num a, struct cmp_num b)
{
    struct cmp_num c;
    c.re = a.re + b.re;
    c.im = a.im + b.im;
    return c;
}

variable_types:
a
struct cmp_num

variable_types:
b
struct cmp_num

variable_types: struct cmp_num { long double re; long double im; }


decompiled_code:
long double *__fastcall c_sqr(long double *a1, long double a2, long double a3)
{
long double *result; // rax

result = a1;
*a1 = a2 * a2 - a3 * a3;
a1[1] = a3 * (a2 + a2);
return result;
}

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

result = a1;
*a1 = a2 * a2 - a3 * a3;
a1[1] = a3 * (a2 + a2);
return result;
}

original_code:
cmp_num c_sqr(cmp_num z)
{
    cmp_num c;
    c.re = (z.re * z.re) - (z.im * z.im);
    c.im = 2 * z.re * z.im;
    return c;
}

canonical_original_code:
struct cmp_num c_sqr(struct cmp_num z)
{
    struct cmp_num c;
    c.re = (z.re * z.re) - (z.im * z.im);
    c.im = 2 * z.re * z.im;
    return c;
}

variable_types:
z
struct cmp_num

return_type: struct cmp_num { long double re; long double im; }


decompiled_code:
long double *__fastcall c_mult(long double *a1, long double a2, long double a3, long double a4, long double a5)
{
long double *result; // rax

result = a1;
*a1 = a2 * a4 - a3 * a5;
a1[1] = a2 * a5 + a3 * a4;
return result;
}

canonical_decompiled_code:
long double *__fastcall func3(long double *a1, long double a2, long double a3, long double a4, long double a5)
{
long double *result; // rax

result = a1;
*a1 = a2 * a4 - a3 * a5;
a1[1] = a2 * a5 + a3 * a4;
return result;
}

original_code:
cmp_num c_mult(cmp_num a, cmp_num b)
{
    cmp_num c;
    c.re = (a.re * b.re) - (a.im * b.im);
    c.im = (a.re * b.im) + (a.im * b.re);
    return c;
}

canonical_original_code:
struct cmp_num c_mult(struct cmp_num a, struct cmp_num b)
{
    struct cmp_num c;
    c.re = (a.re * b.re) - (a.im * b.im);
    c.im = (a.re * b.im) + (a.im * b.re);
    return c;
}

user_defined_types: struct cmp_num { long double re; long double im; }


decompiled_code:
long double __fastcall c_abs(long double a1, long double a2)
{
long double x; // fst7
long double result; // fst7

x = a1 * a1 + a2 * a2;
if ( x < 0.0 )
result = sqrtl(x);
else
result = sqrt(x);
return result;
}

canonical_decompiled_code:
long double __fastcall func4(long double a1, long double a2)
{
long double x; // fst7
long double result; // fst7

x = a1 * a1 + a2 * a2;
if ( x < 0.0 )
result = sqrtl(x);
else
result = sqrt(x);
return result;
}

original_code:
long double c_abs(cmp_num z)
{
    long double a = sqrtl((z.re * z.re) + (z.im * z.im));
    return a;
}

canonical_original_code:
long double c_abs(struct cmp_num z)
{
    long double a = sqrtl((z.re * z.re) + (z.im * z.im));
    return a;
}

variable_types:
a
long double

return_type: long double


decompiled_code:
__int64 __fastcall mandelbrot_algorithm(int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, __int64 a10, __int64 a11, long double a12, long double a13)
{
int i; // ebx
long double v11; // [rsp+20h] [rbp-58h] BYREF
long double v12; // [rsp+30h] [rbp-48h]
long double v13; // [rsp+40h] [rbp-38h] BYREF
long double v14[2]; // [rsp+50h] [rbp-28h]

c_new(&v13, 0.0, 0.0);
if ( a1 <= 0 )
{
i = 0;
}
else
{
for ( i = 0; i != a1; ++i )
{
c_sqr(&v11, v13, v14[0]);
c_add(&v13, v11, v12, a12, a13);
if ( c_abs(v13, v14[0]) > 2.0 )
break;
}
}
++*(_DWORD *)(histogram + 4LL * i - 4);
return *(unsigned int *)(a11 + 4LL * i - 4);
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9, __int64 a10, __int64 a11, long double a12, long double a13)
{
int i; // ebx
long double v11; // [rsp+20h] [rbp-58h] BYREF
long double v12; // [rsp+30h] [rbp-48h]
long double v13; // [rsp+40h] [rbp-38h] BYREF
long double v14[2]; // [rsp+50h] [rbp-28h]

func0(&v13, 0.0, 0.0);
if ( a1 <= 0 )
{
i = 0;
}
else
{
for ( i = 0; i != a1; ++i )
{
func2(&v11, v13, v14[0]);
func1(&v13, v11, v12, a12, a13);
if ( func4(v13, v14[0]) > 2.0 )
break;
}
}
++*(_DWORD *)(histogram + 4LL * i - 4);
return *(unsigned int *)(a11 + 4LL * i - 4);
}

original_code:
Uint32 mandelbrot_algorithm(cmp_num coord, int iterations, SDL_PixelFormat *format, Uint32 *palette)
{
    cmp_num z = c_new(0, 0);
    int i = 0;
    Uint32 pixel = 0;
    for (i = 0; i < iterations; i++) {
        z = c_add(c_sqr(z), coord);
        if (c_abs(z) > 2.0) {
            break;
        }
    }
    histogram[i-1]++;
    pixel = palette[i-1];
    return pixel;
}

canonical_original_code:
unsigned int mandelbrot_algorithm(struct cmp_num coord, int iterations, struct SDL_PixelFormat *format, unsigned int *palette)
{
    struct cmp_num z = c_new(0, 0);
    int i = 0;
    unsigned int pixel = 0;
    for (i = 0; i < iterations; i++) {
        z = c_add(c_sqr(z), coord);
        if (c_abs(z) > 2.0) {
            break;
        }
    }
    histogram[i-1]++;
    pixel = palette[i-1];
    return pixel;
}

variable_types: iterations int

variable_types: struct SDL_PixelFormat { unsigned int format; struct SDL_Palette { int ncolors; struct SDL_Color { unsigned char r; unsigned char g; unsigned char b; unsigned char a; } *colors; unsigned int version; int refcount; } *palette; unsigned char BitsPerPixel; unsigned char BytesPerPixel; unsigned char padding[2]; unsigned int Rmask; unsigned int Gmask; unsigned int Bmask; unsigned int Amask; unsigned char Rloss; unsigned char Gloss; unsigned char Bloss; unsigned char Aloss; unsigned char Rshift; unsigned char Gshift; unsigned char Bshift; unsigned char Ashift; int refcount; struct SDL_PixelFormat *next; } *

variable_types:
palette
unsigned int *

variable_types:
pixel
unsigned int

return_type: unsigned int

user_defined_types: struct SDL_PixelFormat { unsigned int format; struct SDL_Palette *palette; unsigned char BitsPerPixel; unsigned char BytesPerPixel; unsigned char padding[2]; unsigned int Rmask; unsigned int Gmask; unsigned int Bmask; unsigned int Amask; unsigned char Rloss; unsigned char Gloss; unsigned char Bloss; unsigned char Aloss; unsigned char Rshift; unsigned char Gshift; unsigned char Bshift; unsigned char Ashift; int refcount; struct SDL_PixelFormat *next; }

user_defined_types: struct SDL_Palette { int ncolors; struct SDL_Color *colors; unsigned int version; int refcount; }


hash

repo: Travis-Sun/friso

decompiled_code:
__int64 __fastcall hash(char *a1, unsigned int a2)
{
char v2; // dl
unsigned int v3; // eax

v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
++a1;
v3 = v2 + 1313131 * v3;
v2 = *a1;
}
while ( *a1 );
}
else
{
v3 = 0;
}
return v3 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, unsigned int a2)
{
char v2; // dl
unsigned int v3; // eax

v2 = *a1;
if ( *a1 )
{
v3 = 0;
do
{
++a1;
v3 = v2 + 1313131 * v3;
v2 = *a1;
}
while ( *a1 );
}
else
{
v3 = 0;
}
return v3 % a2;
}

original_code:
static inline uint_t hash( fstring str, uint_t length )
{
    uint_t h = 0;
    while ( *str != '\0' )
 h = h * 1313131 + ( *str++ );
    return (h % length);
}

canonical_original_code:
static inline unsigned int hash(char *str, unsigned int length)
{
    unsigned int h = 0;
    while ( *str != '\0' )
 h = h * 1313131 + ( *str++ );
    return (h % length);
}

variable_types:
str
char *

variable_types:
length
unsigned int

variable_types:
h
unsigned int


decompiled_code:
__int64 __fastcall is_prime(int a1)
{
__int64 result; // rax
int v2; // ecx

result = 1LL;
if ( (unsigned int)(a1 - 2) > 1 )
{
result = 0LL;
if ( a1 != 1 && (a1 & 1) != 0 )
{
if ( a1 <= 9 )
{
result = 1LL;
}
else
{
result = (unsigned int)(a1 % 3);
if ( a1 % 3 )
{
v2 = 3;
while ( 1 )
{
++v2;
if ( v2 * v2 >= a1 )
break;
result = (unsigned int)(a1 % v2);
if ( !(a1 % v2) )
return result;
}
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
__int64 result; // rax
int v2; // ecx

result = 1LL;
if ( (unsigned int)(a1 - 2) > 1 )
{
result = 0LL;
if ( a1 != 1 && (a1 & 1) != 0 )
{
if ( a1 <= 9 )
{
result = 1LL;
}
else
{
result = (unsigned int)(a1 % 3);
if ( a1 % 3 )
{
v2 = 3;
while ( 1 )
{
++v2;
if ( v2 * v2 >= a1 )
break;
result = (unsigned int)(a1 % v2);
if ( !(a1 % v2) )
return result;
}
result = 1LL;
}
}
}
}
return result;
}

original_code:
static inline int is_prime( int n )
{
    int j;
    if ( n == 2 || n == 3 )
 return 1;
    if ( n == 1 || n % 2 == 0 )
 return 0;
    for ( j = 3; j * j < n; j++ )
 if ( n % j == 0 )
     return 0;
    return 1;
}

canonical_original_code:
static inline int is_prime(int n)
{
    int j;
    if ( n == 2 || n == 3 )
 return 1;
    if ( n == 1 || n % 2 == 0 )
 return 0;
    for ( j = 3; j * j < n; j++ )
 if ( n % j == 0 )
     return 0;
    return 1;
}

variable_types: n int

variable_types: j int


decompiled_code:
__int64 __fastcall next_prime(int a1)
{
unsigned int i; // ebx

for ( i = ((a1 & 1) == 0) + a1; !(unsigned int)is_prime(i); i += 2 )
;
return i;
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1)
{
unsigned int i; // ebx

for ( i = ((a1 & 1) == 0) + a1; !(unsigned int)func1(i); i += 2 )
;
return i;
}

original_code:
static inline int next_prime( int n )
{
    if ( n % 2 == 0 )
 n++;
    for ( ; ! is_prime( n ); n = n + 2 ) ;
    return n;
}

canonical_original_code:
static inline int next_prime(int n)
{
    if ( n % 2 == 0 )
 n++;
    for ( ; ! is_prime( n ); n = n + 2 ) ;
    return n;
}


decompiled_code:
void __fastcall rebuild_hash(__int64 a1)
{
unsigned int v1; // er12
_QWORD *v2; // r13
unsigned int v3; // er14
__int64 i; // rbx
__int64 v5; // rbp
_QWORD *v6; // rax
_QWORD *ptr; // [rsp+8h] [rbp-40h]

v1 = next_prime(2 * *(_DWORD *)a1 + 1);
ptr = *(_QWORD **)(a1 + 16);
v2 = create_hash_entries(v1);
if ( *(_DWORD *)a1 )
{
v3 = 0;
do
{
for ( i = ptr[v3]; i; *v6 = v5 )
{
v5 = i;
i = *(_QWORD *)(i + 16);
v6 = &v2[(unsigned int)hash(*(char **)v5, v1)];
*(_QWORD *)(v5 + 16) = *v6;
}
++v3;
}
while ( *(_DWORD *)a1 > v3 );
}
*(_QWORD *)(a1 + 16) = v2;
*(_DWORD *)a1 = v1;
*(_DWORD *)(a1 + 12) = (int)(float)((float)(int)v1 * *(float *)(a1 + 8));
free(ptr);
}

original_code:
static inline void rebuild_hash( friso_hash_t _hash )
{
    uint_t t, length = next_prime( _hash->length * 2 + 1 );
    hash_entry_t e, next, *_src = _hash->table, *table = create_hash_entries( length );
    uint_t bucket;
    for ( t = 0; t < _hash->length; t++ )
    {
 e = *( _src + t );
 if ( e != ((void *)0) ) {
     do {
  next = e->_next;
  bucket = hash( e->_key, length );
  e->_next = table[bucket];
  table[bucket] = e;
  e = next;
     } while ( e != ((void *)0) );
 }
    }
    _hash->table = table;
    _hash->length = length;
    _hash->threshold = ( uint_t ) ( _hash->length * _hash->factor );
    free( _src );
}

canonical_original_code:
static inline void rebuild_hash(struct friso_hash_cdt *_hash)
{
    unsigned int t; unsigned int length = next_prime( _hash->length * 2 + 1 );
    struct hash_entry *e; struct hash_entry *next; struct hash_entry **_src = _hash->table; struct hash_entry **table = create_hash_entries( length );
    unsigned int bucket;
    for ( t = 0; t < _hash->length; t++ )
    {
 e = *( _src + t );
 if ( e != ((void *)0) ) {
     do {
  next = e->_next;
  bucket = hash( e->_key, length );
  e->_next = table[bucket];
  table[bucket] = e;
  e = next;
     } while ( e != ((void *)0) );
 }
    }
    _hash->table = table;
    _hash->length = length;
    _hash->threshold = ( uint_t ) ( _hash->length * _hash->factor );
    free( _src );
}

variable_types: struct friso_hash_cdt { unsigned int length; unsigned int size; float factor; unsigned int threshold; struct hash_entry { char *_key; void *_val; struct hash_entry *_next; } **table; } *

variable_types:
t
unsigned int

variable_types:
bucket
unsigned int

user_defined_types: struct friso_hash_cdt { unsigned int length; unsigned int size; float factor; unsigned int threshold; struct hash_entry **table; }


decompiled_code:
_DWORD *new_hash_table()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0x18uLL);
if ( !v0 )
{
puts("Unable to do the memory allocation, program will now exit");
exit(1);
}
v1 = v0;
*v0 = 31;
v0[1] = 0;
v0[2] = 1062836634;
v0[3] = 26;
*((_QWORD *)v0 + 2) = create_hash_entries(0x1FuLL);
return v1;
}

canonical_decompiled_code:
_DWORD *func4()
{
_DWORD *v0; // rax
_DWORD *v1; // rbx

v0 = malloc(0x18uLL);
if ( !v0 )
{
puts("Unable to do the memory allocation, program will now exit");
exit(1);
}
v1 = v0;
*v0 = 31;
v0[1] = 0;
v0[2] = 1062836634;
v0[3] = 26;
*((_QWORD *)v0 + 2) = create_hash_entries(0x1FuLL);
return v1;
}

original_code:
extern friso_hash_t new_hash_table( void )
{
    friso_hash_t _hash = ( friso_hash_t ) malloc(sizeof ( friso_hash_cdt ));
    if ( _hash == ((void *)0) ) {
 printf("Unable to do the memory allocation, program will now exit\n" ); exit(1);
    }
    _hash->length = 31;
    _hash->size = 0;
    _hash->factor = 0.85f;
    _hash->threshold = ( uint_t ) ( _hash->length * _hash->factor );
    _hash->table = create_hash_entries( _hash->length );
    return _hash;
}

canonical_original_code:
extern struct friso_hash_cdt *new_hash_table()
{
    struct friso_hash_cdt *_hash = ( friso_hash_t ) malloc(sizeof ( friso_hash_cdt ));
    if ( _hash == ((void *)0) ) {
 printf("Unable to do the memory allocation, program will now exit\n" ); exit(1);
    }
    _hash->length = 31;
    _hash->size = 0;
    _hash->factor = 0.85f;
    _hash->threshold = ( uint_t ) ( _hash->length * _hash->factor );
    _hash->table = create_hash_entries( _hash->length );
    return _hash;
}

return_type: struct friso_hash_cdt { unsigned int length; unsigned int size; float factor; unsigned int threshold; struct hash_entry { char *_key; void *_val; struct hash_entry *_next; } **table; } *


decompiled_code:
void __fastcall free_hash_table(void *ptr, void (__fastcall *a2)(void *))
{
unsigned int v2; // er13
void *v3; // rbp
_QWORD *v4; // rbx

if ( *(_DWORD *)ptr )
{
v2 = 0;
do
{
v4 = *(_QWORD **)(*((_QWORD *)ptr + 2) + 8LL * v2);
while ( v4 )
{
v3 = v4;
v4 = (_QWORD *)v4[2];
if ( a2 )
a2(v3);
free(v3);
}
++v2;
}
while ( *(_DWORD *)ptr > v2 );
}
free(*((void **)ptr + 2));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr, void (__fastcall *a2)(void *))
{
unsigned int v2; // er13
void *v3; // rbp
_QWORD *v4; // rbx

if ( *(_DWORD *)ptr )
{
v2 = 0;
do
{
v4 = *(_QWORD **)(*((_QWORD *)ptr + 2) + 8LL * v2);
while ( v4 )
{
v3 = v4;
v4 = (_QWORD *)v4[2];
if ( a2 )
a2(v3);
free(v3);
}
++v2;
}
while ( *(_DWORD *)ptr > v2 );
}
free(*((void **)ptr + 2));
free(ptr);
}

original_code:
extern void free_hash_table(
 friso_hash_t _hash,
 fhash_callback_fn_t fentry_func )
{
    register uint_t j;
    hash_entry_t e, n;
    for ( j = 0; j < _hash->length; j++ )
    {
 e = *( _hash->table + j );
 for ( ; e != ((void *)0) ; ) {
     n = e->_next;
     if ( fentry_func != ((void *)0) ) fentry_func(e);
     free( e );
     e = n;
 }
    }
    free( _hash->table );
    free( _hash );
}

canonical_original_code:
extern void free_hash_table(struct friso_hash_cdt *_hash, void (*fentry_func)(struct hash_entry *))
{
    register unsigned int j;
    struct hash_entry *e; struct hash_entry *n;
    for ( j = 0; j < _hash->length; j++ )
    {
 e = *( _hash->table + j );
 for ( ; e != ((void *)0) ; ) {
     n = e->_next;
     if ( fentry_func != ((void *)0) ) fentry_func(e);
     free( e );
     e = n;
 }
    }
    free( _hash->table );
    free( _hash );
}

variable_types:
j
unsigned int

variable_types: struct hash_entry { char *_key; void *_val; struct hash_entry *_next; } *


original_code:
extern void hash_put_mapping(
 friso_hash_t _hash,
 fstring key,
 void * value )
{
    uint_t bucket = ( key == ((void *)0) ) ? 0 : hash( key, _hash->length );
    hash_entry_t e = *( _hash->table + bucket );
    for ( ; e != ((void *)0); e = e->_next )
    {
 if ( key == e->_key
  || ( key != ((void *)0) && e->_key != ((void *)0)
      && strcmp( key, e->_key ) == 0 ) )
 {
     e->_val = value;
     return;
 }
    }
    _hash->table[bucket] = new_hash_entry( key, value, _hash->table[bucket] );
    _hash->size++;
    if ( _hash->size >= _hash->threshold )
 rebuild_hash( _hash );
}

canonical_original_code:
extern void hash_put_mapping(struct friso_hash_cdt *_hash, char *key, void *value)
{
    unsigned int bucket = ( key == ((void *)0) ) ? 0 : hash( key, _hash->length );
    struct hash_entry *e = *( _hash->table + bucket );
    for ( ; e != ((void *)0); e = e->_next )
    {
 if ( key == e->_key
  || ( key != ((void *)0) && e->_key != ((void *)0)
      && strcmp( key, e->_key ) == 0 ) )
 {
     e->_val = value;
     return;
 }
    }
    _hash->table[bucket] = new_hash_entry( key, value, _hash->table[bucket] );
    _hash->size++;
    if ( _hash->size >= _hash->threshold )
 rebuild_hash( _hash );
}

variable_types:
key
char *

variable_types:
value
void *

user_defined_types: struct hash_entry { char *_key; void *_val; struct hash_entry *_next; }


decompiled_code:
__int64 __fastcall hash_exist_mapping(__int64 a1, char *a2)
{
unsigned int v3; // eax
__int64 v4; // rbx
const char *v6; // rsi

v3 = 0;
if ( a2 )
v3 = hash(a2, *(_DWORD *)a1);
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v3);
if ( !v4 )
return 0LL;
while ( 1 )
{
v6 = *(const char **)v4;
if ( *(char **)v4 == a2 )
break;
if ( v6 && a2 && !strcmp(a2, v6) )
return 1LL;
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, char *a2)
{
unsigned int v3; // eax
__int64 v4; // rbx
const char *v6; // rsi

v3 = 0;
if ( a2 )
v3 = func0(a2, *(_DWORD *)a1);
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v3);
if ( !v4 )
return 0LL;
while ( 1 )
{
v6 = *(const char **)v4;
if ( *(char **)v4 == a2 )
break;
if ( v6 && a2 && !strcmp(a2, v6) )
return 1LL;
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
return 0LL;
}
return 1LL;
}

original_code:
extern int hash_exist_mapping(
 friso_hash_t _hash, fstring key )
{
    uint_t bucket = ( key == ((void *)0) ) ? 0 : hash( key, _hash->length );
    hash_entry_t e;
    for ( e = *( _hash->table + bucket );
     e != ((void *)0);
     e = e->_next ) {
 if ( key == e->_key
  || ( key != ((void *)0) && e->_key != ((void *)0)
      && strcmp( key, e->_key ) == 0 ))
 {
     return 1;
 }
    }
    return 0;
}

canonical_original_code:
extern int hash_exist_mapping(struct friso_hash_cdt *_hash, char *key)
{
    unsigned int bucket = ( key == ((void *)0) ) ? 0 : hash( key, _hash->length );
    struct hash_entry *e;
    for ( e = *( _hash->table + bucket );
     e != ((void *)0);
     e = e->_next ) {
 if ( key == e->_key
  || ( key != ((void *)0) && e->_key != ((void *)0)
      && strcmp( key, e->_key ) == 0 ))
 {
     return 1;
 }
    }
    return 0;
}


decompiled_code:
__int64 __fastcall hash_get_value(__int64 a1, char *a2)
{
unsigned int v3; // eax
__int64 v4; // rbx
const char *v5; // rsi

v3 = 0;
if ( a2 )
v3 = hash(a2, *(_DWORD *)a1);
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v3);
if ( v4 )
{
while ( 1 )
{
v5 = *(const char **)v4;
if ( *(char **)v4 == a2 || v5 && a2 && !strcmp(a2, v5) )
break;
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
return v4;
}
v4 = *(_QWORD *)(v4 + 8);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, char *a2)
{
unsigned int v3; // eax
__int64 v4; // rbx
const char *v5; // rsi

v3 = 0;
if ( a2 )
v3 = func0(a2, *(_DWORD *)a1);
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 8LL * v3);
if ( v4 )
{
while ( 1 )
{
v5 = *(const char **)v4;
if ( *(char **)v4 == a2 || v5 && a2 && !strcmp(a2, v5) )
break;
v4 = *(_QWORD *)(v4 + 16);
if ( !v4 )
return v4;
}
v4 = *(_QWORD *)(v4 + 8);
}
return v4;
}

original_code:
extern void *hash_get_value( friso_hash_t _hash, fstring key )
{
    uint_t bucket = ( key == ((void *)0) ) ? 0 : hash( key, _hash->length );
    hash_entry_t e;
    for ( e = *( _hash->table + bucket );
     e != ((void *)0);
     e = e->_next ) {
 if ( key == e->_key
  || ( key != ((void *)0) && e->_key != ((void *)0)
      && strcmp( key, e->_key ) == 0 ))
 {
     return e->_val;
 }
    }
    return ((void *)0);
}

canonical_original_code:
extern void *hash_get_value(struct friso_hash_cdt *_hash, char *key)
{
    unsigned int bucket = ( key == ((void *)0) ) ? 0 : hash( key, _hash->length );
    struct hash_entry *e;
    for ( e = *( _hash->table + bucket );
     e != ((void *)0);
     e = e->_next ) {
 if ( key == e->_key
  || ( key != ((void *)0) && e->_key != ((void *)0)
      && strcmp( key, e->_key ) == 0 ))
 {
     return e->_val;
 }
    }
    return ((void *)0);
}

return_type: void *


original_code:
extern hash_entry_t hash_remove_mapping(
 friso_hash_t _hash, fstring key )
{
    uint_t bucket = ( key == ((void *)0) ) ? 0 : hash( key, _hash->length );
    hash_entry_t e, prev = ((void *)0);
    hash_entry_t b;
    for ( e = *( _hash->table + bucket );
     e != ((void *)0);
     prev = e, e = e->_next ) {
 if ( key == e->_key
  || ( key != ((void *)0) && e->_key != ((void *)0)
      && strcmp( key, e->_key ) == 0 ) )
 {
     b = e;
     if ( prev == ((void *)0) ) {
  _hash->table[bucket] = e->_next;
     } else {
  prev->_next = e->_next;
     }
     _hash->size--;
     return b;
 }
    }
    return ((void *)0);
}

canonical_original_code:
extern struct hash_entry *hash_remove_mapping(struct friso_hash_cdt *_hash, char *key)
{
    unsigned int bucket = ( key == ((void *)0) ) ? 0 : hash( key, _hash->length );
    struct hash_entry *e; struct hash_entry *prev = ((void *)0);
    struct hash_entry *b;
    for ( e = *( _hash->table + bucket );
     e != ((void *)0);
     prev = e, e = e->_next ) {
 if ( key == e->_key
  || ( key != ((void *)0) && e->_key != ((void *)0)
      && strcmp( key, e->_key ) == 0 ) )
 {
     b = e;
     if ( prev == ((void *)0) ) {
  _hash->table[bucket] = e->_next;
     } else {
  prev->_next = e->_next;
     }
     _hash->size--;
     return b;
 }
    }
    return ((void *)0);
}

variable_types: struct friso_hash_cdt { unsigned int length; unsigned int size; float factor; unsigned int threshold; struct hash_entry **table; } *

return_type: struct hash_entry { char *_key; void *_val; struct hash_entry *_next; } *


decompiled_code:
void __fastcall default_fdic_callback(__int64 a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
unsigned int v3; // ebx

v1 = *(_QWORD *)(a1 + 8);
free(*(void **)(v1 + 8));
v2 = *(_QWORD *)(v1 + 16);
if ( v2 )
{
if ( *(_DWORD *)(v2 + 12) )
{
v3 = 0;
do
free(*(void **)(*(_QWORD *)v2 + 8LL * v3++));
while ( *(_DWORD *)(v2 + 12) > v3 );
}
free_array_list(v2);
}
}

original_code:
static inline void default_fdic_callback( hash_entry_t e )
{
 register uint_t i;
 friso_array_t syn;
 lex_entry_t lex = ( lex_entry_t ) e->_val;
 free( lex->word );
 if ( lex->syn != ((void *)0) ) {
  syn = lex->syn;
  for ( i = 0; i < syn->length; i++ ) {
   free( syn->items[i] );
  }
  free_array_list( syn );
 }
}

canonical_original_code:
static inline void default_fdic_callback(struct hash_entry *e)
{
 register unsigned int i;
 struct friso_array_entry *syn;
 struct lex_entry_cdt *lex = ( lex_entry_t ) e->_val;
 free( lex->word );
 if ( lex->syn != ((void *)0) ) {
  syn = lex->syn;
  for ( i = 0; i < syn->length; i++ ) {
   free( syn->items[i] );
  }
  free_array_list( syn );
 }
}

variable_types:
i
unsigned int

variable_types: struct lex_entry_cdt { unsigned int length; unsigned int type; char *word; struct friso_array_entry { void **items; unsigned int allocs; unsigned int length; } *syn; unsigned int fre; } *

user_defined_types: struct lex_entry_cdt { unsigned int length; unsigned int type; char *word; struct friso_array_entry *syn; unsigned int fre; }


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

v1 = 0;
if ( strcmp(a1, "__LEX_CJK_WORDS__") )
{
v1 = 1;
if ( strcmp(a1, "__LEX_CJK_UNITS__") )
{
v1 = 2;
if ( strcmp(a1, "__LEX_ECM_WORDS__") )
{
v1 = 3;
if ( strcmp(a1, "__LEX_CEM_WORDS__") )
{
v1 = 4;
if ( strcmp(a1, "__LEX_CN_LNAME__") )
{
v1 = 5;
if ( strcmp(a1, "__LEX_CN_SNAME__") )
{
v1 = 6;
if ( strcmp(a1, "__LEX_CN_DNAME1__") )
{
v1 = 7;
if ( strcmp(a1, "__LEX_CN_DNAME2__") )
{
v1 = 8;
if ( strcmp(a1, "__LEX_CN_LNA__") )
{
v1 = 9;
if ( strcmp(a1, "__LEX_STOPWORDS__") )
{
v1 = 10;
if ( strcmp(a1, "__LEX_ENPUN_WORDS__") )
v1 = strcmp(a1, "__LEX_EN_WORDS__") == 0 ? 11 : -1;
}
}
}
}
}
}
}
}
}
}
return v1;
}

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

v1 = 0;
if ( strcmp(a1, "__LEX_CJK_WORDS__") )
{
v1 = 1;
if ( strcmp(a1, "__LEX_CJK_UNITS__") )
{
v1 = 2;
if ( strcmp(a1, "__LEX_ECM_WORDS__") )
{
v1 = 3;
if ( strcmp(a1, "__LEX_CEM_WORDS__") )
{
v1 = 4;
if ( strcmp(a1, "__LEX_CN_LNAME__") )
{
v1 = 5;
if ( strcmp(a1, "__LEX_CN_SNAME__") )
{
v1 = 6;
if ( strcmp(a1, "__LEX_CN_DNAME1__") )
{
v1 = 7;
if ( strcmp(a1, "__LEX_CN_DNAME2__") )
{
v1 = 8;
if ( strcmp(a1, "__LEX_CN_LNA__") )
{
v1 = 9;
if ( strcmp(a1, "__LEX_STOPWORDS__") )
{
v1 = 10;
if ( strcmp(a1, "__LEX_ENPUN_WORDS__") )
v1 = strcmp(a1, "__LEX_EN_WORDS__") == 0 ? 11 : -1;
}
}
}
}
}
}
}
}
}
}
return v1;
}

original_code:
static inline friso_lex_t get_lexicon_type_with_constant( fstring _key )
{
 if ( strcmp( _key, "__LEX_CJK_WORDS__" ) == 0 ) {
  return __LEX_CJK_WORDS__;
 }
 else if ( strcmp( _key, "__LEX_CJK_UNITS__" ) == 0 ) {
  return __LEX_CJK_UNITS__;
 }
 else if ( strcmp( _key, "__LEX_ECM_WORDS__" ) == 0 ) {
  return __LEX_ECM_WORDS__;
 }
 else if ( strcmp( _key, "__LEX_CEM_WORDS__" ) == 0 ) {
  return __LEX_CEM_WORDS__;
 }
 else if ( strcmp( _key, "__LEX_CN_LNAME__" ) == 0 ) {
  return __LEX_CN_LNAME__;
 }
 else if ( strcmp( _key, "__LEX_CN_SNAME__" ) == 0 ) {
  return __LEX_CN_SNAME__;
 }
 else if ( strcmp( _key, "__LEX_CN_DNAME1__" ) == 0 ) {
  return __LEX_CN_DNAME1__;
 }
 else if ( strcmp( _key, "__LEX_CN_DNAME2__" ) == 0 ) {
  return __LEX_CN_DNAME2__;
 }
 else if ( strcmp( _key, "__LEX_CN_LNA__" ) == 0 ) {
  return __LEX_CN_LNA__;
 }
 else if ( strcmp( _key, "__LEX_STOPWORDS__" ) == 0 ) {
  return __LEX_STOPWORDS__;
 }
 else if ( strcmp( _key, "__LEX_ENPUN_WORDS__" ) == 0 ) {
  return __LEX_ENPUN_WORDS__;
 }
 else if ( strcmp( _key, "__LEX_EN_WORDS__" ) == 0 ) {
  return __LEX_EN_WORDS__;
 }
 return -1;
}

canonical_original_code:
static inline enum friso_lex_t get_lexicon_type_with_constant(char *_key)
{
 if ( strcmp( _key, "__LEX_CJK_WORDS__" ) == 0 ) {
  return __LEX_CJK_WORDS__;
 }
 else if ( strcmp( _key, "__LEX_CJK_UNITS__" ) == 0 ) {
  return __LEX_CJK_UNITS__;
 }
 else if ( strcmp( _key, "__LEX_ECM_WORDS__" ) == 0 ) {
  return __LEX_ECM_WORDS__;
 }
 else if ( strcmp( _key, "__LEX_CEM_WORDS__" ) == 0 ) {
  return __LEX_CEM_WORDS__;
 }
 else if ( strcmp( _key, "__LEX_CN_LNAME__" ) == 0 ) {
  return __LEX_CN_LNAME__;
 }
 else if ( strcmp( _key, "__LEX_CN_SNAME__" ) == 0 ) {
  return __LEX_CN_SNAME__;
 }
 else if ( strcmp( _key, "__LEX_CN_DNAME1__" ) == 0 ) {
  return __LEX_CN_DNAME1__;
 }
 else if ( strcmp( _key, "__LEX_CN_DNAME2__" ) == 0 ) {
  return __LEX_CN_DNAME2__;
 }
 else if ( strcmp( _key, "__LEX_CN_LNA__" ) == 0 ) {
  return __LEX_CN_LNA__;
 }
 else if ( strcmp( _key, "__LEX_STOPWORDS__" ) == 0 ) {
  return __LEX_STOPWORDS__;
 }
 else if ( strcmp( _key, "__LEX_ENPUN_WORDS__" ) == 0 ) {
  return __LEX_ENPUN_WORDS__;
 }
 else if ( strcmp( _key, "__LEX_EN_WORDS__" ) == 0 ) {
  return __LEX_EN_WORDS__;
 }
 return -1;
}

return_type: enum friso_lex_t { __LEX_CJK_WORDS__=0, __LEX_CJK_UNITS__=1, __LEX_ECM_WORDS__=2, __LEX_CEM_WORDS__=3, __LEX_CN_LNAME__=4, __LEX_CN_SNAME__=5, __LEX_CN_DNAME1__=6, __LEX_CN_DNAME2__=7, __LEX_CN_LNA__=8, __LEX_STOPWORDS__=9, __LEX_ENPUN_WORDS__=10, __LEX_EN_WORDS__=11, __LEX_OTHER_WORDS__=15, __LEX_NCSYN_WORDS__=16 }


decompiled_code:
_QWORD *friso_dic_new()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
_QWORD *v2; // rbx
_QWORD *v3; // rbp

v0 = calloc(8uLL, 0xCuLL);
if ( !v0 )
{
puts("Unable to do the memory allocation, program will now exit");
exit(1);
}
v1 = v0;
v2 = v0;
v3 = v0 + 12;
do
*v2++ = new_hash_table();
while ( v2 != v3 );
return v1;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
_QWORD *v2; // rbx
_QWORD *v3; // rbp

v0 = calloc(8uLL, 0xCuLL);
if ( !v0 )
{
puts("Unable to do the memory allocation, program will now exit");
exit(1);
}
v1 = v0;
v2 = v0;
v3 = v0 + 12;
do
*v2++ = new_hash_table();
while ( v2 != v3 );
return v1;
}

original_code:
extern friso_dic_t friso_dic_new()
{
 register uint_t t;
 friso_dic_t dic = ( friso_dic_t ) calloc(sizeof( friso_hash_t ), 12);
 if ( dic == ((void *)0) ) {
  printf("Unable to do the memory allocation, program will now exit\n" ); exit(1);
 }
 for ( t = 0; t < 12; t++ ) {
  dic[t] = new_hash_table();
 }
 return dic;
}

canonical_original_code:
extern struct friso_hash_cdt **friso_dic_new()
{
 register unsigned int t;
 struct friso_hash_cdt **dic = ( friso_dic_t ) calloc(sizeof( friso_hash_t ), 12);
 if ( dic == ((void *)0) ) {
  printf("Unable to do the memory allocation, program will now exit\n" ); exit(1);
 }
 for ( t = 0; t < 12; t++ ) {
  dic[t] = new_hash_table();
 }
 return dic;
}

variable_types: struct friso_hash_cdt { unsigned int length; unsigned int size; float factor; unsigned int threshold; struct hash_entry { char *_key; void *_val; struct hash_entry *_next; } **table; } **


decompiled_code:
void __fastcall friso_dic_free(void *ptr)
{
_QWORD *v1; // rbx

v1 = ptr;
do
free_hash_table(*v1++, default_fdic_callback);
while ( v1 != (_QWORD *)((char *)ptr + 96) );
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
_QWORD *v1; // rbx

v1 = ptr;
do
free_hash_table(*v1++, default_fdic_callback);
while ( v1 != (_QWORD *)((char *)ptr + 96) );
free(ptr);
}

original_code:
extern void friso_dic_free( friso_dic_t dic )
{
 register uint_t t;
 for ( t = 0; t < 12; t++ ) {
  free_hash_table( dic[t], default_fdic_callback );
 }
 free( dic );
}

canonical_original_code:
extern void friso_dic_free(struct friso_hash_cdt **dic)
{
 register unsigned int t;
 for ( t = 0; t < 12; t++ ) {
  free_hash_table( dic[t], default_fdic_callback );
 }
 free( dic );
}


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

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

original_code:
extern void free_lex_entry( lex_entry_t e )
{
 free( e );
}

canonical_original_code:
extern void free_lex_entry(struct lex_entry_cdt *e)
{
 free( e );
}

user_defined_types: struct friso_array_entry { void **items; unsigned int allocs; unsigned int length; }


decompiled_code:
__int64 __fastcall friso_dic_add(__int64 a1, unsigned int a2, const char *a3, __int64 a4)
{
int v6; // eax
_QWORD *v7; // rax

v6 = strlen(a3);
v7 = new_lex_entry((__int64)a3, a4, 0, v6, a2);
return hash_put_mapping(*(_QWORD *)(a1 + 8LL * a2), a3, v7);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, const char *a3, __int64 a4)
{
int v6; // eax
_QWORD *v7; // rax

v6 = strlen(a3);
v7 = new_lex_entry((__int64)a3, a4, 0, v6, a2);
return hash_put_mapping(*(_QWORD *)(a1 + 8LL * a2), a3, v7);
}

original_code:
extern void friso_dic_add(
  friso_dic_t dic,
  friso_lex_t lex,
  fstring word,
  friso_array_t syn )
{
 if ( lex >= 0 || lex < 12 )
 {
  hash_put_mapping( dic[lex], word,
    new_lex_entry( word, syn, 0,
     (uint_t) strlen(word), (uint_t) lex ) );
 }
}

canonical_original_code:
extern void friso_dic_add(struct friso_hash_cdt **dic, enum friso_lex_t lex, char *word, struct friso_array_entry *syn)
{
 if ( lex >= 0 || lex < 12 )
 {
  hash_put_mapping( dic[lex], word,
    new_lex_entry( word, syn, 0,
     (unsigned int) strlen(word), (unsigned int) lex ) );
 }
}

variable_types: enum friso_lex_t { __LEX_CJK_WORDS__=0, __LEX_CJK_UNITS__=1, __LEX_ECM_WORDS__=2, __LEX_CEM_WORDS__=3, __LEX_CN_LNAME__=4, __LEX_CN_SNAME__=5, __LEX_CN_DNAME1__=6, __LEX_CN_DNAME2__=7, __LEX_CN_LNA__=8, __LEX_STOPWORDS__=9, __LEX_ENPUN_WORDS__=10, __LEX_EN_WORDS__=11, __LEX_OTHER_WORDS__=15, __LEX_NCSYN_WORDS__=16 }

variable_types:
word
char *

variable_types: struct friso_array_entry { void **items; unsigned int allocs; unsigned int length; } *


decompiled_code:
void __fastcall friso_dic_add_with_fre(__int64 a1, unsigned int a2, const char *a3, __int64 a4, int a5)
{
int v8; // eax
_QWORD *v9; // rax

if ( a2 <= 0xB )
{
v8 = strlen(a3);
v9 = new_lex_entry((__int64)a3, a4, a5, v8, a2);
hash_put_mapping(*(_QWORD *)(a1 + 8LL * a2), a3, v9);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, unsigned int a2, const char *a3, __int64 a4, int a5)
{
int v8; // eax
_QWORD *v9; // rax

if ( a2 <= 0xB )
{
v8 = strlen(a3);
v9 = new_lex_entry((__int64)a3, a4, a5, v8, a2);
hash_put_mapping(*(_QWORD *)(a1 + 8LL * a2), a3, v9);
}
}

original_code:
extern void friso_dic_add_with_fre(
  friso_dic_t dic,
  friso_lex_t lex,
  fstring word,
  friso_array_t syn,
  uint_t frequency )
{
 if ( lex >= 0 && lex < 12 ) {
  hash_put_mapping( dic[lex], word,
    new_lex_entry( word, syn, frequency,
     ( uint_t ) strlen(word), ( uint_t ) lex ) );
 }
}

canonical_original_code:
extern void friso_dic_add_with_fre(struct friso_hash_cdt **dic, enum friso_lex_t lex, char *word, struct friso_array_entry *syn, unsigned int frequency)
{
 if ( lex >= 0 && lex < 12 ) {
  hash_put_mapping( dic[lex], word,
    new_lex_entry( word, syn, frequency,
     ( unsigned int ) strlen(word), ( unsigned int ) lex ) );
 }
}

variable_types:
frequency
unsigned int

user_defined_types: enum friso_lex_t { __LEX_CJK_WORDS__=0, __LEX_CJK_UNITS__=1, __LEX_ECM_WORDS__=2, __LEX_CEM_WORDS__=3, __LEX_CN_LNAME__=4, __LEX_CN_SNAME__=5, __LEX_CN_DNAME1__=6, __LEX_CN_DNAME2__=7, __LEX_CN_LNA__=8, __LEX_STOPWORDS__=9, __LEX_ENPUN_WORDS__=10, __LEX_EN_WORDS__=11, __LEX_OTHER_WORDS__=15, __LEX_NCSYN_WORDS__=16 }


decompiled_code:
__int64 __fastcall friso_dic_match(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 0xB )
result = hash_exist_mapping(*(_QWORD *)(a1 + 8LL * a2), a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 0xB )
result = hash_exist_mapping(*(_QWORD *)(a1 + 8LL * a2), a3);
return result;
}

original_code:
extern int friso_dic_match(
  friso_dic_t dic,
  friso_lex_t lex,
  fstring word )
{
 if ( lex >= 0 && lex < 12 ) {
  return hash_exist_mapping( dic[lex], word );
 }
 return 0;
}

canonical_original_code:
extern int friso_dic_match(struct friso_hash_cdt **dic, enum friso_lex_t lex, char *word)
{
 if ( lex >= 0 && lex < 12 ) {
  return hash_exist_mapping( dic[lex], word );
 }
 return 0;
}


decompiled_code:
__int64 __fastcall friso_dic_get(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 0xB )
result = hash_get_value(*(_QWORD *)(a1 + 8LL * a2), a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 0xB )
result = hash_get_value(*(_QWORD *)(a1 + 8LL * a2), a3);
return result;
}

original_code:
extern lex_entry_t friso_dic_get(
  friso_dic_t dic,
  friso_lex_t lex,
  fstring word )
{
 if ( lex >= 0 && lex < 12 ) {
  return ( lex_entry_t ) hash_get_value( dic[lex], word );
 }
 return ((void *)0);
}

canonical_original_code:
extern struct lex_entry_cdt *friso_dic_get(struct friso_hash_cdt **dic, enum friso_lex_t lex, char *word)
{
 if ( lex >= 0 && lex < 12 ) {
  return ( struct lex_entry_cdt * ) hash_get_value( dic[lex], word );
 }
 return ((void *)0);
}

return_type: struct lex_entry_cdt { unsigned int length; unsigned int type; char *word; struct friso_array_entry { void **items; unsigned int allocs; unsigned int length; } *syn; unsigned int fre; } *


decompiled_code:
__int64 __fastcall friso_spec_dic_size(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 0xB )
result = *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = 0LL;
if ( a2 <= 0xB )
result = *(unsigned int *)(*(_QWORD *)(a1 + 8LL * a2) + 4LL);
return result;
}

original_code:
extern uint_t friso_spec_dic_size(
  friso_dic_t dic,
  friso_lex_t lex )
{
 if ( lex >= 0 && lex < 12 ) {
  return dic[lex]->size;
 }
 return 0;
}

canonical_original_code:
extern unsigned int friso_spec_dic_size(struct friso_hash_cdt **dic, enum friso_lex_t lex)
{
 if ( lex >= 0 && lex < 12 ) {
  return dic[lex]->size;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall friso_all_dic_size(__int64 a1)
{
__int64 v1; // rcx
__int64 result; // rax

v1 = a1 + 96;
LODWORD(result) = 0;
do
{
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL) + result);
a1 += 8LL;
}
while ( a1 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
__int64 v1; // rcx
__int64 result; // rax

v1 = a1 + 96;
LODWORD(result) = 0;
do
{
result = (unsigned int)(*(_DWORD *)(*(_QWORD *)a1 + 4LL) + result);
a1 += 8LL;
}
while ( a1 != v1 );
return result;
}

original_code:
extern uint_t friso_all_dic_size(
  friso_dic_t dic )
{
 register uint_t size = 0, t;
 for ( t = 0; t < 12; t++ ) {
  size += dic[t]->size;
 }
 return size;
}

canonical_original_code:
extern unsigned int friso_all_dic_size(struct friso_hash_cdt **dic)
{
 register unsigned int size = 0; register unsigned int t;
 for ( t = 0; t < 12; t++ ) {
  size += dic[t]->size;
 }
 return size;
}

variable_types:
size
unsigned int


decompiled_code:
__int64 __fastcall get_node(__int64 *a1, unsigned int a2)
{
unsigned int v2; // edx
__int64 result; // rax
int v4; // edx
int v5; // ecx

v2 = *((_DWORD *)a1 + 4);
result = 0LL;
if ( v2 > a2 )
{
if ( v2 >> 1 <= a2 )
{
result = a1[1];
do
{
result = *(_QWORD *)(result + 8);
--v2;
}
while ( a2 != v2 );
}
else
{
result = *a1;
v4 = 0;
do
{
result = *(_QWORD *)(result + 16);
v5 = v4++;
}
while ( a2 != v5 );
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 *a1, unsigned int a2)
{
unsigned int v2; // edx
__int64 result; // rax
int v4; // edx
int v5; // ecx

v2 = *((_DWORD *)a1 + 4);
result = 0LL;
if ( v2 > a2 )
{
if ( v2 >> 1 <= a2 )
{
result = a1[1];
do
{
result = *(_QWORD *)(result + 8);
--v2;
}
while ( a2 != v2 );
}
else
{
result = *a1;
v4 = 0;
do
{
result = *(_QWORD *)(result + 16);
v5 = v4++;
}
while ( a2 != v5 );
}
}
return result;
}

original_code:
static inline link_node_t get_node(
 friso_link_t link, uint_t idx )
{
    link_node_t p = ((void *)0);
    register uint_t t;
    if ( idx >= 0 && idx < link->size )
    {
 if ( idx < link->size / 2 ) {
     p = link->head;
     for ( t = 0; t <= idx; t++ )
  p = p->next;
 } else {
     p = link->tail;
     for ( t = link->size; t > idx; t-- )
  p = p->prev;
 }
    }
    return p;
}

canonical_original_code:
static inline struct friso_link_node *get_node(struct friso_link_entry *link, unsigned int idx)
{
    struct friso_link_node *p = ((void *)0);
    register unsigned int t;
    if ( idx >= 0 && idx < link->size )
    {
 if ( idx < link->size / 2 ) {
     p = link->head;
     for ( t = 0; t <= idx; t++ )
  p = p->next;
 } else {
     p = link->tail;
     for ( t = link->size; t > idx; t-- )
  p = p->prev;
 }
    }
    return p;
}

variable_types: struct friso_link_entry { struct friso_link_node *head; struct friso_link_node *tail; unsigned int size; } *

variable_types:
idx
unsigned int

variable_types: struct friso_link_node { void *value; struct friso_link_node *prev; struct friso_link_node *next; } *


original_code:
static inline void * remove_node(
 friso_link_t link, link_node_t node )
{
    void * _value = node->value;
    node->prev->next = node->next;
    node->next->prev = node->prev;
    link->size--;
    free( node );
    return _value;
}

canonical_original_code:
static inline void *remove_node(struct friso_link_entry *link, struct friso_link_node *node)
{
    void *_value = node->value;
    node->prev->next = node->next;
    node->next->prev = node->prev;
    link->size--;
    free( node );
    return _value;
}

variable_types: struct friso_link_entry { struct friso_link_node { void *value; struct friso_link_node *prev; struct friso_link_node *next; } *head; struct friso_link_node *tail; unsigned int size; } *

variable_types:
node
struct friso_link_node *

user_defined_types: struct friso_link_entry { struct friso_link_node *head; struct friso_link_node *tail; unsigned int size; }


decompiled_code:
_QWORD *new_link_list()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // rax

v0 = malloc(0x18uLL);
if ( !v0 )
{
puts("Unable to do the memory allocation, program will now exit");
exit(1);
}
v1 = v0;
v2 = new_node_entry(0LL, 0LL, 0LL);
*v1 = v2;
v3 = new_node_entry(0LL, (__int64)v2, 0LL);
v1[1] = v3;
*(_QWORD *)(*v1 + 16LL) = v3;
*((_DWORD *)v1 + 4) = 0;
return v1;
}

canonical_decompiled_code:
_QWORD *func2()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx
_QWORD *v2; // rax
_QWORD *v3; // rax

v0 = malloc(0x18uLL);
if ( !v0 )
{
puts("Unable to do the memory allocation, program will now exit");
exit(1);
}
v1 = v0;
v2 = new_node_entry(0LL, 0LL, 0LL);
*v1 = v2;
v3 = new_node_entry(0LL, (__int64)v2, 0LL);
v1[1] = v3;
*(_QWORD *)(*v1 + 16LL) = v3;
*((_DWORD *)v1 + 4) = 0;
return v1;
}

original_code:
extern friso_link_t new_link_list( void )
{
    friso_link_t e = ( friso_link_t )
  malloc(sizeof( friso_link_entry ));
    if ( e == ((void *)0) ) {
 printf("Unable to do the memory allocation, program will now exit\n" ); exit(1);
    }
    e->head = new_node_entry( ((void *)0), ((void *)0), ((void *)0) );
    e->tail = new_node_entry( ((void *)0), e->head, ((void *)0) );
    e->head->next = e->tail;
    e->size = 0;
    return e;
}

canonical_original_code:
extern struct friso_link_entry *new_link_list()
{
    struct friso_link_entry *e = ( friso_link_t )
  malloc(sizeof( friso_link_entry ));
    if ( e == ((void *)0) ) {
 printf("Unable to do the memory allocation, program will now exit\n" ); exit(1);
    }
    e->head = new_node_entry( ((void *)0), ((void *)0), ((void *)0) );
    e->tail = new_node_entry( ((void *)0), e->head, ((void *)0) );
    e->head->next = e->tail;
    e->size = 0;
    return e;
}

return_type: struct friso_link_entry { struct friso_link_node { void *value; struct friso_link_node *prev; struct friso_link_node *next; } *head; struct friso_link_node *tail; unsigned int size; } *


decompiled_code:
void __fastcall free_link_list(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
while ( v2 );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
_QWORD *v2; // rbx
void *v3; // rdi

v2 = *(_QWORD **)ptr;
if ( *(_QWORD *)ptr )
{
do
{
v3 = v2;
v2 = (_QWORD *)v2[2];
free(v3);
}
while ( v2 );
}
free(ptr);
}

original_code:
extern void free_link_list( friso_link_t link )
{
    link_node_t node, next;
    for ( node = link->head; node != ((void *)0); )
    {
 next = node->next;
 free( node );
 node = next;
    }
    free( link );
}

canonical_original_code:
extern void free_link_list(struct friso_link_entry *link)
{
    struct friso_link_node *node; struct friso_link_node *next;
    for ( node = link->head; node != ((void *)0); )
    {
 next = node->next;
 free( node );
 node = next;
    }
    free( link );
}

user_defined_types: struct friso_link_node { void *value; struct friso_link_node *prev; struct friso_link_node *next; }


decompiled_code:
__int64 __fastcall link_list_insert_before(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax

result = get_node((__int64 *)a1, a2);
if ( result )
{
result = (__int64)new_node_entry(a3, *(_QWORD *)(result + 8), result);
*(_QWORD *)(*(_QWORD *)(result + 8) + 16LL) = result;
*(_QWORD *)(*(_QWORD *)(result + 16) + 8LL) = result;
++*(_DWORD *)(a1 + 16);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax

result = func0((__int64 *)a1, a2);
if ( result )
{
result = (__int64)new_node_entry(a3, *(_QWORD *)(result + 8), result);
*(_QWORD *)(*(_QWORD *)(result + 8) + 16LL) = result;
*(_QWORD *)(*(_QWORD *)(result + 16) + 8LL) = result;
++*(_DWORD *)(a1 + 16);
}
return result;
}

original_code:
extern void link_list_insert_before(
 friso_link_t link, uint_t idx, void * value )
{
    link_node_t node = get_node( link, idx );
    if ( node != ((void *)0) ) {
 { link_node_t e = new_node_entry( value, node->prev, node ); e->prev->next = e; e->next->prev = e; link->size++; };
    }
}

canonical_original_code:
extern void link_list_insert_before(struct friso_link_entry *link, unsigned int idx, void *value)
{
    struct friso_link_node *node = get_node( link, idx );
    if ( node != ((void *)0) ) {
 { struct friso_link_node *e = new_node_entry( value, node->prev, node ); e->prev->next = e; e->next->prev = e; link->size++; };
    }
}


decompiled_code:
__int64 __fastcall link_list_set(__int64 *a1, unsigned int a2, __int64 a3)
{
__int64 *v4; // rax
__int64 v5; // rdx

v4 = (__int64 *)get_node(a1, a2);
if ( !v4 )
return 0LL;
v5 = *v4;
*v4 = a3;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 *a1, unsigned int a2, __int64 a3)
{
__int64 *v4; // rax
__int64 v5; // rdx

v4 = (__int64 *)func0(a1, a2);
if ( !v4 )
return 0LL;
v5 = *v4;
*v4 = a3;
return v5;
}

original_code:
extern void *link_list_set(
 friso_link_t link, uint_t idx, void * value )
{
    link_node_t node = get_node( link, idx );
    void * _value = ((void *)0);
    if ( node != ((void *)0) ) {
 _value = node->value;
 node->value = value;
    }
    return _value;
}

canonical_original_code:
extern void *link_list_set(struct friso_link_entry *link, unsigned int idx, void *value)
{
    struct friso_link_node *node = get_node( link, idx );
    void *_value = ((void *)0);
    if ( node != ((void *)0) ) {
 _value = node->value;
 node->value = value;
    }
    return _value;
}


decompiled_code:
__int64 __fastcall link_list_remove_node(__int64 a1, __int64 *a2)
{
return remove_node(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 *a2)
{
return func1(a1, a2);
}

original_code:
extern void *link_list_remove_node( friso_link_t link, link_node_t node )
{
    return remove_node( link, node );
}

canonical_original_code:
extern void *link_list_remove_node(struct friso_link_entry *link, struct friso_link_node *node)
{
    return remove_node( link, node );
}


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

result = 0LL;
if ( a1[4] )
result = remove_node((__int64)a1, *(__int64 **)(*(_QWORD *)a1 + 16LL));
return result;
}

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

result = 0LL;
if ( a1[4] )
result = func1((__int64)a1, *(__int64 **)(*(_QWORD *)a1 + 16LL));
return result;
}

original_code:
extern void *link_list_remove_first( friso_link_t link )
{
    if ( link->size > 0 ) {
 return remove_node( link, link->head->next );
    }
    return ((void *)0);
}

canonical_original_code:
extern void *link_list_remove_first(struct friso_link_entry *link)
{
    if ( link->size > 0 ) {
 return remove_node( link, link->head->next );
    }
    return ((void *)0);
}


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

result = 0LL;
if ( *(_DWORD *)(a1 + 16) )
result = remove_node(a1, *(__int64 **)(*(_QWORD *)(a1 + 8) + 8LL));
return result;
}

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

result = 0LL;
if ( *(_DWORD *)(a1 + 16) )
result = func1(a1, *(__int64 **)(*(_QWORD *)(a1 + 8) + 8LL));
return result;
}

original_code:
extern void *link_list_remove_last( friso_link_t link )
{
    if ( link->size > 0 ) {
 return remove_node( link, link->tail->prev );
    }
    return ((void *)0);
}

canonical_original_code:
extern void *link_list_remove_last(struct friso_link_entry *link)
{
    if ( link->size > 0 ) {
 return remove_node( link, link->tail->prev );
    }
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall resize_array_list(__int64 a1, unsigned int a2)
{
_QWORD *v2; // rbp
unsigned int v3; // eax

v2 = create_array_entries(a2);
if ( *(_DWORD *)(a1 + 12) )
{
v3 = 0;
do
{
v2[v3] = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v3);
++v3;
}
while ( *(_DWORD *)(a1 + 12) > v3 );
}
free(*(void **)a1);
*(_QWORD *)a1 = v2;
*(_DWORD *)(a1 + 8) = a2;
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
_QWORD *v2; // rbp
unsigned int v3; // eax

v2 = create_array_entries(a2);
if ( *(_DWORD *)(a1 + 12) )
{
v3 = 0;
do
{
v2[v3] = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v3);
++v3;
}
while ( *(_DWORD *)(a1 + 12) > v3 );
}
free(*(void **)a1);
*(_QWORD *)a1 = v2;
*(_DWORD *)(a1 + 8) = a2;
return a1;
}

original_code:
static inline friso_array_t resize_array_list(
 friso_array_t array,
 uint_t opacity )
{
    register uint_t t;
    void **block = create_array_entries( opacity );
    for ( t = 0; t < array->length ; t++ ) {
 block[t] = array->items[t];
    }
    free( array->items );
    array->items = block;
    array->allocs = opacity;
    return array;
}

canonical_original_code:
static inline struct friso_array_entry *resize_array_list(struct friso_array_entry *array, unsigned int opacity)
{
    register unsigned int t;
    void **block = create_array_entries( opacity );
    for ( t = 0; t < array->length ; t++ ) {
 block[t] = array->items[t];
    }
    free( array->items );
    array->items = block;
    array->allocs = opacity;
    return array;
}

variable_types:
array
struct friso_array_entry *

variable_types:
opacity
unsigned int

variable_types:
t
unsigned int

variable_types:
block
void **

return_type: struct friso_array_entry { void **items; unsigned int allocs; unsigned int length; } *


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

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

original_code:
extern void free_array_list( friso_array_t array )
{
    free( array->items );
    free( array );
}

canonical_original_code:
extern void free_array_list(struct friso_array_entry *array)
{
    free( array->items );
    free( array );
}


decompiled_code:
__int64 __fastcall array_list_add(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( v2 == *(_DWORD *)(a1 + 8) )
resize_array_list(a1, 2 * v2 + 1);
v3 = *(_QWORD *)a1;
LODWORD(result) = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = result + 1;
result = (unsigned int)result;
*(_QWORD *)(v3 + 8LL * (unsigned int)result) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rdx
__int64 result; // rax

v2 = *(_DWORD *)(a1 + 12);
if ( v2 == *(_DWORD *)(a1 + 8) )
func0(a1, 2 * v2 + 1);
v3 = *(_QWORD *)a1;
LODWORD(result) = *(_DWORD *)(a1 + 12);
*(_DWORD *)(a1 + 12) = result + 1;
result = (unsigned int)result;
*(_QWORD *)(v3 + 8LL * (unsigned int)result) = a2;
return result;
}

original_code:
extern void array_list_add( friso_array_t array, void *value )
{
    if ( array->length == array->allocs ) {
 resize_array_list( array, array->length * 2 + 1 );
    }
    array->items[array->length++] = value;
}

canonical_original_code:
extern void array_list_add(struct friso_array_entry *array, void *value)
{
    if ( array->length == array->allocs ) {
 resize_array_list( array, array->length * 2 + 1 );
    }
    array->items[array->length++] = value;
}

variable_types:
value
void *


decompiled_code:
__int64 __fastcall array_list_insert(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // eax
__int64 v6; // rcx

result = *(unsigned int *)(a1 + 12);
if ( (unsigned int)result >= a2 )
{
if ( (_DWORD)result == *(_DWORD *)(a1 + 8) )
resize_array_list(a1, 2 * result + 1);
if ( a2 < *(_DWORD *)(a1 + 12) )
{
v5 = a2;
do
{
v6 = v5++;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v5) = *(_QWORD *)(*(_QWORD *)a1 + 8 * v6);
}
while ( v5 < *(_DWORD *)(a1 + 12) );
}
result = *(_QWORD *)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
++*(_DWORD *)(a1 + 12);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
unsigned int v5; // eax
__int64 v6; // rcx

result = *(unsigned int *)(a1 + 12);
if ( (unsigned int)result >= a2 )
{
if ( (_DWORD)result == *(_DWORD *)(a1 + 8) )
func0(a1, 2 * result + 1);
if ( a2 < *(_DWORD *)(a1 + 12) )
{
v5 = a2;
do
{
v6 = v5++;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v5) = *(_QWORD *)(*(_QWORD *)a1 + 8 * v6);
}
while ( v5 < *(_DWORD *)(a1 + 12) );
}
result = *(_QWORD *)a1;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
++*(_DWORD *)(a1 + 12);
}
return result;
}

original_code:
extern void array_list_insert(
 friso_array_t array,
 uint_t idx,
 void * value )
{
    register uint_t t;
    if ( idx <= array->length )
    {
 if ( array->length == array->allocs ) {
     resize_array_list( array, array->length * 2 + 1 );
 }
 for ( t = idx; t < array->length; t++ ) {
     array->items[t+1] = array->items[t];
 }
 array->items[idx] = value;
 array->length++;
    }
}

canonical_original_code:
extern void array_list_insert(struct friso_array_entry *array, unsigned int idx, void *value)
{
    register unsigned int t;
    if ( idx <= array->length )
    {
 if ( array->length == array->allocs ) {
     resize_array_list( array, array->length * 2 + 1 );
 }
 for ( t = idx; t < array->length; t++ ) {
     array->items[t+1] = array->items[t];
 }
 array->items[idx] = value;
 array->length++;
    }
}


decompiled_code:
__int64 __fastcall array_list_get(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = 0LL;
if ( *(_DWORD *)(a1 + 12) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
__int64 result; // rax

result = 0LL;
if ( *(_DWORD *)(a1 + 12) > a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
extern void *array_list_get( friso_array_t array, uint_t idx )
{
    if ( idx < array->length ) {
 return array->items[idx];
    }
    return ((void *)0);
}

canonical_original_code:
extern void *array_list_get(struct friso_array_entry *array, unsigned int idx)
{
    if ( idx < array->length ) {
 return array->items[idx];
    }
    return ((void *)0);
}


decompiled_code:
__int64 __fastcall array_list_set(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
__int64 *v4; // rcx

result = 0LL;
if ( *(_DWORD *)(a1 + 12) > a2 )
{
v4 = (__int64 *)(*(_QWORD *)a1 + 8LL * a2);
result = *v4;
*v4 = a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
__int64 *v4; // rcx

result = 0LL;
if ( *(_DWORD *)(a1 + 12) > a2 )
{
v4 = (__int64 *)(*(_QWORD *)a1 + 8LL * a2);
result = *v4;
*v4 = a3;
}
return result;
}

original_code:
extern void * array_list_set(
 friso_array_t array,
 uint_t idx,
 void * value )
{
    void * oval = ((void *)0);
    if ( idx < array->length )
    {
 oval = array->items[idx];
 array->items[idx] = value;
    }
    return oval;
}

canonical_original_code:
extern void *array_list_set(struct friso_array_entry *array, unsigned int idx, void *value)
{
    void *oval = ((void *)0);
    if ( idx < array->length )
    {
 oval = array->items[idx];
 array->items[idx] = value;
    }
    return oval;
}

variable_types:
oval
void *


decompiled_code:
__int64 __fastcall array_list_remove(__int64 a1, unsigned int a2)
{
unsigned int v2; // eax
__int64 v3; // r8
unsigned int i; // eax
unsigned int v5; // eax

v2 = *(_DWORD *)(a1 + 12);
v3 = 0LL;
if ( v2 > a2 )
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
for ( i = v2 - 1; a2 < i; i = *(_DWORD *)(a1 + 12) - 1 )
{
v5 = a2++;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v5) = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
}
*(_QWORD *)(*(_QWORD *)a1 + 8LL * i) = 0LL;
--*(_DWORD *)(a1 + 12);
}
return v3;
}

original_code:
extern void * array_list_remove(
 friso_array_t array, uint_t idx )
{
    register uint_t t;
    void *oval = ((void *)0);
    if ( idx < array->length )
    {
 oval = array->items[idx];
 for ( t = idx; t < array->length - 1; t++ ) {
     array->items[t] = array->items[ t + 1 ];
 }
 array->items[array->length - 1] = ((void *)0);
 array->length--;
    }
    return oval;
}

canonical_original_code:
extern void *array_list_remove(struct friso_array_entry *array, unsigned int idx)
{
    register unsigned int t;
    void *oval = ((void *)0);
    if ( idx < array->length )
    {
 oval = array->items[idx];
 for ( t = idx; t < array->length - 1; t++ ) {
     array->items[t] = array->items[ t + 1 ];
 }
 array->items[array->length - 1] = ((void *)0);
 array->length--;
    }
    return oval;
}


decompiled_code:
__int64 __fastcall array_list_trim(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // esi

result = a1;
v2 = *(_DWORD *)(a1 + 12);
if ( v2 < *(_DWORD *)(a1 + 8) )
result = resize_array_list(a1, v2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
unsigned int v2; // esi

result = a1;
v2 = *(_DWORD *)(a1 + 12);
if ( v2 < *(_DWORD *)(a1 + 8) )
result = func0(a1, v2);
return result;
}

original_code:
extern friso_array_t array_list_trim( friso_array_t array )
{
    if ( array->length < array->allocs ) {
 return resize_array_list( array, array->length );
    }
    return array;
}

canonical_original_code:
extern struct friso_array_entry *array_list_trim(struct friso_array_entry *array)
{
    if ( array->length < array->allocs ) {
 return resize_array_list( array, array->length );
    }
    return array;
}


decompiled_code:
__int64 __fastcall array_list_clear(__int64 a1)
{
unsigned int v1; // eax

if ( *(_DWORD *)(a1 + 12) )
{
v1 = 0;
do
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v1++) = 0LL;
while ( *(_DWORD *)(a1 + 12) > v1 );
}
*(_DWORD *)(a1 + 12) = 0;
return a1;
}

original_code:
extern friso_array_t array_list_clear( friso_array_t array )
{
    register uint_t t;
    for ( t = 0; t < array->length; t++ ) {
 array->items[t] = ((void *)0);
    }
    array->length = 0;
    return array;
}

canonical_original_code:
extern struct friso_array_entry *array_list_clear(struct friso_array_entry *array)
{
    register unsigned int t;
    for ( t = 0; t < array->length; t++ ) {
 array->items[t] = ((void *)0);
    }
    array->length = 0;
    return array;
}


decompiled_code:
int __fastcall print_char_binary(char a1)
{
int v2; // ebp
int result; // eax

v2 = 8;
do
{
if ( a1 >= 0 )
result = putchar(48);
else
result = putchar(49);
a1 *= 2;
--v2;
}
while ( v2 );
return result;
}

canonical_decompiled_code:
int __fastcall func0(char a1)
{
int v2; // ebp
int result; // eax

v2 = 8;
do
{
if ( a1 >= 0 )
result = putchar(48);
else
result = putchar(49);
a1 *= 2;
--v2;
}
while ( v2 );
return result;
}

original_code:
extern void print_char_binary( char value )
{
    register uint_t t;
    for ( t = 0; t < 8; t++ )
    {
 if ( ( value & 0x80 ) == 0x80 ) {
     printf("1");
 } else {
     printf("0");
 }
 value <<= 1;
    }
}

canonical_original_code:
extern void print_char_binary(char value)
{
    register unsigned int t;
    for ( t = 0; t < 8; t++ )
    {
 if ( ( value & 0x80 ) == 0x80 ) {
     printf("1");
 } else {
     printf("0");
 }
 value <<= 1;
    }
}

variable_types: value char


decompiled_code:
__int64 __fastcall get_utf8_bytes(char a1)
{
char v1; // al
unsigned int v2; // ecx

v1 = a1;
v2 = 1;
if ( a1 < 0 )
{
v2 = 0;
do
{
++v2;
v1 *= 2;
}
while ( v1 < 0 );
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char a1)
{
char v1; // al
unsigned int v2; // ecx

v1 = a1;
v2 = 1;
if ( a1 < 0 )
{
v2 = 0;
do
{
++v2;
v1 *= 2;
}
while ( v1 < 0 );
}
return v2;
}

original_code:
extern int get_utf8_bytes( char value )
{
    register uint_t t = 0;
    if ( ( value & 0x80 ) == 0 ) return 1;
    for ( ; ( value & 0x80 ) != 0; value <<= 1 )
 t++;
    return t;
}

canonical_original_code:
extern int get_utf8_bytes(char value)
{
    register unsigned int t = 0;
    if ( ( value & 0x80 ) == 0 ) return 1;
    for ( ; ( value & 0x80 ) != 0; value <<= 1 )
 t++;
    return t;
}


decompiled_code:
__int64 __fastcall get_utf8_unicode(char *a1)
{
int v1; // eax
unsigned int v3; // [rsp+Ch] [rbp-Ch]

v3 = 0;
v1 = get_utf8_bytes(*a1);
switch ( v1 )
{
case 2:
LOBYTE(v3) = (*a1 << 6) + (a1[1] & 0x3F);
BYTE1(v3) = (*a1 >> 2) & 7;
break;
case 3:
LOBYTE(v3) = (a1[1] << 6) + (a1[2] & 0x3F);
BYTE1(v3) = 16 * *a1 + ((a1[1] >> 2) & 0xF);
break;
case 1:
LOBYTE(v3) = *a1;
break;
}
return v3;
}

original_code:
extern int get_utf8_unicode( const fstring ch )
{
    int code = 0, bytes = get_utf8_bytes( *ch );
    register uchar_t *bit = ( uchar_t * ) &code;
    register char b1,b2,b3;
    switch ( bytes ) {
 case 1:
     *bit = *ch;
     break;
 case 2:
     b1 = *ch;
     b2 = *(ch + 1);
     *bit = (b1 << 6) + (b2 & 0x3F);
     *(bit+1) = (b1 >> 2) & 0x07;
     break;
 case 3:
     b1 = *ch;
     b2 = *(ch + 1);
     b3 = *(ch + 2);
     *bit = (b2 << 6) + (b3 & 0x3F);
     *(bit+1) = (b1 << 4) + ((b2 >> 2) & 0x0F);
     break;
    }
    return code;
}

canonical_original_code:
extern int get_utf8_unicode(char *ch)
{
    int code = 0; int bytes = get_utf8_bytes( *ch );
    register unsigned char *bit = ( uchar_t * ) &code;
    register char b1; register char b2; register char b3;
    switch ( bytes ) {
 case 1:
     *bit = *ch;
     break;
 case 2:
     b1 = *ch;
     b2 = *(ch + 1);
     *bit = (b1 << 6) + (b2 & 0x3F);
     *(bit+1) = (b1 >> 2) & 0x07;
     break;
 case 3:
     b1 = *ch;
     b2 = *(ch + 1);
     b3 = *(ch + 2);
     *bit = (b2 << 6) + (b3 & 0x3F);
     *(bit+1) = (b1 << 4) + ((b2 >> 2) & 0x0F);
     break;
    }
    return code;
}

variable_types:
ch
char *

variable_types: code int

variable_types: bytes int

variable_types:
bit
unsigned char *


decompiled_code:
__int64 __fastcall utf8_next_word(__int64 a1, _DWORD *a2, void *a3)
{
unsigned int v4; // edx
unsigned int v6; // eax

v4 = 0;
if ( *a2 < *(_DWORD *)(a1 + 12) )
{
v6 = get_utf8_bytes(*(_BYTE *)(*(_QWORD *)a1 + (unsigned int)*a2));
*(_DWORD *)(a1 + 16) = v6;
memcpy(a3, (const void *)(*(_QWORD *)a1 + (unsigned int)*a2), v6);
*a2 += *(_DWORD *)(a1 + 16);
*((_BYTE *)a3 + *(unsigned int *)(a1 + 16)) = 0;
*(_DWORD *)(a1 + 20) = get_utf8_unicode((char *)a3);
v4 = *(_DWORD *)(a1 + 16);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2, void *a3)
{
unsigned int v4; // edx
unsigned int v6; // eax

v4 = 0;
if ( *a2 < *(_DWORD *)(a1 + 12) )
{
v6 = func1(*(_BYTE *)(*(_QWORD *)a1 + (unsigned int)*a2));
*(_DWORD *)(a1 + 16) = v6;
memcpy(a3, (const void *)(*(_QWORD *)a1 + (unsigned int)*a2), v6);
*a2 += *(_DWORD *)(a1 + 16);
*((_BYTE *)a3 + *(unsigned int *)(a1 + 16)) = 0;
*(_DWORD *)(a1 + 20) = func2((char *)a3);
v4 = *(_DWORD *)(a1 + 16);
}
return v4;
}

original_code:
extern int utf8_next_word(
 friso_task_t task,
 uint_t *idx,
 fstring __word )
{
    if ( *idx >= task->length ) return 0;
    task->bytes = get_utf8_bytes( task->text[ *idx ] );
    memcpy(__word, task->text + (*idx), task->bytes);
    (*idx) += task->bytes;
    __word[task->bytes] = '\0';
    task->unicode = get_utf8_unicode( __word );
    return task->bytes;
}

canonical_original_code:
extern int utf8_next_word(struct friso_task_entry *task, unsigned int *idx, char *__word)
{
    if ( *idx >= task->length ) return 0;
    task->bytes = get_utf8_bytes( task->text[ *idx ] );
    memcpy(__word, task->text + (*idx), task->bytes);
    (*idx) += task->bytes;
    __word[task->bytes] = '\0';
    task->unicode = get_utf8_unicode( __word );
    return task->bytes;
}

variable_types: struct friso_task_entry { char *text; unsigned int idx; unsigned int length; unsigned int bytes; unsigned int unicode; struct friso_link_entry { struct friso_link_node { void *value; struct friso_link_node *prev; struct friso_link_node *next; } *head; struct friso_link_node *tail; unsigned int size; } *pool; struct friso_hits_entry { int offset; char word[128]; } *hits; char buffer[7]; } *

variable_types:
idx
unsigned int *

user_defined_types: struct friso_task_entry { char *text; unsigned int idx; unsigned int length; unsigned int bytes; unsigned int unicode; struct friso_link_entry *pool; struct friso_hits_entry *hits; char buffer[7]; }


decompiled_code:
_BOOL8 __fastcall utf8_cjk_string(int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned int)(a1 - 11904) > 0x15F
&& (unsigned int)(a1 - 12736) > 0x2F
&& (unsigned int)(a1 - 13056) > 0xFF
&& (unsigned int)(a1 - 19904) > 0x51FF
&& (unsigned int)(a1 - 63744) > 0x1FF )
{
result = (unsigned int)(a1 - 65072) <= 0x1F;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(int a1)
{
_BOOL8 result; // rax

result = 1LL;
if ( (unsigned int)(a1 - 11904) > 0x15F
&& (unsigned int)(a1 - 12736) > 0x2F
&& (unsigned int)(a1 - 13056) > 0xFF
&& (unsigned int)(a1 - 19904) > 0x51FF
&& (unsigned int)(a1 - 63744) > 0x1FF )
{
result = (unsigned int)(a1 - 65072) <= 0x1F;
}
return result;
}

variable_types:
u
unsigned int

variable_types: c int

variable_types: j int

variable_types: k int


decompiled_code:
_BOOL8 __fastcall utf8_halfwidth_en_char(int a1)
{
return (unsigned int)(a1 - 32) <= 0x5E;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(int a1)
{
return (unsigned int)(a1 - 32) <= 0x5E;
}

original_code:
extern int utf8_halfwidth_en_char( uint_t u )
{
    return ( u >= 32 && u <= 126 );
}

canonical_original_code:
extern int utf8_halfwidth_en_char(unsigned int u)
{
    return ( u >= 32 && u <= 126 );
}


decompiled_code:
__int64 __fastcall utf8_fullwidth_en_char(int a1)
{
return ((unsigned int)(a1 - 65296) <= 9) | (unsigned __int8)(((a1 - 65313) & 0xFFFFFFDF) <= 0x19);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
return ((unsigned int)(a1 - 65296) <= 9) | (unsigned __int8)(((a1 - 65313) & 0xFFFFFFDF) <= 0x19);
}