decompiled_code:
__int64 __fastcall st_slli_bp_mccreight_insert_suffix(int *a1, int *a2, _DWORD *a3, __int64 a4, __int64 a5, unsigned __int64 a6, _QWORD *a7)
{
__int64 v10; // rdi
__int64 v11; // r10
unsigned __int64 v12; // rax
__int64 v13; // rcx
unsigned __int64 v14; // rbx
int v15; // eax
unsigned int v16; // er13
__int64 v17; // rax
__int64 result; // rax
int v19; // er13
__int64 v20; // rdx
__int64 v21; // rcx
__int64 v22; // rax
__int64 v23; // rdx
unsigned __int64 v25; // [rsp+8h] [rbp-60h]
unsigned int v26; // [rsp+1Ch] [rbp-4Ch] BYREF
unsigned int v27; // [rsp+20h] [rbp-48h] BYREF
unsigned int v28; // [rsp+24h] [rbp-44h] BYREF
__int64 v29[8]; // [rsp+28h] [rbp-40h] BYREF

v10 = *a1;
v26 = 0;
v11 = a7[3];
v27 = 0;
v28 = 0;
v12 = a7[5];
v13 = a4 + *(unsigned int *)(v11 + 24 * v10 + 16);
v29[0] = v13;
if ( a7[4] == v12 && v12 < a6 )
{
v25 = a6;
if ( (int)st_slli_bp_reallocate(0LL, a6, a7) > 0 )
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
return 1LL;
}
v13 = v29[0];
v10 = (unsigned int)*a1;
a6 = v25;
}
v14 = a6 + 1;
while ( 1 )
{
v15 = st_slli_bp_branch_once(v10, &v26, &v27, v13, a5, a7);
if ( v15 )
{
if ( v15 != 1 )
{
v16 = -(int)a4;
if ( v15 == 2 )
{
fwrite(
"Information: Creating the first child of the parent.\nThis should not happen more than once!\n",
1uLL,
0x5CuLL,
stderr);
*(_DWORD *)(a7[3] + 24LL * *a1 + 4) = v16;
*(_QWORD *)(a7[2] + 8 * a4) = (unsigned int)*a1;
}
else
{
st_slli_bp_create_leaf((unsigned int)*a1, v26, v27, v16, a7);
}
v17 = *a1;
if ( (int)v17 > 1 )
*a1 = *(_DWORD *)(a7[3] + 24 * v17 + 12);
return 0LL;
}
fprintf(stderr, "Error: Insertion of the suffix number %zu failed!\n", a4);
return 4LL;
}
if ( (unsigned int)st_slli_bp_edge_slowscan((unsigned int)*a1, v26, v29[0], &v28, a5, v14, a7) )
break;
st_slli_bp_edge_descend(a1, &v26, &v27, v29, v14, a7);
v10 = (unsigned int)*a1;
if ( (int)v10 < 0 )
{
fwrite(
"Error: The newly inserted suffix already has the corresponding leaf node\npresent in the suffix tree!\n",
1uLL,
0x65uLL,
stderr);
return 2LL;
}
v13 = v29[0];
}
v19 = v26;
st_slli_bp_split_edge(a1, &v26, &v27, v29, v28, (unsigned int)a4, a7);
st_slli_bp_create_leaf((unsigned int)*a1, v26, v27, (unsigned int)-(int)a4, a7);
v20 = *a2;
if ( !(_DWORD)v20 )
{
v21 = a7[3];
goto LABEL_17;
}
if ( (unsigned int)*a3 + a4 == v29[0] )
{
v21 = a7[3];
*(_DWORD *)(v21 + 24 * v20 + 12) = *a1;
LABEL_17:
v22 = *a1;
*a2 = v22;
v23 = (unsigned int)(*(_DWORD *)(v21 + 24 * v22 + 16) - 1);
*a3 = v23;
result = st_slli_bp_simulate_suffix_link_bottom_up(a1, v19, v23, (__int64)a7);
if ( !(_DWORD)result )
{
*a2 = 0;
*a3 = 0;
return result;
}
return 0LL;
}
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v20);
return 3LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, int *a2, _DWORD *a3, __int64 a4, __int64 a5, unsigned __int64 a6, _QWORD *a7)
{
__int64 v10; // rdi
__int64 v11; // r10
unsigned __int64 v12; // rax
__int64 v13; // rcx
unsigned __int64 v14; // rbx
int v15; // eax
unsigned int v16; // er13
__int64 v17; // rax
__int64 result; // rax
int v19; // er13
__int64 v20; // rdx
__int64 v21; // rcx
__int64 v22; // rax
__int64 v23; // rdx
unsigned __int64 v25; // [rsp+8h] [rbp-60h]
unsigned int v26; // [rsp+1Ch] [rbp-4Ch] BYREF
unsigned int v27; // [rsp+20h] [rbp-48h] BYREF
unsigned int v28; // [rsp+24h] [rbp-44h] BYREF
__int64 v29[8]; // [rsp+28h] [rbp-40h] BYREF

v10 = *a1;
v26 = 0;
v11 = a7[3];
v27 = 0;
v28 = 0;
v12 = a7[5];
v13 = a4 + *(unsigned int *)(v11 + 24 * v10 + 16);
v29[0] = v13;
if ( a7[4] == v12 && v12 < a6 )
{
v25 = a6;
if ( (int)st_slli_bp_reallocate(0LL, a6, a7) > 0 )
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
return 1LL;
}
v13 = v29[0];
v10 = (unsigned int)*a1;
a6 = v25;
}
v14 = a6 + 1;
while ( 1 )
{
v15 = st_slli_bp_branch_once(v10, &v26, &v27, v13, a5, a7);
if ( v15 )
{
if ( v15 != 1 )
{
v16 = -(int)a4;
if ( v15 == 2 )
{
fwrite(
"Information: Creating the first child of the parent.\nThis should not happen more than once!\n",
1uLL,
0x5CuLL,
stderr);
*(_DWORD *)(a7[3] + 24LL * *a1 + 4) = v16;
*(_QWORD *)(a7[2] + 8 * a4) = (unsigned int)*a1;
}
else
{
st_slli_bp_create_leaf((unsigned int)*a1, v26, v27, v16, a7);
}
v17 = *a1;
if ( (int)v17 > 1 )
*a1 = *(_DWORD *)(a7[3] + 24 * v17 + 12);
return 0LL;
}
fprintf(stderr, "Error: Insertion of the suffix number %zu failed!\n", a4);
return 4LL;
}
if ( (unsigned int)st_slli_bp_edge_slowscan((unsigned int)*a1, v26, v29[0], &v28, a5, v14, a7) )
break;
st_slli_bp_edge_descend(a1, &v26, &v27, v29, v14, a7);
v10 = (unsigned int)*a1;
if ( (int)v10 < 0 )
{
fwrite(
"Error: The newly inserted suffix already has the corresponding leaf node\npresent in the suffix tree!\n",
1uLL,
0x65uLL,
stderr);
return 2LL;
}
v13 = v29[0];
}
v19 = v26;
st_slli_bp_split_edge(a1, &v26, &v27, v29, v28, (unsigned int)a4, a7);
st_slli_bp_create_leaf((unsigned int)*a1, v26, v27, (unsigned int)-(int)a4, a7);
v20 = *a2;
if ( !(_DWORD)v20 )
{
v21 = a7[3];
goto LABEL_17;
}
if ( (unsigned int)*a3 + a4 == v29[0] )
{
v21 = a7[3];
*(_DWORD *)(v21 + 24 * v20 + 12) = *a1;
LABEL_17:
v22 = *a1;
*a2 = v22;
v23 = (unsigned int)(*(_DWORD *)(v21 + 24 * v22 + 16) - 1);
*a3 = v23;
result = func0(a1, v19, v23, (__int64)a7);
if ( !(_DWORD)result )
{
*a2 = 0;
*a3 = 0;
return result;
}
return 0LL;
}
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v20);
return 3LL;
}

original_code:
int st_slli_bp_mccreight_insert_suffix (signed_integral_type *parent,
  signed_integral_type *sl_source,
  unsigned_integral_type *sl_targets_depth,
  size_t starting_position,
  const character_type *text,
  size_t length,
  suffix_tree_slli_bp *stree) {
 signed_integral_type latest_child = 0;
 signed_integral_type child = 0;
 signed_integral_type prev_child = 0;
 signed_integral_type last_match_position = 0;
 size_t position = starting_position +
  stree->tbranch[(*parent)].depth;
 size_t tbranch_size = (size_t)(stree->tbranch_size);
 int tmp = 0;
 if ((tbranch_size == stree->branching_nodes) &&
   (tbranch_size < length)) {
  if (st_slli_bp_reallocate((size_t)(0), length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_slli_bp_branch_once((*parent), &child, &prev_child,
     position, text, stree)) == 0) {
  if (st_slli_bp_edge_slowscan((*parent), child, position,
   &last_match_position, text, length + 1, stree) == 0) {
   st_slli_bp_edge_descend(parent, &child, &prev_child,
     &position, length + 1, stree);
   if ((*parent) < 0) {
    fprintf(stderr, "Error: The newly inserted "
      "suffix already has the "
      "corresponding leaf node\n"
      "present in the "
      "suffix tree!\n");
    return (2);
   }
  } else {
   latest_child = child;
   st_slli_bp_split_edge(parent, &child, &prev_child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     stree);
   st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (3);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_slli_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Insertion of the suffix number "
    "%zu failed!\n", starting_position);
  return (4);
 } else if (tmp == 2) {
  fprintf(stderr, "Information: Creating the first child "
    "of the parent.\nThis should not happen "
    "more than once!\n");
  stree->tbranch[(*parent)].first_child =
   (-(signed_integral_type)(starting_position));
  stree->tleaf[starting_position].parent = (*parent);
  stree->tleaf[starting_position].next_brother = 0;
 } else {
  st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 return (0);
}

canonical_original_code:
int st_slli_bp_mccreight_insert_suffix(int *parent, int *sl_source, unsigned int *sl_targets_depth, unsigned long starting_position, char *text, unsigned long length, struct suffix_tree_slli_bp_struct *stree) {
 int latest_child = 0;
 int child = 0;
 int prev_child = 0;
 int last_match_position = 0;
 unsigned long position = starting_position +
  stree->tbranch[(*parent)].depth;
 unsigned long tbranch_size = (size_t)(stree->tbranch_size);
 int tmp = 0;
 if ((tbranch_size == stree->branching_nodes) &&
   (tbranch_size < length)) {
  if (st_slli_bp_reallocate((unsigned long)(0), length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_slli_bp_branch_once((*parent), &child, &prev_child,
     position, text, stree)) == 0) {
  if (st_slli_bp_edge_slowscan((*parent), child, position,
   &last_match_position, text, length + 1, stree) == 0) {
   st_slli_bp_edge_descend(parent, &child, &prev_child,
     &position, length + 1, stree);
   if ((*parent) < 0) {
    fprintf(stderr, "Error: The newly inserted "
      "suffix already has the "
      "corresponding leaf node\n"
      "present in the "
      "suffix tree!\n");
    return (2);
   }
  } else {
   latest_child = child;
   st_slli_bp_split_edge(parent, &child, &prev_child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     stree);
   st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (3);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_slli_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Insertion of the suffix number "
    "%zu failed!\n", starting_position);
  return (4);
 } else if (tmp == 2) {
  fprintf(stderr, "Information: Creating the first child "
    "of the parent.\nThis should not happen "
    "more than once!\n");
  stree->tbranch[(*parent)].first_child =
   (-(signed_integral_type)(starting_position));
  stree->tleaf[starting_position].parent = (*parent);
  stree->tleaf[starting_position].next_brother = 0;
 } else {
  st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 return (0);
}

variable_types:
text
char *

variable_types:
length
unsigned long

variable_types:
position
unsigned long

user_defined_types: struct leaf_record_slli_bp_struct { int parent; int next_brother; }

user_defined_types: struct branch_record_slli_bp_struct { int parent; int first_child; int branch_brother; int suffix_link; unsigned int depth; unsigned int head_position; }


repo: pbasista/stc

decompiled_code:
__int64 __fastcall st_slli_bp_ukkonen_prolong_suffix(__int64 a1, __int64 a2, __int64 *a3, int *a4, int *a5, _DWORD *a6, __int64 a7, __int64 a8)
{
__int64 v9; // rcx
__int64 v11; // rdi
__int64 v12; // r13
int v13; // eax
__int64 v14; // r15
unsigned int v15; // eax
unsigned int v16; // er15
unsigned int v17; // er12
__int64 v18; // rdx
__int64 v19; // rax
int v20; // er12
__int64 v21; // rdx
__int64 v22; // rcx
__int64 v23; // rax
__int64 v24; // rdx
__int64 v25; // rax
__int64 v26; // rdx
unsigned int v31; // [rsp+2Ch] [rbp-4Ch] BYREF
unsigned int v32; // [rsp+30h] [rbp-48h] BYREF
unsigned int v33; // [rsp+34h] [rbp-44h] BYREF
__int64 v34[8]; // [rsp+38h] [rbp-40h] BYREF

v9 = *a3;
v31 = 0;
v32 = 0;
v33 = 0;
v34[0] = v9;
if ( a1 == a2 )
return (unsigned int)-1;
v11 = (unsigned int)*a4;
v12 = a2 - 1;
while ( 1 )
{
v15 = st_slli_bp_branch_once(v11, &v31, &v32, v9, a7, a8);
v16 = v15;
if ( v15 )
{
if ( v15 == 1 )
{
v16 = 2;
fprintf(stderr, "Error: Prolonging of the suffix number %zu to the length of %zu failed!\n", a1, a2 - a1);
}
else
{
v17 = -(int)a1;
if ( v15 == 2 )
{
fwrite(
"Information: Creating the first child of the parent.\nThis should not happen more than once!\n",
1uLL,
0x5CuLL,
stderr);
v18 = *(_QWORD *)(a8 + 24);
*(_DWORD *)(v18 + 24LL * *a4 + 4) = v17;
*(_QWORD *)(*(_QWORD *)(a8 + 16) + 8 * a1) = (unsigned int)*a4;
}
else
{
st_slli_bp_create_leaf((unsigned int)*a4, v31, v32, v17, a8);
v18 = *(_QWORD *)(a8 + 24);
}
v19 = *a4;
if ( (int)v19 > 1 )
{
v19 = *(int *)(v18 + 24 * v19 + 12);
*a4 = v19;
}
v16 = 0;
*a3 = a1 + *(unsigned int *)(v18 + 24 * v19 + 16) + 1;
}
return v16;
}
v13 = st_slli_bp_edge_slowscan((unsigned int)*a4, v31, v34[0], &v33, a7, v12, a8);
if ( v13 )
break;
v14 = *a4;
st_slli_bp_edge_descend(a4, &v31, &v32, v34, v12, a8);
v11 = (unsigned int)*a4;
if ( (int)v11 < 0 )
{
*a4 = v14;
v25 = *(_QWORD *)(a8 + 24);
if ( (_DWORD)v14 != 1 )
{
v14 = *(int *)(v25 + 24 * v14 + 12);
*a4 = v14;
}
v26 = 3 * v14;
v16 = -2;
*a3 = a1 + *(unsigned int *)(v25 + 8 * v26 + 16) + 1;
return v16;
}
if ( a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * (int)v11 + 16) == a2 )
{
v16 = -3;
*a3 = a2;
return v16;
}
v9 = v34[0];
}
if ( v13 == 2 )
{
v16 = -4;
*a3 = *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + a1;
}
else
{
v20 = v31;
st_slli_bp_split_edge(a4, &v31, &v32, v34, v33, (unsigned int)a1, a8);
st_slli_bp_create_leaf((unsigned int)*a4, v31, v32, (unsigned int)-(int)a1, a8);
v21 = *a5;
if ( (_DWORD)v21 )
{
if ( a1 + (unsigned int)*a6 != v34[0] )
{
v16 = 1;
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v21);
return v16;
}
v22 = *(_QWORD *)(a8 + 24);
*(_DWORD *)(v22 + 24 * v21 + 12) = *a4;
}
else
{
v22 = *(_QWORD *)(a8 + 24);
}
v23 = *a4;
*a5 = v23;
v24 = (unsigned int)(*(_DWORD *)(v22 + 24 * v23 + 16) - 1);
*a6 = v24;
if ( !(unsigned int)st_slli_bp_simulate_suffix_link_bottom_up(a4, v20, v24, a8) )
{
*a5 = 0;
*a6 = 0;
}
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + 1;
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 *a3, int *a4, int *a5, _DWORD *a6, __int64 a7, __int64 a8)
{
__int64 v9; // rcx
__int64 v11; // rdi
__int64 v12; // r13
int v13; // eax
__int64 v14; // r15
unsigned int v15; // eax
unsigned int v16; // er15
unsigned int v17; // er12
__int64 v18; // rdx
__int64 v19; // rax
int v20; // er12
__int64 v21; // rdx
__int64 v22; // rcx
__int64 v23; // rax
__int64 v24; // rdx
__int64 v25; // rax
__int64 v26; // rdx
unsigned int v31; // [rsp+2Ch] [rbp-4Ch] BYREF
unsigned int v32; // [rsp+30h] [rbp-48h] BYREF
unsigned int v33; // [rsp+34h] [rbp-44h] BYREF
__int64 v34[8]; // [rsp+38h] [rbp-40h] BYREF

v9 = *a3;
v31 = 0;
v32 = 0;
v33 = 0;
v34[0] = v9;
if ( a1 == a2 )
return (unsigned int)-1;
v11 = (unsigned int)*a4;
v12 = a2 - 1;
while ( 1 )
{
v15 = st_slli_bp_branch_once(v11, &v31, &v32, v9, a7, a8);
v16 = v15;
if ( v15 )
{
if ( v15 == 1 )
{
v16 = 2;
fprintf(stderr, "Error: Prolonging of the suffix number %zu to the length of %zu failed!\n", a1, a2 - a1);
}
else
{
v17 = -(int)a1;
if ( v15 == 2 )
{
fwrite(
"Information: Creating the first child of the parent.\nThis should not happen more than once!\n",
1uLL,
0x5CuLL,
stderr);
v18 = *(_QWORD *)(a8 + 24);
*(_DWORD *)(v18 + 24LL * *a4 + 4) = v17;
*(_QWORD *)(*(_QWORD *)(a8 + 16) + 8 * a1) = (unsigned int)*a4;
}
else
{
st_slli_bp_create_leaf((unsigned int)*a4, v31, v32, v17, a8);
v18 = *(_QWORD *)(a8 + 24);
}
v19 = *a4;
if ( (int)v19 > 1 )
{
v19 = *(int *)(v18 + 24 * v19 + 12);
*a4 = v19;
}
v16 = 0;
*a3 = a1 + *(unsigned int *)(v18 + 24 * v19 + 16) + 1;
}
return v16;
}
v13 = st_slli_bp_edge_slowscan((unsigned int)*a4, v31, v34[0], &v33, a7, v12, a8);
if ( v13 )
break;
v14 = *a4;
st_slli_bp_edge_descend(a4, &v31, &v32, v34, v12, a8);
v11 = (unsigned int)*a4;
if ( (int)v11 < 0 )
{
*a4 = v14;
v25 = *(_QWORD *)(a8 + 24);
if ( (_DWORD)v14 != 1 )
{
v14 = *(int *)(v25 + 24 * v14 + 12);
*a4 = v14;
}
v26 = 3 * v14;
v16 = -2;
*a3 = a1 + *(unsigned int *)(v25 + 8 * v26 + 16) + 1;
return v16;
}
if ( a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * (int)v11 + 16) == a2 )
{
v16 = -3;
*a3 = a2;
return v16;
}
v9 = v34[0];
}
if ( v13 == 2 )
{
v16 = -4;
*a3 = *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + a1;
}
else
{
v20 = v31;
st_slli_bp_split_edge(a4, &v31, &v32, v34, v33, (unsigned int)a1, a8);
st_slli_bp_create_leaf((unsigned int)*a4, v31, v32, (unsigned int)-(int)a1, a8);
v21 = *a5;
if ( (_DWORD)v21 )
{
if ( a1 + (unsigned int)*a6 != v34[0] )
{
v16 = 1;
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v21);
return v16;
}
v22 = *(_QWORD *)(a8 + 24);
*(_DWORD *)(v22 + 24 * v21 + 12) = *a4;
}
else
{
v22 = *(_QWORD *)(a8 + 24);
}
v23 = *a4;
*a5 = v23;
v24 = (unsigned int)(*(_DWORD *)(v22 + 24 * v23 + 16) - 1);
*a6 = v24;
if ( !(unsigned int)func0(a4, v20, v24, a8) )
{
*a5 = 0;
*a6 = 0;
}
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 24) + 24LL * *a4 + 16) + 1;
}
return v16;
}

original_code:
int st_slli_bp_ukkonen_prolong_suffix (size_t starting_position,
  size_t ending_position,
  size_t *active_index,
  signed_integral_type *parent,
  signed_integral_type *sl_source,
  unsigned_integral_type *sl_targets_depth,
  const character_type *text,
  suffix_tree_slli_bp *stree) {
 signed_integral_type latest_child = 0;
 signed_integral_type grandpa = 0;
 signed_integral_type child = 0;
 signed_integral_type prev_child = 0;
 signed_integral_type last_match_position = 0;
 size_t position = (*active_index);
 int tmp = 0;
 int slowscan_return = 0;
 if (starting_position == ending_position) {
  return (-1);
 }
 while ((tmp = st_slli_bp_branch_once((*parent), &child, &prev_child,
     position, text, stree)) == 0) {
  if ((slowscan_return = st_slli_bp_edge_slowscan((*parent),
    child, position, &last_match_position, text,
    ending_position - 1, stree)) == 0) {
   grandpa = (*parent);
   st_slli_bp_edge_descend(parent, &child, &prev_child,
     &position, ending_position - 1, stree);
   if ((*parent) < 0) {
    (*parent) = grandpa;
    if ((*parent) != 1) {
     (*parent) = stree->tbranch[(*parent)].
      suffix_link;
    }
    (*active_index) = starting_position + 1 +
    (size_t)(stree->tbranch[(*parent)].depth);
    return (-2);
   } else if (starting_position +
     stree->tbranch[(*parent)].depth ==
     ending_position) {
    (*active_index) = starting_position +
     stree->tbranch[(*parent)].depth;
    return (-3);
   }
  } else if (slowscan_return == 2) {
   (*active_index) = starting_position +
    stree->tbranch[(*parent)].depth;
   return (-4);
  } else {
   latest_child = child;
   st_slli_bp_split_edge(parent, &child, &prev_child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     stree);
   st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (1);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_slli_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   (*active_index) = starting_position + 1 +
    stree->tbranch[(*parent)].depth;
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Prolonging of the suffix number "
    "%zu to the length of %zu failed!\n",
    starting_position,
    ending_position - starting_position);
  return (2);
 } else if (tmp == 2) {
  fprintf(stderr, "Information: Creating the first child "
    "of the parent.\nThis should not happen "
    "more than once!\n");
  stree->tbranch[(*parent)].first_child =
   (-(signed_integral_type)(starting_position));
  stree->tleaf[starting_position].parent = (*parent);
  stree->tleaf[starting_position].next_brother = 0;
 } else {
  st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 (*active_index) = starting_position + 1 +
  stree->tbranch[(*parent)].depth;
 return (0);
}

canonical_original_code:
int st_slli_bp_ukkonen_prolong_suffix(unsigned long starting_position, unsigned long ending_position, unsigned long *active_index, int *parent, int *sl_source, unsigned int *sl_targets_depth, char *text, struct suffix_tree_slli_bp_struct *stree) {
 int latest_child = 0;
 int grandpa = 0;
 int child = 0;
 int prev_child = 0;
 int last_match_position = 0;
 unsigned long position = (*active_index);
 int tmp = 0;
 int slowscan_return = 0;
 if (starting_position == ending_position) {
  return (-1);
 }
 while ((tmp = st_slli_bp_branch_once((*parent), &child, &prev_child,
     position, text, stree)) == 0) {
  if ((slowscan_return = st_slli_bp_edge_slowscan((*parent),
    child, position, &last_match_position, text,
    ending_position - 1, stree)) == 0) {
   grandpa = (*parent);
   st_slli_bp_edge_descend(parent, &child, &prev_child,
     &position, ending_position - 1, stree);
   if ((*parent) < 0) {
    (*parent) = grandpa;
    if ((*parent) != 1) {
     (*parent) = stree->tbranch[(*parent)].
      suffix_link;
    }
    (*active_index) = starting_position + 1 +
    (unsigned long)(stree->tbranch[(*parent)].depth);
    return (-2);
   } else if (starting_position +
     stree->tbranch[(*parent)].depth ==
     ending_position) {
    (*active_index) = starting_position +
     stree->tbranch[(*parent)].depth;
    return (-3);
   }
  } else if (slowscan_return == 2) {
   (*active_index) = starting_position +
    stree->tbranch[(*parent)].depth;
   return (-4);
  } else {
   latest_child = child;
   st_slli_bp_split_edge(parent, &child, &prev_child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     stree);
   st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (1);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_slli_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   (*active_index) = starting_position + 1 +
    stree->tbranch[(*parent)].depth;
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Prolonging of the suffix number "
    "%zu to the length of %zu failed!\n",
    starting_position,
    ending_position - starting_position);
  return (2);
 } else if (tmp == 2) {
  fprintf(stderr, "Information: Creating the first child "
    "of the parent.\nThis should not happen "
    "more than once!\n");
  stree->tbranch[(*parent)].first_child =
   (-(signed_integral_type)(starting_position));
  stree->tleaf[starting_position].parent = (*parent);
  stree->tleaf[starting_position].next_brother = 0;
 } else {
  st_slli_bp_create_leaf((*parent), child, prev_child,
    (-(signed_integral_type)(starting_position)),
    stree);
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 (*active_index) = starting_position + 1 +
  stree->tbranch[(*parent)].depth;
 return (0);
}

variable_types:
parent
int *

variable_types: struct suffix_tree_slli_bp_struct { unsigned long lr_size; unsigned long br_size; struct leaf_record_slli_bp_struct { int parent; int next_brother; } *tleaf; struct branch_record_slli_bp_struct { int parent; int first_child; int branch_brother; int suffix_link; unsigned int depth; unsigned int head_position; } *tbranch; unsigned long branching_nodes; unsigned long tbranch_size; unsigned long tbsize_increase; } *

variable_types: grandpa int

variable_types: child int

variable_types: tmp int

return_type: int

user_defined_types: struct suffix_tree_slli_bp_struct { unsigned long lr_size; unsigned long br_size; struct leaf_record_slli_bp_struct *tleaf; struct branch_record_slli_bp_struct *tbranch; unsigned long branching_nodes; unsigned long tbranch_size; unsigned long tbsize_increase; }


decompiled_code:
__int64 __fastcall st_slli_bp_ukkonen_prolong_suffixes(__int64 *a1, __int64 a2, __int64 *a3, int *a4, __int64 a5, unsigned __int64 a6, __int64 a7)
{
unsigned __int64 v7; // rax
__int64 v12; // rdi
unsigned __int64 v13; // r8
int v14; // eax
__int64 v15; // rdi
unsigned int v16; // er8
int v18; // eax
int v19; // [rsp+8h] [rbp-40h] BYREF
int v20[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v7 = a6;
v12 = *a1;
v19 = 0;
v20[0] = 0;
v13 = *(_QWORD *)(a7 + 32) + a2 - 1 - v12;
if ( v13 <= a6 )
v7 = *(_QWORD *)(a7 + 32) + a2 - 1 - v12;
if ( v7 > *(_QWORD *)(a7 + 40) )
{
v18 = st_slli_bp_reallocate(v13, a6, a7);
if ( v18 > 0 )
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
return 1;
}
v12 = *a1;
}
while ( 1 )
{
v14 = st_slli_bp_ukkonen_prolong_suffix(v12, a2, a3, a4, &v19, v20, a5, a7);
if ( v14 != -1 )
break;
v12 = *a1 + 1;
*a1 = v12;
}
for ( ; !v14; v14 = st_slli_bp_ukkonen_prolong_suffix(v15, a2, a3, a4, &v19, v20, a5, a7) )
{
v15 = *a1 + 1;
*a1 = v15;
}
v16 = 0;
if ( v14 > 0 )
{
fprintf(stderr, "Error: Could not prolong suffixes to the ending position %zu!\n", a2);
v16 = 2;
}
return v16;
}

original_code:
int st_slli_bp_ukkonen_prolong_suffixes (size_t *starting_position,
  size_t ending_position,
  size_t *active_index,
  signed_integral_type *active_node,
  const character_type *text,
  size_t length,
  suffix_tree_slli_bp *stree) {
 signed_integral_type sl_source = 0;
 unsigned_integral_type sl_targets_depth = 0;
 size_t maximum_possible_size = stree->branching_nodes +
  ending_position - (*starting_position) - 1;
 int tmp = 0;
 size_t tbranch_size = (size_t)(stree->tbranch_size);
 if ((tbranch_size < maximum_possible_size) &&
   (tbranch_size < length)) {
  if (st_slli_bp_reallocate(maximum_possible_size,
     length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_slli_bp_ukkonen_prolong_suffix((*starting_position),
     ending_position, active_index,
     active_node, &sl_source,
     &sl_targets_depth, text,
     stree)) == (-1)) {
  ++(*starting_position);
 }
 while (tmp == 0) {
  ++(*starting_position);
  tmp = st_slli_bp_ukkonen_prolong_suffix((*starting_position),
   ending_position, active_index, active_node, &sl_source,
   &sl_targets_depth, text, stree);
 }
 if (tmp > 0) {
  fprintf(stderr, "Error: Could not prolong suffixes "
    "to the ending position %zu!\n",
    ending_position);
  return (2);
 }
 return (0);
}

canonical_original_code:
int st_slli_bp_ukkonen_prolong_suffixes(unsigned long *starting_position, unsigned long ending_position, unsigned long *active_index, int *active_node, char *text, unsigned long length, struct suffix_tree_slli_bp_struct *stree) {
 int sl_source = 0;
 unsigned int sl_targets_depth = 0;
 unsigned long maximum_possible_size = stree->branching_nodes +
  ending_position - (*starting_position) - 1;
 int tmp = 0;
 unsigned long tbranch_size = (size_t)(stree->tbranch_size);
 if ((tbranch_size < maximum_possible_size) &&
   (tbranch_size < length)) {
  if (st_slli_bp_reallocate(maximum_possible_size,
     length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_slli_bp_ukkonen_prolong_suffix((*starting_position),
     ending_position, active_index,
     active_node, &sl_source,
     &sl_targets_depth, text,
     stree)) == (-1)) {
  ++(*starting_position);
 }
 while (tmp == 0) {
  ++(*starting_position);
  tmp = st_slli_bp_ukkonen_prolong_suffix((*starting_position),
   ending_position, active_index, active_node, &sl_source,
   &sl_targets_depth, text, stree);
 }
 if (tmp > 0) {
  fprintf(stderr, "Error: Could not prolong suffixes "
    "to the ending position %zu!\n",
    ending_position);
  return (2);
 }
 return (0);
}


decompiled_code:
__int64 __fastcall st_slli_bp_create_mccreight(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // r12
__int64 result; // rax
int v6; // [rsp+4h] [rbp-34h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = 1;
v7 = 0;
v8[0] = 0;
puts("Creating suffix tree using McCright's algorithm\n");
if ( (int)st_slli_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 1LL;
if ( a2 < 0xFFFFFFFFFFFFFFFELL )
{
while ( (int)st_slli_bp_mccreight_insert_suffix(&v6, &v7, v8, v4, a1, a2, a3) <= 0 )
{
if ( ++v4 == a2 + 2 )
goto LABEL_7;
}
fprintf(stderr, "Could not insert suffix number %zu. Exiting.\n", v4);
result = 2LL;
}
else
{
LABEL_7:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a2, 0LL, a3[4], 0LL, 0LL, a3[5], 0LL, *a3, 0LL, a3[1], 0LL, 0LL, 0LL);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // r12
__int64 result; // rax
int v6; // [rsp+4h] [rbp-34h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = 1;
v7 = 0;
v8[0] = 0;
puts("Creating suffix tree using McCright's algorithm\n");
if ( (int)st_slli_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 1LL;
if ( a2 < 0xFFFFFFFFFFFFFFFELL )
{
while ( (int)func1(&v6, &v7, v8, v4, a1, a2, a3) <= 0 )
{
if ( ++v4 == a2 + 2 )
goto LABEL_7;
}
fprintf(stderr, "Could not insert suffix number %zu. Exiting.\n", v4);
result = 2LL;
}
else
{
LABEL_7:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a2, 0LL, a3[4], 0LL, 0LL, a3[5], 0LL, *a3, 0LL, a3[1], 0LL, 0LL, 0LL);
result = 0LL;
}
}
return result;
}

original_code:
int st_slli_bp_create_mccreight (const character_type *text,
  size_t length,
  suffix_tree_slli_bp *stree) {
 signed_integral_type starting_node = 1;
 signed_integral_type sl_source = 0;
 unsigned_integral_type sl_targets_depth = 0;
 size_t i = 1;
 printf("Creating suffix tree using McCright's algorithm\n\n");
 if (st_slli_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 1; i < length + 2; ++i) {
  if (st_slli_bp_mccreight_insert_suffix(&starting_node,
     &sl_source, &sl_targets_depth, i,
     text, length, stree) > 0) {
   fprintf(stderr, "Could not insert suffix number "
     "%zu. Exiting.\n", i);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (size_t)(0), stree->branching_nodes,
   (size_t)(0), (size_t)(0), stree->tbranch_size,
   (size_t)(0), stree->lr_size, (size_t)(0),
   stree->br_size, (size_t)(0),
   (size_t)(0), (size_t)(0));
 return (0);
}

canonical_original_code:
int st_slli_bp_create_mccreight(char *text, unsigned long length, struct suffix_tree_slli_bp_struct *stree) {
 int starting_node = 1;
 int sl_source = 0;
 unsigned int sl_targets_depth = 0;
 unsigned long i = 1;
 printf("Creating suffix tree using McCright's algorithm\n\n");
 if (st_slli_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 1; i < length + 2; ++i) {
  if (st_slli_bp_mccreight_insert_suffix(&starting_node,
     &sl_source, &sl_targets_depth, i,
     text, length, stree) > 0) {
   fprintf(stderr, "Could not insert suffix number "
     "%zu. Exiting.\n", i);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (unsigned long)(0), stree->branching_nodes,
   (unsigned long)(0), (unsigned long)(0), stree->tbranch_size,
   (unsigned long)(0), stree->lr_size, (unsigned long)(0),
   stree->br_size, (unsigned long)(0),
   (unsigned long)(0), (unsigned long)(0));
 return (0);
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall st_slli_bp_create_ukkonen(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
int v6; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+18h] [rbp-30h] BYREF

v6 = 1;
v7 = 1LL;
v8[0] = 1LL;
puts("Creating suffix tree using Ukkonen's algorithm\n");
if ( (int)st_slli_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 2LL;
if ( a2 < 0xFFFFFFFFFFFFFFFELL )
{
while ( (int)st_slli_bp_ukkonen_prolong_suffixes(v8, v4, &v7, &v6, a1, a2, (__int64)a3) <= 0 )
{
if ( ++v4 > a2 + 2 )
goto LABEL_7;
}
fprintf(stderr, "Could not create the intermediate tree number %zu. Exiting.\n", v4 - 1);
result = 2LL;
}
else
{
LABEL_7:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a2, 0LL, a3[4], 0LL, 0LL, a3[5], 0LL, *a3, 0LL, a3[1], 0LL, 0LL, 0LL);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
int v6; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+18h] [rbp-30h] BYREF

v6 = 1;
v7 = 1LL;
v8[0] = 1LL;
puts("Creating suffix tree using Ukkonen's algorithm\n");
if ( (int)st_slli_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 2LL;
if ( a2 < 0xFFFFFFFFFFFFFFFELL )
{
while ( (int)func3(v8, v4, &v7, &v6, a1, a2, (__int64)a3) <= 0 )
{
if ( ++v4 > a2 + 2 )
goto LABEL_7;
}
fprintf(stderr, "Could not create the intermediate tree number %zu. Exiting.\n", v4 - 1);
result = 2LL;
}
else
{
LABEL_7:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(a2, 0LL, a3[4], 0LL, 0LL, a3[5], 0LL, *a3, 0LL, a3[1], 0LL, 0LL, 0LL);
result = 0LL;
}
}
return result;
}

original_code:
int st_slli_bp_create_ukkonen (const character_type *text,
  size_t length,
  suffix_tree_slli_bp *stree) {
 signed_integral_type active_node = 1;
 size_t active_index = 1;
 size_t starting_position = 1;
 size_t i = 1;
 printf("Creating suffix tree using Ukkonen's algorithm\n\n");
 if (st_slli_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 2; i <= length + 2; ++i) {
  if (st_slli_bp_ukkonen_prolong_suffixes(&starting_position, i,
     &active_index, &active_node, text,
     length, stree) > 0) {
   fprintf(stderr, "Could not create the intermediate "
     "tree number %zu. Exiting.\n", i - 1);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (size_t)(0), stree->branching_nodes,
   (size_t)(0), (size_t)(0), stree->tbranch_size,
   (size_t)(0), stree->lr_size, (size_t)(0),
   stree->br_size, (size_t)(0),
   (size_t)(0), (size_t)(0));
 return (0);
}

canonical_original_code:
int st_slli_bp_create_ukkonen(char *text, unsigned long length, struct suffix_tree_slli_bp_struct *stree) {
 int active_node = 1;
 unsigned long active_index = 1;
 unsigned long starting_position = 1;
 unsigned long i = 1;
 printf("Creating suffix tree using Ukkonen's algorithm\n\n");
 if (st_slli_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 2; i <= length + 2; ++i) {
  if (st_slli_bp_ukkonen_prolong_suffixes(&starting_position, i,
     &active_index, &active_node, text,
     length, stree) > 0) {
   fprintf(stderr, "Could not create the intermediate "
     "tree number %zu. Exiting.\n", i - 1);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, (unsigned long)(0), stree->branching_nodes,
   (unsigned long)(0), (unsigned long)(0), stree->tbranch_size,
   (unsigned long)(0), stree->lr_size, (unsigned long)(0),
   stree->br_size, (unsigned long)(0),
   (unsigned long)(0), (unsigned long)(0));
 return (0);
}


decompiled_code:
__int64 __fastcall st_shti_bp_simulate_suffix_link_bottom_up(int *a1, int a2, __int64 a3, __int64 a4)
{
int v5; // ecx
__int64 v6; // r12
__int64 result; // rax
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v8[0] = a2;
if ( a2 )
{
v5 = a2 - 1;
if ( a2 > 0 )
v5 = *(_DWORD *)(*(_QWORD *)(a4 + 72) + 16LL * a2 + 12);
v6 = *a1;
v8[0] = v5;
*a1 = 0;
result = st_shti_bp_go_up(a1, v8, a3, a4);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -1 )
{
fwrite("Error: Suffix link simulation failed permanently!\n", 1uLL, 0x32uLL, stderr);
result = 2LL;
}
}
else
{
*(_DWORD *)(*(_QWORD *)(a4 + 72) + 16 * v6 + 12) = *a1;
}
}
else
{
fwrite("Error: Invalid number of child (0)!\n", 1uLL, 0x24uLL, stderr);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2, __int64 a3, __int64 a4)
{
int v5; // ecx
__int64 v6; // r12
__int64 result; // rax
int v8[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v8[0] = a2;
if ( a2 )
{
v5 = a2 - 1;
if ( a2 > 0 )
v5 = *(_DWORD *)(*(_QWORD *)(a4 + 72) + 16LL * a2 + 12);
v6 = *a1;
v8[0] = v5;
*a1 = 0;
result = st_shti_bp_go_up(a1, v8, a3, a4);
if ( (_DWORD)result )
{
if ( (_DWORD)result != -1 )
{
fwrite("Error: Suffix link simulation failed permanently!\n", 1uLL, 0x32uLL, stderr);
result = 2LL;
}
}
else
{
*(_DWORD *)(*(_QWORD *)(a4 + 72) + 16 * v6 + 12) = *a1;
}
}
else
{
fwrite("Error: Invalid number of child (0)!\n", 1uLL, 0x24uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int st_shti_bp_simulate_suffix_link_bottom_up (signed_integral_type *parent,
  signed_integral_type child,
  unsigned_integral_type target_depth,
  suffix_tree_shti_bp *stree) {
 signed_integral_type starting_from = (*parent);
 int tmp = 0;
 if (child == 0) {
  fprintf(stderr, "Error: Invalid number of child (0)!\n");
  return (1);
 } else if (child > 0) {
  child = stree->tbranch[child].suffix_link;
 } else {
  child = child - 1;
 }
 (*parent) = 0;
 if ((tmp = st_shti_bp_go_up(parent, &child, target_depth,
     stree)) == 0) {
  stree->tbranch[starting_from].suffix_link = (*parent);
  return (0);
 } else if (tmp == (-1)) {
  return (-1);
 } else {
  fprintf(stderr, "Error: Suffix link simulation "
    "failed permanently!\n");
  return (2);
 }
}

canonical_original_code:
int st_shti_bp_simulate_suffix_link_bottom_up(int *parent, int child, unsigned int target_depth, struct suffix_tree_shti_bp_struct *stree) {
 int starting_from = (*parent);
 int tmp = 0;
 if (child == 0) {
  fprintf(stderr, "Error: Invalid number of child (0)!\n");
  return (1);
 } else if (child > 0) {
  child = stree->tbranch[child].suffix_link;
 } else {
  child = child - 1;
 }
 (*parent) = 0;
 if ((tmp = st_shti_bp_go_up(parent, &child, target_depth,
     stree)) == 0) {
  stree->tbranch[starting_from].suffix_link = (*parent);
  return (0);
 } else if (tmp == (-1)) {
  return (-1);
 } else {
  fprintf(stderr, "Error: Suffix link simulation "
    "failed permanently!\n");
  return (2);
 }
}

variable_types: struct suffix_tree_shti_bp_struct { unsigned long hs_size; unsigned long lr_size; unsigned long er_size; unsigned long br_size; int crt_type; unsigned long chf_number; struct hash_settings_struct { int crt_type; unsigned int phf_max; unsigned int shf_max; unsigned long chf_number; unsigned int npu_size; unsigned int *chf_as; unsigned int *chf_bs; unsigned long *cp_offsets; unsigned long *cp_sizes; unsigned long allocated_size; } *hs; struct leaf_record_shti_bp_struct { int parent; } *tleaf; struct edge_record_struct { int source_node; int target_node; } *tedge; struct branch_record_shti_bp_struct { int parent; unsigned int depth; unsigned int head_position; int suffix_link; } *tbranch; unsigned long edges; unsigned long tedge_size; unsigned long tesize_increase; unsigned long branching_nodes; unsigned long tbranch_size; unsigned long tbsize_increase; } *

user_defined_types: struct suffix_tree_shti_bp_struct { unsigned long hs_size; unsigned long lr_size; unsigned long er_size; unsigned long br_size; int crt_type; unsigned long chf_number; struct hash_settings_struct *hs; struct leaf_record_shti_bp_struct *tleaf; struct edge_record_struct *tedge; struct branch_record_shti_bp_struct *tbranch; unsigned long edges; unsigned long tedge_size; unsigned long tesize_increase; unsigned long branching_nodes; unsigned long tbranch_size; unsigned long tbsize_increase; }


decompiled_code:
__int64 __fastcall st_shti_bp_mccreight_insert_suffix(int *a1, int *a2, _DWORD *a3, __int64 a4, __int64 a5, unsigned __int64 a6, _QWORD *a7)
{
__int64 v10; // rdi
__int64 v11; // rax
__int64 v12; // rdx
unsigned __int64 v13; // rax
__int64 v14; // rdx
unsigned __int64 v15; // rbx
int v16; // eax
__int64 result; // rax
__int64 v18; // rdx
int v19; // ebx
__int64 v20; // rdx
__int64 v21; // rcx
__int64 v22; // rax
__int64 v23; // rdx
unsigned __int64 v25; // [rsp+8h] [rbp-60h]
unsigned int v26; // [rsp+1Ch] [rbp-4Ch] BYREF
int v27; // [rsp+20h] [rbp-48h] BYREF
unsigned int v28; // [rsp+24h] [rbp-44h] BYREF
__int64 v29[8]; // [rsp+28h] [rbp-40h] BYREF

v10 = *a1;
v26 = 0;
v11 = a7[9] + 16 * v10;
v27 = 0;
v12 = *(unsigned int *)(v11 + 4);
v13 = a7[14];
v28 = 0;
v14 = a4 + v12;
v29[0] = v14;
if ( a7[13] == v13 && v13 < a6 )
{
v25 = a6;
if ( (int)st_shti_bp_reallocate(v13 + 1, 0LL, a5, a6, a7) > 0 )
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
return 1LL;
}
v14 = v29[0];
v10 = (unsigned int)*a1;
a6 = v25;
}
v15 = a6 + 1;
while ( 1 )
{
v16 = st_shti_bp_branch_once(v10, &v26, v14, a5, a7);
if ( v16 )
{
if ( v16 == 1 )
{
fprintf(stderr, "Error: Insertion of the suffix number %zu failed!\n", a4);
result = 6LL;
}
else
{
result = st_shti_bp_create_leaf(
*a1,
(unsigned int)*(char *)(a5 + a4 + *(unsigned int *)(a7[9] + 16LL * *a1 + 4)),
(unsigned int)-(int)a4,
a5,
a7);
if ( !(_DWORD)result )
{
v18 = *a1;
if ( (int)v18 > 1 )
{
*a1 = *(_DWORD *)(a7[9] + 16 * v18 + 12);
return result;
}
return 0LL;
}
fwrite("Error: Could not create a new leaf of the parent!\n", 1uLL, 0x32uLL, stderr);
result = 7LL;
}
return result;
}
if ( (unsigned int)st_shti_bp_edge_slowscan((unsigned int)*a1, v26, v29[0], &v28, a5, v15, a7) )
break;
st_shti_bp_edge_descend(a1, &v26, &v27, v29, v15, a7);
v10 = (unsigned int)*a1;
if ( (int)v10 < 0 )
{
fwrite(
"Error: The newly inserted suffix already has the corresponding leaf node\npresent in the suffix tree!\n",
1uLL,
0x65uLL,
stderr);
return 2LL;
}
v14 = v29[0];
}
v19 = v26;
if ( (unsigned int)st_shti_bp_split_edge(
a1,
(unsigned int)*(char *)(a5 + v29[0]),
&v26,
v29,
v28,
(unsigned int)a4,
a5,
a7) )
{
fwrite("Error: Could not split the parent->child edge!\n", 1uLL, 0x2FuLL, stderr);
result = 3LL;
}
else if ( (unsigned int)st_shti_bp_create_leaf(
(unsigned int)*a1,
(unsigned int)*(char *)(a5 + v29[0]),
(unsigned int)-(int)a4,
a5,
a7) )
{
fwrite("Error: Could not create a new leaf of the parent!\n", 1uLL, 0x32uLL, stderr);
result = 4LL;
}
else
{
v20 = *a2;
if ( !(_DWORD)v20 )
{
v21 = a7[9];
goto LABEL_17;
}
if ( (unsigned int)*a3 + a4 == v29[0] )
{
v21 = a7[9];
*(_DWORD *)(v21 + 16 * v20 + 12) = *a1;
LABEL_17:
v22 = *a1;
*a2 = v22;
v23 = (unsigned int)(*(_DWORD *)(v21 + 16 * v22 + 4) - 1);
*a3 = v23;
result = st_shti_bp_simulate_suffix_link_bottom_up(a1, v19, v23, (__int64)a7);
if ( !(_DWORD)result )
{
*a2 = 0;
*a3 = 0;
return result;
}
return 0LL;
}
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v20);
result = 5LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1, int *a2, _DWORD *a3, __int64 a4, __int64 a5, unsigned __int64 a6, _QWORD *a7)
{
__int64 v10; // rdi
__int64 v11; // rax
__int64 v12; // rdx
unsigned __int64 v13; // rax
__int64 v14; // rdx
unsigned __int64 v15; // rbx
int v16; // eax
__int64 result; // rax
__int64 v18; // rdx
int v19; // ebx
__int64 v20; // rdx
__int64 v21; // rcx
__int64 v22; // rax
__int64 v23; // rdx
unsigned __int64 v25; // [rsp+8h] [rbp-60h]
unsigned int v26; // [rsp+1Ch] [rbp-4Ch] BYREF
int v27; // [rsp+20h] [rbp-48h] BYREF
unsigned int v28; // [rsp+24h] [rbp-44h] BYREF
__int64 v29[8]; // [rsp+28h] [rbp-40h] BYREF

v10 = *a1;
v26 = 0;
v11 = a7[9] + 16 * v10;
v27 = 0;
v12 = *(unsigned int *)(v11 + 4);
v13 = a7[14];
v28 = 0;
v14 = a4 + v12;
v29[0] = v14;
if ( a7[13] == v13 && v13 < a6 )
{
v25 = a6;
if ( (int)st_shti_bp_reallocate(v13 + 1, 0LL, a5, a6, a7) > 0 )
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
return 1LL;
}
v14 = v29[0];
v10 = (unsigned int)*a1;
a6 = v25;
}
v15 = a6 + 1;
while ( 1 )
{
v16 = st_shti_bp_branch_once(v10, &v26, v14, a5, a7);
if ( v16 )
{
if ( v16 == 1 )
{
fprintf(stderr, "Error: Insertion of the suffix number %zu failed!\n", a4);
result = 6LL;
}
else
{
result = st_shti_bp_create_leaf(
*a1,
(unsigned int)*(char *)(a5 + a4 + *(unsigned int *)(a7[9] + 16LL * *a1 + 4)),
(unsigned int)-(int)a4,
a5,
a7);
if ( !(_DWORD)result )
{
v18 = *a1;
if ( (int)v18 > 1 )
{
*a1 = *(_DWORD *)(a7[9] + 16 * v18 + 12);
return result;
}
return 0LL;
}
fwrite("Error: Could not create a new leaf of the parent!\n", 1uLL, 0x32uLL, stderr);
result = 7LL;
}
return result;
}
if ( (unsigned int)st_shti_bp_edge_slowscan((unsigned int)*a1, v26, v29[0], &v28, a5, v15, a7) )
break;
st_shti_bp_edge_descend(a1, &v26, &v27, v29, v15, a7);
v10 = (unsigned int)*a1;
if ( (int)v10 < 0 )
{
fwrite(
"Error: The newly inserted suffix already has the corresponding leaf node\npresent in the suffix tree!\n",
1uLL,
0x65uLL,
stderr);
return 2LL;
}
v14 = v29[0];
}
v19 = v26;
if ( (unsigned int)st_shti_bp_split_edge(
a1,
(unsigned int)*(char *)(a5 + v29[0]),
&v26,
v29,
v28,
(unsigned int)a4,
a5,
a7) )
{
fwrite("Error: Could not split the parent->child edge!\n", 1uLL, 0x2FuLL, stderr);
result = 3LL;
}
else if ( (unsigned int)st_shti_bp_create_leaf(
(unsigned int)*a1,
(unsigned int)*(char *)(a5 + v29[0]),
(unsigned int)-(int)a4,
a5,
a7) )
{
fwrite("Error: Could not create a new leaf of the parent!\n", 1uLL, 0x32uLL, stderr);
result = 4LL;
}
else
{
v20 = *a2;
if ( !(_DWORD)v20 )
{
v21 = a7[9];
goto LABEL_17;
}
if ( (unsigned int)*a3 + a4 == v29[0] )
{
v21 = a7[9];
*(_DWORD *)(v21 + 16 * v20 + 12) = *a1;
LABEL_17:
v22 = *a1;
*a2 = v22;
v23 = (unsigned int)(*(_DWORD *)(v21 + 16 * v22 + 4) - 1);
*a3 = v23;
result = func0(a1, v19, v23, (__int64)a7);
if ( !(_DWORD)result )
{
*a2 = 0;
*a3 = 0;
return result;
}
return 0LL;
}
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v20);
result = 5LL;
}
return result;
}

original_code:
int st_shti_bp_mccreight_insert_suffix (signed_integral_type *parent,
  signed_integral_type *sl_source,
  unsigned_integral_type *sl_targets_depth,
  size_t starting_position,
  const character_type *text,
  size_t length,
  suffix_tree_shti_bp *stree) {
 character_type letter = 0;
 signed_integral_type latest_child = 0;
 signed_integral_type child = 0;
 signed_integral_type prev_child = 0;
 signed_integral_type last_match_position = 0;
 size_t position = starting_position +
  stree->tbranch[(*parent)].depth;
 size_t tbranch_size = stree->tbranch_size;
 int tmp = 0;
 if ((tbranch_size == stree->branching_nodes) &&
   (tbranch_size < length)) {
  if (st_shti_bp_reallocate(tbranch_size + 1, (size_t)(0),
     text, length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_shti_bp_branch_once((*parent), &child,
     position, text, stree)) == 0) {
  if (st_shti_bp_edge_slowscan((*parent), child, position,
   &last_match_position, text, length + 1, stree) == 0) {
   st_shti_bp_edge_descend(parent, &child, &prev_child,
     &position, length + 1, stree);
   if ((*parent) < 0) {
    fprintf(stderr, "Error: The newly inserted "
      "suffix already has the "
      "corresponding leaf node\n"
      "present in the "
      "suffix tree!\n");
    return (2);
   }
  } else {
   latest_child = child;
   letter = text[position];
   if (st_shti_bp_split_edge(parent, letter, &child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     text, stree) != 0) {
    fprintf(stderr, "Error: Could not split "
      "the parent->child edge!\n");
    return (3);
   }
   letter = text[position];
   if (st_shti_bp_create_leaf((*parent), letter,
    (-(signed_integral_type)(starting_position)),
    text, stree)) {
    fprintf(stderr, "Error: Could not create "
      "a new leaf of the parent!\n");
    return (4);
   }
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (5);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_shti_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Insertion of the suffix number "
    "%zu failed!\n", starting_position);
  return (6);
 } else {
  letter = text[starting_position +
   stree->tbranch[(*parent)].depth];
  if (st_shti_bp_create_leaf((*parent), letter,
   (-(signed_integral_type)(starting_position)),
   text, stree)) {
   fprintf(stderr, "Error: Could not create "
     "a new leaf of the parent!\n");
   return (7);
  }
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 return (0);
}

canonical_original_code:
int st_shti_bp_mccreight_insert_suffix(int *parent, int *sl_source, unsigned int *sl_targets_depth, unsigned long starting_position, char *text, unsigned long length, struct suffix_tree_shti_bp_struct *stree) {
 char letter = 0;
 int latest_child = 0;
 int child = 0;
 int prev_child = 0;
 int last_match_position = 0;
 unsigned long position = starting_position +
  stree->tbranch[(*parent)].depth;
 unsigned long tbranch_size = stree->tbranch_size;
 int tmp = 0;
 if ((tbranch_size == stree->branching_nodes) &&
   (tbranch_size < length)) {
  if (st_shti_bp_reallocate(tbranch_size + 1, (unsigned long)(0),
     text, length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_shti_bp_branch_once((*parent), &child,
     position, text, stree)) == 0) {
  if (st_shti_bp_edge_slowscan((*parent), child, position,
   &last_match_position, text, length + 1, stree) == 0) {
   st_shti_bp_edge_descend(parent, &child, &prev_child,
     &position, length + 1, stree);
   if ((*parent) < 0) {
    fprintf(stderr, "Error: The newly inserted "
      "suffix already has the "
      "corresponding leaf node\n"
      "present in the "
      "suffix tree!\n");
    return (2);
   }
  } else {
   latest_child = child;
   letter = text[position];
   if (st_shti_bp_split_edge(parent, letter, &child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     text, stree) != 0) {
    fprintf(stderr, "Error: Could not split "
      "the parent->child edge!\n");
    return (3);
   }
   letter = text[position];
   if (st_shti_bp_create_leaf((*parent), letter,
    (-(signed_integral_type)(starting_position)),
    text, stree)) {
    fprintf(stderr, "Error: Could not create "
      "a new leaf of the parent!\n");
    return (4);
   }
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (5);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_shti_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Insertion of the suffix number "
    "%zu failed!\n", starting_position);
  return (6);
 } else {
  letter = text[starting_position +
   stree->tbranch[(*parent)].depth];
  if (st_shti_bp_create_leaf((*parent), letter,
   (-(signed_integral_type)(starting_position)),
   text, stree)) {
   fprintf(stderr, "Error: Could not create "
     "a new leaf of the parent!\n");
   return (7);
  }
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 return (0);
}

variable_types: letter char

user_defined_types: struct hash_settings_struct { int crt_type; unsigned int phf_max; unsigned int shf_max; unsigned long chf_number; unsigned int npu_size; unsigned int *chf_as; unsigned int *chf_bs; unsigned long *cp_offsets; unsigned long *cp_sizes; unsigned long allocated_size; }

user_defined_types: struct leaf_record_shti_bp_struct { int parent; }

user_defined_types: struct edge_record_struct { int source_node; int target_node; }

user_defined_types: struct branch_record_shti_bp_struct { int parent; unsigned int depth; unsigned int head_position; int suffix_link; }


decompiled_code:
__int64 __fastcall st_shti_bp_ukkonen_prolong_suffix(__int64 a1, __int64 a2, __int64 *a3, int *a4, int *a5, _DWORD *a6, __int64 a7, __int64 a8)
{
__int64 v8; // rdx
__int64 v10; // rdi
__int64 v12; // r13
int v13; // eax
int v14; // eax
unsigned int v15; // er12
__int64 v16; // rax
__int64 v17; // rdx
int v18; // er13
__int64 v19; // rdx
__int64 v20; // rcx
__int64 v21; // rax
__int64 v22; // rdx
__int64 v23; // rdx
int v25; // [rsp+4h] [rbp-74h]
unsigned int v29; // [rsp+2Ch] [rbp-4Ch] BYREF
int v30; // [rsp+30h] [rbp-48h] BYREF
unsigned int v31; // [rsp+34h] [rbp-44h] BYREF
__int64 v32[8]; // [rsp+38h] [rbp-40h] BYREF

v8 = *a3;
v29 = 0;
v30 = 0;
v31 = 0;
v32[0] = v8;
if ( a1 == a2 )
return (unsigned int)-1;
v10 = (unsigned int)*a4;
v12 = a2 - 1;
while ( 1 )
{
v14 = st_shti_bp_branch_once(v10, &v29, v8, a7, a8);
if ( v14 )
{
if ( v14 == 1 )
{
v15 = 4;
fprintf(stderr, "Error: Prolonging of the suffix number %zu to the length of %zu failed!\n", a1, a2 - a1);
}
else
{
v15 = st_shti_bp_create_leaf(
*a4,
(unsigned int)*(char *)(a7 + a1 + *(unsigned int *)(*(_QWORD *)(a8 + 72) + 16LL * *a4 + 4)),
(unsigned int)-(int)a1,
a7,
a8);
if ( v15 )
{
v15 = 5;
fwrite("Error: Could not create a new leaf of the parent!\n", 1uLL, 0x32uLL, stderr);
}
else
{
v16 = *a4;
v17 = *(_QWORD *)(a8 + 72);
if ( (int)v16 > 1 )
{
v16 = *(int *)(v17 + 16 * v16 + 12);
*a4 = v16;
}
*a3 = a1 + *(unsigned int *)(v17 + 16 * v16 + 4) + 1;
}
}
return v15;
}
v13 = st_shti_bp_edge_slowscan((unsigned int)*a4, v29, v32[0], &v31, a7, v12, a8);
if ( v13 )
break;
v25 = *a4;
st_shti_bp_edge_descend(a4, &v29, &v30, v32, v12, a8);
v10 = (unsigned int)*a4;
if ( (int)v10 < 0 )
{
v23 = *(_QWORD *)(a8 + 72);
*a4 = v25;
if ( v25 != 1 )
{
v25 = *(_DWORD *)(v23 + 16LL * v25 + 12);
*a4 = v25;
}
v15 = -2;
*a3 = a1 + *(unsigned int *)(v23 + 16LL * v25 + 4) + 1;
return v15;
}
if ( a1 + *(unsigned int *)(*(_QWORD *)(a8 + 72) + 16LL * (int)v10 + 4) == a2 )
{
v15 = -3;
*a3 = a2;
return v15;
}
v8 = v32[0];
}
if ( v13 == 2 )
{
v15 = -4;
*a3 = *(unsigned int *)(*(_QWORD *)(a8 + 72) + 16LL * *a4 + 4) + a1;
}
else
{
v18 = v29;
if ( (unsigned int)st_shti_bp_split_edge(
a4,
(unsigned int)*(char *)(a7 + v32[0]),
&v29,
v32,
v31,
(unsigned int)a1,
a7,
a8) )
{
v15 = 1;
fwrite("Error: Could not split the parent->child edge!\n", 1uLL, 0x2FuLL, stderr);
return v15;
}
v15 = st_shti_bp_create_leaf(
(unsigned int)*a4,
(unsigned int)*(char *)(a7 + v32[0]),
(unsigned int)-(int)a1,
a7,
a8);
if ( v15 )
{
v15 = 2;
fwrite("Error: Could not create a new leaf of the parent!\n", 1uLL, 0x32uLL, stderr);
}
else
{
v19 = *a5;
if ( (_DWORD)v19 )
{
if ( a1 + (unsigned int)*a6 != v32[0] )
{
v15 = 3;
fprintf(
stderr,
"Error! The last opportunity to set the target of a suffix link missed! (suffix link source = %d)\n",
v19);
return v15;
}
v20 = *(_QWORD *)(a8 + 72);
*(_DWORD *)(v20 + 16 * v19 + 12) = *a4;
}
else
{
v20 = *(_QWORD *)(a8 + 72);
}
v21 = *a4;
*a5 = v21;
v22 = (unsigned int)(*(_DWORD *)(v20 + 16 * v21 + 4) - 1);
*a6 = v22;
if ( !(unsigned int)st_shti_bp_simulate_suffix_link_bottom_up(a4, v18, v22, a8) )
{
*a5 = 0;
*a6 = 0;
}
*a3 = a1 + *(unsigned int *)(*(_QWORD *)(a8 + 72) + 16LL * *a4 + 4) + 1;
}
}
return v15;
}

original_code:
int st_shti_bp_ukkonen_prolong_suffix (size_t starting_position,
  size_t ending_position,
  size_t *active_index,
  signed_integral_type *parent,
  signed_integral_type *sl_source,
  unsigned_integral_type *sl_targets_depth,
  const character_type *text,
  suffix_tree_shti_bp *stree) {
 character_type letter = 0;
 signed_integral_type latest_child = 0;
 signed_integral_type grandpa = 0;
 signed_integral_type child = 0;
 signed_integral_type prev_child = 0;
 signed_integral_type last_match_position = 0;
 size_t position = (*active_index);
 int tmp = 0;
 int slowscan_return = 0;
 if (starting_position == ending_position) {
  return (-1);
 }
 while ((tmp = st_shti_bp_branch_once((*parent), &child,
     position, text, stree)) == 0) {
  if ((slowscan_return = st_shti_bp_edge_slowscan((*parent),
    child, position, &last_match_position, text,
    ending_position - 1, stree)) == 0) {
   grandpa = (*parent);
   st_shti_bp_edge_descend(parent, &child, &prev_child,
     &position, ending_position - 1, stree);
   if ((*parent) < 0) {
    (*parent) = grandpa;
    if ((*parent) != 1) {
     (*parent) = stree->tbranch[(*parent)].
      suffix_link;
    }
    (*active_index) = starting_position + 1 +
     stree->tbranch[(*parent)].depth;
    return (-2);
   } else if (starting_position +
     stree->tbranch[(*parent)].depth ==
     ending_position) {
    (*active_index) = starting_position +
     stree->tbranch[(*parent)].depth;
    return (-3);
   }
  } else if (slowscan_return == 2) {
   (*active_index) = starting_position +
    stree->tbranch[(*parent)].depth;
   return (-4);
  } else {
   latest_child = child;
   letter = text[position];
   if (st_shti_bp_split_edge(parent, letter, &child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     text, stree) != 0) {
    fprintf(stderr, "Error: Could not split "
      "the parent->child edge!\n");
    return (1);
   }
   letter = text[position];
   if (st_shti_bp_create_leaf((*parent), letter,
    (-(signed_integral_type)(starting_position)),
    text, stree)) {
    fprintf(stderr, "Error: Could not create "
      "a new leaf of the parent!\n");
    return (2);
   }
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (3);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_shti_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   (*active_index) = starting_position + 1 +
    stree->tbranch[(*parent)].depth;
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Prolonging of the suffix number "
    "%zu to the length of %zu failed!\n",
    starting_position,
    ending_position - starting_position);
  return (4);
 } else {
  letter = text[starting_position +
   stree->tbranch[(*parent)].depth];
  if (st_shti_bp_create_leaf((*parent), letter,
   (-(signed_integral_type)(starting_position)),
   text, stree)) {
   fprintf(stderr, "Error: Could not create "
     "a new leaf of the parent!\n");
   return (5);
  }
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 (*active_index) = starting_position + 1 +
  stree->tbranch[(*parent)].depth;
 return (0);
}

canonical_original_code:
int st_shti_bp_ukkonen_prolong_suffix(unsigned long starting_position, unsigned long ending_position, unsigned long *active_index, int *parent, int *sl_source, unsigned int *sl_targets_depth, char *text, struct suffix_tree_shti_bp_struct *stree) {
 char letter = 0;
 int latest_child = 0;
 int grandpa = 0;
 int child = 0;
 int prev_child = 0;
 int last_match_position = 0;
 unsigned long position = (*active_index);
 int tmp = 0;
 int slowscan_return = 0;
 if (starting_position == ending_position) {
  return (-1);
 }
 while ((tmp = st_shti_bp_branch_once((*parent), &child,
     position, text, stree)) == 0) {
  if ((slowscan_return = st_shti_bp_edge_slowscan((*parent),
    child, position, &last_match_position, text,
    ending_position - 1, stree)) == 0) {
   grandpa = (*parent);
   st_shti_bp_edge_descend(parent, &child, &prev_child,
     &position, ending_position - 1, stree);
   if ((*parent) < 0) {
    (*parent) = grandpa;
    if ((*parent) != 1) {
     (*parent) = stree->tbranch[(*parent)].
      suffix_link;
    }
    (*active_index) = starting_position + 1 +
     stree->tbranch[(*parent)].depth;
    return (-2);
   } else if (starting_position +
     stree->tbranch[(*parent)].depth ==
     ending_position) {
    (*active_index) = starting_position +
     stree->tbranch[(*parent)].depth;
    return (-3);
   }
  } else if (slowscan_return == 2) {
   (*active_index) = starting_position +
    stree->tbranch[(*parent)].depth;
   return (-4);
  } else {
   latest_child = child;
   letter = text[position];
   if (st_shti_bp_split_edge(parent, letter, &child,
     &position, last_match_position,
    (unsigned_integral_type)(starting_position),
     text, stree) != 0) {
    fprintf(stderr, "Error: Could not split "
      "the parent->child edge!\n");
    return (1);
   }
   letter = text[position];
   if (st_shti_bp_create_leaf((*parent), letter,
    (-(signed_integral_type)(starting_position)),
    text, stree)) {
    fprintf(stderr, "Error: Could not create "
      "a new leaf of the parent!\n");
    return (2);
   }
   if ((*sl_source) != 0) {
    if (position == starting_position +
      (*sl_targets_depth)) {
     stree->tbranch[(*sl_source)].
      suffix_link = (*parent);
    } else {
     fprintf(stderr, "Error! The last "
       "opportunity to "
       "set the target "
       "of a suffix link "
       "missed! (suffix "
       "link source = %d)\n",
       (*sl_source));
     return (3);
    }
   }
   (*sl_source) = (*parent);
   (*sl_targets_depth) =
    stree->tbranch[(*parent)].depth - 1;
   if (st_shti_bp_simulate_suffix_link_bottom_up(parent,
     latest_child, (*sl_targets_depth),
     stree) == 0) {
    (*sl_source) = 0;
    (*sl_targets_depth) = 0;
   }
   (*active_index) = starting_position + 1 +
    stree->tbranch[(*parent)].depth;
   return (0);
  }
 }
 if (tmp == 1) {
  fprintf(stderr, "Error: Prolonging of the suffix number "
    "%zu to the length of %zu failed!\n",
    starting_position,
    ending_position - starting_position);
  return (4);
 } else {
  letter = text[starting_position +
   stree->tbranch[(*parent)].depth];
  if (st_shti_bp_create_leaf((*parent), letter,
   (-(signed_integral_type)(starting_position)),
   text, stree)) {
   fprintf(stderr, "Error: Could not create "
     "a new leaf of the parent!\n");
   return (5);
  }
 }
 if ((*parent) > 1) {
  (*parent) = stree->tbranch[(*parent)].suffix_link;
 }
 (*active_index) = starting_position + 1 +
  stree->tbranch[(*parent)].depth;
 return (0);
}


decompiled_code:
__int64 __fastcall st_shti_bp_ukkonen_prolong_suffixes(__int64 *a1, __int64 a2, __int64 *a3, int *a4, __int64 a5, unsigned __int64 a6, __int64 a7)
{
unsigned __int64 v7; // rax
__int64 v12; // rdi
unsigned __int64 v13; // r10
int v14; // eax
__int64 v15; // rdi
unsigned int v16; // er8
int v18; // eax
int v19; // [rsp+8h] [rbp-40h] BYREF
int v20[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v7 = a6;
v12 = *a1;
v19 = 0;
v20[0] = 0;
v13 = *(_QWORD *)(a7 + 104) + a2 - 1 - v12;
if ( v13 <= a6 )
v7 = *(_QWORD *)(a7 + 104) + a2 - 1 - v12;
if ( v7 > *(_QWORD *)(a7 + 112) )
{
v18 = st_shti_bp_reallocate(v13, 0LL, a5, a6, a7);
if ( v18 > 0 )
{
fwrite("Error: Could not reallocate memory!\n", 1uLL, 0x24uLL, stderr);
return 1;
}
v12 = *a1;
}
while ( 1 )
{
v14 = st_shti_bp_ukkonen_prolong_suffix(v12, a2, a3, a4, &v19, v20, a5, a7);
if ( v14 != -1 )
break;
v12 = *a1 + 1;
*a1 = v12;
}
for ( ; !v14; v14 = st_shti_bp_ukkonen_prolong_suffix(v15, a2, a3, a4, &v19, v20, a5, a7) )
{
v15 = *a1 + 1;
*a1 = v15;
}
v16 = 0;
if ( v14 > 0 )
{
fprintf(stderr, "Error: Could not prolong suffixes to the ending position %zu!\n", a2);
v16 = 2;
}
return v16;
}

original_code:
int st_shti_bp_ukkonen_prolong_suffixes (size_t *starting_position,
  size_t ending_position,
  size_t *active_index,
  signed_integral_type *active_node,
  const character_type *text,
  size_t length,
  suffix_tree_shti_bp *stree) {
 signed_integral_type sl_source = 0;
 unsigned_integral_type sl_targets_depth = 0;
 size_t maximum_possible_size = stree->branching_nodes +
  ending_position - (*starting_position) - 1;
 int tmp = 0;
 size_t tbranch_size = (size_t)(stree->tbranch_size);
 if ((tbranch_size < maximum_possible_size) &&
   (tbranch_size < length)) {
  if (st_shti_bp_reallocate(maximum_possible_size, (size_t)(0),
     text, length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_shti_bp_ukkonen_prolong_suffix((*starting_position),
     ending_position, active_index,
     active_node, &sl_source,
     &sl_targets_depth, text,
     stree)) == (-1)) {
  ++(*starting_position);
 }
 while (tmp == 0) {
  ++(*starting_position);
  tmp = st_shti_bp_ukkonen_prolong_suffix((*starting_position),
   ending_position, active_index, active_node, &sl_source,
   &sl_targets_depth, text, stree);
 }
 if (tmp > 0) {
  fprintf(stderr, "Error: Could not prolong suffixes "
    "to the ending position %zu!\n",
    ending_position);
  return (2);
 }
 return (0);
}

canonical_original_code:
int st_shti_bp_ukkonen_prolong_suffixes(unsigned long *starting_position, unsigned long ending_position, unsigned long *active_index, int *active_node, char *text, unsigned long length, struct suffix_tree_shti_bp_struct *stree) {
 int sl_source = 0;
 unsigned int sl_targets_depth = 0;
 unsigned long maximum_possible_size = stree->branching_nodes +
  ending_position - (*starting_position) - 1;
 int tmp = 0;
 unsigned long tbranch_size = (size_t)(stree->tbranch_size);
 if ((tbranch_size < maximum_possible_size) &&
   (tbranch_size < length)) {
  if (st_shti_bp_reallocate(maximum_possible_size, (unsigned long)(0),
     text, length, stree) > 0) {
   fprintf(stderr, "Error: Could not "
     "reallocate memory!\n");
   return (1);
  }
 }
 while ((tmp = st_shti_bp_ukkonen_prolong_suffix((*starting_position),
     ending_position, active_index,
     active_node, &sl_source,
     &sl_targets_depth, text,
     stree)) == (-1)) {
  ++(*starting_position);
 }
 while (tmp == 0) {
  ++(*starting_position);
  tmp = st_shti_bp_ukkonen_prolong_suffix((*starting_position),
   ending_position, active_index, active_node, &sl_source,
   &sl_targets_depth, text, stree);
 }
 if (tmp > 0) {
  fprintf(stderr, "Error: Could not prolong suffixes "
    "to the ending position %zu!\n",
    ending_position);
  return (2);
 }
 return (0);
}


decompiled_code:
__int64 __fastcall st_shti_bp_create_mccreight(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // r12
__int64 result; // rax
int v6; // [rsp+4h] [rbp-34h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = 1;
v7 = 0;
v8[0] = 0;
puts("Creating suffix tree using McCright's algorithm\n");
if ( (int)st_shti_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 1LL;
if ( a2 < 0xFFFFFFFFFFFFFFFELL )
{
while ( (int)st_shti_bp_mccreight_insert_suffix(&v6, &v7, v8, v4, a1, a2, a3) <= 0 )
{
if ( ++v4 == a2 + 2 )
goto LABEL_7;
}
fprintf(stderr, "Could not insert suffix number %zu. Exiting.\n", v4);
result = 2LL;
}
else
{
LABEL_7:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(
a2,
a3[10],
a3[13],
0LL,
a3[11],
a3[14],
0LL,
a3[1],
a3[2],
a3[3],
0LL,
*(_QWORD *)(a3[6] + 64LL),
*(_QWORD *)(a3[6] + 64LL));
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // r12
__int64 result; // rax
int v6; // [rsp+4h] [rbp-34h] BYREF
int v7; // [rsp+8h] [rbp-30h] BYREF
int v8[11]; // [rsp+Ch] [rbp-2Ch] BYREF

v6 = 1;
v7 = 0;
v8[0] = 0;
puts("Creating suffix tree using McCright's algorithm\n");
if ( (int)st_shti_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 1LL;
if ( a2 < 0xFFFFFFFFFFFFFFFELL )
{
while ( (int)func1(&v6, &v7, v8, v4, a1, a2, a3) <= 0 )
{
if ( ++v4 == a2 + 2 )
goto LABEL_7;
}
fprintf(stderr, "Could not insert suffix number %zu. Exiting.\n", v4);
result = 2LL;
}
else
{
LABEL_7:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(
a2,
a3[10],
a3[13],
0LL,
a3[11],
a3[14],
0LL,
a3[1],
a3[2],
a3[3],
0LL,
*(_QWORD *)(a3[6] + 64LL),
*(_QWORD *)(a3[6] + 64LL));
result = 0LL;
}
}
return result;
}

original_code:
int st_shti_bp_create_mccreight (const character_type *text,
  size_t length,
  suffix_tree_shti_bp *stree) {
 signed_integral_type starting_node = 1;
 signed_integral_type sl_source = 0;
 unsigned_integral_type sl_targets_depth = 0;
 size_t i = 1;
 printf("Creating suffix tree using McCright's algorithm\n\n");
 if (st_shti_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 1; i < length + 2; ++i) {
  if (st_shti_bp_mccreight_insert_suffix(&starting_node,
     &sl_source, &sl_targets_depth, i,
     text, length, stree) > 0) {
   fprintf(stderr, "Could not insert suffix number "
     "%zu. Exiting.\n", i);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, stree->edges, stree->branching_nodes,
   (size_t)(0), stree->tedge_size, stree->tbranch_size,
   (size_t)(0), stree->lr_size, stree->er_size,
   stree->br_size, (size_t)(0),
   stree->hs->allocated_size, stree->hs->allocated_size);
 return (0);
}

canonical_original_code:
int st_shti_bp_create_mccreight(char *text, unsigned long length, struct suffix_tree_shti_bp_struct *stree) {
 int starting_node = 1;
 int sl_source = 0;
 unsigned int sl_targets_depth = 0;
 unsigned long i = 1;
 printf("Creating suffix tree using McCright's algorithm\n\n");
 if (st_shti_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 1; i < length + 2; ++i) {
  if (st_shti_bp_mccreight_insert_suffix(&starting_node,
     &sl_source, &sl_targets_depth, i,
     text, length, stree) > 0) {
   fprintf(stderr, "Could not insert suffix number "
     "%zu. Exiting.\n", i);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, stree->edges, stree->branching_nodes,
   (unsigned long)(0), stree->tedge_size, stree->tbranch_size,
   (unsigned long)(0), stree->lr_size, stree->er_size,
   stree->br_size, (unsigned long)(0),
   stree->hs->allocated_size, stree->hs->allocated_size);
 return (0);
}


decompiled_code:
__int64 __fastcall st_shti_bp_create_ukkonen(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
int v6; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+18h] [rbp-30h] BYREF

v6 = 1;
v7 = 1LL;
v8[0] = 1LL;
puts("Creating suffix tree using Ukkonen's algorithm\n");
if ( (int)st_shti_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 2LL;
if ( a2 < 0xFFFFFFFFFFFFFFFELL )
{
while ( (int)st_shti_bp_ukkonen_prolong_suffixes(v8, v4, &v7, &v6, a1, a2, (__int64)a3) <= 0 )
{
if ( ++v4 > a2 + 2 )
goto LABEL_7;
}
fprintf(stderr, "Could not create the intermediate tree number %zu. Exiting.\n", v4 - 1);
result = 2LL;
}
else
{
LABEL_7:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(
a2,
a3[10],
a3[13],
0LL,
a3[11],
a3[14],
0LL,
a3[1],
a3[2],
a3[3],
0LL,
*(_QWORD *)(a3[6] + 64LL),
*(_QWORD *)(a3[6] + 64LL));
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned __int64 a2, _QWORD *a3)
{
__int64 v4; // rbx
__int64 result; // rax
int v6; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+18h] [rbp-30h] BYREF

v6 = 1;
v7 = 1LL;
v8[0] = 1LL;
puts("Creating suffix tree using Ukkonen's algorithm\n");
if ( (int)st_shti_bp_allocate(a2, a3) > 0 )
{
fwrite("Allocation error. Exiting.\n", 1uLL, 0x1BuLL, stderr);
result = 1LL;
}
else
{
v4 = 2LL;
if ( a2 < 0xFFFFFFFFFFFFFFFELL )
{
while ( (int)func3(v8, v4, &v7, &v6, a1, a2, (__int64)a3) <= 0 )
{
if ( ++v4 > a2 + 2 )
goto LABEL_7;
}
fprintf(stderr, "Could not create the intermediate tree number %zu. Exiting.\n", v4 - 1);
result = 2LL;
}
else
{
LABEL_7:
puts("\nThe suffix tree has been successfully created.");
st_print_stats(
a2,
a3[10],
a3[13],
0LL,
a3[11],
a3[14],
0LL,
a3[1],
a3[2],
a3[3],
0LL,
*(_QWORD *)(a3[6] + 64LL),
*(_QWORD *)(a3[6] + 64LL));
result = 0LL;
}
}
return result;
}

original_code:
int st_shti_bp_create_ukkonen (const character_type *text,
  size_t length,
  suffix_tree_shti_bp *stree) {
 signed_integral_type active_node = 1;
 size_t active_index = 1;
 size_t starting_position = 1;
 size_t i = 1;
 printf("Creating suffix tree using Ukkonen's algorithm\n\n");
 if (st_shti_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 2; i <= length + 2; ++i) {
  if (st_shti_bp_ukkonen_prolong_suffixes(&starting_position, i,
     &active_index, &active_node, text,
     length, stree) > 0) {
   fprintf(stderr, "Could not create the intermediate "
     "tree number %zu. Exiting.\n", i - 1);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, stree->edges, stree->branching_nodes,
   (size_t)(0), stree->tedge_size, stree->tbranch_size,
   (size_t)(0), stree->lr_size, stree->er_size,
   stree->br_size, (size_t)(0),
   stree->hs->allocated_size, stree->hs->allocated_size);
 return (0);
}

canonical_original_code:
int st_shti_bp_create_ukkonen(char *text, unsigned long length, struct suffix_tree_shti_bp_struct *stree) {
 int active_node = 1;
 unsigned long active_index = 1;
 unsigned long starting_position = 1;
 unsigned long i = 1;
 printf("Creating suffix tree using Ukkonen's algorithm\n\n");
 if (st_shti_bp_allocate(length, stree) > 0) {
  fprintf(stderr, "Allocation error. Exiting.\n");
  return (1);
 }
 for (i = 2; i <= length + 2; ++i) {
  if (st_shti_bp_ukkonen_prolong_suffixes(&starting_position, i,
     &active_index, &active_node, text,
     length, stree) > 0) {
   fprintf(stderr, "Could not create the intermediate "
     "tree number %zu. Exiting.\n", i - 1);
   return (2);
  }
 }
 printf("\nThe suffix tree has been successfully created.\n");
 st_print_stats(length, stree->edges, stree->branching_nodes,
   (unsigned long)(0), stree->tedge_size, stree->tbranch_size,
   (unsigned long)(0), stree->lr_size, stree->er_size,
   stree->br_size, (unsigned long)(0),
   stree->hs->allocated_size, stree->hs->allocated_size);
 return (0);
}


decompiled_code:
__int64 __fastcall hs_update(int a1, unsigned __int64 *a2, __int64 a3)
{
__int64 v6; // rax
void *v7; // rax
void *v8; // rbp
int *v9; // rax
int *v10; // r14
void *v11; // rax
void *v12; // rax
const char *v13; // rsi
unsigned __int64 *v14; // rax
unsigned __int64 *v15; // rbp
_QWORD *v16; // rax
unsigned __int64 v17; // r8
unsigned __int64 v18; // rcx
unsigned __int64 v19; // rdx
unsigned __int64 v20; // rtt
__int64 v21; // rdi
unsigned __int64 v22; // rax
unsigned int v23; // er14
__int64 v24; // rbp
__int64 v25; // rsi
__int64 v26; // rdi
__int64 v27; // rax
_QWORD *v28; // rcx
__int64 v29; // rdx
unsigned int v30; // edx
unsigned int v31; // er14
unsigned __int64 v32; // rax
unsigned int v34; // eax

if ( !a3 )
{
v31 = 1;
fwrite("Error: The provided hash settings pointer is NULL!\n", 1uLL, 0x33uLL, stderr);
return v31;
}
if ( !*(_DWORD *)a3 )
{
*(_DWORD *)a3 = 1;
goto LABEL_4;
}
if ( *(_DWORD *)a3 == 1 )
{
LABEL_4:
if ( a1 > 1 )
puts("The selected collision resolution technique: Cuckoo hashing");
v6 = *(_QWORD *)(a3 + 16);
if ( v6 )
{
if ( v6 != 1 )
goto LABEL_10;
fprintf(
stderr,
"Warning: The number of the Cuckoo hash functions\n"
"needs to be at least 2. The provided value (%zu)\n"
"will be adjusted to the default value of %zu.\n",
1uLL,
8uLL);
}
*(_QWORD *)(a3 + 16) = 8LL;
LABEL_10:
free(*(void **)(a3 + 32));
v7 = calloc(*(_QWORD *)(a3 + 16), 4uLL);
*(_QWORD *)(a3 + 32) = v7;
v8 = v7;
v9 = _errno_location();
v10 = v9;
if ( v8 )
{
*v9 = 0;
free(*(void **)(a3 + 40));
v11 = calloc(*(_QWORD *)(a3 + 16), 4uLL);
*(_QWORD *)(a3 + 40) = v11;
if ( v11 )
{
*v10 = 0;
free(*(void **)(a3 + 48));
v12 = calloc(*(_QWORD *)(a3 + 16), 8uLL);
*(_QWORD *)(a3 + 48) = v12;
if ( v12 )
{
*v10 = 0;
free(*(void **)(a3 + 56));
v13 = (_BYTE *)&loc_8;
v14 = (unsigned __int64 *)calloc(*(_QWORD *)(a3 + 16), 8uLL);
*(_QWORD *)(a3 + 56) = v14;
v15 = v14;
if ( v14 )
{
v16 = *(_QWORD **)(a3 + 48);
*v10 = 0;
*(_DWORD *)(a3 + 24) = -5;
*v16 = 0LL;
v17 = *a2;
v18 = *(_QWORD *)(a3 + 16);
v20 = *a2;
v19 = *a2 % v18;
*v15 = *a2 / v18;
v21 = v20 / v18;
if ( v17 < v18 )
{
v13 = "\nWarning: The requested size of the hash table (%zu) is too small.\nIt will now be adjusted.\n\n";
fprintf(
stderr,
"\nWarning: The requested size of the hash table (%zu) is too small.\nIt will now be adjusted.\n\n",
v17);
v15 = *(unsigned __int64 **)(a3 + 56);
v21 = 1LL;
*v15 = 1LL;
}
*v15 = next_prime(v21, v13, v19);
*a2 = **(_QWORD **)(a3 + 56);
**(_DWORD **)(a3 + 32) = (unsigned int)random() % (*(_DWORD *)(a3 + 24) - 1) + 1;
**(_DWORD **)(a3 + 40) = (unsigned int)random() % *(_DWORD *)(a3 + 24);
if ( a1 > 1 )
{
puts("The Cuckoo hash function parameters:");
printf(
"0: {a = %u, b = %u, offset = %zu, size = %zu}\n",
**(unsigned int **)(a3 + 32),
**(unsigned int **)(a3 + 40),
**(_QWORD **)(a3 + 48),
**(_QWORD **)(a3 + 56));
}
v22 = *(_QWORD *)(a3 + 16);
if ( v22 > 1 )
{
v23 = 1;
v24 = 1LL;
do
{
v25 = *(_QWORD *)(a3 + 56);
v26 = *(_QWORD *)(a3 + 48);
v27 = v23 - 1;
v28 = (_QWORD *)(v25 + 8 * v27);
v29 = *(_QWORD *)(v26 + 8 * v27) + *v28;
*(_QWORD *)(v26 + 8 * v24) = v29;
*(_QWORD *)(v25 + 8 * v24) = next_prime(*v28, v25, v29);
*a2 += *(_QWORD *)(*(_QWORD *)(a3 + 56) + 8 * v24);
*(_DWORD *)(*(_QWORD *)(a3 + 32) + 4 * v24) = (unsigned int)random() % (*(_DWORD *)(a3 + 24) - 1) + 1;
v30 = (unsigned int)random() % *(_DWORD *)(a3 + 24);
*(_DWORD *)(*(_QWORD *)(a3 + 40) + 4 * v24) = v30;
if ( a1 > 1 )
printf(
"%u: {a = %u, b = %u, offset = %zu, size = %zu}\n",
v23,
*(unsigned int *)(*(_QWORD *)(a3 + 32) + 4 * v24),
v30,
*(_QWORD *)(*(_QWORD *)(a3 + 48) + 8 * v24),
*(_QWORD *)(*(_QWORD *)(a3 + 56) + 8 * v24));
v22 = *(_QWORD *)(a3 + 16);
v24 = ++v23;
}
while ( v23 < v22 );
}
v31 = 0;
*(_QWORD *)(a3 + 64) = 23 * v22 + 72;
if ( a1 > 1 )
printf("The new hash table size: %zu\n", *a2);
}
else
{
perror("calloc(hs->cp_sizes)");
*v10 = 0;
v31 = 5;
}
}
else
{
perror("calloc(hs->cp_offsets)");
*v10 = 0;
v31 = 4;
}
}
else
{
perror("calloc(hs->chf_bs)");
*v10 = 0;
v31 = 3;
}
}
else
{
perror("calloc(hs->chf_as)");
*v10 = 0;
v31 = 2;
}
return v31;
}
if ( a1 > 1 )
{
puts("The selected collision resolution technique: double hashing");
if ( !*a2 )
{
fprintf(
stderr,
"\nWarning: The requested size of the hash table (%zu) is too small.\nIt will now be adjusted.\n\n",
0LL);
*a2 = 1LL;
}
v34 = ((__int64 (*)(void))next_prime)();
*a2 = v34;
printf("The new hash table size: %zu\n", v34);
v32 = *a2;
}
else
{
if ( !*a2 )
{
fprintf(
stderr,
"\nWarning: The requested size of the hash table (%zu) is too small.\nIt will now be adjusted.\n\n",
0LL);
*a2 = 1LL;
}
LODWORD(v32) = ((__int64 (*)(void))next_prime)();
*a2 = (unsigned int)v32;
}
*(_DWORD *)(a3 + 4) = v32;
v31 = 0;
*(_DWORD *)(a3 + 8) = v32 - 2;
return v31;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, unsigned __int64 *a2, __int64 a3)
{
__int64 v6; // rax
void *v7; // rax
void *v8; // rbp
int *v9; // rax
int *v10; // r14
void *v11; // rax
void *v12; // rax
const char *v13; // rsi
unsigned __int64 *v14; // rax
unsigned __int64 *v15; // rbp
_QWORD *v16; // rax
unsigned __int64 v17; // r8
unsigned __int64 v18; // rcx
unsigned __int64 v19; // rdx
unsigned __int64 v20; // rtt
__int64 v21; // rdi
unsigned __int64 v22; // rax
unsigned int v23; // er14
__int64 v24; // rbp
__int64 v25; // rsi
__int64 v26; // rdi
__int64 v27; // rax
_QWORD *v28; // rcx
__int64 v29; // rdx
unsigned int v30; // edx
unsigned int v31; // er14
unsigned __int64 v32; // rax
unsigned int v34; // eax

if ( !a3 )
{
v31 = 1;
fwrite("Error: The provided hash settings pointer is NULL!\n", 1uLL, 0x33uLL, stderr);
return v31;
}
if ( !*(_DWORD *)a3 )
{
*(_DWORD *)a3 = 1;
goto LABEL_4;
}
if ( *(_DWORD *)a3 == 1 )
{
LABEL_4:
if ( a1 > 1 )
puts("The selected collision resolution technique: Cuckoo hashing");
v6 = *(_QWORD *)(a3 + 16);
if ( v6 )
{
if ( v6 != 1 )
goto LABEL_10;
fprintf(
stderr,
"Warning: The number of the Cuckoo hash functions\n"
"needs to be at least 2. The provided value (%zu)\n"
"will be adjusted to the default value of %zu.\n",
1uLL,
8uLL);
}
*(_QWORD *)(a3 + 16) = 8LL;
LABEL_10:
free(*(void **)(a3 + 32));
v7 = calloc(*(_QWORD *)(a3 + 16), 4uLL);
*(_QWORD *)(a3 + 32) = v7;
v8 = v7;
v9 = _errno_location();
v10 = v9;
if ( v8 )
{
*v9 = 0;
free(*(void **)(a3 + 40));
v11 = calloc(*(_QWORD *)(a3 + 16), 4uLL);
*(_QWORD *)(a3 + 40) = v11;
if ( v11 )
{
*v10 = 0;
free(*(void **)(a3 + 48));
v12 = calloc(*(_QWORD *)(a3 + 16), 8uLL);
*(_QWORD *)(a3 + 48) = v12;
if ( v12 )
{
*v10 = 0;
free(*(void **)(a3 + 56));
v13 = (_BYTE *)&loc_8;
v14 = (unsigned __int64 *)calloc(*(_QWORD *)(a3 + 16), 8uLL);
*(_QWORD *)(a3 + 56) = v14;
v15 = v14;
if ( v14 )
{
v16 = *(_QWORD **)(a3 + 48);
*v10 = 0;
*(_DWORD *)(a3 + 24) = -5;
*v16 = 0LL;
v17 = *a2;
v18 = *(_QWORD *)(a3 + 16);
v20 = *a2;
v19 = *a2 % v18;
*v15 = *a2 / v18;
v21 = v20 / v18;
if ( v17 < v18 )
{
v13 = "\nWarning: The requested size of the hash table (%zu) is too small.\nIt will now be adjusted.\n\n";
fprintf(
stderr,
"\nWarning: The requested size of the hash table (%zu) is too small.\nIt will now be adjusted.\n\n",
v17);
v15 = *(unsigned __int64 **)(a3 + 56);
v21 = 1LL;
*v15 = 1LL;
}
*v15 = next_prime(v21, v13, v19);
*a2 = **(_QWORD **)(a3 + 56);
**(_DWORD **)(a3 + 32) = (unsigned int)random() % (*(_DWORD *)(a3 + 24) - 1) + 1;
**(_DWORD **)(a3 + 40) = (unsigned int)random() % *(_DWORD *)(a3 + 24);
if ( a1 > 1 )
{
puts("The Cuckoo hash function parameters:");
printf(
"0: {a = %u, b = %u, offset = %zu, size = %zu}\n",
**(unsigned int **)(a3 + 32),
**(unsigned int **)(a3 + 40),
**(_QWORD **)(a3 + 48),
**(_QWORD **)(a3 + 56));
}
v22 = *(_QWORD *)(a3 + 16);
if ( v22 > 1 )
{
v23 = 1;
v24 = 1LL;
do
{
v25 = *(_QWORD *)(a3 + 56);
v26 = *(_QWORD *)(a3 + 48);
v27 = v23 - 1;
v28 = (_QWORD *)(v25 + 8 * v27);
v29 = *(_QWORD *)(v26 + 8 * v27) + *v28;
*(_QWORD *)(v26 + 8 * v24) = v29;
*(_QWORD *)(v25 + 8 * v24) = next_prime(*v28, v25, v29);
*a2 += *(_QWORD *)(*(_QWORD *)(a3 + 56) + 8 * v24);
*(_DWORD *)(*(_QWORD *)(a3 + 32) + 4 * v24) = (unsigned int)random() % (*(_DWORD *)(a3 + 24) - 1) + 1;
v30 = (unsigned int)random() % *(_DWORD *)(a3 + 24);
*(_DWORD *)(*(_QWORD *)(a3 + 40) + 4 * v24) = v30;
if ( a1 > 1 )
printf(
"%u: {a = %u, b = %u, offset = %zu, size = %zu}\n",
v23,
*(unsigned int *)(*(_QWORD *)(a3 + 32) + 4 * v24),
v30,
*(_QWORD *)(*(_QWORD *)(a3 + 48) + 8 * v24),
*(_QWORD *)(*(_QWORD *)(a3 + 56) + 8 * v24));
v22 = *(_QWORD *)(a3 + 16);
v24 = ++v23;
}
while ( v23 < v22 );
}
v31 = 0;
*(_QWORD *)(a3 + 64) = 23 * v22 + 72;
if ( a1 > 1 )
printf("The new hash table size: %zu\n", *a2);
}
else
{
perror("calloc(hs->cp_sizes)");
*v10 = 0;
v31 = 5;
}
}
else
{
perror("calloc(hs->cp_offsets)");
*v10 = 0;
v31 = 4;
}
}
else
{
perror("calloc(hs->chf_bs)");
*v10 = 0;
v31 = 3;
}
}
else
{
perror("calloc(hs->chf_as)");
*v10 = 0;
v31 = 2;
}
return v31;
}
if ( a1 > 1 )
{
puts("The selected collision resolution technique: double hashing");
if ( !*a2 )
{
fprintf(
stderr,
"\nWarning: The requested size of the hash table (%zu) is too small.\nIt will now be adjusted.\n\n",
0LL);
*a2 = 1LL;
}
v34 = ((__int64 (*)(void))next_prime)();
*a2 = v34;
printf("The new hash table size: %zu\n", v34);
v32 = *a2;
}
else
{
if ( !*a2 )
{
fprintf(
stderr,
"\nWarning: The requested size of the hash table (%zu) is too small.\nIt will now be adjusted.\n\n",
0LL);
*a2 = 1LL;
}
LODWORD(v32) = ((__int64 (*)(void))next_prime)();
*a2 = (unsigned int)v32;
}
*(_DWORD *)(a3 + 4) = v32;
v31 = 0;
*(_DWORD *)(a3 + 8) = v32 - 2;
return v31;
}

original_code:
int hs_update (const int verbosity_level,
  size_t *new_size,
  hash_settings *hs) {
 static const size_t chf_count_default = 8;
 unsigned_integral_type i = 0;
 if (hs == ((void *)0)) {
  fprintf(stderr, "Error: The provided hash settings "
    "pointer is NULL!\n");
  return (1);
 }
 if (hs->crt_type == 0) {
  hs->crt_type = 1;
 }
 if (hs->crt_type == 1) {
  if (verbosity_level > 1) {
   printf("The selected collision resolution technique: "
     "Cuckoo hashing\n");
  }
  if (hs->chf_number == 0) {
   hs->chf_number = chf_count_default;
  }
  if (hs->chf_number < 2) {
   fprintf(stderr, "Warning: The number of the "
     "Cuckoo hash functions\n"
     "needs to be at least 2. "
     "The provided value (%zu)\n"
     "will be adjusted to the "
     "default value of %zu.\n",
     hs->chf_number, chf_count_default);
   hs->chf_number = chf_count_default;
  }
  free(hs->chf_as);
  hs->chf_as = calloc(hs->chf_number,
    sizeof (unsigned_integral_type));
  if (hs->chf_as == ((void *)0)) {
   perror("calloc(hs->chf_as)");
   (*__errno_location ()) = 0;
   return (2);
  } else {
   (*__errno_location ()) = 0;
  }
  free(hs->chf_bs);
  hs->chf_bs = calloc(hs->chf_number,
    sizeof (unsigned_integral_type));
  if (hs->chf_bs == ((void *)0)) {
   perror("calloc(hs->chf_bs)");
   (*__errno_location ()) = 0;
   return (3);
  } else {
   (*__errno_location ()) = 0;
  }
  free(hs->cp_offsets);
  hs->cp_offsets = calloc(hs->chf_number,
    sizeof (size_t));
  if (hs->cp_offsets == ((void *)0)) {
   perror("calloc(hs->cp_offsets)");
   (*__errno_location ()) = 0;
   return (4);
  } else {
   (*__errno_location ()) = 0;
  }
  free(hs->cp_sizes);
  hs->cp_sizes = calloc(hs->chf_number,
    sizeof (size_t));
  if (hs->cp_sizes == ((void *)0)) {
   perror("calloc(hs->cp_sizes)");
   (*__errno_location ()) = 0;
   return (5);
  } else {
   (*__errno_location ()) = 0;
  }
  hs->npu_size = 4294967291;
  hs->cp_offsets[0] = 0;
  hs->cp_sizes[0] = (*new_size) / hs->chf_number;
  if (hs->cp_sizes[0] == 0) {
   fprintf(stderr, "\nWarning: The requested size of "
     "the hash table (%zu) is too small."
     "\nIt will now be adjusted.\n\n",
     (*new_size));
   hs->cp_sizes[0] = 1;
  }
  hs->cp_sizes[0] = (size_t)
   (next_prime((ull)(hs->cp_sizes[0])));
  (*new_size) = hs->cp_sizes[0];
  hs->chf_as[0] = (unsigned_integral_type)(random()) %
   (hs->npu_size - 1) + 1;
  hs->chf_bs[0] = (unsigned_integral_type)(random()) %
   hs->npu_size;
  if (verbosity_level > 1) {
   printf("The Cuckoo hash function parameters:\n");
   printf("0: {a = %u, b = %u, offset = %zu, "
     "size = %zu}\n", hs->chf_as[0],
     hs->chf_bs[0], hs->cp_offsets[0],
     hs->cp_sizes[0]);
  }
  for (i = 1; i < hs->chf_number; ++i) {
   hs->cp_offsets[i] = hs->cp_offsets[i - 1]
    + hs->cp_sizes[i - 1];
   hs->cp_sizes[i] = (size_t)(
     next_prime((ull)(hs->
       cp_sizes[i - 1])));
   (*new_size) += hs->cp_sizes[i];
   hs->chf_as[i] = (unsigned_integral_type)(random()) %
    (hs->npu_size - 1) + 1;
   hs->chf_bs[i] = (unsigned_integral_type)(random()) %
    hs->npu_size;
   if (verbosity_level > 1) {
    printf("%u: {a = %u, b = %u, offset = %zu, "
      "size = %zu}\n", i,
      hs->chf_as[i], hs->chf_bs[i],
      hs->cp_offsets[i],
      hs->cp_sizes[i]);
   }
  }
  hs->allocated_size = sizeof (hash_settings) +
   (sizeof (unsigned_integral_type) * 2 +
   sizeof (size_t) * 2 - 1) * hs->chf_number;
  if (verbosity_level > 1) {
   printf("The new hash table size: %zu\n", (*new_size));
  }
  return (0);
 } else {
  if (verbosity_level > 1) {
   printf("The selected collision resolution technique: "
     "double hashing\n");
  }
  if ((*new_size) == 0) {
   fprintf(stderr, "\nWarning: The requested size of "
     "the hash table (%zu) is too small."
     "\nIt will now be adjusted.\n\n",
     (*new_size));
   (*new_size) = 1;
  }
  (*new_size) = (unsigned_integral_type)(next_prime((ull)
     (*new_size)));
  if (verbosity_level > 1) {
   printf("The new hash table size: %zu\n", (*new_size));
  }
  hs->phf_max = (unsigned_integral_type)(*new_size);
  hs->shf_max = (unsigned_integral_type)((*new_size) - 2);
  return (0);
 }
}

canonical_original_code:
int hs_update(int verbosity_level, unsigned long *new_size, struct hash_settings_struct *hs) {
 static unsigned long chf_count_default = 8;
 unsigned int i = 0;
 if (hs == ((void *)0)) {
  fprintf(stderr, "Error: The provided hash settings "
    "pointer is NULL!\n");
  return (1);
 }
 if (hs->crt_type == 0) {
  hs->crt_type = 1;
 }
 if (hs->crt_type == 1) {
  if (verbosity_level > 1) {
   printf("The selected collision resolution technique: "
     "Cuckoo hashing\n");
  }
  if (hs->chf_number == 0) {
   hs->chf_number = chf_count_default;
  }
  if (hs->chf_number < 2) {
   fprintf(stderr, "Warning: The number of the "
     "Cuckoo hash functions\n"
     "needs to be at least 2. "
     "The provided value (%zu)\n"
     "will be adjusted to the "
     "default value of %zu.\n",
     hs->chf_number, chf_count_default);
   hs->chf_number = chf_count_default;
  }
  free(hs->chf_as);
  hs->chf_as = calloc(hs->chf_number,
    sizeof (unsigned_integral_type));
  if (hs->chf_as == ((void *)0)) {
   perror("calloc(hs->chf_as)");
   (*__errno_location ()) = 0;
   return (2);
  } else {
   (*__errno_location ()) = 0;
  }
  free(hs->chf_bs);
  hs->chf_bs = calloc(hs->chf_number,
    sizeof (unsigned_integral_type));
  if (hs->chf_bs == ((void *)0)) {
   perror("calloc(hs->chf_bs)");
   (*__errno_location ()) = 0;
   return (3);
  } else {
   (*__errno_location ()) = 0;
  }
  free(hs->cp_offsets);
  hs->cp_offsets = calloc(hs->chf_number,
    sizeof (unsigned long));
  if (hs->cp_offsets == ((void *)0)) {
   perror("calloc(hs->cp_offsets)");
   (*__errno_location ()) = 0;
   return (4);
  } else {
   (*__errno_location ()) = 0;
  }
  free(hs->cp_sizes);
  hs->cp_sizes = calloc(hs->chf_number,
    sizeof (unsigned long));
  if (hs->cp_sizes == ((void *)0)) {
   perror("calloc(hs->cp_sizes)");
   (*__errno_location ()) = 0;
   return (5);
  } else {
   (*__errno_location ()) = 0;
  }
  hs->npu_size = 4294967291;
  hs->cp_offsets[0] = 0;
  hs->cp_sizes[0] = (*new_size) / hs->chf_number;
  if (hs->cp_sizes[0] == 0) {
   fprintf(stderr, "\nWarning: The requested size of "
     "the hash table (%zu) is too small."
     "\nIt will now be adjusted.\n\n",
     (*new_size));
   hs->cp_sizes[0] = 1;
  }
  hs->cp_sizes[0] = (unsigned long)
   (next_prime((ull)(hs->cp_sizes[0])));
  (*new_size) = hs->cp_sizes[0];
  hs->chf_as[0] = (unsigned_integral_type)(random()) %
   (hs->npu_size - 1) + 1;
  hs->chf_bs[0] = (unsigned_integral_type)(random()) %
   hs->npu_size;
  if (verbosity_level > 1) {
   printf("The Cuckoo hash function parameters:\n");
   printf("0: {a = %u, b = %u, offset = %zu, "
     "size = %zu}\n", hs->chf_as[0],
     hs->chf_bs[0], hs->cp_offsets[0],
     hs->cp_sizes[0]);
  }
  for (i = 1; i < hs->chf_number; ++i) {
   hs->cp_offsets[i] = hs->cp_offsets[i - 1]
    + hs->cp_sizes[i - 1];
   hs->cp_sizes[i] = (unsigned long)(
     next_prime((ull)(hs->
       cp_sizes[i - 1])));
   (*new_size) += hs->cp_sizes[i];
   hs->chf_as[i] = (unsigned_integral_type)(random()) %
    (hs->npu_size - 1) + 1;
   hs->chf_bs[i] = (unsigned_integral_type)(random()) %
    hs->npu_size;
   if (verbosity_level > 1) {
    printf("%u: {a = %u, b = %u, offset = %zu, "
      "size = %zu}\n", i,
      hs->chf_as[i], hs->chf_bs[i],
      hs->cp_offsets[i],
      hs->cp_sizes[i]);
   }
  }
  hs->allocated_size = sizeof (hash_settings) +
   (sizeof (unsigned_integral_type) * 2 +
   sizeof (unsigned long) * 2 - 1) * hs->chf_number;
  if (verbosity_level > 1) {
   printf("The new hash table size: %zu\n", (*new_size));
  }
  return (0);
 } else {
  if (verbosity_level > 1) {
   printf("The selected collision resolution technique: "
     "double hashing\n");
  }
  if ((*new_size) == 0) {
   fprintf(stderr, "\nWarning: The requested size of "
     "the hash table (%zu) is too small."
     "\nIt will now be adjusted.\n\n",
     (*new_size));
   (*new_size) = 1;
  }
  (*new_size) = (unsigned_integral_type)(next_prime((ull)
     (*new_size)));
  if (verbosity_level > 1) {
   printf("The new hash table size: %zu\n", (*new_size));
  }
  hs->phf_max = (unsigned_integral_type)(*new_size);
  hs->shf_max = (unsigned_integral_type)((*new_size) - 2);
  return (0);
 }
}

variable_types: struct hash_settings_struct { int crt_type; unsigned int phf_max; unsigned int shf_max; unsigned long chf_number; unsigned int npu_size; unsigned int *chf_as; unsigned int *chf_bs; unsigned long *cp_offsets; unsigned long *cp_sizes; unsigned long allocated_size; } *

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall hs_deallocate(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(*((void **)ptr + 7));
free(ptr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *ptr)
{
if ( !ptr )
return 0xFFFFFFFFLL;
free(*((void **)ptr + 4));
free(*((void **)ptr + 5));
free(*((void **)ptr + 6));
free(*((void **)ptr + 7));
free(ptr);
return 0LL;
}

original_code:
int hs_deallocate (hash_settings *hs) {
 if (hs == ((void *)0)) {
  return (-1);
 } else {
  free(hs->chf_as);
  hs->chf_as = ((void *)0);
  free(hs->chf_bs);
  hs->chf_bs = ((void *)0);
  free(hs->cp_offsets);
  hs->cp_offsets = ((void *)0);
  free(hs->cp_sizes);
  hs->cp_sizes = ((void *)0);
  free(hs);
  hs = ((void *)0);
  return (0);
 }
}

canonical_original_code:
int hs_deallocate(struct hash_settings_struct *hs) {
 if (hs == ((void *)0)) {
  return (-1);
 } else {
  free(hs->chf_as);
  hs->chf_as = ((void *)0);
  free(hs->chf_bs);
  hs->chf_bs = ((void *)0);
  free(hs->cp_offsets);
  hs->cp_offsets = ((void *)0);
  free(hs->cp_sizes);
  hs->cp_sizes = ((void *)0);
  free(hs);
  hs = ((void *)0);
  return (0);
 }
}


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

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

original_code:
int er_empty (const edge_record er) {
 if ((er.source_node == 0) && (er.target_node == 0)) {
  return (1);
 } else {
  return (0);
 }
}

canonical_original_code:
int er_empty(struct edge_record_struct er) {
 if ((er.source_node == 0) && (er.target_node == 0)) {
  return (1);
 } else {
  return (0);
 }
}

variable_types: struct edge_record_struct { int source_node; int target_node; }


decompiled_code:
_BOOL8 __fastcall er_vacant(int a1)
{
return a1 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(int a1)
{
return a1 == 0;
}

original_code:
int er_vacant (const edge_record er) {
 if (er.source_node == 0) {
  return (1);
 } else {
  return (0);
 }
}

canonical_original_code:
int er_vacant(struct edge_record_struct er) {
 if (er.source_node == 0) {
  return (1);
 } else {
  return (0);
 }
}


decompiled_code:
unsigned __int64 __fastcall primary_hf(int a1, char a2, __int64 a3)
{
return (a1 ^ (unsigned __int64)((__int64)a2 << 32)) % *(unsigned int *)(a3 + 4);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(int a1, char a2, __int64 a3)
{
return (a1 ^ (unsigned __int64)((__int64)a2 << 32)) % *(unsigned int *)(a3 + 4);
}

original_code:
size_t primary_hf (signed_integral_type source_node,
  character_type letter,
  const hash_settings *hs) {
 unsigned long long key =
  (unsigned long long)(source_node) ^
  ((unsigned long long)(letter) << 32);
 return ((size_t)(key % hs->phf_max));
}

canonical_original_code:
unsigned long primary_hf(int source_node, char letter, struct hash_settings_struct *hs) {
 unsigned long long key = (unsigned long long)(source_node) ^
  ((unsigned long long)(letter) << 32);
 return ((unsigned long)(key % hs->phf_max));
}

variable_types:
key
unsigned long long

return_type: unsigned long


decompiled_code:
unsigned __int64 __fastcall secondary_hf(int a1, char a2, __int64 a3)
{
return (a1 ^ (unsigned __int64)((__int64)a2 << 32)) % *(unsigned int *)(a3 + 8) + 1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func6(int a1, char a2, __int64 a3)
{
return (a1 ^ (unsigned __int64)((__int64)a2 << 32)) % *(unsigned int *)(a3 + 8) + 1;
}

original_code:
size_t secondary_hf (signed_integral_type source_node,
  character_type letter,
  const hash_settings *hs) {
 unsigned long long key =
  (unsigned long long)(source_node) ^
  ((unsigned long long)(letter) << 32);
 return ((size_t)(key % hs->shf_max + 1));
}

canonical_original_code:
unsigned long secondary_hf(int source_node, char letter, struct hash_settings_struct *hs) {
 unsigned long long key = (unsigned long long)(source_node) ^
  ((unsigned long long)(letter) << 32);
 return ((unsigned long)(key % hs->shf_max + 1));
}