original_code:
uint8_t graph_create_clustered(
  graph_t *g,
  uint32_t nnodes,
  uint32_t nclusters,
  double internal,
  double external,
  double sizerange
) {
  uint64_t ni;
  uint64_t nj;
  uint64_t ci;
  uint64_t cj;
  array_t sizes;
  uint64_t nci;
  graph_label_t lbl;
  uint32_t sz;
  uint32_t tmp;
  if (g == ((void *)0)) goto fail;
  if (nnodes == 0) goto fail;
  if (nclusters == 0) goto fail;
  if (nclusters > nnodes) goto fail;
  if (internal < 0.0) goto fail;
  if (internal > 1.0) goto fail;
  if (external < 0.0) goto fail;
  if (external > 1.0) goto fail;
  if (sizerange < 0.0) goto fail;
  if (sizerange > 1.0) goto fail;
  if (array_create(&sizes, sizeof(uint32_t), nclusters)) goto fail;
  if (_create_sizes(nnodes, nclusters, &sizes, sizerange)) goto fail;
  array_get(&sizes, sizes.size-1, &nnodes);
  if (graph_create(g, nnodes, 0)) goto fail;
  memset(&lbl, 0, sizeof(graph_label_t));
  ci = 0;
  for (nci = 0, ni = 0; ni < nnodes; ni++, nci++) {
    array_get(&sizes, ci, &sz);
    if (ni == sz) {
      ci++;
      nci = 0;
    }
    if (ci == 0) {
      array_get(&sizes, 0, &sz);
    }
    else {
      array_get(&sizes, ci-1, &tmp);
      array_get(&sizes, ci, &sz);
      sz -= tmp;
    }
    _mk_label(&lbl, sizes.size, ci, sz, nci);
    graph_set_nodelabel(g, ni, &lbl);
    cj = ci;
    for (nj = ni+1; nj < nnodes; nj++) {
      array_get(&sizes, cj, &sz);
      if (nj == sz) cj++;
      if (ci == cj) {
        if (((double)rand()/2147483647) <= internal) {
          if (graph_add_edge(g, ni, nj, 1.0)) goto fail;
        }
      }
      else {
        if (((double)rand()/2147483647) <= external) {
          if (graph_add_edge(g, ni, nj, 1.0)) goto fail;
        }
      }
    }
  }
  array_free(&sizes);
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_create_clustered(struct _graph *g, unsigned int nnodes, unsigned int nclusters, double internal, double external, double sizerange) {
  unsigned long ni;
  unsigned long nj;
  unsigned long ci;
  unsigned long cj;
  struct _array sizes;
  unsigned long nci;
  struct _graph_label lbl;
  unsigned int sz;
  unsigned int tmp;
  if (g == ((void *)0)) goto fail;
  if (nnodes == 0) goto fail;
  if (nclusters == 0) goto fail;
  if (nclusters > nnodes) goto fail;
  if (internal < 0.0) goto fail;
  if (internal > 1.0) goto fail;
  if (external < 0.0) goto fail;
  if (external > 1.0) goto fail;
  if (sizerange < 0.0) goto fail;
  if (sizerange > 1.0) goto fail;
  if (array_create(&sizes, sizeof(unsigned int), nclusters)) goto fail;
  if (_create_sizes(nnodes, nclusters, &sizes, sizerange)) goto fail;
  array_get(&sizes, sizes.size-1, &nnodes);
  if (graph_create(g, nnodes, 0)) goto fail;
  memset(&lbl, 0, sizeof(graph_label_t));
  ci = 0;
  for (nci = 0, ni = 0; ni < nnodes; ni++, nci++) {
    array_get(&sizes, ci, &sz);
    if (ni == sz) {
      ci++;
      nci = 0;
    }
    if (ci == 0) {
      array_get(&sizes, 0, &sz);
    }
    else {
      array_get(&sizes, ci-1, &tmp);
      array_get(&sizes, ci, &sz);
      sz -= tmp;
    }
    _mk_label(&lbl, sizes.size, ci, sz, nci);
    graph_set_nodelabel(g, ni, &lbl);
    cj = ci;
    for (nj = ni+1; nj < nnodes; nj++) {
      array_get(&sizes, cj, &sz);
      if (nj == sz) cj++;
      if (ci == cj) {
        if (((double)rand()/2147483647) <= internal) {
          if (graph_add_edge(g, ni, nj, 1.0)) goto fail;
        }
      }
      else {
        if (((double)rand()/2147483647) <= external) {
          if (graph_add_edge(g, ni, nj, 1.0)) goto fail;
        }
      }
    }
  }
  array_free(&sizes);
  return 0;
fail:
  return 1;
}

variable_types:
nclusters
unsigned int

variable_types: internal double

variable_types: external double

variable_types: sizerange double

variable_types:
ni
unsigned long

variable_types:
nj
unsigned long

variable_types:
ci
unsigned long

variable_types:
cj
unsigned long

variable_types: struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); }

variable_types:
nci
unsigned long

variable_types: struct _graph_label { unsigned int labelval; float xval; float yval; float zval; unsigned int meta[16]; }

variable_types:
sz
unsigned int

variable_types:
tmp
unsigned int


repo: pauldmccarthy/ccnet

decompiled_code:
__int64 __fastcall graph_create_clustered_by_degree(__int64 a1, signed int a2, signed int a3, double a4, double a5, double a6)
{
double v7; // xmm1_8
double v9; // [rsp+8h] [rbp-40h]
double v10; // [rsp+8h] [rbp-40h]
double v11; // [rsp+10h] [rbp-38h]
double v12; // [rsp+10h] [rbp-38h]
double v14; // [rsp+20h] [rbp-28h]

v9 = (double)a3;
v11 = round((double)a2 / (double)a3);
v10 = round((v11 - 1.0) * v11 * v9 * 0.5);
v12 = round((double)(a3 * (a3 - 1)) * 0.5 * (v11 * v11));
v14 = round(0.5 * (a4 * (double)a2));
v7 = round(0.5 * ((double)a2 * a5));
return graph_create_clustered(a1, a2, a3, v14 / v10, v7 / v12, a6);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, signed int a2, signed int a3, double a4, double a5, double a6)
{
double v7; // xmm1_8
double v9; // [rsp+8h] [rbp-40h]
double v10; // [rsp+8h] [rbp-40h]
double v11; // [rsp+10h] [rbp-38h]
double v12; // [rsp+10h] [rbp-38h]
double v14; // [rsp+20h] [rbp-28h]

v9 = (double)a3;
v11 = round((double)a2 / (double)a3);
v10 = round((v11 - 1.0) * v11 * v9 * 0.5);
v12 = round((double)(a3 * (a3 - 1)) * 0.5 * (v11 * v11));
v14 = round(0.5 * (a4 * (double)a2));
v7 = round(0.5 * ((double)a2 * a5));
return func2(a1, a2, a3, v14 / v10, v7 / v12, a6);
}

original_code:
uint8_t graph_create_clustered_by_degree(
  graph_t *g,
  uint32_t nnodes,
  uint32_t nclusters,
  double intdegree,
  double extdegree,
  double sizerange
) {
  double clustsz;
  double maxintra;
  double maxinter;
  double nintra;
  double ninter;
  double intdens;
  double extdens;
  clustsz = round((double)nnodes / nclusters);
  maxintra = round(nclusters * (clustsz*(clustsz-1))/2.0);
  maxinter = round((clustsz*clustsz) * ((nclusters * (nclusters-1))/2.0));
  nintra = round((intdegree*nnodes)/2);
  ninter = round((extdegree*nnodes)/2);
  intdens = nintra / maxintra;
  extdens = ninter / maxinter;
  return graph_create_clustered(
    g, nnodes, nclusters, intdens, extdens, sizerange);
}

canonical_original_code:
unsigned char graph_create_clustered_by_degree(struct _graph *g, unsigned int nnodes, unsigned int nclusters, double intdegree, double extdegree, double sizerange) {
  double clustsz;
  double maxintra;
  double maxinter;
  double nintra;
  double ninter;
  double intdens;
  double extdens;
  clustsz = round((double)nnodes / nclusters);
  maxintra = round(nclusters * (clustsz*(clustsz-1))/2.0);
  maxinter = round((clustsz*clustsz) * ((nclusters * (nclusters-1))/2.0));
  nintra = round((intdegree*nnodes)/2);
  ninter = round((extdegree*nnodes)/2);
  intdens = nintra / maxintra;
  extdens = ninter / maxinter;
  return graph_create_clustered(
    g, nnodes, nclusters, intdens, extdens, sizerange);
}

variable_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *

variable_types:
nnodes
unsigned int

variable_types: intdegree double

variable_types: extdegree double

variable_types: clustsz double

variable_types: maxintra double

variable_types: maxinter double

variable_types: nintra double

variable_types: ninter double

variable_types: intdens double

variable_types: extdens double

return_type: unsigned char

user_defined_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); }


decompiled_code:
__int64 __fastcall graph_create_clustered_by_total(__int64 a1, signed int a2, signed int a3, double a4, double a5, double a6)
{
double v7; // xmm1_8
__int64 result; // rax
double v10; // [rsp+18h] [rbp-30h]
double v11; // [rsp+18h] [rbp-30h]
double v12; // [rsp+20h] [rbp-28h]

if ( a5 < 0.0
|| a5 > 1.0
|| (v10 = (double)a3,
v12 = round((double)a2 / (double)a3),
v11 = round((v12 - 1.0) * v12 * v10 * 0.5),
v7 = (a5 * (double)a2 * (double)(a2 - 1) * 0.5 - v11 * a4) / round((double)(a3 * (a3 - 1)) * 0.5 * (v12 * v12)),
v7 < 0.0) )
{
result = 1LL;
}
else
{
result = graph_create_clustered(a1, a2, a3, a4, v7, a6);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, signed int a2, signed int a3, double a4, double a5, double a6)
{
double v7; // xmm1_8
__int64 result; // rax
double v10; // [rsp+18h] [rbp-30h]
double v11; // [rsp+18h] [rbp-30h]
double v12; // [rsp+20h] [rbp-28h]

if ( a5 < 0.0
|| a5 > 1.0
|| (v10 = (double)a3,
v12 = round((double)a2 / (double)a3),
v11 = round((v12 - 1.0) * v12 * v10 * 0.5),
v7 = (a5 * (double)a2 * (double)(a2 - 1) * 0.5 - v11 * a4) / round((double)(a3 * (a3 - 1)) * 0.5 * (v12 * v12)),
v7 < 0.0) )
{
result = 1LL;
}
else
{
result = func2(a1, a2, a3, a4, v7, a6);
}
return result;
}

original_code:
uint8_t graph_create_clustered_by_total(
  graph_t *g,
  uint32_t nnodes,
  uint32_t nclusters,
  double internal,
  double total,
  double sizerange
) {
  double clustsz;
  double external;
  double maxintra;
  double maxinter;
  if (total < 0.0) return 1;
  if (total > 1.0) return 1;
  clustsz = round((double)nnodes / nclusters);
  maxintra = round(nclusters * (clustsz*(clustsz-1))/2.0);
  maxinter = round((clustsz*clustsz) * ((nclusters * (nclusters-1))/2.0));
  external = (total * nnodes * (nnodes-1))/2.0 - internal*maxintra;
  external /= maxinter;
  if (external < 0.0) return 1;
  return graph_create_clustered(
    g, nnodes, nclusters, internal, external, sizerange);
}

canonical_original_code:
unsigned char graph_create_clustered_by_total(struct _graph *g, unsigned int nnodes, unsigned int nclusters, double internal, double total, double sizerange) {
  double clustsz;
  double external;
  double maxintra;
  double maxinter;
  if (total < 0.0) return 1;
  if (total > 1.0) return 1;
  clustsz = round((double)nnodes / nclusters);
  maxintra = round(nclusters * (clustsz*(clustsz-1))/2.0);
  maxinter = round((clustsz*clustsz) * ((nclusters * (nclusters-1))/2.0));
  external = (total * nnodes * (nnodes-1))/2.0 - internal*maxintra;
  external /= maxinter;
  if (external < 0.0) return 1;
  return graph_create_clustered(
    g, nnodes, nclusters, internal, external, sizerange);
}

variable_types:
nclusters
unsigned int

variable_types: internal double

variable_types: total double

variable_types: sizerange double

variable_types: external double

user_defined_types: struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); }


decompiled_code:
__int64 __fastcall graph_prune(__int64 a1, __int64 a2, unsigned int a3, double a4)
{
size_t v5; // rbx
void *v6; // rax
void *v7; // rbp
unsigned int v8; // er12
unsigned int v10; // er8
unsigned __int64 i; // r15
unsigned int v12; // [rsp+1Ch] [rbp-6Ch] BYREF
char v13[4]; // [rsp+20h] [rbp-68h] BYREF
unsigned int v14; // [rsp+24h] [rbp-64h]
unsigned int *v15; // [rsp+30h] [rbp-58h]

v15 = 0LL;
v5 = (unsigned int)graph_num_nodes();
v6 = calloc(v5, 4uLL);
if ( !v6 )
{
LABEL_4:
v8 = 1;
if ( v15 )
array_free(v13);
return v8;
}
v7 = v6;
if ( (unsigned __int8)array_create(v13, 4LL, 10LL) || (unsigned __int8)find_components(a1, (__int64)v7, (__int64)v13) )
goto LABEL_3;
v10 = v14;
if ( !a3 )
{
if ( v14 )
{
for ( i = 0LL; i < v14; ++i )
{
array_get(v13, (unsigned int)i, &v12);
if ( a3 < v12 )
a3 = v12;
v10 = v14;
}
a3 = (a3 < 2) + a3 - 1;
}
if ( a4 > 0.0 && a4 > (double)(int)a3 / (double)(int)v5 )
a3 = 1;
}
v8 = prune(a1, a2, a3, (__int64)v7, v10, v15);
if ( (_BYTE)v8 )
{
LABEL_3:
free(v7);
goto LABEL_4;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3, double a4)
{
size_t v5; // rbx
void *v6; // rax
void *v7; // rbp
unsigned int v8; // er12
unsigned int v10; // er8
unsigned __int64 i; // r15
unsigned int v12; // [rsp+1Ch] [rbp-6Ch] BYREF
char v13[4]; // [rsp+20h] [rbp-68h] BYREF
unsigned int v14; // [rsp+24h] [rbp-64h]
unsigned int *v15; // [rsp+30h] [rbp-58h]

v15 = 0LL;
v5 = (unsigned int)graph_num_nodes();
v6 = calloc(v5, 4uLL);
if ( !v6 )
{
LABEL_4:
v8 = 1;
if ( v15 )
array_free(v13);
return v8;
}
v7 = v6;
if ( (unsigned __int8)array_create(v13, 4LL, 10LL) || (unsigned __int8)func1(a1, (__int64)v7, (__int64)v13) )
goto LABEL_3;
v10 = v14;
if ( !a3 )
{
if ( v14 )
{
for ( i = 0LL; i < v14; ++i )
{
array_get(v13, (unsigned int)i, &v12);
if ( a3 < v12 )
a3 = v12;
v10 = v14;
}
a3 = (a3 < 2) + a3 - 1;
}
if ( a4 > 0.0 && a4 > (double)(int)a3 / (double)(int)v5 )
a3 = 1;
}
v8 = func2(a1, a2, a3, (__int64)v7, v10, v15);
if ( (_BYTE)v8 )
{
LABEL_3:
free(v7);
goto LABEL_4;
}
return v8;
}

original_code:
uint8_t graph_prune(graph_t *gin, graph_t *gout, uint32_t size, double prop) {
  uint32_t *components;
  array_t sizes;
  uint32_t nnodes;
  uint64_t i;
  uint32_t s;
  components = ((void *)0);
  sizes.data = ((void *)0);
  nnodes = graph_num_nodes(gin);
  components = calloc(nnodes,sizeof(uint32_t));
  if (components == ((void *)0)) goto fail;
  if (array_create(&sizes, sizeof(uint32_t), 10))
    goto fail;
  if (_find_components(gin, components, &sizes))
    goto fail;
  if (size == 0) {
    for (i = 0; i < sizes.size; i++) {
      array_get(&sizes, i, &s);
      if (s > size) size = s;
    }
    if (size > 1)
      size -= 1;
    if (prop > 0) {
      if (size / ((double)nnodes) < prop) {
        size = 1;
      }
    }
  }
  if (_prune(gin, gout, size, components, sizes.size, (uint32_t *)sizes.data))
    goto fail;
  return 0;
fail:
  if (components != ((void *)0)) free(components);
  if (sizes.data != ((void *)0)) array_free(&sizes);
  return 1;
}

canonical_original_code:
unsigned char graph_prune(struct _graph *gin, struct _graph *gout, unsigned int size, double prop) {
  unsigned int *components;
  struct _array sizes;
  unsigned int nnodes;
  unsigned long i;
  unsigned int s;
  components = ((void *)0);
  sizes.data = ((void *)0);
  nnodes = graph_num_nodes(gin);
  components = calloc(nnodes,sizeof(unsigned int));
  if (components == ((void *)0)) goto fail;
  if (array_create(&sizes, sizeof(unsigned int), 10))
    goto fail;
  if (_find_components(gin, components, &sizes))
    goto fail;
  if (size == 0) {
    for (i = 0; i < sizes.size; i++) {
      array_get(&sizes, i, &s);
      if (s > size) size = s;
    }
    if (size > 1)
      size -= 1;
    if (prop > 0) {
      if (size / ((double)nnodes) < prop) {
        size = 1;
      }
    }
  }
  if (_prune(gin, gout, size, components, sizes.size, (unsigned int *)sizes.data))
    goto fail;
  return 0;
fail:
  if (components != ((void *)0)) free(components);
  if (sizes.data != ((void *)0)) array_free(&sizes);
  return 1;
}

variable_types:
gout
struct _graph *

variable_types:
size
unsigned int

variable_types: prop double

variable_types:
components
unsigned int *

variable_types: struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); }

variable_types:
i
unsigned long

variable_types:
s
unsigned int


decompiled_code:
bool __fastcall graph_threshold_weight(__int64 a1, __int64 a2, char a3, char a4, double a5)
{
unsigned int v7; // eax
bool result; // al

v7 = graph_num_nodes();
if ( (unsigned __int8)graph_create(a2, v7, 0LL) || (unsigned __int8)graph_copy_nodelabels(a1, a2) )
result = 1;
else
result = (unsigned __int8)threshold_edges(a1, a2, a3, a4, a5) != 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __int64 a2, char a3, char a4, double a5)
{
unsigned int v7; // eax
bool result; // al

v7 = graph_num_nodes();
if ( (unsigned __int8)graph_create(a2, v7, 0LL) || (unsigned __int8)graph_copy_nodelabels(a1, a2) )
result = 1;
else
result = (unsigned __int8)func0(a1, a2, a3, a4, a5) != 0;
return result;
}

original_code:
uint8_t graph_threshold_weight(
  graph_t *gin,
  graph_t *gout,
  double threshold,
  uint8_t absval,
  uint8_t reverse) {
  if (graph_create( gout, graph_num_nodes(gin), 0)) goto fail;
  if (graph_copy_nodelabels(gin, gout)) goto fail;
  if (_threshold_edges( gin, gout, threshold, absval, reverse)) goto fail;
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_threshold_weight(struct _graph *gin, struct _graph *gout, double threshold, unsigned char absval, unsigned char reverse) {
  if (graph_create( gout, graph_num_nodes(gin), 0)) goto fail;
  if (graph_copy_nodelabels(gin, gout)) goto fail;
  if (_threshold_edges( gin, gout, threshold, absval, reverse)) goto fail;
  return 0;
fail:
  return 1;
}

variable_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *

variable_types: threshold double

variable_types:
absval
unsigned char

variable_types:
reverse
unsigned char


decompiled_code:
__int64 __fastcall graph_threshold_edges(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, void (__fastcall *a6)(__int64), unsigned __int8 (__fastcall *a7)(__int64, void *, char *, _BYTE *), unsigned __int8 (__fastcall *a8)(__int64, _BYTE *))
{
unsigned int v10; // er13
unsigned int v11; // er12
void *v13; // r13
__int64 v14; // r14
__int64 v15; // r15
__int64 v16; // rbp
_BYTE v17[16]; // [rsp+0h] [rbp-78h] BYREF
char v18[16]; // [rsp+10h] [rbp-68h] BYREF
__int64 v19; // [rsp+20h] [rbp-58h]

v19 = 0LL;
v10 = graph_num_nodes();
if ( (unsigned __int8)array_create(v18, 16LL, 10LL)
|| (unsigned __int8)graph_copy(a1, a2)
|| (v11 = stats_cache_init(a2), (_BYTE)v11)
|| (v13 = calloc(v10, 8uLL)) == 0LL )
{
v11 = 1;
if ( v19 )
array_free(v18);
}
else
{
a6(a2);
v14 = a3;
if ( a3 )
{
v15 = a3 - 1;
v16 = 0LL;
while ( 1 )
{
array_clear(v18);
if ( a7(a2, v13, v18, v17) )
break;
if ( v16 == v15 )
goto LABEL_18;
if ( a8(a2, v17) )
break;
if ( ++v16 == v14 )
goto LABEL_18;
}
if ( v19 )
array_free(v18);
v11 = 1;
free(v13);
}
else
{
LABEL_18:
array_free(v18);
free(v13);
}
}
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, void (__fastcall *a6)(__int64), unsigned __int8 (__fastcall *a7)(__int64, void *, char *, _BYTE *), unsigned __int8 (__fastcall *a8)(__int64, _BYTE *))
{
unsigned int v10; // er13
unsigned int v11; // er12
void *v13; // r13
__int64 v14; // r14
__int64 v15; // r15
__int64 v16; // rbp
_BYTE v17[16]; // [rsp+0h] [rbp-78h] BYREF
char v18[16]; // [rsp+10h] [rbp-68h] BYREF
__int64 v19; // [rsp+20h] [rbp-58h]

v19 = 0LL;
v10 = graph_num_nodes();
if ( (unsigned __int8)array_create(v18, 16LL, 10LL)
|| (unsigned __int8)graph_copy(a1, a2)
|| (v11 = stats_cache_init(a2), (_BYTE)v11)
|| (v13 = calloc(v10, 8uLL)) == 0LL )
{
v11 = 1;
if ( v19 )
array_free(v18);
}
else
{
a6(a2);
v14 = a3;
if ( a3 )
{
v15 = a3 - 1;
v16 = 0LL;
while ( 1 )
{
array_clear(v18);
if ( a7(a2, v13, v18, v17) )
break;
if ( v16 == v15 )
goto LABEL_18;
if ( a8(a2, v17) )
break;
if ( ++v16 == v14 )
goto LABEL_18;
}
if ( v19 )
array_free(v18);
v11 = 1;
free(v13);
}
else
{
LABEL_18:
array_free(v18);
free(v13);
}
}
return v11;
}

original_code:
uint8_t graph_threshold_edges(
  graph_t *gin,
  graph_t *gout,
  uint32_t nedges,
  uint32_t flags,
  void *opt,
  uint8_t (*init)(graph_t *g),
  uint8_t (*remove)(
    graph_t *g,
    double *space,
    array_t *edges,
    graph_edge_t *edge),
  uint8_t (*recalc)(
    graph_t *g,
    graph_edge_t *edge)
) {
  uint64_t i;
  uint32_t nnodes;
  double *space;
  array_t edges;
  graph_edge_t edge;
  edges.data = ((void *)0);
  space = ((void *)0);
  nnodes = graph_num_nodes(gin);
  if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail;
  if (graph_copy(gin, gout)) goto fail;
  if (stats_cache_init(gout)) goto fail;
  space = calloc(nnodes,sizeof(double));
  if (space == ((void *)0)) goto fail;
  init(gout);
  for (i = 0; i < nedges; i++) {
    array_clear(&edges);
    if (remove(gout, space, &edges, &edge)) goto fail;
    if (i == nedges -1) break;
    if (recalc(gout, &edge)) goto fail;
  }
  array_free(&edges);
  free(space);
  return 0;
fail:
  if (edges.data != ((void *)0)) array_free(&edges);
  if (space != ((void *)0)) free(space);
  return 1;
}

canonical_original_code:
unsigned char graph_threshold_edges(struct _graph *gin, struct _graph *gout, unsigned int nedges, unsigned int flags, void *opt, unsigned char (*init)(struct _graph *g), unsigned char (*remove)(struct _graph *g, double *space, struct _array *edges, struct _graph_edge *edge), unsigned char (*recalc)(struct _graph *g, struct _graph_edge *edge)) {
  unsigned long i;
  unsigned int nnodes;
  double *space;
  struct _array edges;
  struct _graph_edge edge;
  edges.data = ((void *)0);
  space = ((void *)0);
  nnodes = graph_num_nodes(gin);
  if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail;
  if (graph_copy(gin, gout)) goto fail;
  if (stats_cache_init(gout)) goto fail;
  space = calloc(nnodes,sizeof(double));
  if (space == ((void *)0)) goto fail;
  init(gout);
  for (i = 0; i < nedges; i++) {
    array_clear(&edges);
    if (remove(gout, space, &edges, &edge)) goto fail;
    if (i == nedges -1) break;
    if (recalc(gout, &edge)) goto fail;
  }
  array_free(&edges);
  free(space);
  return 0;
fail:
  if (edges.data != ((void *)0)) array_free(&edges);
  if (space != ((void *)0)) free(space);
  return 1;
}

variable_types:
nedges
unsigned int

variable_types:
flags
unsigned int

variable_types:
opt
void *

variable_types:
init
unsigned char (*)(struct _graph *g)

variable_types: unsigned char (*)(struct _graph *g, double *space, struct _array *edges, struct _graph_edge { unsigned int u; unsigned int v; double val; } *edge)

variable_types: unsigned char (*)(struct _graph *g, struct _graph_edge *edge)

variable_types:
nnodes
unsigned int

variable_types:
space
double *


decompiled_code:
__int64 __fastcall graph_threshold_components(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5, void (__fastcall *a6)(__int64), unsigned __int8 (__fastcall *a7)(__int64, void *, char *, char *), unsigned __int8 (__fastcall *a8)(__int64, char *))
{
unsigned int v11; // eax
unsigned int v12; // er12
unsigned int v14; // er13
void *v15; // r13
unsigned __int64 v16; // r15
unsigned int v17; // eax
char v18[16]; // [rsp+10h] [rbp-78h] BYREF
char v19[16]; // [rsp+20h] [rbp-68h] BYREF
__int64 v20; // [rsp+30h] [rbp-58h]

v20 = 0LL;
v11 = graph_num_nodes();
if ( v11 >= a3 )
{
v14 = v11;
if ( !(unsigned __int8)array_create(v19, 16LL, 10LL) && !(unsigned __int8)graph_copy(a1, a2) )
{
v12 = stats_cache_init(a2);
if ( !(_BYTE)v12 )
{
v15 = calloc(v14, 8uLL);
if ( v15 )
{
a6(a2);
v16 = (unsigned int)stats_num_components(a2, a4, 0LL, 0LL);
do
{
if ( v16 < a3 )
{
array_clear(v19);
if ( a7(a2, v15, v19, v18) )
break;
v17 = stats_num_components(a2, a4, 0LL, 0LL);
v16 = v17;
if ( v17 < a3 )
continue;
}
free(v15);
array_free(v19);
return v12;
}
while ( !a8(a2, v18) );
free(v15);
}
}
}
}
v12 = 1;
if ( v20 )
array_free(v19);
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, __int64 a5, void (__fastcall *a6)(__int64), unsigned __int8 (__fastcall *a7)(__int64, void *, char *, char *), unsigned __int8 (__fastcall *a8)(__int64, char *))
{
unsigned int v11; // eax
unsigned int v12; // er12
unsigned int v14; // er13
void *v15; // r13
unsigned __int64 v16; // r15
unsigned int v17; // eax
char v18[16]; // [rsp+10h] [rbp-78h] BYREF
char v19[16]; // [rsp+20h] [rbp-68h] BYREF
__int64 v20; // [rsp+30h] [rbp-58h]

v20 = 0LL;
v11 = graph_num_nodes();
if ( v11 >= a3 )
{
v14 = v11;
if ( !(unsigned __int8)array_create(v19, 16LL, 10LL) && !(unsigned __int8)graph_copy(a1, a2) )
{
v12 = stats_cache_init(a2);
if ( !(_BYTE)v12 )
{
v15 = calloc(v14, 8uLL);
if ( v15 )
{
a6(a2);
v16 = (unsigned int)stats_num_components(a2, a4, 0LL, 0LL);
do
{
if ( v16 < a3 )
{
array_clear(v19);
if ( a7(a2, v15, v19, v18) )
break;
v17 = stats_num_components(a2, a4, 0LL, 0LL);
v16 = v17;
if ( v17 < a3 )
continue;
}
free(v15);
array_free(v19);
return v12;
}
while ( !a8(a2, v18) );
free(v15);
}
}
}
}
v12 = 1;
if ( v20 )
array_free(v19);
return v12;
}

original_code:
uint8_t graph_threshold_components(
  graph_t *gin,
  graph_t *gout,
  uint32_t cmplimit,
  uint32_t igndis,
  void *opt,
  uint8_t (*init)(graph_t *g),
  uint8_t (*remove)(
    graph_t *g,
    double *space,
    array_t *edges,
    graph_edge_t *edge),
  uint8_t (*recalc)(
    graph_t *g,
    graph_edge_t *edge)
) {
  uint32_t nnodes;
  uint64_t ncmps;
  double *space;
  array_t edges;
  graph_edge_t edge;
  edges.data = ((void *)0);
  space = ((void *)0);
  nnodes = graph_num_nodes(gin);
  if (cmplimit > nnodes) goto fail;
  if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail;
  if (graph_copy(gin, gout)) goto fail;
  if (stats_cache_init(gout)) goto fail;
  space = calloc(nnodes,sizeof(double));
  if (space == ((void *)0)) goto fail;
  init(gout);
  ncmps = stats_num_components(gout, igndis, ((void *)0), ((void *)0));
  while (ncmps < cmplimit) {
    array_clear(&edges);
    if (remove(gout, space, &edges, &edge)) goto fail;
    ncmps = stats_num_components(gout, igndis, ((void *)0), ((void *)0));
    if (ncmps >= cmplimit) break;
    if (recalc(gout, &edge)) goto fail;
  }
  free(space);
  array_free(&edges);
  return 0;
fail:
  if (space != ((void *)0)) free(space);
  if (edges.data != ((void *)0)) array_free(&edges);
  return 1;
}

canonical_original_code:
unsigned char graph_threshold_components(struct _graph *gin, struct _graph *gout, unsigned int cmplimit, unsigned int igndis, void *opt, unsigned char (*init)(struct _graph *g), unsigned char (*remove)(struct _graph *g, double *space, struct _array *edges, struct _graph_edge *edge), unsigned char (*recalc)(struct _graph *g, struct _graph_edge *edge)) {
  unsigned int nnodes;
  unsigned long ncmps;
  double *space;
  struct _array edges;
  struct _graph_edge edge;
  edges.data = ((void *)0);
  space = ((void *)0);
  nnodes = graph_num_nodes(gin);
  if (cmplimit > nnodes) goto fail;
  if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail;
  if (graph_copy(gin, gout)) goto fail;
  if (stats_cache_init(gout)) goto fail;
  space = calloc(nnodes,sizeof(double));
  if (space == ((void *)0)) goto fail;
  init(gout);
  ncmps = stats_num_components(gout, igndis, ((void *)0), ((void *)0));
  while (ncmps < cmplimit) {
    array_clear(&edges);
    if (remove(gout, space, &edges, &edge)) goto fail;
    ncmps = stats_num_components(gout, igndis, ((void *)0), ((void *)0));
    if (ncmps >= cmplimit) break;
    if (recalc(gout, &edge)) goto fail;
  }
  free(space);
  array_free(&edges);
  return 0;
fail:
  if (space != ((void *)0)) free(space);
  if (edges.data != ((void *)0)) array_free(&edges);
  return 1;
}

variable_types:
gout
struct _graph *

variable_types:
cmplimit
unsigned int

variable_types:
igndis
unsigned int

variable_types:
ncmps
unsigned long

variable_types: struct _graph_edge { unsigned int u; unsigned int v; double val; }


decompiled_code:
__int64 __fastcall graph_threshold_modularity(__int64 a1, __int64 a2, unsigned int a3, double a4, __int64 a5, __int64 a6, void (__fastcall *a7)(char *), unsigned __int8 (__fastcall *a8)(char *, void *, char *, char *), unsigned __int8 (__fastcall *a9)(char *, char *))
{
size_t v12; // r15
void *v13; // r13
void *v14; // rdi
void *v15; // rdi
void *v17; // r15
void *v18; // rax
void *v19; // rax
__int64 v20; // r14
__int64 v21; // r12
double v22; // [rsp+8h] [rbp-2B0h]
size_t nmemb; // [rsp+10h] [rbp-2A8h]
char v24[16]; // [rsp+20h] [rbp-298h] BYREF
char v25[16]; // [rsp+30h] [rbp-288h] BYREF
__int64 v26; // [rsp+40h] [rbp-278h]
char v27[272]; // [rsp+60h] [rbp-258h] BYREF
char v28[128]; // [rsp+170h] [rbp-148h] BYREF
__int64 v29; // [rsp+1F0h] [rbp-C8h]

v26 = 0LL;
v29 = 0LL;
if ( a6 )
{
*(_QWORD *)(a6 + 8) = 0LL;
*(_QWORD *)(a6 + 16) = 0LL;
*(_DWORD *)a6 = a3;
}
v12 = (unsigned int)graph_num_nodes(a1);
if ( (unsigned __int8)graph_copy(a1, v27)
|| (unsigned __int8)stats_cache_init(v27)
|| (unsigned __int8)array_create(v25, 16LL, 10LL)
|| (v13 = calloc(v12, 4uLL)) == 0LL )
{
v13 = 0LL;
}
else
{
v17 = calloc(v12, 8uLL);
if ( v17 )
{
nmemb = a3;
if ( !a6
|| (v18 = calloc(a3, 8uLL), (*(_QWORD *)(a6 + 8) = v18) != 0LL)
&& (v19 = calloc(a3, 4uLL), (*(_QWORD *)(a6 + 16) = v19) != 0LL) )
{
a7(v27);
v20 = 0LL;
v22 = *(double *)&LC1;
if ( a3 )
{
while ( 1 )
{
array_clear(v25);
if ( a8(v27, v17, v25, v24) )
break;
v21 = (unsigned int)stats_num_components(v27, 0LL, 0LL, v13);
stats_modularity(a1, v21, v13);
if ( a6 )
{
*(double *)(*(_QWORD *)(a6 + 8) + 8 * v20) = a4;
*(_DWORD *)(*(_QWORD *)(a6 + 16) + 4 * v20) = v21;
}
if ( a4 >= v22 )
{
if ( v29 )
graph_free(v28);
v29 = 0LL;
v22 = a4;
if ( (unsigned __int8)graph_copy(v27, v28) )
break;
}
if ( a9(v27, v24) )
break;
if ( nmemb == ++v20 )
goto LABEL_36;
}
}
else
{
LABEL_36:
if ( !(unsigned __int8)graph_copy(v28, a2) )
{
free(v17);
array_free(v25);
return 0LL;
}
}
}
free(v17);
}
}
if ( v26 )
array_free(v25);
if ( v29 )
graph_free(v28);
if ( v13 )
free(v13);
if ( a6 )
{
v14 = *(void **)(a6 + 8);
if ( v14 )
free(v14);
v15 = *(void **)(a6 + 16);
if ( v15 )
free(v15);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3, double a4, __int64 a5, __int64 a6, void (__fastcall *a7)(char *), unsigned __int8 (__fastcall *a8)(char *, void *, char *, char *), unsigned __int8 (__fastcall *a9)(char *, char *))
{
size_t v12; // r15
void *v13; // r13
void *v14; // rdi
void *v15; // rdi
void *v17; // r15
void *v18; // rax
void *v19; // rax
__int64 v20; // r14
__int64 v21; // r12
double v22; // [rsp+8h] [rbp-2B0h]
size_t nmemb; // [rsp+10h] [rbp-2A8h]
char v24[16]; // [rsp+20h] [rbp-298h] BYREF
char v25[16]; // [rsp+30h] [rbp-288h] BYREF
__int64 v26; // [rsp+40h] [rbp-278h]
char v27[272]; // [rsp+60h] [rbp-258h] BYREF
char v28[128]; // [rsp+170h] [rbp-148h] BYREF
__int64 v29; // [rsp+1F0h] [rbp-C8h]

v26 = 0LL;
v29 = 0LL;
if ( a6 )
{
*(_QWORD *)(a6 + 8) = 0LL;
*(_QWORD *)(a6 + 16) = 0LL;
*(_DWORD *)a6 = a3;
}
v12 = (unsigned int)graph_num_nodes(a1);
if ( (unsigned __int8)graph_copy(a1, v27)
|| (unsigned __int8)stats_cache_init(v27)
|| (unsigned __int8)array_create(v25, 16LL, 10LL)
|| (v13 = calloc(v12, 4uLL)) == 0LL )
{
v13 = 0LL;
}
else
{
v17 = calloc(v12, 8uLL);
if ( v17 )
{
nmemb = a3;
if ( !a6
|| (v18 = calloc(a3, 8uLL), (*(_QWORD *)(a6 + 8) = v18) != 0LL)
&& (v19 = calloc(a3, 4uLL), (*(_QWORD *)(a6 + 16) = v19) != 0LL) )
{
a7(v27);
v20 = 0LL;
v22 = *(double *)&LC1;
if ( a3 )
{
while ( 1 )
{
array_clear(v25);
if ( a8(v27, v17, v25, v24) )
break;
v21 = (unsigned int)stats_num_components(v27, 0LL, 0LL, v13);
stats_modularity(a1, v21, v13);
if ( a6 )
{
*(double *)(*(_QWORD *)(a6 + 8) + 8 * v20) = a4;
*(_DWORD *)(*(_QWORD *)(a6 + 16) + 4 * v20) = v21;
}
if ( a4 >= v22 )
{
if ( v29 )
graph_free(v28);
v29 = 0LL;
v22 = a4;
if ( (unsigned __int8)graph_copy(v27, v28) )
break;
}
if ( a9(v27, v24) )
break;
if ( nmemb == ++v20 )
goto LABEL_36;
}
}
else
{
LABEL_36:
if ( !(unsigned __int8)graph_copy(v28, a2) )
{
free(v17);
array_free(v25);
return 0LL;
}
}
}
free(v17);
}
}
if ( v26 )
array_free(v25);
if ( v29 )
graph_free(v28);
if ( v13 )
free(v13);
if ( a6 )
{
v14 = *(void **)(a6 + 8);
if ( v14 )
free(v14);
v15 = *(void **)(a6 + 16);
if ( v15 )
free(v15);
}
return 1LL;
}

original_code:
uint8_t graph_threshold_modularity(
  graph_t *gin,
  graph_t *gout,
  uint32_t edgelimit,
  uint32_t flags,
  void *opt,
  uint8_t (*init)(graph_t *g),
  uint8_t (*remove)(
    graph_t *g,
    double *space,
    array_t *edges,
    graph_edge_t *edge),
  uint8_t (*recalc)(
    graph_t *g,
    graph_edge_t *edge)
) {
  uint32_t nnodes;
  uint64_t i;
  graph_t lgin;
  array_t edges;
  graph_edge_t edge;
  graph_t gmod;
  double *space;
  double mod;
  double maxmod;
  uint32_t ncmps;
  uint32_t *components;
  mod_opt_t *modopt;
  maxmod = -1.0;
  modopt = opt;
  space = ((void *)0);
  edges.data = ((void *)0);
  gmod.neighbours = ((void *)0);
  components = ((void *)0);
  if (modopt != ((void *)0)) {
    modopt->modularity = ((void *)0);
    modopt->ncmps = ((void *)0);
    modopt->nvals = edgelimit;
  }
  nnodes = graph_num_nodes(gin);
  if (graph_copy(gin, &lgin)) goto fail;
  if (stats_cache_init(&lgin)) goto fail;
  if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail;
  components = calloc(nnodes,sizeof(uint32_t));
  if (components == ((void *)0)) goto fail;
  space = calloc(nnodes,sizeof(double));
  if (space == ((void *)0)) goto fail;
  if (modopt != ((void *)0)) {
    modopt->modularity = calloc(edgelimit,sizeof(double));
    if (modopt->modularity == ((void *)0)) goto fail;
    modopt->ncmps = calloc(edgelimit,sizeof(uint32_t));
    if (modopt->ncmps == ((void *)0)) goto fail;
  }
  init(&lgin);
  for (i = 0; i < edgelimit; i++) {
    array_clear(&edges);
    if (remove(&lgin, space, &edges, &edge)) goto fail;
    ncmps = stats_num_components(&lgin, 0, ((void *)0), components);
    mod = stats_modularity(gin, ncmps, components);
    if (modopt != ((void *)0)) {
      modopt->modularity[i] = mod;
      modopt->ncmps[i] = ncmps;
    }
    if (mod >= maxmod) {
      maxmod = mod;
      if (gmod.neighbours != ((void *)0))
        graph_free(&gmod);
      gmod.neighbours = ((void *)0);
      if (graph_copy(&lgin, &gmod)) goto fail;
    }
    if (recalc(&lgin, &edge)) goto fail;
  }
  if (graph_copy(&gmod, gout)) goto fail;
  free(space);
  array_free(&edges);
  return 0;
fail:
  if (space != ((void *)0)) free(space);
  if (edges.data != ((void *)0)) array_free(&edges);
  if (gmod.neighbours != ((void *)0)) graph_free(&gmod);
  if (components != ((void *)0)) free(components);
  if (modopt != ((void *)0)) {
    if (modopt->modularity != ((void *)0)) free(modopt->modularity);
    if (modopt->ncmps != ((void *)0)) free(modopt->ncmps);
  }
  return 1;
}

canonical_original_code:
unsigned char graph_threshold_modularity(struct _graph *gin, struct _graph *gout, unsigned int edgelimit, unsigned int flags, void *opt, unsigned char (*init)(struct _graph *g), unsigned char (*remove)(struct _graph *g, double *space, struct _array *edges, struct _graph_edge *edge), unsigned char (*recalc)(struct _graph *g, struct _graph_edge *edge)) {
  unsigned int nnodes;
  unsigned long i;
  struct _graph lgin;
  struct _array edges;
  struct _graph_edge edge;
  struct _graph gmod;
  double *space;
  double mod;
  double maxmod;
  unsigned int ncmps;
  unsigned int *components;
  struct _mod_opt *modopt;
  maxmod = -1.0;
  modopt = opt;
  space = ((void *)0);
  edges.data = ((void *)0);
  gmod.neighbours = ((void *)0);
  components = ((void *)0);
  if (modopt != ((void *)0)) {
    modopt->modularity = ((void *)0);
    modopt->ncmps = ((void *)0);
    modopt->nvals = edgelimit;
  }
  nnodes = graph_num_nodes(gin);
  if (graph_copy(gin, &lgin)) goto fail;
  if (stats_cache_init(&lgin)) goto fail;
  if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail;
  components = calloc(nnodes,sizeof(unsigned int));
  if (components == ((void *)0)) goto fail;
  space = calloc(nnodes,sizeof(double));
  if (space == ((void *)0)) goto fail;
  if (modopt != ((void *)0)) {
    modopt->modularity = calloc(edgelimit,sizeof(double));
    if (modopt->modularity == ((void *)0)) goto fail;
    modopt->ncmps = calloc(edgelimit,sizeof(unsigned int));
    if (modopt->ncmps == ((void *)0)) goto fail;
  }
  init(&lgin);
  for (i = 0; i < edgelimit; i++) {
    array_clear(&edges);
    if (remove(&lgin, space, &edges, &edge)) goto fail;
    ncmps = stats_num_components(&lgin, 0, ((void *)0), components);
    mod = stats_modularity(gin, ncmps, components);
    if (modopt != ((void *)0)) {
      modopt->modularity[i] = mod;
      modopt->ncmps[i] = ncmps;
    }
    if (mod >= maxmod) {
      maxmod = mod;
      if (gmod.neighbours != ((void *)0))
        graph_free(&gmod);
      gmod.neighbours = ((void *)0);
      if (graph_copy(&lgin, &gmod)) goto fail;
    }
    if (recalc(&lgin, &edge)) goto fail;
  }
  if (graph_copy(&gmod, gout)) goto fail;
  free(space);
  array_free(&edges);
  return 0;
fail:
  if (space != ((void *)0)) free(space);
  if (edges.data != ((void *)0)) array_free(&edges);
  if (gmod.neighbours != ((void *)0)) graph_free(&gmod);
  if (components != ((void *)0)) free(components);
  if (modopt != ((void *)0)) {
    if (modopt->modularity != ((void *)0)) free(modopt->modularity);
    if (modopt->ncmps != ((void *)0)) free(modopt->ncmps);
  }
  return 1;
}

variable_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *

variable_types:
edgelimit
unsigned int

variable_types:
i
unsigned long

variable_types: mod double

variable_types: maxmod double

variable_types:
ncmps
unsigned int

variable_types:
components
unsigned int *

variable_types: struct _mod_opt { unsigned int nvals; double *modularity; unsigned int *ncmps; } *

user_defined_types: struct _graph_edge { unsigned int u; unsigned int v; double val; }


decompiled_code:
__int64 __fastcall graph_threshold_chira(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, void (__fastcall *a6)(char *), unsigned __int8 (__fastcall *a7)(char *, void *, char *, char *), unsigned __int8 (__fastcall *a8)(char *, char *))
{
__int64 v9; // r12
size_t v10; // r14
void *v11; // rbp
unsigned int v12; // er12
void *v14; // r14
__int64 v15; // r15
unsigned int v16; // eax
double v17; // xmm0_8
double v18; // [rsp+8h] [rbp-2A0h]
char v19[16]; // [rsp+10h] [rbp-298h] BYREF
char v20[16]; // [rsp+20h] [rbp-288h] BYREF
__int64 v21; // [rsp+30h] [rbp-278h]
char v22[272]; // [rsp+50h] [rbp-258h] BYREF
char v23[128]; // [rsp+160h] [rbp-148h] BYREF
__int64 v24; // [rsp+1E0h] [rbp-C8h]

v9 = a3;
v21 = 0LL;
v24 = 0LL;
v10 = (unsigned int)graph_num_nodes(a1);
if ( (unsigned __int8)graph_copy(a1, v22)
|| (unsigned __int8)stats_cache_init(v22)
|| (unsigned __int8)array_create(v20, 16LL, 10LL)
|| (v11 = calloc(v10, 4uLL)) == 0LL )
{
v11 = 0LL;
}
else
{
v14 = calloc(v10, 8uLL);
if ( v14 )
{
a6(v22);
if ( v9 )
{
v15 = 0LL;
v18 = *(double *)&LC1;
while ( 1 )
{
array_clear(v20);
if ( a7(v22, v14, v20, v19) )
break;
v16 = stats_num_components(v22, 0LL, 0LL, v11);
v17 = stats_chira(a1, v16, v11);
if ( v17 >= v18 )
{
if ( v24 )
graph_free(v23);
v24 = 0LL;
v18 = v17;
if ( (unsigned __int8)graph_copy(v22, v23) )
break;
}
if ( a8(v22, v19) )
break;
if ( ++v15 == v9 )
goto LABEL_24;
}
}
else
{
LABEL_24:
v12 = graph_copy(v23, a2);
if ( !(_BYTE)v12 )
{
free(v14);
array_free(v20);
return v12;
}
}
free(v14);
}
}
if ( v21 )
array_free(v20);
if ( v24 )
graph_free(v23);
v12 = 1;
if ( v11 )
free(v11);
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, void (__fastcall *a6)(char *), unsigned __int8 (__fastcall *a7)(char *, void *, char *, char *), unsigned __int8 (__fastcall *a8)(char *, char *))
{
__int64 v9; // r12
size_t v10; // r14
void *v11; // rbp
unsigned int v12; // er12
void *v14; // r14
__int64 v15; // r15
unsigned int v16; // eax
double v17; // xmm0_8
double v18; // [rsp+8h] [rbp-2A0h]
char v19[16]; // [rsp+10h] [rbp-298h] BYREF
char v20[16]; // [rsp+20h] [rbp-288h] BYREF
__int64 v21; // [rsp+30h] [rbp-278h]
char v22[272]; // [rsp+50h] [rbp-258h] BYREF
char v23[128]; // [rsp+160h] [rbp-148h] BYREF
__int64 v24; // [rsp+1E0h] [rbp-C8h]

v9 = a3;
v21 = 0LL;
v24 = 0LL;
v10 = (unsigned int)graph_num_nodes(a1);
if ( (unsigned __int8)graph_copy(a1, v22)
|| (unsigned __int8)stats_cache_init(v22)
|| (unsigned __int8)array_create(v20, 16LL, 10LL)
|| (v11 = calloc(v10, 4uLL)) == 0LL )
{
v11 = 0LL;
}
else
{
v14 = calloc(v10, 8uLL);
if ( v14 )
{
a6(v22);
if ( v9 )
{
v15 = 0LL;
v18 = *(double *)&LC1;
while ( 1 )
{
array_clear(v20);
if ( a7(v22, v14, v20, v19) )
break;
v16 = stats_num_components(v22, 0LL, 0LL, v11);
v17 = stats_chira(a1, v16, v11);
if ( v17 >= v18 )
{
if ( v24 )
graph_free(v23);
v24 = 0LL;
v18 = v17;
if ( (unsigned __int8)graph_copy(v22, v23) )
break;
}
if ( a8(v22, v19) )
break;
if ( ++v15 == v9 )
goto LABEL_24;
}
}
else
{
LABEL_24:
v12 = graph_copy(v23, a2);
if ( !(_BYTE)v12 )
{
free(v14);
array_free(v20);
return v12;
}
}
free(v14);
}
}
if ( v21 )
array_free(v20);
if ( v24 )
graph_free(v23);
v12 = 1;
if ( v11 )
free(v11);
return v12;
}

original_code:
uint8_t graph_threshold_chira(
  graph_t *gin,
  graph_t *gout,
  uint32_t edgelimit,
  uint32_t flags,
  void *opt,
  uint8_t (*init)(graph_t *g),
  uint8_t (*remove)(
    graph_t *g,
    double *space,
    array_t *edges,
    graph_edge_t *edge),
  uint8_t (*recalc)(
    graph_t *g,
    graph_edge_t *edge)
) {
  uint32_t nnodes;
  uint64_t i;
  graph_t lgin;
  array_t edges;
  graph_edge_t edge;
  graph_t gmod;
  double *space;
  double mod;
  double maxmod;
  uint32_t ncmps;
  uint32_t *components;
  maxmod = -1.0;
  space = ((void *)0);
  edges.data = ((void *)0);
  gmod.neighbours = ((void *)0);
  components = ((void *)0);
  nnodes = graph_num_nodes(gin);
  if (graph_copy(gin, &lgin)) goto fail;
  if (stats_cache_init(&lgin)) goto fail;
  if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail;
  components = calloc(nnodes,sizeof(uint32_t));
  if (components == ((void *)0)) goto fail;
  space = calloc(nnodes,sizeof(double));
  if (space == ((void *)0)) goto fail;
  init(&lgin);
  for (i = 0; i < edgelimit; i++) {
    array_clear(&edges);
    if (remove(&lgin, space, &edges, &edge)) goto fail;
    ncmps = stats_num_components(&lgin, 0, ((void *)0), components);
    mod = stats_chira(gin, ncmps, components);
    if (mod >= maxmod) {
      maxmod = mod;
      if (gmod.neighbours != ((void *)0))
        graph_free(&gmod);
      gmod.neighbours = ((void *)0);
      if (graph_copy(&lgin, &gmod)) goto fail;
    }
    if (recalc(&lgin, &edge)) goto fail;
  }
  if (graph_copy(&gmod, gout)) goto fail;
  free(space);
  array_free(&edges);
  return 0;
fail:
  if (space != ((void *)0)) free(space);
  if (edges.data != ((void *)0)) array_free(&edges);
  if (gmod.neighbours != ((void *)0)) graph_free(&gmod);
  if (components != ((void *)0)) free(components);
  return 1;
}

canonical_original_code:
unsigned char graph_threshold_chira(struct _graph *gin, struct _graph *gout, unsigned int edgelimit, unsigned int flags, void *opt, unsigned char (*init)(struct _graph *g), unsigned char (*remove)(struct _graph *g, double *space, struct _array *edges, struct _graph_edge *edge), unsigned char (*recalc)(struct _graph *g, struct _graph_edge *edge)) {
  unsigned int nnodes;
  unsigned long i;
  struct _graph lgin;
  struct _array edges;
  struct _graph_edge edge;
  struct _graph gmod;
  double *space;
  double mod;
  double maxmod;
  unsigned int ncmps;
  unsigned int *components;
  maxmod = -1.0;
  space = ((void *)0);
  edges.data = ((void *)0);
  gmod.neighbours = ((void *)0);
  components = ((void *)0);
  nnodes = graph_num_nodes(gin);
  if (graph_copy(gin, &lgin)) goto fail;
  if (stats_cache_init(&lgin)) goto fail;
  if (array_create(&edges, sizeof(graph_edge_t), 10)) goto fail;
  components = calloc(nnodes,sizeof(unsigned int));
  if (components == ((void *)0)) goto fail;
  space = calloc(nnodes,sizeof(double));
  if (space == ((void *)0)) goto fail;
  init(&lgin);
  for (i = 0; i < edgelimit; i++) {
    array_clear(&edges);
    if (remove(&lgin, space, &edges, &edge)) goto fail;
    ncmps = stats_num_components(&lgin, 0, ((void *)0), components);
    mod = stats_chira(gin, ncmps, components);
    if (mod >= maxmod) {
      maxmod = mod;
      if (gmod.neighbours != ((void *)0))
        graph_free(&gmod);
      gmod.neighbours = ((void *)0);
      if (graph_copy(&lgin, &gmod)) goto fail;
    }
    if (recalc(&lgin, &edge)) goto fail;
  }
  if (graph_copy(&gmod, gout)) goto fail;
  free(space);
  array_free(&edges);
  return 0;
fail:
  if (space != ((void *)0)) free(space);
  if (edges.data != ((void *)0)) array_free(&edges);
  if (gmod.neighbours != ((void *)0)) graph_free(&gmod);
  if (components != ((void *)0)) free(components);
  return 1;
}

variable_types:
flags
unsigned int

variable_types:
opt
void *

variable_types:
init
unsigned char (*)(struct _graph *g)

variable_types: unsigned char (*)(struct _graph *g, double *space, struct _array *edges, struct _graph_edge { unsigned int u; unsigned int v; double val; } *edge)

variable_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); }


decompiled_code:
__int64 __fastcall edge_array_create(__int64 a1, unsigned __int16 a2, __int64 a3)
{
size_t v4; // r12
void *v5; // rax
__int64 v6; // rbx
unsigned int v7; // eax
_QWORD *v8; // r8
__int64 v9; // rbx

*(_QWORD *)a3 = a1;
*(_WORD *)(a3 + 8) = a2;
*(_QWORD *)(a3 + 16) = 0LL;
v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 0x28uLL);
*(_QWORD *)(a3 + 16) = v5;
if ( !v5 )
return 1LL;
v6 = 0LL;
if ( v4 )
{
while ( 1 )
{
v7 = graph_num_neighbours(a1, (unsigned int)v6);
if ( (unsigned __int8)array_create(*(_QWORD *)(a3 + 16) + 40 * v6, a2, v7) )
break;
if ( v4 == ++v6 )
goto LABEL_12;
}
v8 = *(_QWORD **)(a3 + 16);
v9 = 0LL;
if ( v8 )
{
do
{
if ( v8[5 * v9 + 2] )
{
array_free();
v8 = *(_QWORD **)(a3 + 16);
}
++v9;
}
while ( v4 != v9 );
free(v8);
}
return 1LL;
}
LABEL_12:
*(_QWORD *)(a3 + 24) = 0LL;
*(_QWORD *)(a3 + 40) = edge_added;
*(_QWORD *)(a3 + 48) = edge_removed;
*(_QWORD *)(a3 + 32) = a3;
graph_add_event_listener(a1, a3 + 24);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int16 a2, __int64 a3)
{
size_t v4; // r12
void *v5; // rax
__int64 v6; // rbx
unsigned int v7; // eax
_QWORD *v8; // r8
__int64 v9; // rbx

*(_QWORD *)a3 = a1;
*(_WORD *)(a3 + 8) = a2;
*(_QWORD *)(a3 + 16) = 0LL;
v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 0x28uLL);
*(_QWORD *)(a3 + 16) = v5;
if ( !v5 )
return 1LL;
v6 = 0LL;
if ( v4 )
{
while ( 1 )
{
v7 = graph_num_neighbours(a1, (unsigned int)v6);
if ( (unsigned __int8)array_create(*(_QWORD *)(a3 + 16) + 40 * v6, a2, v7) )
break;
if ( v4 == ++v6 )
goto LABEL_12;
}
v8 = *(_QWORD **)(a3 + 16);
v9 = 0LL;
if ( v8 )
{
do
{
if ( v8[5 * v9 + 2] )
{
array_free();
v8 = *(_QWORD **)(a3 + 16);
}
++v9;
}
while ( v4 != v9 );
free(v8);
}
return 1LL;
}
LABEL_12:
*(_QWORD *)(a3 + 24) = 0LL;
*(_QWORD *)(a3 + 40) = edge_added;
*(_QWORD *)(a3 + 48) = edge_removed;
*(_QWORD *)(a3 + 32) = a3;
graph_add_event_listener(a1, a3 + 24);
return 0LL;
}

original_code:
uint8_t edge_array_create(
  graph_t *g, uint16_t valsz, edge_array_t *ea) {
  uint64_t i;
  uint32_t nnodes;
  uint32_t nnbrs;
  ea->g = g;
  ea->valsz = valsz;
  ea->vals = ((void *)0);
  nnodes = graph_num_nodes(g);
  ea->vals = calloc(nnodes, sizeof(array_t));
  if (ea->vals == ((void *)0)) goto fail;
  for (i = 0; i < nnodes; i++) {
    nnbrs = graph_num_neighbours(g, i);
    if (array_create(&ea->vals[i], valsz, nnbrs))
      goto fail;
  }
  memset(&ea->gel, 0, sizeof(graph_event_listener_t));
  ea->gel.edge_added = _edge_added;
  ea->gel.edge_removed = _edge_removed;
  ea->gel.ctx = ea;
  graph_add_event_listener(g, &ea->gel);
  return 0;
fail:
  if (ea->vals != ((void *)0)) {
    for (i = 0; i < nnodes; i++) {
      if (ea->vals[i].data != ((void *)0)) array_free(&ea->vals[i]);
    }
    free(ea->vals);
  }
  return 1;
}

canonical_original_code:
unsigned char edge_array_create(struct _graph *g, unsigned short valsz, struct _edge_array *ea) {
  unsigned long i;
  unsigned int nnodes;
  unsigned int nnbrs;
  ea->g = g;
  ea->valsz = valsz;
  ea->vals = ((void *)0);
  nnodes = graph_num_nodes(g);
  ea->vals = calloc(nnodes, sizeof(array_t));
  if (ea->vals == ((void *)0)) goto fail;
  for (i = 0; i < nnodes; i++) {
    nnbrs = graph_num_neighbours(g, i);
    if (array_create(&ea->vals[i], valsz, nnbrs))
      goto fail;
  }
  memset(&ea->gel, 0, sizeof(graph_event_listener_t));
  ea->gel.edge_added = _edge_added;
  ea->gel.edge_removed = _edge_removed;
  ea->gel.ctx = ea;
  graph_add_event_listener(g, &ea->gel);
  return 0;
fail:
  if (ea->vals != ((void *)0)) {
    for (i = 0; i < nnodes; i++) {
      if (ea->vals[i].data != ((void *)0)) array_free(&ea->vals[i]);
    }
    free(ea->vals);
  }
  return 1;
}

variable_types:
valsz
unsigned short

variable_types: struct _edge_array { struct _graph *g; unsigned short valsz; struct _array *vals; struct _graph_event_listener { unsigned long id; void *ctx; void (*edge_added)(struct _graph *g, void *ctx, unsigned int u, unsigned int v, unsigned int uidx, unsigned int vidx, float wt); void (*edge_removed)(struct _graph *g, void *ctx, unsigned int u, unsigned int v, unsigned int uidx, unsigned int vidx); } gel; } *

variable_types:
nnodes
unsigned int

variable_types:
nnbrs
unsigned int

user_defined_types: struct _edge_array { struct _graph *g; unsigned short valsz; struct _array *vals; struct _graph_event_listener gel; }


decompiled_code:
void __fastcall edge_array_free(_QWORD *a1)
{
unsigned int v1; // eax
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rdx

if ( a1 )
{
graph_remove_event_listener(*a1, a1 + 3);
if ( a1[2] )
{
v1 = graph_num_nodes(*a1);
v2 = v1;
if ( v1 )
{
v3 = 0LL;
do
{
v4 = 5 * v3++;
array_free(a1[2] + 8 * v4);
}
while ( v3 != v2 );
}
free((void *)a1[2]);
}
*a1 = 0LL;
a1[2] = 0LL;
}
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1)
{
unsigned int v1; // eax
__int64 v2; // r12
__int64 v3; // rbx
__int64 v4; // rdx

if ( a1 )
{
graph_remove_event_listener(*a1, a1 + 3);
if ( a1[2] )
{
v1 = graph_num_nodes(*a1);
v2 = v1;
if ( v1 )
{
v3 = 0LL;
do
{
v4 = 5 * v3++;
array_free(a1[2] + 8 * v4);
}
while ( v3 != v2 );
}
free((void *)a1[2]);
}
*a1 = 0LL;
a1[2] = 0LL;
}
}

original_code:
void edge_array_free(edge_array_t *ea) {
  uint64_t i;
  uint32_t nnodes;
  if (ea == ((void *)0)) return;
  graph_remove_event_listener(ea->g, &ea->gel);
  if (ea->vals != ((void *)0)) {
    nnodes = graph_num_nodes(ea->g);
    for (i = 0; i < nnodes; i++)
      array_free(&ea->vals[i]);
    free(ea->vals);
  }
  ea->g = ((void *)0);
  ea->vals = ((void *)0);
}

canonical_original_code:
void edge_array_free(struct _edge_array *ea) {
  unsigned long i;
  unsigned int nnodes;
  if (ea == ((void *)0)) return;
  graph_remove_event_listener(ea->g, &ea->gel);
  if (ea->vals != ((void *)0)) {
    nnodes = graph_num_nodes(ea->g);
    for (i = 0; i < nnodes; i++)
      array_free(&ea->vals[i]);
    free(ea->vals);
  }
  ea->g = ((void *)0);
  ea->vals = ((void *)0);
}

variable_types: struct _edge_array { struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *g; unsigned short valsz; struct _array *vals; struct _graph_event_listener { unsigned long id; void *ctx; void (*edge_added)(struct _graph *g, void *ctx, unsigned int u, unsigned int v, unsigned int uidx, unsigned int vidx, float wt); void (*edge_removed)(struct _graph *g, void *ctx, unsigned int u, unsigned int v, unsigned int uidx, unsigned int vidx); } gel; } *

return_type: void


decompiled_code:
__int64 __fastcall edge_array_get_all(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 40LL * a2 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 16) + 40LL * a2 + 16);
}

original_code:
void * edge_array_get_all(edge_array_t *ea, uint32_t u) {
  return ea->vals[u].data;
}

canonical_original_code:
void *edge_array_get_all(struct _edge_array *ea, unsigned int u) {
  return ea->vals[u].data;
}

variable_types:
u
unsigned int

return_type: void *

user_defined_types: struct _graph_event_listener { unsigned long id; void *ctx; void (*edge_added)(struct _graph *g, void *ctx, unsigned int u, unsigned int v, unsigned int uidx, unsigned int vidx, float wt); void (*edge_removed)(struct _graph *g, void *ctx, unsigned int u, unsigned int v, unsigned int uidx, unsigned int vidx); }


decompiled_code:
__int64 __fastcall edge_array_set_all(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rbx
__int64 v6; // r13
__int64 v7; // r12
__int64 v8; // rsi
__int64 v9; // rdx

result = graph_num_neighbours(*(_QWORD *)a1, a2);
v5 = (unsigned int)result;
if ( (_DWORD)result )
{
v6 = 0LL;
v7 = 40LL * a2;
do
{
v8 = (unsigned int)v6;
v9 = v6 * *(unsigned __int16 *)(a1 + 8);
++v6;
result = array_set(v7 + *(_QWORD *)(a1 + 16), v8, a3 + v9);
}
while ( v6 != v5 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // rbx
__int64 v6; // r13
__int64 v7; // r12
__int64 v8; // rsi
__int64 v9; // rdx

result = graph_num_neighbours(*(_QWORD *)a1, a2);
v5 = (unsigned int)result;
if ( (_DWORD)result )
{
v6 = 0LL;
v7 = 40LL * a2;
do
{
v8 = (unsigned int)v6;
v9 = v6 * *(unsigned __int16 *)(a1 + 8);
++v6;
result = array_set(v7 + *(_QWORD *)(a1 + 16), v8, a3 + v9);
}
while ( v6 != v5 );
}
return result;
}

original_code:
void edge_array_set_all(edge_array_t *ea, uint32_t u, void *vals) {
  uint64_t i;
  uint32_t nnbrs;
  uint8_t *uvals;
  uvals = vals;
  nnbrs = graph_num_neighbours(ea->g, u);
  for (i = 0; i < nnbrs; i++)
    array_set(&ea->vals[u], i, uvals + (i * (ea->valsz)));
}

canonical_original_code:
void edge_array_set_all(struct _edge_array *ea, unsigned int u, void *vals) {
  unsigned long i;
  unsigned int nnbrs;
  unsigned char *uvals;
  uvals = vals;
  nnbrs = graph_num_neighbours(ea->g, u);
  for (i = 0; i < nnbrs; i++)
    array_set(&ea->vals[u], i, uvals + (i * (ea->valsz)));
}

variable_types:
vals
void *

variable_types:
i
unsigned long

variable_types:
uvals
unsigned char *


decompiled_code:
__int64 __fastcall edge_array_get_by_idx(__int64 a1, unsigned int a2, unsigned int a3)
{
return array_getd(*(_QWORD *)(a1 + 16) + 40LL * a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, unsigned int a3)
{
return array_getd(*(_QWORD *)(a1 + 16) + 40LL * a2, a3);
}

original_code:
void * edge_array_get_by_idx(edge_array_t *ea, uint32_t u, uint32_t vidx) {
  return array_getd(&ea->vals[u], vidx);
}

canonical_original_code:
void *edge_array_get_by_idx(struct _edge_array *ea, unsigned int u, unsigned int vidx) {
  return array_getd(&ea->vals[u], vidx);
}

variable_types:
vidx
unsigned int


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

v2 = graph_get_nbr_idx(*a1);
return edge_array_get_by_idx((__int64)a1, a2, v2);
}

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

v2 = graph_get_nbr_idx(*a1);
return func6((__int64)a1, a2, v2);
}

original_code:
void * edge_array_get(edge_array_t *ea, uint32_t u, uint32_t v) {
  uint32_t vidx;
  vidx = graph_get_nbr_idx(ea->g, u, v);
  return edge_array_get_by_idx(ea, u, vidx);
}

canonical_original_code:
void *edge_array_get(struct _edge_array *ea, unsigned int u, unsigned int v) {
  unsigned int vidx;
  vidx = graph_get_nbr_idx(ea->g, u, v);
  return edge_array_get_by_idx(ea, u, vidx);
}

variable_types:
v
unsigned int


decompiled_code:
__int64 __fastcall edge_array_set_by_idx(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4)
{
return array_set(*(_QWORD *)(a1 + 16) + 40LL * a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4)
{
return array_set(*(_QWORD *)(a1 + 16) + 40LL * a2, a3, a4);
}

original_code:
void edge_array_set_by_idx(
  edge_array_t *ea, uint32_t u, uint32_t vidx, void * val) {
  array_set(&ea->vals[u], vidx, val);
}

canonical_original_code:
void edge_array_set_by_idx(struct _edge_array *ea, unsigned int u, unsigned int vidx, void *val) {
  array_set(&ea->vals[u], vidx, val);
}

variable_types:
val
void *


decompiled_code:
__int64 __fastcall edge_array_set(_QWORD *a1, unsigned int a2, unsigned int a3, __int64 a4)
{
unsigned int v6; // eax
__int64 result; // rax
unsigned int v8; // eax

v6 = graph_get_nbr_idx(*a1);
edge_array_set_by_idx((__int64)a1, a2, v6, a4);
result = graph_is_directed(*a1);
if ( !(_BYTE)result )
{
v8 = graph_get_nbr_idx(*a1);
result = edge_array_set_by_idx((__int64)a1, a3, v8, a4);
}
return result;
}

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

v6 = graph_get_nbr_idx(*a1);
func8((__int64)a1, a2, v6, a4);
result = graph_is_directed(*a1);
if ( !(_BYTE)result )
{
v8 = graph_get_nbr_idx(*a1);
result = func8((__int64)a1, a3, v8, a4);
}
return result;
}

original_code:
void edge_array_set(edge_array_t *ea, uint32_t u, uint32_t v, void * val) {
  uint32_t uidx;
  uint32_t vidx;
  vidx = graph_get_nbr_idx(ea->g, u, v);
  edge_array_set_by_idx(ea, u, vidx, val);
  if (!graph_is_directed(ea->g)) {
    uidx = graph_get_nbr_idx(ea->g, v, u);
    edge_array_set_by_idx(ea, v, uidx, val);
  }
}

canonical_original_code:
void edge_array_set(struct _edge_array *ea, unsigned int u, unsigned int v, void *val) {
  unsigned int uidx;
  unsigned int vidx;
  vidx = graph_get_nbr_idx(ea->g, u, v);
  edge_array_set_by_idx(ea, u, vidx, val);
  if (!graph_is_directed(ea->g)) {
    uidx = graph_get_nbr_idx(ea->g, v, u);
    edge_array_set_by_idx(ea, v, uidx, val);
  }
}

variable_types:
uidx
unsigned int


decompiled_code:
__int64 __fastcall graph_group_by_label(__int64 a1, __int64 a2)
{
__int64 v2; // r13
void *v3; // rax
void *v4; // rbp
void *v5; // rax
unsigned int v7; // er14
__int64 v8; // rbp

*(_QWORD *)(a2 + 16) = 0LL;
*(_OWORD *)a2 = 0LL;
v2 = (unsigned int)graph_num_nodes();
v3 = calloc(1uLL, 0x28uLL);
*(_QWORD *)(a2 + 8) = v3;
if ( !v3 )
return 1LL;
v4 = v3;
v5 = calloc(1uLL, 0x28uLL);
*(_QWORD *)(a2 + 16) = v5;
if ( !v5 )
return 1LL;
if ( (unsigned __int8)array_create(v4, 4LL, 10LL) )
return 1LL;
v7 = array_create(*(_QWORD *)(a2 + 16), 40LL, 10LL);
if ( (_BYTE)v7 )
return 1LL;
array_set_cmps(*(_QWORD *)(a2 + 8), &compare_u32, &compare_u32_insert);
*(_DWORD *)a2 = 0;
*(_DWORD *)(a2 + 4) = v2;
if ( v2 )
{
v8 = 0LL;
while ( !add_node_to_ptn(a1, v8, a2) )
{
if ( ++v8 == v2 )
goto LABEL_10;
}
return 1LL;
}
LABEL_10:
*(_DWORD *)a2 = *(_DWORD *)(*(_QWORD *)(a2 + 16) + 4LL);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // r13
void *v3; // rax
void *v4; // rbp
void *v5; // rax
unsigned int v7; // er14
__int64 v8; // rbp

*(_QWORD *)(a2 + 16) = 0LL;
*(_OWORD *)a2 = 0LL;
v2 = (unsigned int)graph_num_nodes();
v3 = calloc(1uLL, 0x28uLL);
*(_QWORD *)(a2 + 8) = v3;
if ( !v3 )
return 1LL;
v4 = v3;
v5 = calloc(1uLL, 0x28uLL);
*(_QWORD *)(a2 + 16) = v5;
if ( !v5 )
return 1LL;
if ( (unsigned __int8)array_create(v4, 4LL, 10LL) )
return 1LL;
v7 = array_create(*(_QWORD *)(a2 + 16), 40LL, 10LL);
if ( (_BYTE)v7 )
return 1LL;
array_set_cmps(*(_QWORD *)(a2 + 8), &compare_u32, &compare_u32_insert);
*(_DWORD *)a2 = 0;
*(_DWORD *)(a2 + 4) = v2;
if ( v2 )
{
v8 = 0LL;
while ( !func0(a1, v8, a2) )
{
if ( ++v8 == v2 )
goto LABEL_10;
}
return 1LL;
}
LABEL_10:
*(_DWORD *)a2 = *(_DWORD *)(*(_QWORD *)(a2 + 16) + 4LL);
return v7;
}

original_code:
uint8_t graph_group_by_label(graph_t *g, node_partition_t *ptn ) {
  uint64_t i;
  uint32_t nnodes;
  memset(ptn, 0, sizeof(node_partition_t));
  nnodes = graph_num_nodes(g);
  ptn->partids = calloc(1, sizeof(array_t));
  if (ptn->partids == ((void *)0)) goto fail;
  ptn->parts = calloc(1, sizeof(array_t));
  if (ptn->parts == ((void *)0)) goto fail;
  if (array_create(ptn->partids, sizeof(uint32_t), 10)) goto fail;
  if (array_create(ptn->parts, sizeof(array_t), 10)) goto fail;
  array_set_cmps(ptn->partids, compare_u32, compare_u32_insert);
  ptn->nparts = 0;
  ptn->nnodes = nnodes;
  for (i = 0; i < nnodes; i++) {
    if (_add_node_to_ptn(g, i, ptn)) goto fail;
  }
  ptn->nparts = ptn->parts->size;
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_group_by_label(struct _graph *g, struct _node_partition *ptn) {
  unsigned long i;
  unsigned int nnodes;
  memset(ptn, 0, sizeof(node_partition_t));
  nnodes = graph_num_nodes(g);
  ptn->partids = calloc(1, sizeof(array_t));
  if (ptn->partids == ((void *)0)) goto fail;
  ptn->parts = calloc(1, sizeof(array_t));
  if (ptn->parts == ((void *)0)) goto fail;
  if (array_create(ptn->partids, sizeof(unsigned int), 10)) goto fail;
  if (array_create(ptn->parts, sizeof(array_t), 10)) goto fail;
  array_set_cmps(ptn->partids, compare_u32, compare_u32_insert);
  ptn->nparts = 0;
  ptn->nnodes = nnodes;
  for (i = 0; i < nnodes; i++) {
    if (_add_node_to_ptn(g, i, ptn)) goto fail;
  }
  ptn->nparts = ptn->parts->size;
  return 0;
fail:
  return 1;
}

variable_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *

variable_types: struct _node_partition { unsigned int nparts; unsigned int nnodes; struct _array *partids; struct _array *parts; } *


decompiled_code:
double __fastcall stats_newman_error(__int64 a1)
{
int v1; // ebx
double result; // xmm0_8
int v3; // er12
unsigned __int64 i; // rbp
char v5[12]; // [rsp+10h] [rbp-88h] BYREF
int v6; // [rsp+1Ch] [rbp-7Ch]
char v7[16]; // [rsp+20h] [rbp-78h] BYREF
__int64 v8; // [rsp+30h] [rbp-68h]
char v9[4]; // [rsp+50h] [rbp-48h] BYREF
unsigned int v10; // [rsp+54h] [rbp-44h]
__int64 v11; // [rsp+60h] [rbp-38h]

v8 = 0LL;
v11 = 0LL;
v1 = graph_num_nodes();
if ( (unsigned __int8)array_create(v7, 16LL, 10LL)
|| (unsigned __int8)array_create(v9, 16LL, 10LL)
|| (unsigned __int8)graph_communities(a1, 1LL, v7)
|| (unsigned __int8)find_max_groups(a1, (__int64)v7, (__int64)v9) )
{
if ( v8 )
array_free(v7);
result = *(double *)&LC0;
if ( v11 )
{
array_free(v9);
result = *(double *)&LC0;
}
}
else
{
array_set_cmps(v9, group_component_cmp, 0LL);
v3 = v10;
if ( v10 )
{
v3 = 0;
for ( i = 0LL; i < v10; ++i )
{
array_get(v9, (unsigned int)i, v5);
if ( (unsigned int)array_count(v9, v5) == 1 )
v3 += v6;
}
}
array_free(v9);
array_free(v7);
result = (double)v3 / (double)v1;
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
int v1; // ebx
double result; // xmm0_8
int v3; // er12
unsigned __int64 i; // rbp
char v5[12]; // [rsp+10h] [rbp-88h] BYREF
int v6; // [rsp+1Ch] [rbp-7Ch]
char v7[16]; // [rsp+20h] [rbp-78h] BYREF
__int64 v8; // [rsp+30h] [rbp-68h]
char v9[4]; // [rsp+50h] [rbp-48h] BYREF
unsigned int v10; // [rsp+54h] [rbp-44h]
__int64 v11; // [rsp+60h] [rbp-38h]

v8 = 0LL;
v11 = 0LL;
v1 = graph_num_nodes();
if ( (unsigned __int8)array_create(v7, 16LL, 10LL)
|| (unsigned __int8)array_create(v9, 16LL, 10LL)
|| (unsigned __int8)graph_communities(a1, 1LL, v7)
|| (unsigned __int8)func1(a1, (__int64)v7, (__int64)v9) )
{
if ( v8 )
array_free(v7);
result = *(double *)&LC0;
if ( v11 )
{
array_free(v9);
result = *(double *)&LC0;
}
}
else
{
array_set_cmps(v9, group_component_cmp, 0LL);
v3 = v10;
if ( v10 )
{
v3 = 0;
for ( i = 0LL; i < v10; ++i )
{
array_get(v9, (unsigned int)i, v5);
if ( (unsigned int)array_count(v9, v5) == 1 )
v3 += v6;
}
}
array_free(v9);
array_free(v7);
result = (double)v3 / (double)v1;
}
return result;
}

original_code:
double stats_newman_error(graph_t *g) {
  uint64_t i;
  uint32_t nnodes;
  uint32_t ncorrect;
  array_t allgroups;
  array_t maxgroups;
  node_group_t group;
  allgroups.data = ((void *)0);
  maxgroups.data = ((void *)0);
  ncorrect = 0;
  nnodes = graph_num_nodes(g);
  if (array_create(&allgroups, sizeof(node_group_t), 10)) goto fail;
  if (array_create(&maxgroups, sizeof(node_group_t), 10)) goto fail;
  if (graph_communities(g, 1, &allgroups)) goto fail;
  if (_find_max_groups( g, &allgroups, &maxgroups)) goto fail;
  array_set_cmps(&maxgroups, _group_component_cmp, ((void *)0));
  for (i = 0; i < maxgroups.size; i++) {
    array_get(&maxgroups, i, &group);
    if (array_count(&maxgroups, &group) == 1)
      ncorrect += group.nnodes;
  }
  array_free(&maxgroups);
  array_free(&allgroups);
  return (double)ncorrect/nnodes;
fail:
  if (allgroups.data != ((void *)0)) array_free(&allgroups);
  if (maxgroups.data != ((void *)0)) array_free(&maxgroups);
  return -1;
}

canonical_original_code:
double stats_newman_error(struct _graph *g) {
  unsigned long i;
  unsigned int nnodes;
  unsigned int ncorrect;
  struct _array allgroups;
  struct _array maxgroups;
  struct _node_group group;
  allgroups.data = ((void *)0);
  maxgroups.data = ((void *)0);
  ncorrect = 0;
  nnodes = graph_num_nodes(g);
  if (array_create(&allgroups, sizeof(node_group_t), 10)) goto fail;
  if (array_create(&maxgroups, sizeof(node_group_t), 10)) goto fail;
  if (graph_communities(g, 1, &allgroups)) goto fail;
  if (_find_max_groups( g, &allgroups, &maxgroups)) goto fail;
  array_set_cmps(&maxgroups, _group_component_cmp, ((void *)0));
  for (i = 0; i < maxgroups.size; i++) {
    array_get(&maxgroups, i, &group);
    if (array_count(&maxgroups, &group) == 1)
      ncorrect += group.nnodes;
  }
  array_free(&maxgroups);
  array_free(&allgroups);
  return (double)ncorrect/nnodes;
fail:
  if (allgroups.data != ((void *)0)) array_free(&allgroups);
  if (maxgroups.data != ((void *)0)) array_free(&maxgroups);
  return -1;
}

variable_types:
ncorrect
unsigned int

variable_types: struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); }

variable_types: struct _node_group { unsigned int component; unsigned int labelval; unsigned int labelidx; unsigned int nnodes; }

return_type: double


decompiled_code:
double __fastcall stats_mutual_information(unsigned int a1, _DWORD *a2, _DWORD *a3)
{
double v5; // r12
double v6; // [rsp+0h] [rbp-80h]
__int128 v7[2]; // [rsp+8h] [rbp-78h] BYREF
__int64 v8; // [rsp+28h] [rbp-58h]
__int128 v9[2]; // [rsp+38h] [rbp-48h] BYREF
__int64 v10; // [rsp+58h] [rbp-28h]

v7[0] = 0LL;
v8 = 0LL;
v10 = 0LL;
v7[1] = 0LL;
v9[0] = 0LL;
v9[1] = 0LL;
if ( (unsigned __int8)partition(a1, a2, (__int64)v7) || (unsigned __int8)partition(a1, a3, (__int64)v9) )
return *(double *)&LC5;
v5 = mutual_information(a1, (__int64)v7, (__int64)v9);
v6 = entropy((__int64)v7, a1);
return v5 / ((v6 + entropy((__int64)v9, a1)) * 0.5);
}

original_code:
double stats_mutual_information(
  uint32_t n, uint32_t *lblsj, uint32_t *lblsk) {
  array_t setsj;
  array_t setsk;
  double mi;
  double nmi;
  double entj;
  double entk;
  memset(&setsj, 0, sizeof(array_t));
  memset(&setsk, 0, sizeof(array_t));
  if (_partition(n, lblsj, &setsj)) goto fail;
  if (_partition(n, lblsk, &setsk)) goto fail;
  mi = _mutual_information(n, &setsj, &setsk);
  entj = _entropy(&setsj, n);
  entk = _entropy(&setsk, n);
  nmi = mi / ((entj + entk)/2.0);
  return nmi;
fail:
  return -1;
}

canonical_original_code:
double stats_mutual_information(unsigned int n, unsigned int *lblsj, unsigned int *lblsk) {
  struct _array setsj;
  struct _array setsk;
  double mi;
  double nmi;
  double entj;
  double entk;
  memset(&setsj, 0, sizeof(array_t));
  memset(&setsk, 0, sizeof(array_t));
  if (_partition(n, lblsj, &setsj)) goto fail;
  if (_partition(n, lblsk, &setsk)) goto fail;
  mi = _mutual_information(n, &setsj, &setsk);
  entj = _entropy(&setsj, n);
  entk = _entropy(&setsk, n);
  nmi = mi / ((entj + entk)/2.0);
  return nmi;
fail:
  return -1;
}

variable_types:
n
unsigned int

variable_types:
lblsj
unsigned int *

variable_types:
lblsk
unsigned int *

variable_types: mi double

variable_types: nmi double

variable_types: entj double

variable_types: entk double


decompiled_code:
double __fastcall stats_graph_mutual_information(__int64 a1)
{
size_t v1; // r13
_DWORD *v2; // r15
_DWORD *v3; // r12
__int64 i; // rbx

v1 = (unsigned int)graph_num_nodes();
v2 = calloc(v1, 4uLL);
v3 = calloc(v1, 4uLL);
stats_num_components(a1, 0LL, 0LL, v2);
if ( v1 )
{
for ( i = 0LL; i != v1; ++i )
v3[i] = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)i);
}
return stats_mutual_information(v1, v2, v3);
}

canonical_decompiled_code:
double __fastcall func5(__int64 a1)
{
size_t v1; // r13
_DWORD *v2; // r15
_DWORD *v3; // r12
__int64 i; // rbx

v1 = (unsigned int)graph_num_nodes();
v2 = calloc(v1, 4uLL);
v3 = calloc(v1, 4uLL);
stats_num_components(a1, 0LL, 0LL, v2);
if ( v1 )
{
for ( i = 0LL; i != v1; ++i )
v3[i] = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)i);
}
return func4(v1, v2, v3);
}

original_code:
double stats_graph_mutual_information(graph_t *g) {
  uint64_t i;
  uint32_t nnodes;
  uint32_t *lblsj;
  uint32_t *lblsk;
  nnodes = graph_num_nodes(g);
  lblsj = calloc(nnodes, sizeof(uint32_t));
  lblsk = calloc(nnodes, sizeof(uint32_t));
  stats_num_components(g, 0, ((void *)0), lblsj);
  for (i = 0; i < nnodes; i++)
    lblsk[i] = graph_get_nodelabel(g, i)->labelval;
  return stats_mutual_information(nnodes, lblsj, lblsk);
}

canonical_original_code:
double stats_graph_mutual_information(struct _graph *g) {
  unsigned long i;
  unsigned int nnodes;
  unsigned int *lblsj;
  unsigned int *lblsk;
  nnodes = graph_num_nodes(g);
  lblsj = calloc(nnodes, sizeof(unsigned int));
  lblsk = calloc(nnodes, sizeof(unsigned int));
  stats_num_components(g, 0, ((void *)0), lblsj);
  for (i = 0; i < nnodes; i++)
    lblsk[i] = graph_get_nodelabel(g, i)->labelval;
  return stats_mutual_information(nnodes, lblsj, lblsk);
}

variable_types:
i
unsigned long

variable_types:
nnodes
unsigned int


decompiled_code:
double __fastcall stats_approx_clustering(__int64 a1, int a2)
{
int v2; // ebp
__int64 i; // rbx
double v4; // xmm0_8
double v6[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a2 )
{
v2 = 0;
for ( i = 0LL; i != a2; ++i )
v2 -= !test_next_triple(a1) - 1;
v4 = (double)v2;
}
else
{
v4 = 0.0;
}
v6[0] = v4 / (double)a2;
stats_cache_add(a1, 1LL, 0LL, 8LL);
stats_cache_update(a1, 1LL, 0LL, -1LL, v6);
return v6[0];
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, int a2)
{
int v2; // ebp
__int64 i; // rbx
double v4; // xmm0_8
double v6[6]; // [rsp+8h] [rbp-30h] BYREF

if ( a2 )
{
v2 = 0;
for ( i = 0LL; i != a2; ++i )
v2 -= !func0(a1) - 1;
v4 = (double)v2;
}
else
{
v4 = 0.0;
}
v6[0] = v4 / (double)a2;
stats_cache_add(a1, 1LL, 0LL, 8LL);
stats_cache_update(a1, 1LL, 0LL, -1LL, v6);
return v6[0];
}

original_code:
double stats_approx_clustering(graph_t *g, uint32_t ntriples) {
  uint64_t i;
  uint32_t ntriangles;
  double clust;
  for (i = 0, ntriangles = 0; i < ntriples; i++) {
    if (_test_next_triple(g)) ntriangles ++;
  }
  clust = (double)ntriangles/ntriples;
  stats_cache_add(g,
                  STATS_CACHE_APPROX_CLUSTERING,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_APPROX_CLUSTERING, 0, -1, &clust);
  return clust;
}

canonical_original_code:
double stats_approx_clustering(struct _graph *g, unsigned int ntriples) {
  unsigned long i;
  unsigned int ntriangles;
  double clust;
  for (i = 0, ntriangles = 0; i < ntriples; i++) {
    if (_test_next_triple(g)) ntriangles ++;
  }
  clust = (double)ntriangles/ntriples;
  stats_cache_add(g,
                  STATS_CACHE_APPROX_CLUSTERING,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_APPROX_CLUSTERING, 0, -1, &clust);
  return clust;
}

variable_types:
ntriples
unsigned int

variable_types:
ntriangles
unsigned int

variable_types: clust double


decompiled_code:
__int64 __fastcall graph_init_pathsharing(__int64 a1)
{
unsigned int v1; // eax
unsigned __int64 v2; // rbp
__int64 v3; // r15
__int64 v4; // r14
__int64 i; // rbx
unsigned __int64 v6; // rdx
__int64 v8; // [rsp+8h] [rbp-40h]

v1 = graph_num_nodes();
v8 = v1;
if ( v1 )
{
v2 = 0LL;
do
{
v3 = (unsigned int)graph_num_neighbours(a1, (unsigned int)v2);
v4 = graph_get_neighbours(a1, (unsigned int)v2);
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
v6 = *(unsigned int *)(v4 + 4 * i);
if ( v6 >= v2 )
stats_edge_pathsharing(a1, (unsigned int)v2, v6);
}
}
++v2;
}
while ( v2 != v8 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // eax
unsigned __int64 v2; // rbp
__int64 v3; // r15
__int64 v4; // r14
__int64 i; // rbx
unsigned __int64 v6; // rdx
__int64 v8; // [rsp+8h] [rbp-40h]

v1 = graph_num_nodes();
v8 = v1;
if ( v1 )
{
v2 = 0LL;
do
{
v3 = (unsigned int)graph_num_neighbours(a1, (unsigned int)v2);
v4 = graph_get_neighbours(a1, (unsigned int)v2);
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
{
v6 = *(unsigned int *)(v4 + 4 * i);
if ( v6 >= v2 )
stats_edge_pathsharing(a1, (unsigned int)v2, v6);
}
}
++v2;
}
while ( v2 != v8 );
}
return 0LL;
}

original_code:
uint8_t graph_init_pathsharing(graph_t *g) {
  uint64_t i;
  uint64_t j;
  uint32_t nnodes;
  uint32_t nnbrs;
  uint32_t *nbrs;
  nnodes = graph_num_nodes(g);
  for (i = 0; i < nnodes; i++) {
    nnbrs = graph_num_neighbours(g, i);
    nbrs = graph_get_neighbours(g, i);
    for (j = 0; j < nnbrs; j++) {
      if (i > nbrs[j]) continue;
      stats_edge_pathsharing(g, i, nbrs[j]);
    }
  }
  return 0;
}

canonical_original_code:
unsigned char graph_init_pathsharing(struct _graph *g) {
  unsigned long i;
  unsigned long j;
  unsigned int nnodes;
  unsigned int nnbrs;
  unsigned int *nbrs;
  nnodes = graph_num_nodes(g);
  for (i = 0; i < nnodes; i++) {
    nnbrs = graph_num_neighbours(g, i);
    nbrs = graph_get_neighbours(g, i);
    for (j = 0; j < nnbrs; j++) {
      if (i > nbrs[j]) continue;
      stats_edge_pathsharing(g, i, nbrs[j]);
    }
  }
  return 0;
}

variable_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *

variable_types:
j
unsigned long

variable_types:
nnbrs
unsigned int

variable_types:
nbrs
unsigned int *


original_code:
uint8_t graph_remove_pathsharing(
  graph_t *g, double *share, array_t *edges, graph_edge_t *edge) {
  uint64_t i;
  uint64_t j;
  uint32_t nnodes;
  uint32_t nnbrs;
  uint32_t *nbrs;
  double min;
  min = 1.0;
  nnodes = graph_num_nodes(g);
  for (i = 0; i < nnodes; i++) {
    nnbrs = graph_num_neighbours(g, i);
    nbrs = graph_get_neighbours(g, i);
    stats_cache_edge_pathsharing(g, i, share);
    for (j = 0; j < nnbrs; j++) {
      if (i > nbrs[j]) continue;
      if (share[j] > min) continue;
      edge->u = i;
      edge->v = nbrs[j];
      if (share[j] < min) {
        array_clear(edges);
        min = share[j];
      }
      if (array_append(edges, edge)) goto fail;
    }
  }
  i = floor((edges->size) * ((double)random() / 2147483647));
  if (array_get(edges, i, edge)) goto fail;
  if (graph_remove_edge(g, edge->u, edge->v)) goto fail;
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_remove_pathsharing(struct _graph *g, double *share, struct _array *edges, struct _graph_edge *edge) {
  unsigned long i;
  unsigned long j;
  unsigned int nnodes;
  unsigned int nnbrs;
  unsigned int *nbrs;
  double min;
  min = 1.0;
  nnodes = graph_num_nodes(g);
  for (i = 0; i < nnodes; i++) {
    nnbrs = graph_num_neighbours(g, i);
    nbrs = graph_get_neighbours(g, i);
    stats_cache_edge_pathsharing(g, i, share);
    for (j = 0; j < nnbrs; j++) {
      if (i > nbrs[j]) continue;
      if (share[j] > min) continue;
      edge->u = i;
      edge->v = nbrs[j];
      if (share[j] < min) {
        array_clear(edges);
        min = share[j];
      }
      if (array_append(edges, edge)) goto fail;
    }
  }
  i = floor((edges->size) * ((double)random() / 2147483647));
  if (array_get(edges, i, edge)) goto fail;
  if (graph_remove_edge(g, edge->u, edge->v)) goto fail;
  return 0;
fail:
  return 1;
}

variable_types:
share
double *

variable_types:
edges
struct _array *

variable_types: struct _graph_edge { unsigned int u; unsigned int v; double val; } *

variable_types: min double


decompiled_code:
__int64 __fastcall graph_recalculate_pathsharing(__int64 a1, unsigned int *a2)
{
unsigned int v2; // er15
unsigned int *v3; // rbx
__int64 v4; // r13
__int64 v5; // r14
__int64 v6; // r15
__int64 v7; // rdx
__int64 i; // r15
__int64 v9; // rdx
unsigned int *v10; // r15
__int64 v11; // rdx
__int64 v13; // [rsp+8h] [rbp-40h]
unsigned int *v14; // [rsp+8h] [rbp-40h]

v2 = graph_num_neighbours(a1, *a2);
v3 = (unsigned int *)graph_get_neighbours(a1, *a2);
v4 = (unsigned int)graph_num_neighbours(a1, a2[1]);
v5 = graph_get_neighbours(a1, a2[1]);
v13 = v2;
if ( !v2 )
{
if ( !v4 )
return 0LL;
LABEL_5:
for ( i = 0LL; i != v4; ++i )
{
v9 = *(unsigned int *)(v5 + 4 * i);
stats_edge_pathsharing(a1, a2[1], v9);
}
if ( !v13 )
return 0LL;
goto LABEL_8;
}
v6 = 0LL;
do
{
v7 = v3[v6++];
stats_edge_pathsharing(a1, *a2, v7);
}
while ( v6 != v13 );
v4 = (unsigned int)v4;
if ( (_DWORD)v4 )
goto LABEL_5;
LABEL_8:
v14 = &v3[v13];
do
{
v10 = (unsigned int *)v5;
if ( v4 )
{
do
{
v11 = *v10++;
stats_edge_pathsharing(a1, *v3, v11);
}
while ( (unsigned int *)(v5 + 4 * v4) != v10 );
}
++v3;
}
while ( v14 != v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned int v2; // er15
unsigned int *v3; // rbx
__int64 v4; // r13
__int64 v5; // r14
__int64 v6; // r15
__int64 v7; // rdx
__int64 i; // r15
__int64 v9; // rdx
unsigned int *v10; // r15
__int64 v11; // rdx
__int64 v13; // [rsp+8h] [rbp-40h]
unsigned int *v14; // [rsp+8h] [rbp-40h]

v2 = graph_num_neighbours(a1, *a2);
v3 = (unsigned int *)graph_get_neighbours(a1, *a2);
v4 = (unsigned int)graph_num_neighbours(a1, a2[1]);
v5 = graph_get_neighbours(a1, a2[1]);
v13 = v2;
if ( !v2 )
{
if ( !v4 )
return 0LL;
LABEL_5:
for ( i = 0LL; i != v4; ++i )
{
v9 = *(unsigned int *)(v5 + 4 * i);
stats_edge_pathsharing(a1, a2[1], v9);
}
if ( !v13 )
return 0LL;
goto LABEL_8;
}
v6 = 0LL;
do
{
v7 = v3[v6++];
stats_edge_pathsharing(a1, *a2, v7);
}
while ( v6 != v13 );
v4 = (unsigned int)v4;
if ( (_DWORD)v4 )
goto LABEL_5;
LABEL_8:
v14 = &v3[v13];
do
{
v10 = (unsigned int *)v5;
if ( v4 )
{
do
{
v11 = *v10++;
stats_edge_pathsharing(a1, *v3, v11);
}
while ( (unsigned int *)(v5 + 4 * v4) != v10 );
}
++v3;
}
while ( v14 != v3 );
return 0LL;
}

original_code:
uint8_t graph_recalculate_pathsharing(graph_t *g, graph_edge_t *edge) {
  uint64_t i;
  uint64_t j;
  uint32_t unnbrs;
  uint32_t *unbrs;
  uint32_t vnnbrs;
  uint32_t *vnbrs;
  unnbrs = graph_num_neighbours(g, edge->u);
  unbrs = graph_get_neighbours(g, edge->u);
  vnnbrs = graph_num_neighbours(g, edge->v);
  vnbrs = graph_get_neighbours(g, edge->v);
  for (i = 0; i < unnbrs; i++)
    stats_edge_pathsharing(g, edge->u, unbrs[i]);
  for (i = 0; i < vnnbrs; i++)
    stats_edge_pathsharing(g, edge->v, vnbrs[i]);
  for (i = 0; i < unnbrs; i++)
    for (j = 0; j < vnnbrs; j++)
      stats_edge_pathsharing(g, unbrs[i],vnbrs[j]);
  return 0;
}

canonical_original_code:
unsigned char graph_recalculate_pathsharing(struct _graph *g, struct _graph_edge *edge) {
  unsigned long i;
  unsigned long j;
  unsigned int unnbrs;
  unsigned int *unbrs;
  unsigned int vnnbrs;
  unsigned int *vnbrs;
  unnbrs = graph_num_neighbours(g, edge->u);
  unbrs = graph_get_neighbours(g, edge->u);
  vnnbrs = graph_num_neighbours(g, edge->v);
  vnbrs = graph_get_neighbours(g, edge->v);
  for (i = 0; i < unnbrs; i++)
    stats_edge_pathsharing(g, edge->u, unbrs[i]);
  for (i = 0; i < vnnbrs; i++)
    stats_edge_pathsharing(g, edge->v, vnbrs[i]);
  for (i = 0; i < unnbrs; i++)
    for (j = 0; j < vnnbrs; j++)
      stats_edge_pathsharing(g, unbrs[i],vnbrs[j]);
  return 0;
}

variable_types:
unnbrs
unsigned int

variable_types:
unbrs
unsigned int *

variable_types:
vnnbrs
unsigned int

variable_types:
vnbrs
unsigned int *


decompiled_code:
__int64 __fastcall graph_create_er_random(__int64 a1, unsigned int a2, double a3)
{
unsigned int v3; // er13
unsigned __int64 v4; // r14
unsigned int v5; // er15
unsigned __int64 v6; // rbx
int v7; // eax
float v8; // xmm0_4
char v11[136]; // [rsp+10h] [rbp-88h] BYREF

if ( !a1 || !a2 || a3 > 1.0 || a3 < 0.0 || (v3 = graph_create(a1, a2, 0LL), (_BYTE)v3) )
{
LABEL_12:
v3 = 1;
graph_free(a1);
return v3;
}
v4 = 0LL;
LABEL_7:
v5 = v4;
mk_label((__int64)v11);
graph_set_nodelabel(a1, (unsigned int)v4++, v11);
if ( v4 < a2 )
{
v6 = v4;
while ( 1 )
{
if ( a3 >= (double)rand() / 2147483647.0 )
{
v7 = rand();
v8 = (double)v7 / 2147483647.0 + (double)v7 / 2147483647.0 - 1.0;
if ( (unsigned __int8)graph_add_edge(a1, v5, (unsigned int)v6, v8) )
goto LABEL_12;
}
if ( ++v6 >= a2 )
goto LABEL_7;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, double a3)
{
unsigned int v3; // er13
unsigned __int64 v4; // r14
unsigned int v5; // er15
unsigned __int64 v6; // rbx
int v7; // eax
float v8; // xmm0_4
char v11[136]; // [rsp+10h] [rbp-88h] BYREF

if ( !a1 || !a2 || a3 > 1.0 || a3 < 0.0 || (v3 = graph_create(a1, a2, 0LL), (_BYTE)v3) )
{
LABEL_12:
v3 = 1;
graph_free(a1);
return v3;
}
v4 = 0LL;
LABEL_7:
v5 = v4;
func0((__int64)v11);
graph_set_nodelabel(a1, (unsigned int)v4++, v11);
if ( v4 < a2 )
{
v6 = v4;
while ( 1 )
{
if ( a3 >= (double)rand() / 2147483647.0 )
{
v7 = rand();
v8 = (double)v7 / 2147483647.0 + (double)v7 / 2147483647.0 - 1.0;
if ( (unsigned __int8)graph_add_edge(a1, v5, (unsigned int)v6, v8) )
goto LABEL_12;
}
if ( ++v6 >= a2 )
goto LABEL_7;
}
}
return v3;
}

original_code:
uint8_t graph_create_er_random(
  graph_t *g, uint32_t nnodes, double density) {
  uint64_t i;
  uint64_t j;
  double prob;
  double wt;
  graph_label_t lbl;
  if (g == ((void *)0)) goto fail;
  if (nnodes == 0) goto fail;
  if (density > 1.0) goto fail;
  if (density < 0.0) goto fail;
  if (graph_create(g, nnodes, 0)) goto fail;
  for (i = 0; i < nnodes; i++) {
    _mk_label(&lbl);
    graph_set_nodelabel(g, i, &lbl);
    for (j = i+1; j < nnodes; j++) {
      prob = (double)rand() / 2147483647;
      if (prob <= density) {
        wt = -1.0 + 2.0*((double)rand() / 2147483647);
        if (graph_add_edge(g, i, j, wt)) goto fail;
      }
    }
  }
  return 0;
fail:
  graph_free(g);
  return 1;
}

canonical_original_code:
unsigned char graph_create_er_random(struct _graph *g, unsigned int nnodes, double density) {
  unsigned long i;
  unsigned long j;
  double prob;
  double wt;
  struct _graph_label lbl;
  if (g == ((void *)0)) goto fail;
  if (nnodes == 0) goto fail;
  if (density > 1.0) goto fail;
  if (density < 0.0) goto fail;
  if (graph_create(g, nnodes, 0)) goto fail;
  for (i = 0; i < nnodes; i++) {
    _mk_label(&lbl);
    graph_set_nodelabel(g, i, &lbl);
    for (j = i+1; j < nnodes; j++) {
      prob = (double)rand() / 2147483647;
      if (prob <= density) {
        wt = -1.0 + 2.0*((double)rand() / 2147483647);
        if (graph_add_edge(g, i, j, wt)) goto fail;
      }
    }
  }
  return 0;
fail:
  graph_free(g);
  return 1;
}

variable_types: density double

variable_types:
i
unsigned long

variable_types: prob double

variable_types: wt double

variable_types: struct _graph_label { unsigned int labelval; float xval; float yval; float zval; unsigned int meta[16]; }


decompiled_code:
// attributes: thunk
__int64 stats_er_clustering()
{
return stats_density();
}

canonical_decompiled_code:
__int64 func1()
{
return stats_density();
}

original_code:
double stats_er_clustering(graph_t *g) {
  return stats_density(g);
}

canonical_original_code:
double stats_er_clustering(struct _graph *g) {
  return stats_density(g);
}

variable_types: struct _graph { unsigned int numnodes; unsigned int numedges; struct _array { unsigned int capacity; unsigned int size; unsigned int datasz; unsigned char *data; int (*cmp)(void *a, void *b); int (*cmpins)(void *a, void *b); } numneighbours; struct _array nodelabels; struct _array labelvals; struct _array *neighbours; struct _array *weights; unsigned short flags; struct _array event_listeners; void *ctx[5]; void (*ctx_free[5])(void *); } *


decompiled_code:
double __fastcall stats_local_smallworld_index(__int64 a1, unsigned int a2)
{
double v2; // xmm2_8
double v4; // [rsp+8h] [rbp-30h]
double v5; // [rsp+10h] [rbp-28h] BYREF
double v6[4]; // [rsp+18h] [rbp-20h] BYREF

stats_cache_node_pathlength(a1, a2, v6);
stats_cache_node_clustering(a1, a2, &v5);
v4 = stats_er_clustering(a1);
v2 = COERCE_DOUBLE(stats_er_pathlength(a1));
return v5 / v4 / (v6[0] / v2);
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, unsigned int a2)
{
double v2; // xmm2_8
double v4; // [rsp+8h] [rbp-30h]
double v5; // [rsp+10h] [rbp-28h] BYREF
double v6[4]; // [rsp+18h] [rbp-20h] BYREF

stats_cache_node_pathlength(a1, a2, v6);
stats_cache_node_clustering(a1, a2, &v5);
v4 = func1(a1);
v2 = COERCE_DOUBLE(stats_er_pathlength(a1));
return v5 / v4 / (v6[0] / v2);
}

original_code:
double stats_local_smallworld_index(graph_t *g, uint32_t n) {
  double clustering;
  double pathlength;
  double randClustering;
  double randPathlength;
  double gamma;
  double lambda;
  stats_cache_node_pathlength(g, n, &pathlength);
  stats_cache_node_clustering(g, n, &clustering);
  randClustering = stats_er_clustering(g);
  randPathlength = stats_er_pathlength(g);
  gamma = clustering / randClustering;
  lambda = pathlength / randPathlength;
  return gamma / lambda;
}

canonical_original_code:
double stats_local_smallworld_index(struct _graph *g, unsigned int n) {
  double clustering;
  double pathlength;
  double randClustering;
  double randPathlength;
  double gamma;
  double lambda;
  stats_cache_node_pathlength(g, n, &pathlength);
  stats_cache_node_clustering(g, n, &clustering);
  randClustering = stats_er_clustering(g);
  randPathlength = stats_er_pathlength(g);
  gamma = clustering / randClustering;
  lambda = pathlength / randPathlength;
  return gamma / lambda;
}

variable_types:
n
unsigned int

variable_types: clustering double

variable_types: pathlength double

variable_types: randClustering double

variable_types: randPathlength double

variable_types: gamma double

variable_types: lambda double


decompiled_code:
__int64 __fastcall graph_level_stack(__int64 a1, int a2, _QWORD *a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

*a3 = 0LL;
v5[0] = a2;
if ( (unsigned __int8)stack_create(a3, 40LL, 20LL)
|| (result = bfs(a1, v5, 1LL, 0LL, a3, 0LL, bfs_cb, 0LL), (_BYTE)result) )
{
if ( *a3 )
stack_free(a3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, _QWORD *a3)
{
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

*a3 = 0LL;
v5[0] = a2;
if ( (unsigned __int8)stack_create(a3, 40LL, 20LL)
|| (result = bfs(a1, v5, 1LL, 0LL, a3, 0LL, bfs_cb, 0LL), (_BYTE)result) )
{
if ( *a3 )
stack_free(a3);
result = 1LL;
}
return result;
}

original_code:
uint8_t graph_level_stack(graph_t *g, uint32_t u, cstack_t *stack) {
  stack->data = ((void *)0);
  if (stack_create(stack, sizeof(array_t), 20)) goto fail;
  if (bfs(g, &u, 1, ((void *)0), stack, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
  return 0;
fail:
  if (stack->data != ((void *)0)) stack_free(stack);
  return 1;
}

canonical_original_code:
unsigned char graph_level_stack(struct _graph *g, unsigned int u, struct _stack *stack) {
  stack->data = ((void *)0);
  if (stack_create(stack, sizeof(array_t), 20)) goto fail;
  if (bfs(g, &u, 1, ((void *)0), stack, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
  return 0;
fail:
  if (stack->data != ((void *)0)) stack_free(stack);
  return 1;
}

variable_types:
u
unsigned int

variable_types: struct _stack { unsigned char *data; unsigned int size; unsigned int elemsz; unsigned int capacity; } *


decompiled_code:
__int64 __fastcall graph_communities(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v3; // r12
unsigned int v5; // er15
__int64 v6; // r13
__int64 v7; // rax
unsigned int v8; // er15
__int64 v9; // rax
__int64 v11; // r12
__int64 v12; // [rsp+0h] [rbp-68h]
int v13; // [rsp+8h] [rbp-60h]
int v14; // [rsp+1Ch] [rbp-4Ch] BYREF
int v15; // [rsp+20h] [rbp-48h] BYREF
int v16; // [rsp+24h] [rbp-44h]
int v17; // [rsp+28h] [rbp-40h]
int v18; // [rsp+2Ch] [rbp-3Ch]

v3 = 0LL;
v5 = graph_num_nodes();
v6 = graph_get_labelvals(a1);
v13 = graph_num_labelvals(a1);
array_set_cmps(a3, group_cmp, 0LL);
v12 = v5;
if ( v5 )
{
do
{
stats_cache_node_component(a1, v3, &v14);
v16 = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)v3);
v15 = v14;
v7 = array_find(a3, &v15, 1LL);
v8 = v7;
if ( v7 == -1 )
{
if ( v13 )
{
v9 = 0LL;
while ( *(_DWORD *)(v6 + 4 * v9) != v16 )
{
if ( ++v9 == v13 )
{
LODWORD(v9) = v13;
break;
}
}
}
else
{
LODWORD(v9) = 0;
}
v17 = v9;
v18 = 1;
if ( (unsigned __int8)array_insert_sorted(a3, &v15, 1LL, 0LL) == 2 )
return 1LL;
}
else
{
if ( (unsigned __int8)array_get(a3, (unsigned int)v7, &v15) )
return 1LL;
++v18;
array_set(a3, v8, &v15);
}
++v3;
}
while ( v3 != v12 );
}
v11 = 1LL;
array_set_cmps(a3, group_size_cmp, 0LL);
array_sort(a3);
if ( a2 > 1 )
{
do
{
v18 = v11;
while ( array_remove_by_val(a3, &v15, 1LL) >= 0 )
;
++v11;
}
while ( v11 != a2 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3)
{
__int64 v3; // r12
unsigned int v5; // er15
__int64 v6; // r13
__int64 v7; // rax
unsigned int v8; // er15
__int64 v9; // rax
__int64 v11; // r12
__int64 v12; // [rsp+0h] [rbp-68h]
int v13; // [rsp+8h] [rbp-60h]
int v14; // [rsp+1Ch] [rbp-4Ch] BYREF
int v15; // [rsp+20h] [rbp-48h] BYREF
int v16; // [rsp+24h] [rbp-44h]
int v17; // [rsp+28h] [rbp-40h]
int v18; // [rsp+2Ch] [rbp-3Ch]

v3 = 0LL;
v5 = graph_num_nodes();
v6 = graph_get_labelvals(a1);
v13 = graph_num_labelvals(a1);
array_set_cmps(a3, group_cmp, 0LL);
v12 = v5;
if ( v5 )
{
do
{
stats_cache_node_component(a1, v3, &v14);
v16 = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)v3);
v15 = v14;
v7 = array_find(a3, &v15, 1LL);
v8 = v7;
if ( v7 == -1 )
{
if ( v13 )
{
v9 = 0LL;
while ( *(_DWORD *)(v6 + 4 * v9) != v16 )
{
if ( ++v9 == v13 )
{
LODWORD(v9) = v13;
break;
}
}
}
else
{
LODWORD(v9) = 0;
}
v17 = v9;
v18 = 1;
if ( (unsigned __int8)array_insert_sorted(a3, &v15, 1LL, 0LL) == 2 )
return 1LL;
}
else
{
if ( (unsigned __int8)array_get(a3, (unsigned int)v7, &v15) )
return 1LL;
++v18;
array_set(a3, v8, &v15);
}
++v3;
}
while ( v3 != v12 );
}
v11 = 1LL;
array_set_cmps(a3, group_size_cmp, 0LL);
array_sort(a3);
if ( a2 > 1 )
{
do
{
v18 = v11;
while ( array_remove_by_val(a3, &v15, 1LL) >= 0 )
;
++v11;
}
while ( v11 != a2 );
}
return 0LL;
}

original_code:
uint8_t graph_communities(graph_t *g, uint32_t sz, array_t *groups) {
  uint64_t i;
  uint64_t j;
  int64_t gidx;
  uint32_t nnodes;
  uint32_t *lblvals;
  uint32_t nlblvals;
  node_group_t group;
  uint32_t tmp;
  nnodes = graph_num_nodes(g);
  lblvals = graph_get_labelvals(g);
  nlblvals = graph_num_labelvals(g);
  array_set_cmps(groups, _group_cmp, ((void *)0));
  for (i = 0; i < nnodes; i++) {
    stats_cache_node_component(g, i, &tmp);
    group.labelval = graph_get_nodelabel(g, i)->labelval;
    group.component = tmp;
    gidx = array_find(groups, &group, 1);
    if (gidx == -1) {
      for (j = 0; j < nlblvals; j++) {
        if (lblvals[j] == group.labelval) break;
      }
      group.labelidx = j;
      group.nnodes = 1;
      if (array_insert_sorted(groups, &group, 1, ((void *)0)) == 2)
        goto fail;
    }
    else {
      if (array_get(groups, gidx, &group)) goto fail;
      group.nnodes ++;
      array_set(groups, gidx, &group);
    }
  }
  array_set_cmps(groups, _group_size_cmp, ((void *)0));
  array_sort(groups);
  for (i = 1; i < sz; i++) {
    group.nnodes = i;
    while (array_remove_by_val(groups, &group, 1) >= 0);
  }
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_communities(struct _graph *g, unsigned int sz, struct _array *groups) {
  unsigned long i;
  unsigned long j;
  long gidx;
  unsigned int nnodes;
  unsigned int *lblvals;
  unsigned int nlblvals;
  struct _node_group group;
  unsigned int tmp;
  nnodes = graph_num_nodes(g);
  lblvals = graph_get_labelvals(g);
  nlblvals = graph_num_labelvals(g);
  array_set_cmps(groups, _group_cmp, ((void *)0));
  for (i = 0; i < nnodes; i++) {
    stats_cache_node_component(g, i, &tmp);
    group.labelval = graph_get_nodelabel(g, i)->labelval;
    group.component = tmp;
    gidx = array_find(groups, &group, 1);
    if (gidx == -1) {
      for (j = 0; j < nlblvals; j++) {
        if (lblvals[j] == group.labelval) break;
      }
      group.labelidx = j;
      group.nnodes = 1;
      if (array_insert_sorted(groups, &group, 1, ((void *)0)) == 2)
        goto fail;
    }
    else {
      if (array_get(groups, gidx, &group)) goto fail;
      group.nnodes ++;
      array_set(groups, gidx, &group);
    }
  }
  array_set_cmps(groups, _group_size_cmp, ((void *)0));
  array_sort(groups);
  for (i = 1; i < sz; i++) {
    group.nnodes = i;
    while (array_remove_by_val(groups, &group, 1) >= 0);
  }
  return 0;
fail:
  return 1;
}

variable_types:
sz
unsigned int

variable_types:
groups
struct _array *

variable_types:
j
unsigned long

variable_types: gidx long

variable_types:
nnodes
unsigned int

variable_types:
lblvals
unsigned int *

variable_types:
nlblvals
unsigned int

variable_types: struct _node_group { unsigned int component; unsigned int labelval; unsigned int labelidx; unsigned int nnodes; }

variable_types:
tmp
unsigned int