main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

if ( argc <= 1 )
print_error(USAGE);
init_option();
init_parser((unsigned int)argc, argv);
init_filter_tree((unsigned int)argc);
free_parser();
if ( SLODWORD(options[0]) > 0 )
{
v3 = 0;
do
{
find(*(char **)options[1]);
++v3;
}
while ( SLODWORD(options[0]) > v3 );
}
free_filter_tree();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebx

if ( argc <= 1 )
func4(USAGE);
func0();
init_parser((unsigned int)argc, argv);
init_filter_tree((unsigned int)argc);
free_parser();
if ( SLODWORD(options[0]) > 0 )
{
v3 = 0;
do
{
find(*(char **)options[1]);
++v3;
}
while ( SLODWORD(options[0]) > v3 );
}
free_filter_tree();
return 0;
}

original_code:
int main(int argc, char * argv[]) {
  if (argc < 2) {
    print_error(USAGE);
  }
  init_option();
  init_parser(argc, argv);
  init_filter_tree(argc);
  free_parser();
  int i;
  for (i = 0; i < options.pathes_num; i++) {
    find(options.find_pathes[0]);
  }
  free_filter_tree();
  free_option();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  if (argc < 2) {
    print_error(USAGE);
  }
  init_option();
  init_parser(argc, argv);
  init_filter_tree(argc);
  free_parser();
  int i;
  for (i = 0; i < options.pathes_num; i++) {
    find(options.find_pathes[0]);
  }
  free_filter_tree();
  free_option();
  return 0;
}

variable_types: i int


repo: sheimi/tiny-find

decompiled_code:
__int64 get_exp()
{
int v0; // eax

v0 = i_0;
if ( post_exp_index - 1 == i_0 )
return 0LL;
++i_0;
return *((_QWORD *)post_exp + v0 + 1);
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // eax

v0 = i_0;
if ( post_exp_index - 1 == i_0 )
return 0LL;
++i_0;
return *((_QWORD *)post_exp + v0 + 1);
}

original_code:
char * get_exp() {
  static int i = -1;
  if (i == post_exp_index - 1) {
    return ((void *)0);
  }
  i++;
  return post_exp[i];
}

canonical_original_code:
char *get_exp() {
  static int i = -1;
  if (i == post_exp_index - 1) {
    return ((void *)0);
  }
  i++;
  return post_exp[i];
}

return_type: char *


decompiled_code:
__int64 __fastcall is_exp(char *s1)
{
int v1; // ebp
__int64 v2; // rbx

v1 = ALL_EXP_LEN;
if ( ALL_EXP_LEN <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, (&ALL_EXP)[v2]) )
{
if ( ++v2 == v1 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s1)
{
int v1; // ebp
__int64 v2; // rbx

v1 = ALL_EXP_LEN;
if ( ALL_EXP_LEN <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, (&ALL_EXP)[v2]) )
{
if ( ++v2 == v1 )
return 0LL;
}
return 1LL;
}

original_code:
bool is_exp(char * arg) {
  int i;
  for (i = 0; i < ALL_EXP_LEN; i++) {
    if ((strcmp(arg, ALL_EXP[i]) == 0))
      return 1;
  }
  return 0;
}

canonical_original_code:
int is_exp(char *arg) {
  int i;
  for (i = 0; i < ALL_EXP_LEN; i++) {
    if ((strcmp(arg, ALL_EXP[i]) == 0))
      return 1;
  }
  return 0;
}

variable_types:
arg
char *

return_type: int


decompiled_code:
__int64 __fastcall is_options(char *s1)
{
int v1; // er12
__int64 v2; // rbx

v1 = OPTIONS_LEN;
if ( OPTIONS_LEN <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, OPTIONS[v2]) )
{
if ( v1 <= (int)++v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *s1)
{
int v1; // er12
__int64 v2; // rbx

v1 = OPTIONS_LEN;
if ( OPTIONS_LEN <= 0 )
return 0LL;
v2 = 0LL;
while ( strcmp(s1, OPTIONS[v2]) )
{
if ( v1 <= (int)++v2 )
return 0LL;
}
return 1LL;
}

original_code:
bool is_options(char * arg) {
  int i;
  for (i = 0; i < OPTIONS_LEN; i++) {
    if ((strcmp(arg, OPTIONS[i]) == 0))
      return 1;
  }
  return 0;
}

canonical_original_code:
int is_options(char *arg) {
  int i;
  for (i = 0; i < OPTIONS_LEN; i++) {
    if ((strcmp(arg, OPTIONS[i]) == 0))
      return 1;
  }
  return 0;
}


decompiled_code:
_BOOL8 __fastcall is_logic_op(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-and") )
{
v1 = 1;
if ( strcmp(a1, "-or") )
{
v1 = 1;
if ( strcmp(a1, "-not") )
{
v1 = 1;
if ( strcmp(a1, "(") )
v1 = strcmp(a1, ")") == 0;
}
}
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-and") )
{
v1 = 1;
if ( strcmp(a1, "-or") )
{
v1 = 1;
if ( strcmp(a1, "-not") )
{
v1 = 1;
if ( strcmp(a1, "(") )
v1 = strcmp(a1, ")") == 0;
}
}
}
return v1;
}

original_code:
bool is_logic_op(char * exp) {
  return (strcmp(exp, "-and") == 0) || (strcmp(exp, "-or") == 0) || (strcmp(exp, "-not") == 0)
         || (strcmp(exp, "(") == 0) || (strcmp(exp, ")") == 0);
}

canonical_original_code:
int is_logic_op(char *exp) {
  return (strcmp(exp, "-and") == 0) || (strcmp(exp, "-or") == 0) || (strcmp(exp, "-not") == 0)
         || (strcmp(exp, "(") == 0) || (strcmp(exp, ")") == 0);
}

variable_types:
exp
char *


decompiled_code:
__int64 __fastcall push_back_exp(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = post_exp_index;
*((_QWORD *)post_exp + post_exp_index) = a1;
result = (unsigned int)(v1 + 1);
post_exp_index = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = post_exp_index;
*((_QWORD *)post_exp + post_exp_index) = a1;
result = (unsigned int)(v1 + 1);
post_exp_index = result;
return result;
}

original_code:
void push_back_exp(char * exp) {
  post_exp[post_exp_index] = exp;
  post_exp_index++;
}

canonical_original_code:
void push_back_exp(char *exp) {
  post_exp[post_exp_index] = exp;
  post_exp_index++;
}

return_type: void


decompiled_code:
__int64 __fastcall push_stack(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = stack_index;
*((_QWORD *)help_stack + stack_index) = a1;
result = (unsigned int)(v1 + 1);
stack_index = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // eax
__int64 result; // rax

v1 = stack_index;
*((_QWORD *)help_stack + stack_index) = a1;
result = (unsigned int)(v1 + 1);
stack_index = result;
return result;
}

original_code:
void push_stack(char * exp) {
  help_stack[stack_index] = exp;
  stack_index++;
}

canonical_original_code:
void push_stack(char *exp) {
  help_stack[stack_index] = exp;
  stack_index++;
}


decompiled_code:
__int64 pop_stack()
{
return *((_QWORD *)help_stack + --stack_index);
}

canonical_decompiled_code:
__int64 func6()
{
return *((_QWORD *)help_stack + --stack_index);
}

original_code:
char * pop_stack() {
  stack_index--;
  return help_stack[stack_index];
}

canonical_original_code:
char *pop_stack() {
  stack_index--;
  return help_stack[stack_index];
}


decompiled_code:
void *top_stack()
{
void *v0; // rdx

v0 = &unk_9BA;
if ( stack_index )
v0 = (void *)*((_QWORD *)help_stack + stack_index - 1);
return v0;
}

canonical_decompiled_code:
void *func7()
{
void *v0; // rdx

v0 = &unk_9BA;
if ( stack_index )
v0 = (void *)*((_QWORD *)help_stack + stack_index - 1);
return v0;
}

original_code:
char * top_stack() {
  if (stack_index == 0) {
    return "";
  }
  return help_stack[stack_index - 1];
}

canonical_original_code:
char *top_stack() {
  if (stack_index == 0) {
    return "";
  }
  return help_stack[stack_index - 1];
}


decompiled_code:
_BOOL8 stack_empty()
{
return stack_index == 0;
}

canonical_decompiled_code:
_BOOL8 func8()
{
return stack_index == 0;
}

original_code:
bool stack_empty() {
  return stack_index == 0;
}

canonical_original_code:
int stack_empty() {
  return stack_index == 0;
}


decompiled_code:
_BOOL8 __fastcall set_post_exp(const char *a1, const char *a2, __int64 a3, __int64 a4, const char **a5)
{
const char *v5; // r12
int v6; // ebp
int v7; // ebx
bool v8; // cf
bool v9; // zf
bool v10; // cf
bool v11; // zf
bool v12; // cf
bool v13; // zf
bool v14; // cf
bool v15; // zf
__int64 v16; // rax
int v17; // ebx
_BOOL8 result; // rax
bool v19; // cf
bool v20; // zf
int v21; // er14
const char *v22; // rdi
__int64 v23; // rcx
bool v24; // cf
bool v25; // zf
char v26; // al
bool v27; // cf
bool v28; // zf
__int64 v29; // rdx
__int64 v30; // r13
const char *v31; // rdi
__int64 v32; // rcx
char v33; // al
const char **v34; // r13
const char *v35; // rdi
__int64 v36; // rcx
char v37; // al
bool v38; // cf
bool v39; // zf
__int64 v40; // rcx
char v41; // al
bool v42; // cf
bool v43; // zf
__int64 v44; // rcx
char v45; // al
bool v46; // cf
bool v47; // zf
__int64 v48; // rcx
char v49; // al
bool v50; // cf
bool v51; // zf
int v52; // ecx
__int64 v53; // rax
_BYTE *v54; // rdx
int v55; // ecx
__int64 v56; // rax
_BYTE *v57; // rdx
__int64 v58; // rcx
char v59; // al
bool v60; // cf
bool v61; // zf
const char *v62; // rdi
__int64 v63; // rcx
char v64; // al
bool v65; // cf
bool v66; // zf
const char *v67; // rdi
__int64 v68; // rcx
const char *v69; // rsi
char v70; // al
bool v71; // cf
bool v72; // zf
const char *v73; // rdi
__int64 v74; // rcx
int v75; // er15
bool v76; // cf
bool v77; // zf
bool v78; // cf
bool v79; // zf
const char *v80; // rax
const char *v81; // rdi
__int64 v82; // rcx
bool v83; // cf
bool v84; // zf
__int64 v85; // rcx
bool v86; // cf
bool v87; // zf
const char *v88; // rax
__int64 v89; // rcx
char v90; // al
bool v91; // cf
bool v92; // zf
const char *v93; // rdi
__int64 v94; // rcx
char v95; // dl
bool v96; // cf
bool v97; // zf
__int64 v98; // rcx
const char *v99; // rdi
__int64 v100; // rcx
bool v101; // cf
bool v102; // zf
const char *v103; // rdi
__int64 v104; // rcx
int v105; // er15
__int64 v106; // rax
bool v107; // cf
bool v108; // zf
const char *v109; // rdi
__int64 v110; // rcx
bool v111; // cf
bool v112; // zf
const char *v113; // rax
__int64 v114; // rcx
int v115; // [rsp+Ch] [rbp-3Ch]

v5 = a2;
if ( (int)a1 <= 1 )
{
v7 = 1;
LABEL_142:
a1 = (const char *)USAGE;
print_error(USAGE, a2, a3, a4, a5);
*((_QWORD *)&options + 1) = &v5[8 * v7];
goto LABEL_28;
}
v6 = (int)a1;
a5 = (const char **)(a2 + 8);
v7 = 1;
while ( **a5 == 45 )
{
v12 = __CFADD__(v7, 1);
v13 = v7++ == -1;
a1 = "-L";
a4 = 3LL;
a2 = *a5;
do
{
if ( !a4 )
break;
v12 = *a2 < (unsigned int)*a1;
v13 = *a2++ == *a1++;
--a4;
}
while ( v13 );
LOBYTE(a3) = (!v12 && !v13) - v12;
v8 = 0;
v9 = (_BYTE)a3 == 0;
if ( (_BYTE)a3 )
{
a1 = "-P";
a4 = 3LL;
a2 = *a5;
do
{
if ( !a4 )
break;
v8 = *a2 < (unsigned int)*a1;
v9 = *a2++ == *a1++;
--a4;
}
while ( v9 );
LOBYTE(a3) = (!v8 && !v9) - v8;
v10 = 0;
v11 = (_BYTE)a3 == 0;
if ( (_BYTE)a3 )
{
a1 = "-H";
a4 = 3LL;
a2 = *a5;
do
{
if ( !a4 )
break;
v10 = *a2 < (unsigned int)*a1;
v11 = *a2++ == *a1++;
--a4;
}
while ( v11 );
LOBYTE(a3) = (!v10 && !v11) - v10;
v14 = 0;
v15 = (_BYTE)a3 == 0;
if ( (_BYTE)a3 )
{
a1 = "-f";
a4 = 3LL;
a2 = *a5;
do
{
if ( !a4 )
break;
v14 = *a2 < (unsigned int)*a1;
v15 = *a2++ == *a1++;
--a4;
}
while ( v15 );
if ( (!v14 && !v15) == v14 )
break;
}
else
{
*((_DWORD *)&options + 18) = 2;
}
}
else
{
*((_DWORD *)&options + 18) = 1;
}
}
else
{
*((_DWORD *)&options + 18) = 0;
}
++a5;
if ( v6 == v7 )
goto LABEL_142;
}
if ( v7 >= v6 )
goto LABEL_142;
v16 = v7;
*((_QWORD *)&options + 1) = &v5[8 * v7];
while ( 1 )
{
v17 = v16;
if ( **(_BYTE **)&v5[8 * v16] == 45 )
break;
++options;
if ( v6 <= (int)++v16 )
goto LABEL_28;
}
v19 = v6 < (unsigned int)v16;
v20 = v6 == (_DWORD)v16;
if ( v6 > (int)v16 )
{
v115 = 0;
v21 = 0;
do
{
v29 = 8LL * v17;
v30 = *(_QWORD *)&v5[v29];
v31 = "-depth";
v32 = 7LL;
a2 = (const char *)v30;
do
{
if ( !v32 )
break;
v19 = *a2 < (unsigned int)*v31;
v20 = *a2++ == *v31++;
--v32;
}
while ( v20 );
v33 = (!v19 && !v20) - v19;
v24 = 0;
v25 = v33 == 0;
if ( v33 )
{
v22 = "-maxdepth";
v23 = 10LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v23 )
break;
v24 = *a2 < (unsigned int)*v22;
v25 = *a2++ == *v22++;
--v23;
}
while ( v25 );
v26 = (!v24 && !v25) - v24;
v27 = 0;
v28 = v26 == 0;
if ( v26 )
{
v35 = "-mindepth";
v36 = 10LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v36 )
break;
v27 = *a2 < (unsigned int)*v35;
v28 = *a2++ == *v35++;
--v36;
}
while ( v28 );
v37 = (!v27 && !v28) - v27;
v38 = 0;
v39 = v37 == 0;
if ( v37 )
{
a1 = "-exec";
v40 = 6LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v40 )
break;
v38 = *a2 < (unsigned int)*a1;
v39 = *a2++ == *a1++;
--v40;
}
while ( v39 );
v41 = (!v38 && !v39) - v38;
v42 = 0;
v43 = v41 == 0;
if ( !v41 )
{
v52 = v17 + 1;
*((_DWORD *)&options + 6) = 1;
*((_DWORD *)&options + 17) = 0;
*((_QWORD *)&options + 4) = &v5[v29 + 8];
if ( **(_BYTE **)&v5[v29 + 16] != 59 )
{
v53 = v17 + 2;
do
{
v52 = v53;
v54 = *(_BYTE **)&v5[8 * v53++ + 8];
}
while ( *v54 != 59 );
}
*((_DWORD *)&options + 10) = v52 - v17 + 1;
v17 = v52 + 1;
goto LABEL_37;
}
a1 = "-ok";
v44 = 4LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v44 )
break;
v42 = *a2 < (unsigned int)*a1;
v43 = *a2++ == *a1++;
--v44;
}
while ( v43 );
v45 = (!v42 && !v43) - v42;
v46 = 0;
v47 = v45 == 0;
if ( !v45 )
{
v55 = v17 + 1;
*((_DWORD *)&options + 11) = 1;
*((_DWORD *)&options + 17) = 0;
*((_QWORD *)&options + 6) = &v5[v29 + 8];
if ( **(_BYTE **)&v5[v29 + 16] != 59 )
{
v56 = v17 + 2;
do
{
v55 = v56;
v57 = *(_BYTE **)&v5[8 * v56++ + 8];
}
while ( *v57 != 59 );
}
*((_DWORD *)&options + 14) = v55 - v17 + 1;
v17 = v55 + 1;
goto LABEL_37;
}
a1 = "-print";
v48 = 7LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v48 )
break;
v46 = *a2 < (unsigned int)*a1;
v47 = *a2++ == *a1++;
--v48;
}
while ( v47 );
v49 = (!v46 && !v47) - v46;
v50 = 0;
v51 = v49 == 0;
if ( v49 )
{
a1 = "-print0";
v58 = 8LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v58 )
break;
v50 = *a2 < (unsigned int)*a1;
v51 = *a2++ == *a1++;
--v58;
}
while ( v51 );
v59 = (!v50 && !v51) - v50;
v60 = 0;
v61 = v59 == 0;
if ( v59 )
{
v62 = "(";
v63 = 2LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v63 )
break;
v60 = *a2 < (unsigned int)*v62;
v61 = *a2++ == *v62++;
--v63;
}
while ( v61 );
v64 = (!v60 && !v61) - v60;
v65 = 0;
v66 = v64 == 0;
if ( !v64 )
goto LABEL_92;
v67 = ")";
v68 = 2LL;
v69 = *(const char **)&v5[8 * v17];
do
{
if ( !v68 )
break;
v65 = *v69 < (unsigned int)*v67;
v66 = *v69++ == *v67++;
--v68;
}
while ( v66 );
v70 = (!v65 && !v66) - v65;
v71 = 0;
v72 = v70 == 0;
if ( !v70 )
{
while ( !stack_empty() )
{
v69 = (const char *)top_stack();
v67 = "(";
v85 = 2LL;
do
{
if ( !v85 )
break;
v83 = *v69 < (unsigned int)*v67;
v84 = *v69++ == *v67++;
--v85;
}
while ( v84 );
if ( (!v83 && !v84) == v83 )
break;
v67 = (const char *)((__int64 (*)(void))pop_stack)();
push_back_exp((__int64)v67);
}
pop_stack(v67, v69);
v88 = (const char *)top_stack();
a1 = "-not";
v89 = 5LL;
a2 = v88;
do
{
if ( !v89 )
break;
v86 = *a2 < (unsigned int)*a1;
v87 = *a2++ == *a1++;
--v89;
}
while ( v87 );
v90 = (!v86 && !v87) - v86;
v91 = 0;
v92 = v90 == 0;
if ( !v90 )
{
v93 = "-and";
v94 = 5LL;
a2 = (const char *)*((_QWORD *)post_exp + post_exp_index - 1);
do
{
if ( !v94 )
break;
v91 = *a2 < (unsigned int)*v93;
v92 = *a2++ == *v93++;
--v94;
}
while ( v92 );
v95 = (!v91 && !v92) - v91;
v96 = 0;
v97 = v95 == 0;
if ( v95 )
{
v93 = "-or";
v98 = 4LL;
a2 = (const char *)*((_QWORD *)post_exp + post_exp_index - 1);
do
{
if ( !v98 )
break;
v96 = *a2 < (unsigned int)*v93;
v97 = *a2++ == *v93++;
--v98;
}
while ( v97 );
if ( (!v96 && !v97) != v96 )
{
v93 = "-and";
push_back_exp((__int64)"-and");
}
}
a1 = (const char *)pop_stack(v93, a2);
push_back_exp((__int64)a1);
}
goto LABEL_37;
}
v73 = "-and";
v74 = 5LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v74 )
break;
v71 = *a2 < (unsigned int)*v73;
v72 = *a2++ == *v73++;
--v74;
}
while ( v72 );
v75 = (char)((!v71 && !v72) - v71);
v76 = 0;
v77 = v75 == 0;
if ( v75 )
{
v99 = "-or";
v100 = 4LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v100 )
break;
v76 = *a2 < (unsigned int)*v99;
v77 = *a2++ == *v99++;
--v100;
}
while ( v77 );
v75 = (char)((!v76 && !v77) - v76);
v101 = 0;
v102 = v75 == 0;
if ( v75 )
{
v103 = "-not";
v104 = 5LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v104 )
break;
v101 = *a2 < (unsigned int)*v103;
v102 = *a2++ == *v103++;
--v104;
}
while ( v102 );
if ( (!v101 && !v102) != v101 )
{
v105 = is_exp(*(char **)&v5[8 * v17]);
if ( v105 )
{
a1 = (const char *)v30;
push_back_exp(v30);
if ( v21 )
v115 = v21;
else
v21 = 1;
}
else
{
push_back_exp(v30);
v113 = (const char *)top_stack();
a1 = "-not";
v114 = 5LL;
a2 = v113;
do
{
if ( !v114 )
break;
v111 = *a2 < (unsigned int)*a1;
v112 = *a2++ == *a1++;
--v114;
}
while ( v112 );
if ( (!v111 && !v112) == v111 )
{
a1 = (const char *)pop_stack(a1, a2);
push_back_exp((__int64)a1);
}
if ( v115 )
{
a1 = "-and";
push_back_exp((__int64)"-and");
v115 = v105;
}
}
goto LABEL_37;
}
LABEL_92:
a1 = *(const char **)&v5[8 * v17];
push_stack((__int64)a1);
goto LABEL_37;
}
while ( !stack_empty() )
{
a2 = (const char *)top_stack();
v109 = "(";
v110 = 2LL;
do
{
if ( !v110 )
break;
v107 = *a2 < (unsigned int)*v109;
v108 = *a2++ == *v109++;
--v110;
}
while ( v108 );
if ( (!v107 && !v108) == v107 )
break;
v106 = pop_stack(v109, a2);
push_back_exp(v106);
}
}
else if ( !stack_empty() )
{
v80 = (const char *)top_stack();
v81 = "-and";
v82 = 5LL;
a2 = v80;
do
{
if ( !v82 )
break;
v78 = *a2 < (unsigned int)*v81;
v79 = *a2++ == *v81++;
--v82;
}
while ( v79 );
v21 = (char)((!v78 && !v79) - v78);
if ( (!v78 && !v79) == v78 )
{
a1 = (const char *)v30;
push_back_exp(v30);
goto LABEL_37;
}
}
a1 = (const char *)v30;
push_stack(v30);
v21 = v75;
}
else
{
*((_DWORD *)&options + 17) = 0;
*((_DWORD *)&options + 16) = 1;
}
}
else
{
*((_DWORD *)&options + 17) = 0;
*((_DWORD *)&options + 15) = 1;
}
}
else
{
++v17;
a1 = *(const char **)&v5[v29 + 8];
*((_DWORD *)&options + 4) = atoi(a1);
}
}
else
{
++v17;
a1 = *(const char **)&v5[v29 + 8];
*((_DWORD *)&options + 5) = atoi(a1);
}
}
else
{
++v17;
v34 = (const char **)&v5[v29 + 8];
*((_DWORD *)&options + 5) = atoi(*v34);
a1 = *v34;
*((_DWORD *)&options + 4) = atoi(*v34);
}
LABEL_37:
v19 = v6 < (unsigned int)++v17;
v20 = v6 == v17;
}
while ( v6 > v17 );
}
LABEL_28:
while ( 1 )
{
result = stack_empty();
if ( result )
break;
a1 = (const char *)pop_stack(a1, a2);
push_back_exp((__int64)a1);
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(const char *a1, const char *a2, __int64 a3, __int64 a4, const char **a5)
{
const char *v5; // r12
int v6; // ebp
int v7; // ebx
bool v8; // cf
bool v9; // zf
bool v10; // cf
bool v11; // zf
bool v12; // cf
bool v13; // zf
bool v14; // cf
bool v15; // zf
__int64 v16; // rax
int v17; // ebx
_BOOL8 result; // rax
bool v19; // cf
bool v20; // zf
int v21; // er14
const char *v22; // rdi
__int64 v23; // rcx
bool v24; // cf
bool v25; // zf
char v26; // al
bool v27; // cf
bool v28; // zf
__int64 v29; // rdx
__int64 v30; // r13
const char *v31; // rdi
__int64 v32; // rcx
char v33; // al
const char **v34; // r13
const char *v35; // rdi
__int64 v36; // rcx
char v37; // al
bool v38; // cf
bool v39; // zf
__int64 v40; // rcx
char v41; // al
bool v42; // cf
bool v43; // zf
__int64 v44; // rcx
char v45; // al
bool v46; // cf
bool v47; // zf
__int64 v48; // rcx
char v49; // al
bool v50; // cf
bool v51; // zf
int v52; // ecx
__int64 v53; // rax
_BYTE *v54; // rdx
int v55; // ecx
__int64 v56; // rax
_BYTE *v57; // rdx
__int64 v58; // rcx
char v59; // al
bool v60; // cf
bool v61; // zf
const char *v62; // rdi
__int64 v63; // rcx
char v64; // al
bool v65; // cf
bool v66; // zf
const char *v67; // rdi
__int64 v68; // rcx
const char *v69; // rsi
char v70; // al
bool v71; // cf
bool v72; // zf
const char *v73; // rdi
__int64 v74; // rcx
int v75; // er15
bool v76; // cf
bool v77; // zf
bool v78; // cf
bool v79; // zf
const char *v80; // rax
const char *v81; // rdi
__int64 v82; // rcx
bool v83; // cf
bool v84; // zf
__int64 v85; // rcx
bool v86; // cf
bool v87; // zf
const char *v88; // rax
__int64 v89; // rcx
char v90; // al
bool v91; // cf
bool v92; // zf
const char *v93; // rdi
__int64 v94; // rcx
char v95; // dl
bool v96; // cf
bool v97; // zf
__int64 v98; // rcx
const char *v99; // rdi
__int64 v100; // rcx
bool v101; // cf
bool v102; // zf
const char *v103; // rdi
__int64 v104; // rcx
int v105; // er15
__int64 v106; // rax
bool v107; // cf
bool v108; // zf
const char *v109; // rdi
__int64 v110; // rcx
bool v111; // cf
bool v112; // zf
const char *v113; // rax
__int64 v114; // rcx
int v115; // [rsp+Ch] [rbp-3Ch]

v5 = a2;
if ( (int)a1 <= 1 )
{
v7 = 1;
LABEL_142:
a1 = (const char *)USAGE;
print_error(USAGE, a2, a3, a4, a5);
*((_QWORD *)&options + 1) = &v5[8 * v7];
goto LABEL_28;
}
v6 = (int)a1;
a5 = (const char **)(a2 + 8);
v7 = 1;
while ( **a5 == 45 )
{
v12 = __CFADD__(v7, 1);
v13 = v7++ == -1;
a1 = "-L";
a4 = 3LL;
a2 = *a5;
do
{
if ( !a4 )
break;
v12 = *a2 < (unsigned int)*a1;
v13 = *a2++ == *a1++;
--a4;
}
while ( v13 );
LOBYTE(a3) = (!v12 && !v13) - v12;
v8 = 0;
v9 = (_BYTE)a3 == 0;
if ( (_BYTE)a3 )
{
a1 = "-P";
a4 = 3LL;
a2 = *a5;
do
{
if ( !a4 )
break;
v8 = *a2 < (unsigned int)*a1;
v9 = *a2++ == *a1++;
--a4;
}
while ( v9 );
LOBYTE(a3) = (!v8 && !v9) - v8;
v10 = 0;
v11 = (_BYTE)a3 == 0;
if ( (_BYTE)a3 )
{
a1 = "-H";
a4 = 3LL;
a2 = *a5;
do
{
if ( !a4 )
break;
v10 = *a2 < (unsigned int)*a1;
v11 = *a2++ == *a1++;
--a4;
}
while ( v11 );
LOBYTE(a3) = (!v10 && !v11) - v10;
v14 = 0;
v15 = (_BYTE)a3 == 0;
if ( (_BYTE)a3 )
{
a1 = "-f";
a4 = 3LL;
a2 = *a5;
do
{
if ( !a4 )
break;
v14 = *a2 < (unsigned int)*a1;
v15 = *a2++ == *a1++;
--a4;
}
while ( v15 );
if ( (!v14 && !v15) == v14 )
break;
}
else
{
*((_DWORD *)&options + 18) = 2;
}
}
else
{
*((_DWORD *)&options + 18) = 1;
}
}
else
{
*((_DWORD *)&options + 18) = 0;
}
++a5;
if ( v6 == v7 )
goto LABEL_142;
}
if ( v7 >= v6 )
goto LABEL_142;
v16 = v7;
*((_QWORD *)&options + 1) = &v5[8 * v7];
while ( 1 )
{
v17 = v16;
if ( **(_BYTE **)&v5[8 * v16] == 45 )
break;
++options;
if ( v6 <= (int)++v16 )
goto LABEL_28;
}
v19 = v6 < (unsigned int)v16;
v20 = v6 == (_DWORD)v16;
if ( v6 > (int)v16 )
{
v115 = 0;
v21 = 0;
do
{
v29 = 8LL * v17;
v30 = *(_QWORD *)&v5[v29];
v31 = "-depth";
v32 = 7LL;
a2 = (const char *)v30;
do
{
if ( !v32 )
break;
v19 = *a2 < (unsigned int)*v31;
v20 = *a2++ == *v31++;
--v32;
}
while ( v20 );
v33 = (!v19 && !v20) - v19;
v24 = 0;
v25 = v33 == 0;
if ( v33 )
{
v22 = "-maxdepth";
v23 = 10LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v23 )
break;
v24 = *a2 < (unsigned int)*v22;
v25 = *a2++ == *v22++;
--v23;
}
while ( v25 );
v26 = (!v24 && !v25) - v24;
v27 = 0;
v28 = v26 == 0;
if ( v26 )
{
v35 = "-mindepth";
v36 = 10LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v36 )
break;
v27 = *a2 < (unsigned int)*v35;
v28 = *a2++ == *v35++;
--v36;
}
while ( v28 );
v37 = (!v27 && !v28) - v27;
v38 = 0;
v39 = v37 == 0;
if ( v37 )
{
a1 = "-exec";
v40 = 6LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v40 )
break;
v38 = *a2 < (unsigned int)*a1;
v39 = *a2++ == *a1++;
--v40;
}
while ( v39 );
v41 = (!v38 && !v39) - v38;
v42 = 0;
v43 = v41 == 0;
if ( !v41 )
{
v52 = v17 + 1;
*((_DWORD *)&options + 6) = 1;
*((_DWORD *)&options + 17) = 0;
*((_QWORD *)&options + 4) = &v5[v29 + 8];
if ( **(_BYTE **)&v5[v29 + 16] != 59 )
{
v53 = v17 + 2;
do
{
v52 = v53;
v54 = *(_BYTE **)&v5[8 * v53++ + 8];
}
while ( *v54 != 59 );
}
*((_DWORD *)&options + 10) = v52 - v17 + 1;
v17 = v52 + 1;
goto LABEL_37;
}
a1 = "-ok";
v44 = 4LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v44 )
break;
v42 = *a2 < (unsigned int)*a1;
v43 = *a2++ == *a1++;
--v44;
}
while ( v43 );
v45 = (!v42 && !v43) - v42;
v46 = 0;
v47 = v45 == 0;
if ( !v45 )
{
v55 = v17 + 1;
*((_DWORD *)&options + 11) = 1;
*((_DWORD *)&options + 17) = 0;
*((_QWORD *)&options + 6) = &v5[v29 + 8];
if ( **(_BYTE **)&v5[v29 + 16] != 59 )
{
v56 = v17 + 2;
do
{
v55 = v56;
v57 = *(_BYTE **)&v5[8 * v56++ + 8];
}
while ( *v57 != 59 );
}
*((_DWORD *)&options + 14) = v55 - v17 + 1;
v17 = v55 + 1;
goto LABEL_37;
}
a1 = "-print";
v48 = 7LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v48 )
break;
v46 = *a2 < (unsigned int)*a1;
v47 = *a2++ == *a1++;
--v48;
}
while ( v47 );
v49 = (!v46 && !v47) - v46;
v50 = 0;
v51 = v49 == 0;
if ( v49 )
{
a1 = "-print0";
v58 = 8LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v58 )
break;
v50 = *a2 < (unsigned int)*a1;
v51 = *a2++ == *a1++;
--v58;
}
while ( v51 );
v59 = (!v50 && !v51) - v50;
v60 = 0;
v61 = v59 == 0;
if ( v59 )
{
v62 = "(";
v63 = 2LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v63 )
break;
v60 = *a2 < (unsigned int)*v62;
v61 = *a2++ == *v62++;
--v63;
}
while ( v61 );
v64 = (!v60 && !v61) - v60;
v65 = 0;
v66 = v64 == 0;
if ( !v64 )
goto LABEL_92;
v67 = ")";
v68 = 2LL;
v69 = *(const char **)&v5[8 * v17];
do
{
if ( !v68 )
break;
v65 = *v69 < (unsigned int)*v67;
v66 = *v69++ == *v67++;
--v68;
}
while ( v66 );
v70 = (!v65 && !v66) - v65;
v71 = 0;
v72 = v70 == 0;
if ( !v70 )
{
while ( !func8() )
{
v69 = (const char *)func7();
v67 = "(";
v85 = 2LL;
do
{
if ( !v85 )
break;
v83 = *v69 < (unsigned int)*v67;
v84 = *v69++ == *v67++;
--v85;
}
while ( v84 );
if ( (!v83 && !v84) == v83 )
break;
v67 = (const char *)((__int64 (*)(void))pop_stack)();
func4((__int64)v67);
}
func6(v67, v69);
v88 = (const char *)func7();
a1 = "-not";
v89 = 5LL;
a2 = v88;
do
{
if ( !v89 )
break;
v86 = *a2 < (unsigned int)*a1;
v87 = *a2++ == *a1++;
--v89;
}
while ( v87 );
v90 = (!v86 && !v87) - v86;
v91 = 0;
v92 = v90 == 0;
if ( !v90 )
{
v93 = "-and";
v94 = 5LL;
a2 = (const char *)*((_QWORD *)post_exp + post_exp_index - 1);
do
{
if ( !v94 )
break;
v91 = *a2 < (unsigned int)*v93;
v92 = *a2++ == *v93++;
--v94;
}
while ( v92 );
v95 = (!v91 && !v92) - v91;
v96 = 0;
v97 = v95 == 0;
if ( v95 )
{
v93 = "-or";
v98 = 4LL;
a2 = (const char *)*((_QWORD *)post_exp + post_exp_index - 1);
do
{
if ( !v98 )
break;
v96 = *a2 < (unsigned int)*v93;
v97 = *a2++ == *v93++;
--v98;
}
while ( v97 );
if ( (!v96 && !v97) != v96 )
{
v93 = "-and";
func4((__int64)"-and");
}
}
a1 = (const char *)func6(v93, a2);
func4((__int64)a1);
}
goto LABEL_37;
}
v73 = "-and";
v74 = 5LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v74 )
break;
v71 = *a2 < (unsigned int)*v73;
v72 = *a2++ == *v73++;
--v74;
}
while ( v72 );
v75 = (char)((!v71 && !v72) - v71);
v76 = 0;
v77 = v75 == 0;
if ( v75 )
{
v99 = "-or";
v100 = 4LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v100 )
break;
v76 = *a2 < (unsigned int)*v99;
v77 = *a2++ == *v99++;
--v100;
}
while ( v77 );
v75 = (char)((!v76 && !v77) - v76);
v101 = 0;
v102 = v75 == 0;
if ( v75 )
{
v103 = "-not";
v104 = 5LL;
a2 = *(const char **)&v5[8 * v17];
do
{
if ( !v104 )
break;
v101 = *a2 < (unsigned int)*v103;
v102 = *a2++ == *v103++;
--v104;
}
while ( v102 );
if ( (!v101 && !v102) != v101 )
{
v105 = func1(*(char **)&v5[8 * v17]);
if ( v105 )
{
a1 = (const char *)v30;
func4(v30);
if ( v21 )
v115 = v21;
else
v21 = 1;
}
else
{
func4(v30);
v113 = (const char *)func7();
a1 = "-not";
v114 = 5LL;
a2 = v113;
do
{
if ( !v114 )
break;
v111 = *a2 < (unsigned int)*a1;
v112 = *a2++ == *a1++;
--v114;
}
while ( v112 );
if ( (!v111 && !v112) == v111 )
{
a1 = (const char *)func6(a1, a2);
func4((__int64)a1);
}
if ( v115 )
{
a1 = "-and";
func4((__int64)"-and");
v115 = v105;
}
}
goto LABEL_37;
}
LABEL_92:
a1 = *(const char **)&v5[8 * v17];
func5((__int64)a1);
goto LABEL_37;
}
while ( !func8() )
{
a2 = (const char *)func7();
v109 = "(";
v110 = 2LL;
do
{
if ( !v110 )
break;
v107 = *a2 < (unsigned int)*v109;
v108 = *a2++ == *v109++;
--v110;
}
while ( v108 );
if ( (!v107 && !v108) == v107 )
break;
v106 = func6(v109, a2);
func4(v106);
}
}
else if ( !func8() )
{
v80 = (const char *)func7();
v81 = "-and";
v82 = 5LL;
a2 = v80;
do
{
if ( !v82 )
break;
v78 = *a2 < (unsigned int)*v81;
v79 = *a2++ == *v81++;
--v82;
}
while ( v79 );
v21 = (char)((!v78 && !v79) - v78);
if ( (!v78 && !v79) == v78 )
{
a1 = (const char *)v30;
func4(v30);
goto LABEL_37;
}
}
a1 = (const char *)v30;
func5(v30);
v21 = v75;
}
else
{
*((_DWORD *)&options + 17) = 0;
*((_DWORD *)&options + 16) = 1;
}
}
else
{
*((_DWORD *)&options + 17) = 0;
*((_DWORD *)&options + 15) = 1;
}
}
else
{
++v17;
a1 = *(const char **)&v5[v29 + 8];
*((_DWORD *)&options + 4) = atoi(a1);
}
}
else
{
++v17;
a1 = *(const char **)&v5[v29 + 8];
*((_DWORD *)&options + 5) = atoi(a1);
}
}
else
{
++v17;
v34 = (const char **)&v5[v29 + 8];
*((_DWORD *)&options + 5) = atoi(*v34);
a1 = *v34;
*((_DWORD *)&options + 4) = atoi(*v34);
}
LABEL_37:
v19 = v6 < (unsigned int)++v17;
v20 = v6 == v17;
}
while ( v6 > v17 );
}
LABEL_28:
while ( 1 )
{
result = func8();
if ( result )
break;
a1 = (const char *)func6(a1, a2);
func4((__int64)a1);
}
return result;
}

original_code:
void set_post_exp(int argc, char * argv[]) {
  int i = 1;
  bool flag_c1 = 0;
  bool flag_c2 = 0;
  while (i < argc && argv[i][0] == '-') {
    char * exp = argv[i];
    i++;
    if ((strcmp(exp, "-L") == 0)) {
      options.symbol_handle = S_L;
    } else if ((strcmp(exp, "-P") == 0)) {
      options.symbol_handle = S_P;
    } else if ((strcmp(exp, "-H") == 0)) {
      options.symbol_handle = S_H;
    } else if ((strcmp(exp, "-f") == 0)) {
      break;
    }
  }
  if (i >= argc) {
    print_error(USAGE);
  }
  options.find_pathes = &argv[i];
  while (i < argc && argv[i][0] != '-') {
    options.pathes_num++;
    i++;
  }
  for (; i < argc; i++) {
    char * exp = argv[i];
    if ((strcmp(exp, "-depth") == 0)) {
      i++;
      options.max_depth = atoi(argv[i]);
      options.min_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-maxdepth") == 0)) {
      i++;
      options.max_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-mindepth") == 0)) {
      i++;
      options.min_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-exec") == 0)) {
      int count = i;
      i++;
      options.is_exec = 1;
      options.no_actions = 0;
      options.argv = &argv[i];
      while (argv[i + 1][0] != ';') {
        i++;
      }
      options.argc = i - count + 1;
      i++;
    } else if ((strcmp(exp, "-ok") == 0)) {
      int count = i;
      i++;
      options.is_ok= 1;
      options.no_actions = 0;
      options.ok_argv = &argv[i];
      while (argv[i + 1][0] != ';') {
        i++;
      }
      options.ok_argc = i - count + 1;
      i++;
    } else if ((strcmp(exp, "-print") == 0)) {
      options.no_actions = 0;
      options.is_print = 1;
    } else if ((strcmp(exp, "-print0") == 0)) {
      options.no_actions = 0;
      options.is_print0 = 1;
    } else if ((strcmp(exp, "(") == 0)) {
      push_stack(exp);
    } else if ((strcmp(exp, ")") == 0)) {
      while (!stack_empty() && (strcmp(top_stack(), "(") != 0)) {
        push_back_exp(pop_stack());
      }
      pop_stack();
      if ((strcmp(top_stack(), "-not") == 0)) {
        char * tmp = post_exp[post_exp_index - 1];
        if ((strcmp(tmp, "-and") != 0) && (strcmp(tmp, "-or") != 0)) {
          push_back_exp("-and");
        }
        push_back_exp(pop_stack());
      }
    } else if ((strcmp(exp, "-and") == 0)) {
      if (!stack_empty() && (strcmp(top_stack(), "-and") == 0)) {
        push_back_exp(exp);
      } else {
        push_stack(exp);
      }
      flag_c1 = 0;
    } else if ((strcmp(exp, "-or") == 0)) {
      while (!stack_empty() && (strcmp(top_stack(), "(") != 0)) {
        push_back_exp(pop_stack());
      }
      push_stack(exp);
      flag_c1 = 0;
    } else if ((strcmp(exp, "-not") == 0)) {
      push_stack(exp);
    } else if (is_exp(exp)) {
      push_back_exp(exp);
      if (flag_c1) {
        flag_c2 = 1;
      }
      flag_c1 = 1;
    } else {
      push_back_exp(exp);
      if ((strcmp(top_stack(), "-not") == 0)) {
        push_back_exp(pop_stack());
      }
      if (flag_c2) {
        push_back_exp("-and");
        flag_c2 = 0;
      }
    }
  }
  while (!stack_empty()) {
    push_back_exp(pop_stack());
  }
}

canonical_original_code:
void set_post_exp(int argc, char *argv[]) {
  int i = 1;
  int flag_c1 = 0;
  int flag_c2 = 0;
  while (i < argc && argv[i][0] == '-') {
    char *exp = argv[i];
    i++;
    if ((strcmp(exp, "-L") == 0)) {
      options.symbol_handle = S_L;
    } else if ((strcmp(exp, "-P") == 0)) {
      options.symbol_handle = S_P;
    } else if ((strcmp(exp, "-H") == 0)) {
      options.symbol_handle = S_H;
    } else if ((strcmp(exp, "-f") == 0)) {
      break;
    }
  }
  if (i >= argc) {
    print_error(USAGE);
  }
  options.find_pathes = &argv[i];
  while (i < argc && argv[i][0] != '-') {
    options.pathes_num++;
    i++;
  }
  for (; i < argc; i++) {
    char *exp = argv[i];
    if ((strcmp(exp, "-depth") == 0)) {
      i++;
      options.max_depth = atoi(argv[i]);
      options.min_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-maxdepth") == 0)) {
      i++;
      options.max_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-mindepth") == 0)) {
      i++;
      options.min_depth = atoi(argv[i]);
    } else if ((strcmp(exp, "-exec") == 0)) {
      int count = i;
      i++;
      options.is_exec = 1;
      options.no_actions = 0;
      options.argv = &argv[i];
      while (argv[i + 1][0] != ';') {
        i++;
      }
      options.argc = i - count + 1;
      i++;
    } else if ((strcmp(exp, "-ok") == 0)) {
      int count = i;
      i++;
      options.is_ok= 1;
      options.no_actions = 0;
      options.ok_argv = &argv[i];
      while (argv[i + 1][0] != ';') {
        i++;
      }
      options.ok_argc = i - count + 1;
      i++;
    } else if ((strcmp(exp, "-print") == 0)) {
      options.no_actions = 0;
      options.is_print = 1;
    } else if ((strcmp(exp, "-print0") == 0)) {
      options.no_actions = 0;
      options.is_print0 = 1;
    } else if ((strcmp(exp, "(") == 0)) {
      push_stack(exp);
    } else if ((strcmp(exp, ")") == 0)) {
      while (!stack_empty() && (strcmp(top_stack(), "(") != 0)) {
        push_back_exp(pop_stack());
      }
      pop_stack();
      if ((strcmp(top_stack(), "-not") == 0)) {
        char *tmp = post_exp[post_exp_index - 1];
        if ((strcmp(tmp, "-and") != 0) && (strcmp(tmp, "-or") != 0)) {
          push_back_exp("-and");
        }
        push_back_exp(pop_stack());
      }
    } else if ((strcmp(exp, "-and") == 0)) {
      if (!stack_empty() && (strcmp(top_stack(), "-and") == 0)) {
        push_back_exp(exp);
      } else {
        push_stack(exp);
      }
      flag_c1 = 0;
    } else if ((strcmp(exp, "-or") == 0)) {
      while (!stack_empty() && (strcmp(top_stack(), "(") != 0)) {
        push_back_exp(pop_stack());
      }
      push_stack(exp);
      flag_c1 = 0;
    } else if ((strcmp(exp, "-not") == 0)) {
      push_stack(exp);
    } else if (is_exp(exp)) {
      push_back_exp(exp);
      if (flag_c1) {
        flag_c2 = 1;
      }
      flag_c1 = 1;
    } else {
      push_back_exp(exp);
      if ((strcmp(top_stack(), "-not") == 0)) {
        push_back_exp(pop_stack());
      }
      if (flag_c2) {
        push_back_exp("-and");
        flag_c2 = 0;
      }
    }
  }
  while (!stack_empty()) {
    push_back_exp(pop_stack());
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: count int

variable_types:
tmp
char *


decompiled_code:
_BOOL8 __fastcall init_parser(unsigned int a1, const char *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
const char **v4; // r8

post_exp = malloc(8LL * (int)a1);
help_stack = malloc(8LL * (int)a1);
post_exp_index = 0;
stack_index = 0;
return set_post_exp((const char *)a1, a2, v2, v3, v4);
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(unsigned int a1, const char *a2)
{
__int64 v2; // rdx
__int64 v3; // rcx
const char **v4; // r8

post_exp = malloc(8LL * (int)a1);
help_stack = malloc(8LL * (int)a1);
post_exp_index = 0;
stack_index = 0;
return func9((const char *)a1, a2, v2, v3, v4);
}

original_code:
void init_parser(int argc, char * argv[]) {
  post_exp = (char **)(malloc(sizeof(char **) * argc));
  help_stack = (char **)(malloc(sizeof(char **) * argc));
  post_exp_index = 0;
  stack_index = 0;
  set_post_exp(argc, argv);
}

canonical_original_code:
void init_parser(int argc, char *argv[]) {
  post_exp = (char **)(malloc(sizeof(char **) * argc));
  help_stack = (char **)(malloc(sizeof(char **) * argc));
  post_exp_index = 0;
  stack_index = 0;
  set_post_exp(argc, argv);
}


decompiled_code:
void free_parser()
{
free(post_exp);
free(help_stack);
}

canonical_decompiled_code:
void func11()
{
free(post_exp);
free(help_stack);
}


canonical_name: main

repo: sheimi/tiny-server

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
init_dispatcher(argc, argv, envp);
create_childpool((unsigned int)argc, argv);
free_childpool();
free_dispatcher();
return 0;
}

original_code:
int main(int argc, char * argv[]) {
  init_dispatcher();
  create_childpool(argc, argv);
  free_childpool();
  free_dispatcher();
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
  init_dispatcher();
  create_childpool(argc, argv);
  free_childpool();
  free_dispatcher();
  return 0;
}


decompiled_code:
void __fastcall handle_request(unsigned int a1)
{
char *v1; // rax
char *v2; // rbx
size_t v3; // rax
struct stat v4; // [rsp+0h] [rbp-178h] BYREF
char s[232]; // [rsp+90h] [rbp-E8h] BYREF

v1 = parse_request();
if ( v1 )
{
v2 = v1;
sprintf(s, "htdocs%s", v1 + 16);
v3 = strlen(s);
if ( *((_BYTE *)&v4.__unused[2] + v3 + 7) == 47 )
strcpy(&s[v3], "index.html");
if ( stat(s, &v4) == -1 )
{
not_found();
}
else
{
if ( (v4.st_mode & 0xF000) == 0x4000 )
strcat(s, "/index.html");
serve_file(a1, s);
}
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func6(unsigned int a1)
{
char *v1; // rax
char *v2; // rbx
size_t v3; // rax
struct stat v4; // [rsp+0h] [rbp-178h] BYREF
char s[232]; // [rsp+90h] [rbp-E8h] BYREF

v1 = func1();
if ( v1 )
{
v2 = v1;
sprintf(s, "htdocs%s", v1 + 16);
v3 = strlen(s);
if ( *((_BYTE *)&v4.__unused[2] + v3 + 7) == 47 )
strcpy(&s[v3], "index.html");
if ( stat(s, &v4) == -1 )
{
func2();
}
else
{
if ( (v4.st_mode & 0xF000) == 0x4000 )
strcat(s, "/index.html");
func5(a1, s);
}
free(v2);
}
}

original_code:
void handle_request(int fd) {
  char path[200];
  struct stat st;
  Request * request = parse_request(fd);
  if (!request)
    return;
  sprintf(path, "htdocs%s", request->url);
  if (path[strlen(path) - 1] == '/')
    strcat(path, "index.html");
  if (stat(path, &st) == -1) {
    not_found(fd);
  } else {
    if ((st.st_mode & 0170000) == 0040000)
      strcat(path, "/index.html");
    serve_file(fd, path);
  }
  free(request);
}

canonical_original_code:
void handle_request(int fd) {
  char path[200];
  struct stat st;
  struct Request *request = parse_request(fd);
  if (!request)
    return;
  sprintf(path, "htdocs%s", request->url);
  if (path[strlen(path) - 1] == '/')
    strcat(path, "index.html");
  if (stat(path, &st) == -1) {
    not_found(fd);
  } else {
    if ((st.st_mode & 0170000) == 0040000)
      strcat(path, "/index.html");
    serve_file(fd, path);
  }
  free(request);
}

variable_types: fd int

variable_types:
path
char [200]

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: struct Request { char method[16]; char url[128]; char *query_string; char protocol[8]; char host[32]; char connection[16]; char accept[16]; char agent[128]; char encoding[32]; char lang[32]; } *

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
void init_dispatcher()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void init_dispatcher() {
}

canonical_original_code:
void init_dispatcher() {
}


dispatch

decompiled_code:
void dispatch()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code:
void dispatch(request_info * dif) {
}

canonical_original_code:
void dispatch(struct _request_info *dif) {
}

variable_types: struct _request_info { char *url; char *method; } *


decompiled_code:
void free_dispatcher()
{
;
}

canonical_decompiled_code:
void func2()
{
;
}

original_code:
void free_dispatcher() {
}

canonical_original_code:
void free_dispatcher() {
}


decompiled_code:
_QWORD *init_request_info()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *result; // rax

result = malloc(8uLL);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
request_info * init_request_info() {
  request_info * ri = (request_info *) (malloc(sizeof(request_info *)));
  ri->url = 0;
  ri->method = 0;
  return ri;
}

canonical_original_code:
struct _request_info *init_request_info() {
  struct _request_info *ri = (request_info *) (malloc(sizeof(request_info *)));
  ri->url = 0;
  ri->method = 0;
  return ri;
}

return_type: struct _request_info { char *url; char *method; } *


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

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

original_code:
void free_request_info(request_info * ri) {
  free(ri);
}

canonical_original_code:
void free_request_info(struct _request_info *ri) {
  free(ri);
}

user_defined_types: struct _request_info { char *url; char *method; }


decompiled_code:
void __fastcall socketpair_wrapper(int a1, int a2, int a3, int *a4)
{
if ( socketpair(a1, a2, a3, a4) < 0 )
perror("socketpair error");
}

canonical_decompiled_code:
void __fastcall func0(int a1, int a2, int a3, int *a4)
{
if ( socketpair(a1, a2, a3, a4) < 0 )
perror("socketpair error");
}

original_code:
void socketpair_wrapper(int family, int type, int protocol, int * fd) {
  int n;
  if ( (n = socketpair(family, type, protocol, fd)) < 0)
    perror("socketpair error");
}

canonical_original_code:
void socketpair_wrapper(int family, int type, int protocol, int *fd) {
  int n;
  if ( (n = socketpair(family, type, protocol, fd)) < 0)
    perror("socketpair error");
}

variable_types: family int

variable_types: type int

variable_types: protocol int

variable_types:
fd
int *

variable_types: n int


decompiled_code:
__int64 fork_wrapper()
{
__pid_t v0; // ebx

v0 = fork();
if ( v0 < 0 )
perror("fork error");
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func1()
{
__pid_t v0; // ebx

v0 = fork();
if ( v0 < 0 )
perror("fork error");
return (unsigned int)v0;
}

original_code:
pid_t fork_wrapper() {
  pid_t pid;
  if ((pid = fork()) < 0)
    perror("fork error");
  return pid;
}

canonical_original_code:
int fork_wrapper() {
  int pid;
  if ((pid = fork()) < 0)
    perror("fork error");
  return pid;
}

variable_types: pid int


decompiled_code:
void __fastcall dup2_wrapper(int a1, int a2)
{
if ( dup2(a1, a2) == -1 )
perror("dup error");
}

canonical_decompiled_code:
void __fastcall func2(int a1, int a2)
{
if ( dup2(a1, a2) == -1 )
perror("dup error");
}

original_code:
void dup2_wrapper(int fd1, int fd2) {
  if (dup2(fd1, fd2) == -1)
    perror("dup error");
}


decompiled_code:
__sighandler_t __fastcall signal_wrapper(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v4; // [rsp+A0h] [rbp-A8h] BYREF

v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
v4.sa_flags = 0;
if ( sigaction(sig, &v4, &v3) < 0 )
perror("signal error");
return v3.sa_handler;
}

canonical_decompiled_code:
__sighandler_t __fastcall func3(int sig, void (*a2)(int))
{
struct sigaction v3; // [rsp+0h] [rbp-148h] BYREF
struct sigaction v4; // [rsp+A0h] [rbp-A8h] BYREF

v4.sa_handler = a2;
sigemptyset(&v4.sa_mask);
v4.sa_flags = 0;
if ( sigaction(sig, &v4, &v3) < 0 )
perror("signal error");
return v3.sa_handler;
}

original_code:
sigfunc signal_wrapper(int signo, sigfunc func) {
  struct sigaction act, oact;
  act.__sigaction_handler.sa_handler = func;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;
  if (sigaction(signo, &act, &oact) < 0)
    perror("signal error");
  return oact.__sigaction_handler.sa_handler;
}

canonical_original_code:
void (*signal_wrapper(int signo, void (*func)(int signo)))(int signo) {
  struct sigaction act; struct sigaction oact;
  act.__sigaction_handler.sa_handler = func;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0;
  if (sigaction(signo, &act, &oact) < 0)
    perror("signal error");
  return oact.__sigaction_handler.sa_handler;
}

variable_types: signo int

variable_types:
func
void (*)(int signo)

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

return_type: void (*)(int signo)

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

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


decompiled_code:
__int64 __fastcall tcp_listen(const char *a1, const char *a2, socklen_t *a3)
{
struct addrinfo *v4; // r12
int v5; // eax
unsigned int v6; // ebx
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF
int optval[7]; // [rsp+4Ch] [rbp-1Ch] BYREF

optval[0] = 1;
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
perror("error");
v4 = pai;
while ( 1 )
{
v5 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
v6 = v5;
if ( v5 >= 0 )
break;
LABEL_4:
pai = pai->ai_next;
if ( !pai )
goto LABEL_12;
}
setsockopt(v5, 1, 2, optval, 4u);
if ( bind(v6, pai->ai_addr, pai->ai_addrlen) )
{
close(v6);
goto LABEL_4;
}
if ( pai )
goto LABEL_9;
LABEL_12:
perror("error");
LABEL_9:
listen(v6, 1024);
if ( a3 )
*a3 = pai->ai_addrlen;
freeaddrinfo(v4);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, const char *a2, socklen_t *a3)
{
struct addrinfo *v4; // r12
int v5; // eax
unsigned int v6; // ebx
struct addrinfo *pai; // [rsp+8h] [rbp-60h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-58h] BYREF
int optval[7]; // [rsp+4Ch] [rbp-1Ch] BYREF

optval[0] = 1;
*(_QWORD *)&req.ai_flags = 1LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
if ( getaddrinfo(a1, a2, &req, &pai) )
perror("error");
v4 = pai;
while ( 1 )
{
v5 = socket(pai->ai_family, pai->ai_socktype, pai->ai_protocol);
v6 = v5;
if ( v5 >= 0 )
break;
LABEL_4:
pai = pai->ai_next;
if ( !pai )
goto LABEL_12;
}
setsockopt(v5, 1, 2, optval, 4u);
if ( bind(v6, pai->ai_addr, pai->ai_addrlen) )
{
close(v6);
goto LABEL_4;
}
if ( pai )
goto LABEL_9;
LABEL_12:
perror("error");
LABEL_9:
listen(v6, 1024);
if ( a3 )
*a3 = pai->ai_addrlen;
freeaddrinfo(v4);
return v6;
}

original_code:
int tcp_listen(const char * host, const char * serv, socklen_t * addrlenp) {
  int listenfd, n;
  const int on = 1;
  struct addrinfo hints, *res, *ressave;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = 0x0001;
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
    perror("error");
  ressave = res;
  do {
    listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (listenfd < 0)
      continue;
    setsockopt(listenfd, 1, 2, &on, sizeof(on));
    if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
      break;
    close(listenfd);
  } while ( (res = res->ai_next) != ((void *)0));
  if (res == ((void *)0))
    perror("error");
  listen(listenfd, 1024);
  if (addrlenp)
    *addrlenp = res->ai_addrlen;
  freeaddrinfo(ressave);
  return(listenfd);
}

canonical_original_code:
int tcp_listen(char *host, char *serv, unsigned int *addrlenp) {
  int listenfd; int n;
  int on = 1;
  struct addrinfo hints; struct addrinfo *res; struct addrinfo *ressave;
  bzero(&hints, sizeof(struct addrinfo));
  hints.ai_flags = 0x0001;
  hints.ai_family = 0;
  hints.ai_socktype = SOCK_STREAM;
  if ( (n = getaddrinfo(host, serv, &hints, &res)) != 0)
    perror("error");
  ressave = res;
  do {
    listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
    if (listenfd < 0)
      continue;
    setsockopt(listenfd, 1, 2, &on, sizeof(on));
    if (bind(listenfd, res->ai_addr, res->ai_addrlen) == 0)
      break;
    close(listenfd);
  } while ( (res = res->ai_next) != ((void *)0));
  if (res == ((void *)0))
    perror("error");
  listen(listenfd, 1024);
  if (addrlenp)
    *addrlenp = res->ai_addrlen;
  freeaddrinfo(ressave);
  return(listenfd);
}

variable_types:
host
char *

variable_types:
serv
char *

variable_types:
addrlenp
unsigned int *

variable_types: listenfd int

variable_types: on int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


decompiled_code:
void __noreturn sig_int()
{
__int64 v0; // rbx

if ( idle_num > 0 )
{
v0 = 0LL;
do
kill(*((_DWORD *)pids + v0++), 15);
while ( idle_num > (int)v0 );
}
while ( wait(0LL) > 0 )
;
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
__int64 v0; // rbx

if ( idle_num > 0 )
{
v0 = 0LL;
do
kill(*((_DWORD *)pids + v0++), 15);
while ( idle_num > (int)v0 );
}
while ( wait(0LL) > 0 )
;
exit(0);
}

original_code:
static void sig_int(int signo) {
  int i;
  for (i = 0; i < idle_num; i++) {
    kill(pids[i], 15);
  }
  while (wait(((void *)0)) > 0);
  exit(0);
}

variable_types: i int


decompiled_code:
void __fastcall __noreturn create_childpool(__int64 a1, __int64 a2)
{
int v2; // er12
int v3; // er13
__int64 i; // rbx
_DWORD *v5; // rbp
signed int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = atoi(*(const char **)(a2 + 24));
pid_len = v2;
idle_num = v2;
v3 = tcp_listen(*(_QWORD *)(a2 + 8), *(_QWORD *)(a2 + 16), v6);
pids = malloc(4LL * v2);
if ( v2 > 0 )
{
for ( i = 0LL; i != v2; *v5 = child_make(i++, v3, v6[0]) )
v5 = (char *)pids + 4 * i;
}
signal_wrapper(2LL, sig_int);
while ( 1 )
pause();
}

canonical_decompiled_code:
void __fastcall __noreturn func3(__int64 a1, __int64 a2)
{
int v2; // er12
int v3; // er13
__int64 i; // rbx
_DWORD *v5; // rbp
signed int v6[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v2 = atoi(*(const char **)(a2 + 24));
pid_len = v2;
idle_num = v2;
v3 = tcp_listen(*(_QWORD *)(a2 + 8), *(_QWORD *)(a2 + 16), v6);
pids = malloc(4LL * v2);
if ( v2 > 0 )
{
for ( i = 0LL; i != v2; *v5 = func2(i++, v3, v6[0]) )
v5 = (char *)pids + 4 * i;
}
signal_wrapper(2LL, sig_int);
while ( 1 )
pause();
}

original_code:
void create_childpool(int argc, char * argv[]){
  int i;
  int num = atoi(argv[3]);
  pid_len = num;
  idle_num = num;
  socklen_t addrlen;
  int listenfd;
  listenfd = tcp_listen(argv[1], argv[2], &addrlen);
  pids = (pid_t *)(malloc(sizeof(pid_t) * num));
  for (i = 0; i < num; i++) {
    pids[i] = child_make(i, listenfd, addrlen);
  }
  signal_wrapper(2, sig_int);
  while(1) {
    pause();
  }
}

canonical_original_code:
void create_childpool(int argc, char *argv[]){
  int i;
  int num = atoi(argv[3]);
  pid_len = num;
  idle_num = num;
  unsigned int addrlen;
  int listenfd;
  listenfd = tcp_listen(argv[1], argv[2], &addrlen);
  pids = (int *)(malloc(sizeof(pid_t) * num));
  for (i = 0; i < num; i++) {
    pids[i] = child_make(i, listenfd, addrlen);
  }
  signal_wrapper(2, sig_int);
  while(1) {
    pause();
  }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: num int

variable_types:
addrlen
unsigned int


decompiled_code:
void free_childpool()
{
free(pids);
}

canonical_decompiled_code:
void func4()
{
free(pids);
}

original_code:
void free_childpool() {
  free(pids);
}

canonical_original_code:
void free_childpool() {
  free(pids);
}


repo: shellygr/SwProj

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

result = (double *)malloc(0x18uLL);
if ( result )
{
*(_DWORD *)result = a1;
result[1] = a3;
*((_DWORD *)result + 4) = a2;
*((_DWORD *)result + 5) = 0;
}
return result;
}

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

result = (double *)malloc(0x18uLL);
if ( result )
{
*(_DWORD *)result = a1;
result[1] = a3;
*((_DWORD *)result + 4) = a2;
*((_DWORD *)result + 5) = 0;
}
return result;
}

original_code:
void* init_tuple(int size, double score, int place) {
 tuple *ret = (tuple *) malloc(sizeof(tuple));
 if (ret == ((void *)0))
  return ((void *)0);
 ret->size = size;
 ret->score = score;
 ret->place = place;
 ret->diameter = 0;
 return ret;
}

canonical_original_code:
void *init_tuple(int size, double score, int place) {
 struct tuple *ret = (tuple *) malloc(sizeof(tuple));
 if (ret == ((void *)0))
  return ((void *)0);
 ret->size = size;
 ret->score = score;
 ret->place = place;
 ret->diameter = 0;
 return ret;
}

variable_types: size int

variable_types: score double

variable_types: place int

variable_types: struct tuple { int size; double score; int place; int diameter; } *

return_type: void *


decompiled_code:
__int64 __fastcall compare_to(__int64 a1, __int64 a2)
{
__int64 result; // rax
double v3; // xmm0_8
double v4; // xmm1_8

result = 1LL;
if ( *(_DWORD *)a1 <= *(_DWORD *)a2 )
{
if ( *(_DWORD *)a1 < *(_DWORD *)a2 )
{
result = 0xFFFFFFFFLL;
}
else
{
v3 = *(double *)(a1 + 8);
v4 = *(double *)(a2 + 8);
if ( v3 <= v4 )
{
if ( v4 > v3 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(*(_DWORD *)(a1 + 16) - *(_DWORD *)(a2 + 16));
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 result; // rax
double v3; // xmm0_8
double v4; // xmm1_8

result = 1LL;
if ( *(_DWORD *)a1 <= *(_DWORD *)a2 )
{
if ( *(_DWORD *)a1 < *(_DWORD *)a2 )
{
result = 0xFFFFFFFFLL;
}
else
{
v3 = *(double *)(a1 + 8);
v4 = *(double *)(a2 + 8);
if ( v3 <= v4 )
{
if ( v4 > v3 )
result = 0xFFFFFFFFLL;
else
result = (unsigned int)(*(_DWORD *)(a1 + 16) - *(_DWORD *)(a2 + 16));
}
}
}
return result;
}

original_code:
int compare_to(const void *a, const void *b) {
 tuple *x = (tuple *) a;
 tuple *y = (tuple *) b;
 if ((x->size) > (y->size)) {
  return 1;
 }
 if ((x->size) < (y->size)) {
  return -1;
 }
 if ((x->score) > (y->score)) {
  return 1;
 }
 if ((x->score) < (y->score)) {
  return -1;
 }
 return (x->place) - (y->place);
}

canonical_original_code:
int compare_to(void *a, void *b) {
 struct tuple *x = (tuple *) a;
 struct tuple *y = (tuple *) b;
 if ((x->size) > (y->size)) {
  return 1;
 }
 if ((x->size) < (y->size)) {
  return -1;
 }
 if ((x->score) > (y->score)) {
  return 1;
 }
 if ((x->score) < (y->score)) {
  return -1;
 }
 return (x->place) - (y->place);
}

variable_types:
a
void *

variable_types:
b
void *

user_defined_types: struct tuple { int size; double score; int place; int diameter; }


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

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

original_code:
void destroy_elem(elem* elm) {
 free(elm);
}

canonical_original_code:
void destroy_elem(struct elem *elm) {
 free(elm);
}

variable_types: struct elem { void *content; struct elem *next; } *


decompiled_code:
_QWORD *init_queue()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

original_code:
queue * init_queue() {
 queue *q = (queue*) malloc(sizeof(queue));
 if (q == ((void *)0))
  return ((void *)0);
 q->head = ((void *)0);
 q->tail = ((void *)0);
 return q;
}

canonical_original_code:
struct queue *init_queue() {
 struct queue *q = (queue*) malloc(sizeof(queue));
 if (q == ((void *)0))
  return ((void *)0);
 q->head = ((void *)0);
 q->tail = ((void *)0);
 return q;
}

variable_types: struct queue { struct elem { void *content; struct elem *next; } *head; struct elem *tail; } *

user_defined_types: struct queue { struct elem *head; struct elem *tail; }


decompiled_code:
void __fastcall destroy_queue(void *ptr)
{
_QWORD *v2; // rdi
_QWORD *i; // rbx

v2 = *(_QWORD **)ptr;
for ( i = (_QWORD *)v2[1]; i; i = (_QWORD *)i[1] )
{
free(v2);
v2 = i;
}
free(v2);
free(ptr);
}

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

v2 = *(_QWORD **)ptr;
for ( i = (_QWORD *)v2[1]; i; i = (_QWORD *)i[1] )
{
free(v2);
v2 = i;
}
free(v2);
free(ptr);
}

original_code:
void destroy_queue(queue *q) {
 elem *current = q->head;
 elem *nxt = current->next;
 while (nxt != ((void *)0)) {
  free(current);
  current = nxt;
  nxt = current->next;
 }
 free(current);
 free(q);
}

canonical_original_code:
void destroy_queue(struct queue *q) {
 struct elem *current = q->head;
 struct elem *nxt = current->next;
 while (nxt != ((void *)0)) {
  free(current);
  current = nxt;
  nxt = current->next;
 }
 free(current);
 free(q);
}

user_defined_types: struct elem { void *content; struct elem *next; }


enqueue

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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

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

result = *(_QWORD *)(a1 + 8);
*(_QWORD *)(result + 8) = a2;
*(_QWORD *)(a1 + 8) = a2;
return result;
}

original_code:
void enqueue(queue* q, elem* elm) {
 (q->tail)->next = elm;
 q->tail = elm;
}

canonical_original_code:
void enqueue(struct queue *q, struct elem *elm) {
 (q->tail)->next = elm;
 q->tail = elm;
}

variable_types:
elm
struct elem *


decompiled_code:
__int64 __fastcall is_empty(_QWORD *a1)
{
return (a1[1] == *a1) & (unsigned __int8)(*a1 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
return (a1[1] == *a1) & (unsigned __int8)(*a1 == 0LL);
}

original_code:
int is_empty(queue* q) {
 if ((q->head == q->tail) && (q->head == ((void *)0)))
  return 1;
 return 0;
}

canonical_original_code:
int is_empty(struct queue *q) {
 if ((q->head == q->tail) && (q->head == ((void *)0)))
  return 1;
 return 0;
}


dequeue

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

if ( (unsigned int)is_empty(a1) )
return 0LL;
result = *a1;
*a1 = *(_QWORD *)(*a1 + 8LL);
return result;
}

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

if ( (unsigned int)func4(a1) )
return 0LL;
result = *a1;
*a1 = *(_QWORD *)(*a1 + 8LL);
return result;
}

original_code:
elem* dequeue(queue* q) {
 elem *dequeued;
 if (is_empty(q)) {
  return ((void *)0);
 }
 dequeued = q->head;
 q->head = (q->head)->next;
 return dequeued;
}

canonical_original_code:
struct elem *dequeue(struct queue *q) {
 struct elem *dequeued;
 if (is_empty(q)) {
  return ((void *)0);
 }
 dequeued = q->head;
 q->head = (q->head)->next;
 return dequeued;
}

variable_types: struct queue { struct elem *head; struct elem *tail; } *

return_type: struct elem { void *content; struct elem *next; } *


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

result = a1;
if ( a1 )
result = (a1 & (a1 - 1)) == 0;
return result;
}

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

result = a1;
if ( a1 )
result = (a1 & (a1 - 1)) == 0;
return result;
}

original_code:
int is_power_two(int x) {
 return ((x != 0) && !(x & (x - 1)));
}

variable_types: x int


decompiled_code:
void **__fastcall init_array(void **a1)
{
*a1 = malloc(8uLL);
return a1;
}

canonical_decompiled_code:
void **__fastcall func1(void **a1)
{
*a1 = malloc(8uLL);
return a1;
}

original_code:
dynamic_array* init_array(dynamic_array *arr) {
 *arr = (void **) malloc(sizeof(void *));
 if (arr == ((void *)0)) {
  send_perror("malloc");
 }
 return arr;
}

canonical_original_code:
void ***init_array(void ***arr) {
 *arr = (void **) malloc(sizeof(void *));
 if (arr == ((void *)0)) {
  send_perror("malloc");
 }
 return arr;
}

variable_types:
arr
void ***

return_type: void ***


decompiled_code:
__int64 __fastcall get_element(int a1, __int64 a2)
{
return *(_QWORD *)(a2 + 8LL * a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
return *(_QWORD *)(a2 + 8LL * a1);
}

original_code:
void* get_element(int index, dynamic_array *arr) {
 return (arr[index]);
}

canonical_original_code:
void *get_element(int index, void ***arr) {
 return (arr[index]);
}

variable_types: index int


decompiled_code:
__int64 __fastcall double_and_add(void *ptr, unsigned int *a2, __int64 a3)
{
unsigned int v4; // ebp
void *v5; // rax
_QWORD *v6; // rdx
signed int v7; // eax

v4 = *a2;
if ( !(unsigned int)is_power_two(*a2) )
goto LABEL_4;
v5 = realloc(*(void **)ptr, 8LL * (int)(2 * v4));
if ( v5 )
{
*(_QWORD *)ptr = v5;
LABEL_4:
v6 = *(_QWORD **)ptr;
v7 = (*a2)++;
v6[v7] = a3;
printf("array size now %d\n", *a2);
return 0LL;
}
free(ptr);
send_perror("realloc");
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *ptr, unsigned int *a2, __int64 a3)
{
unsigned int v4; // ebp
void *v5; // rax
_QWORD *v6; // rdx
signed int v7; // eax

v4 = *a2;
if ( !(unsigned int)func0(*a2) )
goto LABEL_4;
v5 = realloc(*(void **)ptr, 8LL * (int)(2 * v4));
if ( v5 )
{
*(_QWORD *)ptr = v5;
LABEL_4:
v6 = *(_QWORD **)ptr;
v7 = (*a2)++;
v6[v7] = a3;
printf("array size now %d\n", *a2);
return 0LL;
}
free(ptr);
send_perror("realloc");
return 2LL;
}

original_code:
int double_and_add(dynamic_array *arr, int *arr_size, void *element) {
 if (is_power_two(*arr_size)) {
  dynamic_array tmp;
  if ((tmp = realloc(*arr, 2 * (*arr_size) * sizeof(void*))) == ((void *)0)) {
   free(arr);
   send_perror("realloc");
   return 2;
  } else {
   *arr = tmp;
  }
 }
 (*arr)[(*arr_size)++] = element;
 printf("array size now %d\n", *arr_size);
 return 0;
}

canonical_original_code:
int double_and_add(void ***arr, int *arr_size, void *element) {
 if (is_power_two(*arr_size)) {
  void **tmp;
  if ((tmp = realloc(*arr, 2 * (*arr_size) * sizeof(void *))) == ((void *)0)) {
   free(arr);
   send_perror("realloc");
   return 2;
  } else {
   *arr = tmp;
  }
 }
 (*arr)[(*arr_size)++] = element;
 printf("array size now %d\n", *arr_size);
 return 0;
}

variable_types:
element
void *

variable_types:
tmp
void **


decompiled_code:
_BOOL8 __fastcall check_one_param(const char *a1)
{
return strpbrk(a1, delim) == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1)
{
return strpbrk(a1, delim) == 0LL;
}

original_code:
int check_one_param(char *param) {
 if (strpbrk(param, " \n\t\v\f\r") != ((void *)0)) {
  return 0;
 }
 return 1;
}

variable_types:
param
char *


decompiled_code:
_BOOL8 __fastcall check_and_get_three_params(char *a1, char **a2, char **a3, char **a4)
{
char *v6; // rax
int v7; // er13

v6 = strtok(a1, delim);
if ( v6 )
{
v7 = 0;
do
{
switch ( ++v7 )
{
case 1:
*a2 = v6;
break;
case 2:
*a3 = v6;
break;
case 3:
*a4 = v6;
break;
}
v6 = strtok(0LL, delim);
}
while ( v6 );
}
else
{
v7 = 0;
}
return v7 == 3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(char *a1, char **a2, char **a3, char **a4)
{
char *v6; // rax
int v7; // er13

v6 = strtok(a1, delim);
if ( v6 )
{
v7 = 0;
do
{
switch ( ++v7 )
{
case 1:
*a2 = v6;
break;
case 2:
*a3 = v6;
break;
case 3:
*a4 = v6;
break;
}
v6 = strtok(0LL, delim);
}
while ( v6 );
}
else
{
v7 = 0;
}
return v7 == 3;
}

original_code:
int check_and_get_three_params(char *params, char **first_param,
  char **second_param, char **weight) {
 char *next_token = strtok(params, " \n\t\v\f\r");
 int count = 0;
 while (next_token != ((void *)0)) {
  count++;
  if (count == 1) {
   *first_param = next_token;
  } else if (count == 2) {
   *second_param = next_token;
  } else if (count == 3)
   *weight = next_token;
  next_token = strtok(((void *)0), " \n\t\v\f\r");
 }
 return (count == 3 ? 1 : 0);
}

variable_types:
params
char *

variable_types:
weight
char **

variable_types: count int


decompiled_code:
_BOOL8 __fastcall check_string_is_non_negative_integer(char *nptr)
{
size_t v1; // r13
char *v2; // rbx
const unsigned __int16 **v3; // rax
__int64 v4; // rdx
_BOOL8 result; // rax
int v6; // eax

v1 = strlen(nptr);
v2 = nptr;
while ( v2 != &nptr[v1] )
{
v3 = _ctype_b_loc();
v4 = *v2++;
if ( ((*v3)[v4] & 0x800) == 0 )
return 0LL;
}
v6 = atoi(nptr);
if ( v1 > 0xA || v6 < 0 )
result = 0LL;
else
result = memcmp(nptr, "2147483647", 0xAuLL) == 0 || v6 != 0x7FFFFFFF;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(char *nptr)
{
size_t v1; // r13
char *v2; // rbx
const unsigned __int16 **v3; // rax
__int64 v4; // rdx
_BOOL8 result; // rax
int v6; // eax

v1 = strlen(nptr);
v2 = nptr;
while ( v2 != &nptr[v1] )
{
v3 = _ctype_b_loc();
v4 = *v2++;
if ( ((*v3)[v4] & 0x800) == 0 )
return 0LL;
}
v6 = atoi(nptr);
if ( v1 > 0xA || v6 < 0 )
result = 0LL;
else
result = memcmp(nptr, "2147483647", 0xAuLL) == 0 || v6 != 0x7FFFFFFF;
return result;
}

original_code:
int check_string_is_non_negative_integer(char *str) {
 int i;
 for (i = 0; i < strlen(str); i++) {
  if (!((*__ctype_b_loc ())[(int) ((*(str + i)))] & (unsigned short int) _ISdigit))
   return 0;
 }
 if (atoi(str) < 0 || strlen(str) > 10)
  return 0;
 else if ((strncmp(str, "2147483647", 10) != 0) && (atoi(str) == 2147483647))
  return 0;
 return 1;
}

canonical_original_code:
int check_string_is_non_negative_integer(char *str) {
 int i;
 for (i = 0; i < strlen(str); i++) {
  if (!((*__ctype_b_loc ())[(int) ((*(str + i)))] & (unsigned short) _ISdigit))
   return 0;
 }
 if (atoi(str) < 0 || strlen(str) > 10)
  return 0;
 else if ((strncmp(str, "2147483647", 10) != 0) && (atoi(str) == 2147483647))
  return 0;
 return 1;
}

variable_types:
str
char *

variable_types: i int


decompiled_code:
_BOOL8 __fastcall check_string_is_double(char *nptr)
{
char *v1; // rbx
char *v2; // rbp
int v3; // er12
double v4; // xmm0_8
_BOOL8 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v1 = nptr;
v2 = &nptr[strlen(nptr)];
v3 = 0;
while ( v1 != v2 )
{
if ( ((*_ctype_b_loc())[*v1] & 0x800) == 0 )
{
if ( *v1 != 46 || v3 )
return 0LL;
v3 = 1;
}
++v1;
}
v4 = strtod(nptr, &endptr);
if ( v4 == INFINITY )
return 0LL;
result = 0LL;
if ( !*endptr && v4 <= 1.0 )
result = v4 >= 0.0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(char *nptr)
{
char *v1; // rbx
char *v2; // rbp
int v3; // er12
double v4; // xmm0_8
_BOOL8 result; // rax
char *endptr; // [rsp+8h] [rbp-30h] BYREF

v1 = nptr;
v2 = &nptr[strlen(nptr)];
v3 = 0;
while ( v1 != v2 )
{
if ( ((*_ctype_b_loc())[*v1] & 0x800) == 0 )
{
if ( *v1 != 46 || v3 )
return 0LL;
v3 = 1;
}
++v1;
}
v4 = strtod(nptr, &endptr);
if ( v4 == INFINITY )
return 0LL;
result = 0LL;
if ( !*endptr && v4 <= 1.0 )
result = v4 >= 0.0;
return result;
}

original_code:
int check_string_is_double(char *str) {
 int i;
 int flag = 0;
 char *tmp;
 double weight;
 for (i = 0; i < strlen(str); i++) {
  if (!((*__ctype_b_loc ())[(int) ((*(str + i)))] & (unsigned short int) _ISdigit)) {
   if (flag == 1) {
    return 0;
   }
   if (*(str + i) == '.') {
    flag = 1;
   } else {
    return 0;
   }
  }
 }
 weight = strtod(str, &tmp);
 if (weight == (__builtin_huge_val ()) || strlen(tmp) > 0 || weight > 1 || weight < 0) {
  return 0;
 }
 return 1;
}

canonical_original_code:
int check_string_is_double(char *str) {
 int i;
 int flag = 0;
 char *tmp;
 double weight;
 for (i = 0; i < strlen(str); i++) {
  if (!((*__ctype_b_loc ())[(int) ((*(str + i)))] & (unsigned short) _ISdigit)) {
   if (flag == 1) {
    return 0;
   }
   if (*(str + i) == '.') {
    flag = 1;
   } else {
    return 0;
   }
  }
 }
 weight = strtod(str, &tmp);
 if (weight == (__builtin_huge_val ()) || strlen(tmp) > 0 || weight > 1 || weight < 0) {
  return 0;
 }
 return 1;
}

variable_types: flag int

variable_types:
tmp
char *

variable_types: weight double


decompiled_code:
_BOOL8 __fastcall is_legal_id(int a1, _DWORD *a2)
{
return *a2 > a1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(int a1, _DWORD *a2)
{
return *a2 > a1;
}

original_code:
int is_legal_id(int id, network *net) {
 return (id >= net->num_of_vertices ? 0 : 1);
}

canonical_original_code:
int is_legal_id(int id, struct network *net) {
 return (id >= net->num_of_vertices ? 0 : 1);
}

variable_types: id int

variable_types: struct network { int num_of_vertices; void **vertices; } *


decompiled_code:
__int64 __fastcall add_vertex(__int64 a1, unsigned int *a2)
{
__int64 v2; // rax
unsigned int *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a2;
v2 = init_vertex(a1, *a2);
if ( v2 )
return add_vertex_to_network(&v4, v2);
send_perror("malloc");
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int *a2)
{
__int64 v2; // rax
unsigned int *v4; // [rsp+8h] [rbp-10h] BYREF

v4 = a2;
v2 = init_vertex(a1, *a2);
if ( v2 )
return add_vertex_to_network(&v4, v2);
send_perror("malloc");
return 2LL;
}

original_code:
int add_vertex(char *name, network *net) {
 vertex *vrtx = init_vertex(name, net->num_of_vertices);
 if (vrtx == ((void *)0)) {
  send_perror("malloc");
  return 2;
 }
 return add_vertex_to_network(&net, vrtx);
}

canonical_original_code:
int add_vertex(char *name, struct network *net) {
 struct vertex *vrtx = init_vertex(name, net->num_of_vertices);
 if (vrtx == ((void *)0)) {
  send_perror("malloc");
  return 2;
 }
 return add_vertex_to_network(&net, vrtx);
}

variable_types:
name
char *

variable_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; } *

user_defined_types: struct network { int num_of_vertices; void **vertices; }


decompiled_code:
__int64 __fastcall add_edge(__int64 a1, unsigned int a2, __int64 a3, double a4)
{
__int64 result; // rax
__int64 v6; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+18h] [rbp-30h] BYREF

v8[0] = get_vertex(a1, a3);
v7 = get_vertex(a2, a3);
v6 = 0LL;
init_edge(&v6, (unsigned int)a1, a2, a4);
result = add_edge_to_vertex(v8, &v7, v6);
if ( (_DWORD)result != 2 )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3, double a4)
{
__int64 result; // rax
__int64 v6; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+18h] [rbp-30h] BYREF

v8[0] = get_vertex(a1, a3);
v7 = get_vertex(a2, a3);
v6 = 0LL;
init_edge(&v6, (unsigned int)a1, a2, a4);
result = add_edge_to_vertex(v8, &v7, v6);
if ( (_DWORD)result != 2 )
result = 0LL;
return result;
}

original_code:
int add_edge(int first_id, int second_id, double weight, network *net) {
 vertex *src_vrtx = get_vertex(first_id, net);
 vertex *dest_vrtx = get_vertex(second_id, net);
 edge *e = ((void *)0);
 init_edge(&e, first_id, second_id, weight);
 if ((add_edge_to_vertex(&src_vrtx, &dest_vrtx, e) == 2))
  return 2;
 return 0;
}

canonical_original_code:
int add_edge(int first_id, int second_id, double weight, struct network *net) {
 struct vertex *src_vrtx = get_vertex(first_id, net);
 struct vertex *dest_vrtx = get_vertex(second_id, net);
 struct edge *e = ((void *)0);
 init_edge(&e, first_id, second_id, weight);
 if ((add_edge_to_vertex(&src_vrtx, &dest_vrtx, e) == 2))
  return 2;
 return 0;
}

variable_types: struct edge { int from; int to; double weight; } *

user_defined_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; }


decompiled_code:
__int64 __fastcall dispatch_add_vertex(char *a1, unsigned int *a2)
{
char v2; // bp
__int64 result; // rax

if ( !*a1 )
goto LABEL_4;
v2 = *a1;
if ( ((*_ctype_b_loc())[v2] & 0x2000) != 0 )
{
if ( !check_one_param(a1 + 1) )
{
LABEL_4:
send_error(14LL);
return 1LL;
}
result = add_vertex((__int64)(a1 + 1), a2);
}
else
{
send_error(3LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1, unsigned int *a2)
{
char v2; // bp
__int64 result; // rax

if ( !*a1 )
goto LABEL_4;
v2 = *a1;
if ( ((*_ctype_b_loc())[v2] & 0x2000) != 0 )
{
if ( !func0(a1 + 1) )
{
LABEL_4:
send_error(14LL);
return 1LL;
}
result = func5((__int64)(a1 + 1), a2);
}
else
{
send_error(3LL);
result = 1LL;
}
return result;
}

original_code:
int dispatch_add_vertex(char *params, network *net) {
 if (params[0] == '\0')
  send_error(14);
 else if (!((*__ctype_b_loc ())[(int) ((params[0]))] & (unsigned short int) _ISspace))
  send_error(3);
 else if (check_one_param(params + 1) == 0) {
  send_error(14);
 } else {
  return add_vertex(params + 1, net);
 }
 return 1;
}

canonical_original_code:
int dispatch_add_vertex(char *params, struct network *net) {
 if (params[0] == '\0')
  send_error(14);
 else if (!((*__ctype_b_loc ())[(int) ((params[0]))] & (unsigned short) _ISspace))
  send_error(3);
 else if (check_one_param(params + 1) == 0) {
  send_error(14);
 } else {
  return add_vertex(params + 1, net);
 }
 return 1;
}


decompiled_code:
__int64 __fastcall dispatch_add_edge(char *a1, _DWORD *a2)
{
char v2; // bp
__int64 result; // rax
unsigned int v4; // ebx
int v5; // ebp
double v6; // xmm0_8
char *v7; // [rsp+8h] [rbp-40h] BYREF
char *v8; // [rsp+10h] [rbp-38h] BYREF
char *nptr; // [rsp+18h] [rbp-30h] BYREF

nptr = 0LL;
v8 = 0LL;
if ( *a1 )
{
v2 = *a1;
if ( ((*_ctype_b_loc())[v2] & 0x2000) != 0 )
{
if ( check_and_get_three_params(a1 + 1, &nptr, &v8, &v7) )
{
if ( check_string_is_non_negative_integer(nptr) && check_string_is_non_negative_integer(v8) )
{
if ( check_string_is_double(v7) )
{
v4 = atoi(nptr);
v5 = atoi(v8);
v6 = strtod(v7, 0LL);
if ( is_legal_id(v4, a2) && is_legal_id(v5, a2) )
{
if ( v4 == v5 )
{
send_error(8LL);
result = 1LL;
}
else
{
result = add_edge(v4, v5, (__int64)a2, v6);
}
}
else
{
send_error(7LL);
result = 1LL;
}
}
else
{
send_error(4294967292LL);
result = 1LL;
}
}
else
{
send_error(5LL);
result = 1LL;
}
}
else
{
send_error(24LL);
result = 1LL;
}
}
else
{
send_error(3LL);
result = 1LL;
}
}
else
{
send_error(24LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1, _DWORD *a2)
{
char v2; // bp
__int64 result; // rax
unsigned int v4; // ebx
int v5; // ebp
double v6; // xmm0_8
char *v7; // [rsp+8h] [rbp-40h] BYREF
char *v8; // [rsp+10h] [rbp-38h] BYREF
char *nptr; // [rsp+18h] [rbp-30h] BYREF

nptr = 0LL;
v8 = 0LL;
if ( *a1 )
{
v2 = *a1;
if ( ((*_ctype_b_loc())[v2] & 0x2000) != 0 )
{
if ( func1(a1 + 1, &nptr, &v8, &v7) )
{
if ( func2(nptr) && func2(v8) )
{
if ( func3(v7) )
{
v4 = atoi(nptr);
v5 = atoi(v8);
v6 = strtod(v7, 0LL);
if ( func4(v4, a2) && func4(v5, a2) )
{
if ( v4 == v5 )
{
send_error(8LL);
result = 1LL;
}
else
{
result = func6(v4, v5, (__int64)a2, v6);
}
}
else
{
send_error(7LL);
result = 1LL;
}
}
else
{
send_error(4294967292LL);
result = 1LL;
}
}
else
{
send_error(5LL);
result = 1LL;
}
}
else
{
send_error(24LL);
result = 1LL;
}
}
else
{
send_error(3LL);
result = 1LL;
}
}
else
{
send_error(24LL);
result = 1LL;
}
return result;
}

original_code:
int dispatch_add_edge(char *params, network *net) {
 char *first_param = ((void *)0), *second_param = ((void *)0), *third_param;
 if (params[0] == '\0')
  send_error(24);
 else if (!((*__ctype_b_loc ())[(int) ((params[0]))] & (unsigned short int) _ISspace))
  send_error(3);
 else if (check_and_get_three_params(params + 1, &first_param, &second_param,
   &third_param) == 0) {
  send_error(24);
  return 1;
 } else if ((check_string_is_non_negative_integer(first_param) == 0)
   || (check_string_is_non_negative_integer(second_param) == 0)) {
  send_error(5);
  return 1;
 } else if (!check_string_is_double(third_param)) {
  send_error(-4);
  return 1;
 } else {
  int first_id = atoi(first_param);
  int second_id = atoi(second_param);
  double weight = strtod(third_param, ((void *)0));
  if ((is_legal_id(first_id, net) == 0)
    || (is_legal_id(second_id, net) == 0)) {
   send_error(7);
   return 1;
  } else if (first_id == second_id) {
   send_error(8);
   return 1;
  } else {
   return add_edge(first_id, second_id, weight, net);
  }
 }
 return 1;
}

canonical_original_code:
int dispatch_add_edge(char *params, struct network *net) {
 char *first_param = ((void *)0); char *second_param = ((void *)0); char *third_param;
 if (params[0] == '\0')
  send_error(24);
 else if (!((*__ctype_b_loc ())[(int) ((params[0]))] & (unsigned short) _ISspace))
  send_error(3);
 else if (check_and_get_three_params(params + 1, &first_param, &second_param,
   &third_param) == 0) {
  send_error(24);
  return 1;
 } else if ((check_string_is_non_negative_integer(first_param) == 0)
   || (check_string_is_non_negative_integer(second_param) == 0)) {
  send_error(5);
  return 1;
 } else if (!check_string_is_double(third_param)) {
  send_error(-4);
  return 1;
 } else {
  int first_id = atoi(first_param);
  int second_id = atoi(second_param);
  double weight = strtod(third_param, ((void *)0));
  if ((is_legal_id(first_id, net) == 0)
    || (is_legal_id(second_id, net) == 0)) {
   send_error(7);
   return 1;
  } else if (first_id == second_id) {
   send_error(8);
   return 1;
  } else {
   return add_edge(first_id, second_id, weight, net);
  }
 }
 return 1;
}


decompiled_code:
__int64 __fastcall dispatch_command(int a1, char *a2, unsigned int *a3)
{
if ( a1 == 1 )
return dispatch_add_vertex(a2, a3);
if ( a1 == 2 )
return dispatch_add_edge(a2, a3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, char *a2, unsigned int *a3)
{
if ( a1 == 1 )
return func7(a2, a3);
if ( a1 == 2 )
return func8(a2, a3);
return 1LL;
}

original_code:
int dispatch_command(int code, char *params, network *net) {
 switch (code) {
 case 1:
  return dispatch_add_vertex(params, net);
 case 2:
  return dispatch_add_edge(params, net);
 }
 return 1;
}

canonical_original_code:
int dispatch_command(int code, char *params, struct network *net) {
 switch (code) {
 case 1:
  return dispatch_add_vertex(params, net);
 case 2:
  return dispatch_add_edge(params, net);
 }
 return 1;
}

variable_types: code int


decompiled_code:
__int64 __fastcall init_network(void *ptr)
{
char *v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = (char *)malloc(0x10uLL);
*(_QWORD *)ptr = v1;
if ( !v1 )
return 2LL;
v2 = *(_QWORD *)init_array(v1 + 8);
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = v2;
if ( v2 )
{
**(_DWORD **)ptr = 0;
result = 0LL;
}
else
{
free(ptr);
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void *ptr)
{
char *v1; // rax
__int64 v2; // rax
__int64 result; // rax

v1 = (char *)malloc(0x10uLL);
*(_QWORD *)ptr = v1;
if ( !v1 )
return 2LL;
v2 = *(_QWORD *)init_array(v1 + 8);
*(_QWORD *)(*(_QWORD *)ptr + 8LL) = v2;
if ( v2 )
{
**(_DWORD **)ptr = 0;
result = 0LL;
}
else
{
free(ptr);
result = 2LL;
}
return result;
}

original_code:
int init_network(network **net) {
 if ((*net = (network*) malloc(sizeof(network))) == ((void *)0))
  return 2;
 if (((*net)->vertices = *init_array(&(*net)->vertices)) == ((void *)0)) {
  free(net);
  return 2;
 }
 (*net)->num_of_vertices = 0;
 return 0;
}

canonical_original_code:
int init_network(struct network **net) {
 if ((*net = (struct network *) malloc(sizeof(network))) == ((void *)0))
  return 2;
 if (((*net)->vertices = *init_array(&(*net)->vertices)) == ((void *)0)) {
  free(net);
  return 2;
 }
 (*net)->num_of_vertices = 0;
 return 0;
}

variable_types: struct network { int num_of_vertices; void **vertices; } **


decompiled_code:
void __fastcall destroy_net(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
destroy_vertex(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
destroy_vertex(*(_QWORD *)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void destroy_net(network *net) {
 int i;
 for (i = 0; i < net->num_of_vertices; i++) {
  destroy_vertex((net->vertices[i]));
 }
 free(net->vertices);
 free(net);
}

canonical_original_code:
void destroy_net(struct network *net) {
 int i;
 for (i = 0; i < net->num_of_vertices; i++) {
  destroy_vertex((net->vertices[i]));
 }
 free(net->vertices);
 free(net);
}


decompiled_code:
__int64 __fastcall get_vertex(int a1, __int64 a2)
{
return *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL * a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
return *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL * a1);
}

original_code:
vertex* get_vertex(int id, network *net) {
 return (net->vertices[id]);
}

canonical_original_code:
struct vertex *get_vertex(int id, struct network *net) {
 return (net->vertices[id]);
}

return_type: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; } *


decompiled_code:
__int64 __fastcall add_vertex_to_network(_QWORD *a1, __int64 a2)
{
return double_and_add(*a1 + 8LL, *a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, __int64 a2)
{
return double_and_add(*a1 + 8LL, *a1, a2);
}

original_code:
int add_vertex_to_network(network **net, vertex *vrtx) {
 int i;
 i = double_and_add(&((*net)->vertices), &((*net)->num_of_vertices), vrtx);
 return i;
}

canonical_original_code:
int add_vertex_to_network(struct network **net, struct vertex *vrtx) {
 int i;
 i = double_and_add(&((*net)->vertices), &((*net)->num_of_vertices), vrtx);
 return i;
}


original_code:
void get_prices_array(network *net, double *prices) {
 int i, k;
 vertex currVertex;
 int counter = 0;
 vertex *vertices = (vertex*) (net->vertices);
 int from, to;
 edge **currNeighList;
 for (i = 0; i < net->num_of_vertices; i++) {
  currVertex = vertices[i];
  currNeighList = (edge **)currVertex.adjacency_list;
  for (k = 0; k < currVertex.deg; k++) {
   from = currNeighList[k]->from;
   to = currNeighList[k]->to;
   if ((from == i) && (to > i)) {
    prices[counter + to - i] = currNeighList[k]->weight;
   } else {
    if ((to == i) && (from > i)) {
     prices[counter + from - i] = currNeighList[k]->weight;
    }
   }
  }
  counter += (net->num_of_vertices - i - 1);
 }
}

canonical_original_code:
void get_prices_array(struct network *net, double *prices) {
 int i; int k;
 struct vertex currVertex;
 int counter = 0;
 struct vertex *vertices = (vertex*) (net->vertices);
 int from; int to;
 struct edge **currNeighList;
 for (i = 0; i < net->num_of_vertices; i++) {
  currVertex = vertices[i];
  currNeighList = (struct edge **)currVertex.adjacency_list;
  for (k = 0; k < currVertex.deg; k++) {
   from = currNeighList[k]->from;
   to = currNeighList[k]->to;
   if ((from == i) && (to > i)) {
    prices[counter + to - i] = currNeighList[k]->weight;
   } else {
    if ((to == i) && (from > i)) {
     prices[counter + from - i] = currNeighList[k]->weight;
    }
   }
  }
  counter += (net->num_of_vertices - i - 1);
 }
}

variable_types:
prices
double *

variable_types: k int

variable_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; }

variable_types: counter int

variable_types: from int

variable_types: to int

variable_types: struct edge { int from; int to; double weight; } **


original_code:
void get_id_array(int nV, int ***id) {
 int i, j;
 int counter = 0;
 for (i = 0; i < nV; i++) {
  for (j = 0; j < nV - i - 1; j++) {
   (*id)[i][j] = counter++;
  }
 }
}

canonical_original_code:
void get_id_array(int nV, int ***id) {
 int i; int j;
 int counter = 0;
 for (i = 0; i < nV; i++) {
  for (j = 0; j < nV - i - 1; j++) {
   (*id)[i][j] = counter++;
  }
 }
}

variable_types: nV int

variable_types:
id
int ***

variable_types: i int

variable_types: j int


decompiled_code:
void __fastcall send_perror(const char *a1)
{
char v1[88]; // [rsp+0h] [rbp-58h] BYREF

sprintf(v1, "Error: standard function %s has failed\n", a1);
perror(v1);
}

canonical_decompiled_code:
void __fastcall func0(const char *a1)
{
char v1[88]; // [rsp+0h] [rbp-58h] BYREF

sprintf(v1, "Error: standard function %s has failed\n", a1);
perror(v1);
}

original_code:
void send_perror(char *func) {
 char error_text[80];
 sprintf(error_text, "Error: standard function %s has failed\n", func);
 perror(error_text);
}

variable_types:
func
char *


decompiled_code:
int __fastcall send_error(int a1)
{
const char *v1; // rsi
int result; // eax
__int64 v3; // rdx
char v4[19]; // [rsp+5h] [rbp-13h] BYREF

if ( a1 <= 0 )
{
switch ( a1 )
{
case -4:
v1 = "Error: Weight must be a number in the form x.xxx... between 0 and 1\n";
break;
case -3:
v1 = "Error: Should have 3 arguments: input folder, output folder, constant C\n";
break;
case -2:
v1 = "Error: Folder name must end with a '/'\n";
break;
case -1:
v1 = "Error: input folder must contain a file named 'network'\n";
break;
case 0:
v1 = "Error: Constant c must be 0 <= c <= 1\n";
break;
default:
v1 = 0LL;
break;
}
LABEL_5:
result = printf("%s", v1);
}
else
{
switch ( a1 % 10 )
{
case 1:
v1 = "Error: command must have at least one character\n";
goto LABEL_5;
case 2:
v1 = "Error: command length must be less than or equal to 500 characters\n";
goto LABEL_5;
case 3:
v1 = "Error: command not found\n";
goto LABEL_5;
case 4:
goto LABEL_19;
case 5:
v1 = "Error: ID parameter is not a non-negative integer\n";
goto LABEL_5;
case 6:
v1 = "Error: cannot add vertex - too many vertices\n";
goto LABEL_5;
case 7:
v1 = "Error: ID number is not in the system\n";
goto LABEL_5;
case 8:
v1 = "Error: edge must be between two different vertices\n";
goto LABEL_5;
case 9:
v1 = "Error: edge is in the graph\n";
goto LABEL_5;
default:
if ( a1 % 10 != 4 )
{
v1 = 0LL;
goto LABEL_5;
}
LABEL_19:
v3 = (unsigned int)((a1 - 4) / 10);
switch ( (int)v3 )
{
case 1:
strcpy(v4, "add_vertex");
break;
case 2:
strcpy(v4, "add_edge");
v3 = 3LL;
break;
case 3:
strcpy(v4, "print");
v3 = 0LL;
break;
case 4:
strcpy(v4, "page_rank");
v3 = 0LL;
break;
case 5:
strcpy(v4, "quit");
v3 = 0LL;
break;
default:
v3 = 0LL;
break;
}
result = printf("Error: command %s must have %d parameters\n", v4, v3);
break;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int a1)
{
const char *v1; // rsi
int result; // eax
__int64 v3; // rdx
char v4[19]; // [rsp+5h] [rbp-13h] BYREF

if ( a1 <= 0 )
{
switch ( a1 )
{
case -4:
v1 = "Error: Weight must be a number in the form x.xxx... between 0 and 1\n";
break;
case -3:
v1 = "Error: Should have 3 arguments: input folder, output folder, constant C\n";
break;
case -2:
v1 = "Error: Folder name must end with a '/'\n";
break;
case -1:
v1 = "Error: input folder must contain a file named 'network'\n";
break;
case 0:
v1 = "Error: Constant c must be 0 <= c <= 1\n";
break;
default:
v1 = 0LL;
break;
}
LABEL_5:
result = printf("%s", v1);
}
else
{
switch ( a1 % 10 )
{
case 1:
v1 = "Error: command must have at least one character\n";
goto LABEL_5;
case 2:
v1 = "Error: command length must be less than or equal to 500 characters\n";
goto LABEL_5;
case 3:
v1 = "Error: command not found\n";
goto LABEL_5;
case 4:
goto LABEL_19;
case 5:
v1 = "Error: ID parameter is not a non-negative integer\n";
goto LABEL_5;
case 6:
v1 = "Error: cannot add vertex - too many vertices\n";
goto LABEL_5;
case 7:
v1 = "Error: ID number is not in the system\n";
goto LABEL_5;
case 8:
v1 = "Error: edge must be between two different vertices\n";
goto LABEL_5;
case 9:
v1 = "Error: edge is in the graph\n";
goto LABEL_5;
default:
if ( a1 % 10 != 4 )
{
v1 = 0LL;
goto LABEL_5;
}
LABEL_19:
v3 = (unsigned int)((a1 - 4) / 10);
switch ( (int)v3 )
{
case 1:
strcpy(v4, "add_vertex");
break;
case 2:
strcpy(v4, "add_edge");
v3 = 3LL;
break;
case 3:
strcpy(v4, "print");
v3 = 0LL;
break;
case 4:
strcpy(v4, "page_rank");
v3 = 0LL;
break;
case 5:
strcpy(v4, "quit");
v3 = 0LL;
break;
default:
v3 = 0LL;
break;
}
result = printf("Error: command %s must have %d parameters\n", v4, v3);
break;
}
}
return result;
}

original_code:
void send_error(int code) {
 char *error_message = ((void *)0);
 if (code <= 0) {
  switch (code) {
   case -1: error_message = "Error: input folder must contain a file named 'network'\n"; break;
   case -2: error_message = "Error: Folder name must end with a '/'\n"; break;
   case -3: error_message = "Error: Should have 3 arguments: input folder, output folder, constant C\n"; break;
   case -4: error_message = "Error: Weight must be a number in the form x.xxx... between 0 and 1\n"; break;
   case 0: error_message = "Error: Constant c must be 0 <= c <= 1\n"; break;
  }
  printf("%s", error_message);
 } else {
  switch(code % 10) {
   case 1: error_message = "Error: command must have at least one character\n"; break;
   case 2: error_message = "Error: command length must be less than or equal to 500 characters\n"; break;
   case 3: error_message = "Error: command not found\n"; break;
   case 4: error_message = "Error: command %s must have %d  parameters\n"; break;
   case 5: error_message = "Error: ID parameter is not a non-negative integer\n"; break;
   case 6: error_message = "Error: cannot add vertex - too many vertices\n"; break;
   case 7: error_message = "Error: ID number is not in the system\n"; break;
   case 8: error_message = "Error: edge must be between two different vertices\n"; break;
   case 9: error_message = "Error: edge is in the graph\n"; break;
  }
  if (code % 10 != 4) {
   printf("%s", error_message);
  } else {
   char command_name[11];
   int num_of_params;
   switch ((code-4)/10) {
    case 1: strncpy(command_name, "add_vertex", 11); num_of_params = 1; break;
    case 2: strncpy(command_name, "add_edge", 9); num_of_params = 3; break;
    case 3: strncpy(command_name, "print", 6); num_of_params = 0; break;
    case 4: strncpy(command_name, "page_rank", 10); num_of_params = 0; break;
    case 5: strncpy(command_name, "quit", 5); num_of_params = 0; break;
   }
   printf("Error: command %s must have %d  parameters\n", command_name, num_of_params);
  }
 }
}


decompiled_code:
__int64 __fastcall int_to_string(unsigned int a1)
{
char *v1; // rax
int v2; // edx
__int64 result; // rax

v1 = (char *)malloc(0xAuLL);
if ( v1 )
{
v2 = sprintf(v1, "%d", a1);
result = 0LL;
if ( v2 < 0 )
{
send_perror("sprintf");
result = 2LL;
}
}
else
{
send_perror("malloc");
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
char *v1; // rax
int v2; // edx
__int64 result; // rax

v1 = (char *)malloc(0xAuLL);
if ( v1 )
{
v2 = sprintf(v1, "%d", a1);
result = 0LL;
if ( v2 < 0 )
{
send_perror("sprintf");
result = 2LL;
}
}
else
{
send_perror("malloc");
result = 2LL;
}
return result;
}

original_code:
int int_to_string(int x, char *str) {
 str = (char *) malloc(10 * sizeof(char));
 if (str == ((void *)0)) {
  send_perror("malloc");
  return 2;
 }
 if (sprintf(str, "%d", x) < 0) {
  send_perror("sprintf");
  return 2;
 }
 return 0;
}

variable_types: x int

variable_types:
str
char *


decompiled_code:
const char *__fastcall color_from_cluster_id(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = "#0000ff";
break;
case 2:
result = "#00ffff";
break;
case 3:
result = "#8A2BE2";
break;
case 4:
result = "#A52A2A";
break;
case 5:
result = "#7FFF00";
break;
case 6:
result = "#006400";
break;
case 7:
result = "#FFD700";
break;
case 8:
result = "#FF69B4";
break;
case 9:
result = "#FF4500";
break;
case 10:
result = "#C0C0C0";
break;
default:
result = "#C0C0C0";
break;
}
return result;
}

canonical_decompiled_code:
const char *__fastcall func4(int a1)
{
const char *result; // rax

switch ( a1 )
{
case 1:
result = "#0000ff";
break;
case 2:
result = "#00ffff";
break;
case 3:
result = "#8A2BE2";
break;
case 4:
result = "#A52A2A";
break;
case 5:
result = "#7FFF00";
break;
case 6:
result = "#006400";
break;
case 7:
result = "#FFD700";
break;
case 8:
result = "#FF69B4";
break;
case 9:
result = "#FF4500";
break;
case 10:
result = "#C0C0C0";
break;
default:
result = "#C0C0C0";
break;
}
return result;
}

original_code:
char *color_from_cluster_id(int cluster_id) {
 switch (cluster_id) {
 case 1: return "#0000ff";
 case 2: return "#00ffff";
 case 3: return "#8A2BE2";
 case 4: return "#A52A2A";
 case 5: return "#7FFF00";
 case 6: return "#006400";
 case 7: return "#FFD700";
 case 8: return "#FF69B4";
 case 9: return "#FF4500";
 case 10: return "#C0C0C0";
 default: return "#C0C0C0";
 }
}


decompiled_code:
__int64 __fastcall best_solution_writer(int *a1, _QWORD *a2, __int64 a3)
{
__int64 v3; // rax
__int64 result; // rax

v3 = get_full_path(a3, "best_clusters.xgmml");
if ( v3 )
result = write_all(a1, a2, 5, v3);
else
result = 2LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int *a1, _QWORD *a2, __int64 a3)
{
__int64 v3; // rax
__int64 result; // rax

v3 = get_full_path(a3, "best_clusters.xgmml");
if ( v3 )
result = func7(a1, a2, 5, v3);
else
result = 2LL;
return result;
}

original_code:
int best_solution_writer(network *net, int **edges, char *out_dir) {
 char *filename = get_full_path(out_dir, "best_clusters.xgmml");
 if (filename == ((void *)0)) {
  return 2;
 }
 return write_all(net, edges, 5, filename);
}

canonical_original_code:
int best_solution_writer(struct network *net, int **edges, char *out_dir) {
 char *filename = get_full_path(out_dir, "best_clusters.xgmml");
 if (filename == ((void *)0)) {
  return 2;
 }
 return write_all(net, edges, 5, filename);
}

variable_types: struct network { int num_of_vertices; void **vertices; } *

variable_types:
edges
int **

variable_types:
filename
char *


decompiled_code:
__int64 __fastcall cluster_sol_writer(int *a1, _QWORD *a2, __int64 a3, int a4)
{
__int64 v5; // rax
__int64 result; // rax

v5 = get_full_path(a3, "clustering_solution.xgmml");
if ( v5 )
result = write_all(a1, a2, a4, v5);
else
result = 2LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, _QWORD *a2, __int64 a3, int a4)
{
__int64 v5; // rax
__int64 result; // rax

v5 = get_full_path(a3, "clustering_solution.xgmml");
if ( v5 )
result = func7(a1, a2, a4, v5);
else
result = 2LL;
return result;
}

original_code:
int cluster_sol_writer(network *net, int **edges, char *out_dir, int num_of_clusters) {
 char *filename = get_full_path(out_dir, "clustering_solution.xgmml");
 if (filename == ((void *)0)) {
  return 2;
 }
 return write_all(net, edges, num_of_clusters, filename);
}

canonical_original_code:
int cluster_sol_writer(struct network *net, int **edges, char *out_dir, int num_of_clusters) {
 char *filename = get_full_path(out_dir, "clustering_solution.xgmml");
 if (filename == ((void *)0)) {
  return 2;
 }
 return write_all(net, edges, num_of_clusters, filename);
}


decompiled_code:
void __fastcall destroy_vertex(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 6) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 2) + 8 * v1++));
while ( *((_DWORD *)ptr + 6) > (int)v1 );
}
free(*((void **)ptr + 2));
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
__int64 v1; // rbx

if ( *((int *)ptr + 6) > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 2) + 8 * v1++));
while ( *((_DWORD *)ptr + 6) > (int)v1 );
}
free(*((void **)ptr + 2));
free(*(void **)ptr);
free(ptr);
}

original_code:
void destroy_vertex(vertex *vrtx) {
 if (vrtx->deg > 0) {
  int j;
  for (j = 0; j < vrtx->deg; j++)
   free(vrtx->adjacency_list[j]);
 }
 free(vrtx->adjacency_list);
 free(vrtx->name);
 free(vrtx);
}

canonical_original_code:
void destroy_vertex(struct vertex *vrtx) {
 if (vrtx->deg > 0) {
  int j;
  for (j = 0; j < vrtx->deg; j++)
   free(vrtx->adjacency_list[j]);
 }
 free(vrtx->adjacency_list);
 free(vrtx->name);
 free(vrtx);
}

variable_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; } *


decompiled_code:
__int64 __fastcall double_vertices(void **a1, __int64 a2)
{
void *v2; // rax
__int64 result; // rax

v2 = realloc(*a1, 16 * a2);
if ( v2 )
{
*a1 = v2;
result = 0LL;
}
else
{
send_perror("realloc");
result = 2LL;
}
return result;
}

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

v2 = realloc(*a1, 16 * a2);
if ( v2 )
{
*a1 = v2;
result = 0LL;
}
else
{
send_perror("realloc");
result = 2LL;
}
return result;
}

original_code:
int double_vertices(vertex ***v, size_t current_size) {
 vertex **tmp;
 if ((tmp = realloc(*v, 2 * current_size * sizeof(vertex*))) == ((void *)0)) {
  send_perror("realloc");
  return 2;
 } else {
  *v = tmp;
 }
 return 0;
}

canonical_original_code:
int double_vertices(struct vertex ***v, unsigned long current_size) {
 struct vertex **tmp;
 if ((tmp = realloc(*v, 2 * current_size * sizeof(struct vertex *))) == ((void *)0)) {
  send_perror("realloc");
  return 2;
 } else {
  *v = tmp;
 }
 return 0;
}

variable_types: struct vertex { char *name; int id; void **adjacency_list; int deg; int cluster_id; } ***