decompiled_code:
__int64 __fastcall graph_threshold_chira(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, void (__fastcall *a6)(char *), unsigned __int8 (__fastcall *a7)(char *, void *, char *, char *), unsigned __int8 (__fastcall *a8)(char *, char *))
{
unsigned int v10; // er13
void *v11; // rbp
unsigned int v12; // ebx
void *v14; // r15
__int64 v15; // r13
unsigned int v16; // eax
double v17; // r12
double v18; // [rsp+0h] [rbp-2A8h]
char v19[128]; // [rsp+10h] [rbp-298h] BYREF
__int64 v20; // [rsp+90h] [rbp-218h]
char v21[16]; // [rsp+120h] [rbp-188h] BYREF
char v22[16]; // [rsp+130h] [rbp-178h] BYREF
__int64 v23; // [rsp+140h] [rbp-168h]
char v24[328]; // [rsp+160h] [rbp-148h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3, __int64 a4, __int64 a5, void (__fastcall *a6)(char *), unsigned __int8 (__fastcall *a7)(char *, void *, char *, char *), unsigned __int8 (__fastcall *a8)(char *, char *))
{
unsigned int v10; // er13
void *v11; // rbp
unsigned int v12; // ebx
void *v14; // r15
__int64 v15; // r13
unsigned int v16; // eax
double v17; // r12
double v18; // [rsp+0h] [rbp-2A8h]
char v19[128]; // [rsp+10h] [rbp-298h] BYREF
__int64 v20; // [rsp+90h] [rbp-218h]
char v21[16]; // [rsp+120h] [rbp-188h] BYREF
char v22[16]; // [rsp+130h] [rbp-178h] BYREF
__int64 v23; // [rsp+140h] [rbp-168h]
char v24[328]; // [rsp+160h] [rbp-148h] BYREF

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

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); }


repo: pauldmccarthy/ccnet

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
__int64 result; // rax
__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;
if ( v4 )
{
v6 = 0LL;
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_6;
}
v9 = 0LL;
if ( *(_QWORD *)(a3 + 16) )
{
do
{
if ( *(_QWORD *)(*(_QWORD *)(a3 + 16) + 40 * v9 + 16) )
array_free();
++v9;
}
while ( v4 != v9 );
free(*(void **)(a3 + 16));
result = 1LL;
}
else
{
result = 1LL;
}
}
else
{
LABEL_6:
*(_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);
result = 0LL;
}
return result;
}

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
__int64 result; // rax
__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;
if ( v4 )
{
v6 = 0LL;
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_6;
}
v9 = 0LL;
if ( *(_QWORD *)(a3 + 16) )
{
do
{
if ( *(_QWORD *)(*(_QWORD *)(a3 + 16) + 40 * v9 + 16) )
array_free();
++v9;
}
while ( v4 != v9 );
free(*(void **)(a3 + 16));
result = 1LL;
}
else
{
result = 1LL;
}
}
else
{
LABEL_6:
*(_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);
result = 0LL;
}
return result;
}

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: 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:
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:
i
unsigned long

variable_types:
nnodes
unsigned int

variable_types:
nnbrs
unsigned int

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 *); }

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

if ( a1 )
{
graph_remove_event_listener(*a1, a1 + 3);
if ( a1[2] )
{
v1 = graph_num_nodes(*a1);
v2 = v1;
if ( v1 )
{
v3 = 0LL;
do
array_free(a1[2] + 40 * v3++);
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

if ( a1 )
{
graph_remove_event_listener(*a1, a1 + 3);
if ( a1[2] )
{
v1 = graph_num_nodes(*a1);
v2 = v1;
if ( v1 )
{
v3 = 0LL;
do
array_free(a1[2] + 40 * v3++);
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); }

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 edge_array_set_all(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // r12
__int64 v6; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
__int64 v5; // r12
__int64 v6; // rbx

result = graph_num_neighbours(*(_QWORD *)a1, a2);
v5 = (unsigned int)result;
if ( (_DWORD)result )
{
v6 = 0LL;
do
{
result = array_set(
*(_QWORD *)(a1 + 16) + 40LL * (unsigned int)a2,
(unsigned int)v6,
a3 + v6 * *(unsigned __int16 *)(a1 + 8));
++v6;
}
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:
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)
{
int v2; // er13
void *v3; // rax
void *v4; // rbp
void *v5; // rax
unsigned int v6; // er14
__int64 v8; // rbp

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
v2 = graph_num_nodes();
v3 = calloc(1uLL, 0x28uLL);
*(_QWORD *)(a2 + 8) = v3;
if ( !v3 )
return 1;
v4 = v3;
v5 = calloc(1uLL, 0x28uLL);
*(_QWORD *)(a2 + 16) = v5;
if ( !v5 )
return 1;
v6 = 1;
if ( !(unsigned __int8)array_create(v4, 4LL, 10LL) )
{
v6 = array_create(*(_QWORD *)(a2 + 16), 40LL, 10LL);
if ( (_BYTE)v6 )
{
v6 = 1;
}
else
{
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_11;
}
v6 = 1;
}
else
{
LABEL_11:
*(_DWORD *)a2 = *(_DWORD *)(*(_QWORD *)(a2 + 16) + 4LL);
}
}
}
return v6;
}

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

*(_QWORD *)a2 = 0LL;
*(_QWORD *)(a2 + 8) = 0LL;
*(_QWORD *)(a2 + 16) = 0LL;
v2 = graph_num_nodes();
v3 = calloc(1uLL, 0x28uLL);
*(_QWORD *)(a2 + 8) = v3;
if ( !v3 )
return 1;
v4 = v3;
v5 = calloc(1uLL, 0x28uLL);
*(_QWORD *)(a2 + 16) = v5;
if ( !v5 )
return 1;
v6 = 1;
if ( !(unsigned __int8)array_create(v4, 4LL, 10LL) )
{
v6 = array_create(*(_QWORD *)(a2 + 16), 40LL, 10LL);
if ( (_BYTE)v6 )
{
v6 = 1;
}
else
{
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_11;
}
v6 = 1;
}
else
{
LABEL_11:
*(_DWORD *)a2 = *(_DWORD *)(*(_QWORD *)(a2 + 16) + 4LL);
}
}
}
return v6;
}

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 _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; // ebp
double result; // xmm0_8
int v3; // er12
unsigned __int64 i; // rbx
_DWORD v5[4]; // [rsp+0h] [rbp-88h] BYREF
char v6[4]; // [rsp+10h] [rbp-78h] BYREF
unsigned int v7; // [rsp+14h] [rbp-74h]
__int64 v8; // [rsp+20h] [rbp-68h]
char v9[16]; // [rsp+40h] [rbp-48h] BYREF
__int64 v10; // [rsp+50h] [rbp-38h]

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

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
int v1; // ebp
double result; // xmm0_8
int v3; // er12
unsigned __int64 i; // rbx
_DWORD v5[4]; // [rsp+0h] [rbp-88h] BYREF
char v6[4]; // [rsp+10h] [rbp-78h] BYREF
unsigned int v7; // [rsp+14h] [rbp-74h]
__int64 v8; // [rsp+20h] [rbp-68h]
char v9[16]; // [rsp+40h] [rbp-48h] BYREF
__int64 v10; // [rsp+50h] [rbp-38h]

v10 = 0LL;
v8 = 0LL;
v1 = graph_num_nodes();
if ( (unsigned __int8)array_create(v9, 16LL, 10LL)
|| (unsigned __int8)array_create(v6, 16LL, 10LL)
|| (unsigned __int8)graph_communities(a1, 1LL, v9)
|| (unsigned __int8)func1(a1, (__int64)v9, (__int64)v6) )
{
if ( v10 )
array_free(v9);
result = *(double *)&LC0;
if ( v8 )
{
array_free(v6);
result = *(double *)&LC0;
}
}
else
{
array_set_cmps(v6, group_component_cmp, 0LL);
v3 = v7;
if ( v7 )
{
v3 = 0;
for ( i = 0LL; i < v7; ++i )
{
array_get(v6, (unsigned int)i, v5);
if ( (unsigned int)array_count(v6, v5) == 1 )
v3 += v5[3];
}
}
array_free(v6);
array_free(v9);
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 _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 result; // xmm0_8
double v5; // rbp
double v6; // r14
__int64 v7[6]; // [rsp+0h] [rbp-78h] BYREF
__int64 v8[9]; // [rsp+30h] [rbp-48h] BYREF

v8[0] = 0LL;
v8[1] = 0LL;
v8[2] = 0LL;
v8[3] = 0LL;
v8[4] = 0LL;
v7[0] = 0LL;
v7[1] = 0LL;
v7[2] = 0LL;
v7[3] = 0LL;
v7[4] = 0LL;
result = *(double *)&LC4;
if ( !(unsigned __int8)partition(a1, a2, (__int64)v8) )
{
result = *(double *)&LC4;
if ( !(unsigned __int8)partition(a1, a3, (__int64)v7) )
{
v5 = mutual_information(a1, (__int64)v8, (__int64)v7);
v6 = entropy((__int64)v8, a1).m128d_f64[0];
result = v5 / ((v6 + entropy((__int64)v7, a1).m128d_f64[0]) * 0.5);
}
}
return result;
}

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: 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: 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; // r14
_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; // r14
_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: 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:
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 v5[6]; // [rsp+8h] [rbp-30h] BYREF

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

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

if ( a2 )
{
v2 = 0;
for ( i = 0LL; i != a2; ++i )
v2 -= !func0(a1) - 1;
}
else
{
v2 = 0;
}
v5[0] = (double)v2 / (double)a2;
stats_cache_add(a1, 1LL, 0LL, 8LL);
stats_cache_update(a1, 1LL, 0LL, -1LL, v5);
return v5[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 i; // rbx
int v4; // er12
__int64 v5; // r13
__int64 v7; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
unsigned int v1; // eax
unsigned __int64 v2; // rbp
__int64 i; // rbx
int v4; // er12
__int64 v5; // r13
__int64 v7; // [rsp+8h] [rbp-40h]

v1 = graph_num_nodes();
v7 = v1;
if ( v1 )
{
v2 = 0LL;
do
{
v4 = graph_num_neighbours(a1, (unsigned int)v2);
v5 = graph_get_neighbours(a1, (unsigned int)v2);
if ( v4 )
{
for ( i = 0LL; i != v4; ++i )
{
if ( *(unsigned int *)(v5 + 4 * i) >= v2 )
stats_edge_pathsharing(a1, (unsigned int)v2);
}
}
++v2;
}
while ( v2 != v7 );
}
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:
j
unsigned long

variable_types:
nnbrs
unsigned int

variable_types:
nbrs
unsigned int *


decompiled_code:
bool __fastcall graph_remove_pathsharing(__int64 a1, __int64 a2, __int64 a3, unsigned int *a4)
{
unsigned int v5; // eax
unsigned __int64 v6; // r12
__int64 v7; // rbx
int v8; // er15
__int64 v9; // rbp
__m128d v10; // xmm0
double v11; // xmm1_8
__m128d v12; // xmm1
unsigned __int64 v13; // rsi
char v14; // dl
bool result; // al
double v16; // [rsp+8h] [rbp-60h]
double v17; // [rsp+8h] [rbp-60h]
__int64 v19; // [rsp+28h] [rbp-40h]

v5 = graph_num_nodes();
v19 = v5;
if ( v5 )
{
v16 = *(double *)&LC0;
v6 = 0LL;
while ( 1 )
{
v8 = graph_num_neighbours(a1, (unsigned int)v6);
v9 = graph_get_neighbours(a1, (unsigned int)v6);
stats_cache_edge_pathsharing(a1, (unsigned int)v6, a2);
if ( v8 )
break;
LABEL_9:
if ( ++v6 == v19 )
goto LABEL_12;
}
v7 = 0LL;
while ( 1 )
{
if ( *(unsigned int *)(v9 + 4 * v7) >= v6 && *(double *)(a2 + 8 * v7) <= v16 )
{
*a4 = v6;
a4[1] = *(_DWORD *)(v9 + 4 * v7);
if ( v16 > *(double *)(a2 + 8 * v7) )
{
array_clear(a3);
v16 = *(double *)(a2 + 8 * v7);
}
if ( (unsigned __int8)array_append(a3, a4) )
break;
}
if ( ++v7 == v8 )
goto LABEL_9;
}
result = 1;
}
else
{
LABEL_12:
v17 = (double)*(int *)(a3 + 4);
v10.m128d_f64[0] = (double)(int)random() / 2147483647.0 * v17;
v11 = v10.m128d_f64[0];
if ( COERCE_DOUBLE(*(_QWORD *)&v10.m128d_f64[0] & LC3) < 4.503599627370496e15 )
{
v12.m128d_f64[0] = (double)(int)v10.m128d_f64[0];
*(_QWORD *)&v11 = ~LC3 & *(_QWORD *)&v10.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v12.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v12, v10) & LC0));
}
if ( v11 >= 9.223372036854776e18 )
v13 = (unsigned int)(int)(v11 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v13 = (unsigned int)(int)v11;
v14 = array_get(a3, v13, a4);
result = 1;
if ( !v14 )
result = (unsigned __int8)graph_remove_edge(a1, *a4, a4[1]) != 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, __int64 a2, __int64 a3, unsigned int *a4)
{
unsigned int v5; // eax
unsigned __int64 v6; // r12
__int64 v7; // rbx
int v8; // er15
__int64 v9; // rbp
__m128d v10; // xmm0
double v11; // xmm1_8
__m128d v12; // xmm1
unsigned __int64 v13; // rsi
char v14; // dl
bool result; // al
double v16; // [rsp+8h] [rbp-60h]
double v17; // [rsp+8h] [rbp-60h]
__int64 v19; // [rsp+28h] [rbp-40h]

v5 = graph_num_nodes();
v19 = v5;
if ( v5 )
{
v16 = *(double *)&LC0;
v6 = 0LL;
while ( 1 )
{
v8 = graph_num_neighbours(a1, (unsigned int)v6);
v9 = graph_get_neighbours(a1, (unsigned int)v6);
stats_cache_edge_pathsharing(a1, (unsigned int)v6, a2);
if ( v8 )
break;
LABEL_9:
if ( ++v6 == v19 )
goto LABEL_12;
}
v7 = 0LL;
while ( 1 )
{
if ( *(unsigned int *)(v9 + 4 * v7) >= v6 && *(double *)(a2 + 8 * v7) <= v16 )
{
*a4 = v6;
a4[1] = *(_DWORD *)(v9 + 4 * v7);
if ( v16 > *(double *)(a2 + 8 * v7) )
{
array_clear(a3);
v16 = *(double *)(a2 + 8 * v7);
}
if ( (unsigned __int8)array_append(a3, a4) )
break;
}
if ( ++v7 == v8 )
goto LABEL_9;
}
result = 1;
}
else
{
LABEL_12:
v17 = (double)*(int *)(a3 + 4);
v10.m128d_f64[0] = (double)(int)random() / 2147483647.0 * v17;
v11 = v10.m128d_f64[0];
if ( COERCE_DOUBLE(*(_QWORD *)&v10.m128d_f64[0] & LC3) < 4.503599627370496e15 )
{
v12.m128d_f64[0] = (double)(int)v10.m128d_f64[0];
*(_QWORD *)&v11 = ~LC3 & *(_QWORD *)&v10.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v12.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v12, v10) & LC0));
}
if ( v11 >= 9.223372036854776e18 )
v13 = (unsigned int)(int)(v11 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v13 = (unsigned int)(int)v11;
v14 = array_get(a3, v13, a4);
result = 1;
if ( !v14 )
result = (unsigned __int8)graph_remove_edge(a1, *a4, a4[1]) != 0;
}
return result;
}

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; // ebp
__int64 v3; // r15
__int64 v4; // r13
__int64 v5; // r14
__int64 v6; // rbp
__int64 i; // rbp
unsigned int *v8; // rbp
__int64 v9; // r12
__int64 v11; // [rsp+8h] [rbp-40h]
unsigned int *v12; // [rsp+8h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
unsigned int v2; // ebp
__int64 v3; // r15
__int64 v4; // r13
__int64 v5; // r14
__int64 v6; // rbp
__int64 i; // rbp
unsigned int *v8; // rbp
__int64 v9; // r12
__int64 v11; // [rsp+8h] [rbp-40h]
unsigned int *v12; // [rsp+8h] [rbp-40h]

v2 = graph_num_neighbours(a1, *a2);
v3 = graph_get_neighbours(a1, *a2);
LODWORD(v4) = graph_num_neighbours(a1, a2[1]);
v5 = graph_get_neighbours(a1, a2[1]);
v11 = v2;
if ( !v2 )
{
v4 = (unsigned int)v4;
if ( !(_DWORD)v4 )
return 0LL;
LABEL_5:
for ( i = 0LL; i != v4; ++i )
stats_edge_pathsharing(a1, a2[1]);
if ( !v11 )
return 0LL;
goto LABEL_8;
}
v6 = 0LL;
do
{
stats_edge_pathsharing(a1, *a2);
++v6;
}
while ( v6 != v11 );
v4 = (unsigned int)v4;
if ( (_DWORD)v4 )
goto LABEL_5;
LABEL_8:
v8 = (unsigned int *)v3;
v12 = (unsigned int *)(v3 + 4 * v11);
do
{
v9 = v5;
if ( v4 )
{
do
{
stats_edge_pathsharing(a1, *v8);
v9 += 4LL;
}
while ( v9 != v5 + 4 * v4 );
}
++v8;
}
while ( v12 != v8 );
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 *

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


decompiled_code:
__int64 __fastcall graph_create_er_random(__int64 a1, __int64 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 ( !(_DWORD)a2 || !a1 || a3 > 1.0 || a3 < 0.0 || (v3 = graph_create(a1, a2, 0LL), (_BYTE)v3) )
{
LABEL_12:
graph_free(a1);
return 1;
}
v4 = 0LL;
LABEL_7:
mk_label((__int64)v11);
v5 = v4;
graph_set_nodelabel(a1, (unsigned int)v4++, v11);
if ( v4 < (unsigned int)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 >= (unsigned int)a2 )
goto LABEL_7;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 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 ( !(_DWORD)a2 || !a1 || a3 > 1.0 || a3 < 0.0 || (v3 = graph_create(a1, a2, 0LL), (_BYTE)v3) )
{
LABEL_12:
graph_free(a1);
return 1;
}
v4 = 0LL;
LABEL_7:
func0((__int64)v11);
v5 = v4;
graph_set_nodelabel(a1, (unsigned int)v4++, v11);
if ( v4 < (unsigned int)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 >= (unsigned int)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: 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: density double

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:
__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);
}


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

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

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

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

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

v5[0] = a2;
*a3 = 0LL;
if ( (unsigned __int8)stack_create(a3, 40LL, 20LL)
|| (result = bfs(a1, v5, 1LL, 0LL, a3, 0LL, bfs_cb, 0LL), (_BYTE)result) )
{
result = 1LL;
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

v5[0] = a2;
*a3 = 0LL;
if ( (unsigned __int8)stack_create(a3, 40LL, 20LL)
|| (result = bfs(a1, v5, 1LL, 0LL, a3, 0LL, bfs_cb, 0LL), (_BYTE)result) )
{
result = 1LL;
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)
{
int v4; // er15
__int64 v5; // r13
__int64 i; // r12
int v7; // edx
__int64 v8; // rax
__int64 v9; // rax
unsigned int v10; // ebp
__int64 j; // rbp
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]

v4 = graph_num_nodes();
v5 = graph_get_labelvals(a1);
v13 = graph_num_labelvals(a1);
array_set_cmps(a3, group_cmp, 0LL);
if ( v4 )
{
for ( i = 0LL; i != v4; ++i )
{
stats_cache_node_component(a1, i, &v14);
v16 = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)i);
v15 = v14;
v9 = array_find(a3, &v15, 1LL);
v10 = v9;
if ( v9 == -1 )
{
v7 = v13;
if ( v13 )
{
v8 = 0LL;
while ( *(_DWORD *)(v5 + 4 * v8) != v16 )
{
if ( ++v8 == v13 )
goto LABEL_9;
}
v7 = v8;
}
LABEL_9:
v17 = v7;
v18 = 1;
if ( (unsigned __int8)array_insert_sorted(a3, &v15, 1LL, 0LL) == 2 )
return 1LL;
}
else
{
if ( (unsigned __int8)array_get(a3, (unsigned int)v9, &v15) )
return 1LL;
++v18;
array_set(a3, v10, &v15);
}
}
}
array_set_cmps(a3, group_size_cmp, 0LL);
array_sort(a3);
if ( a2 <= 1 )
return 0LL;
for ( j = 1LL; j != a2; ++j )
{
v18 = j;
while ( array_remove_by_val(a3, &v15, 1LL) >= 0 )
;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2, __int64 a3)
{
int v4; // er15
__int64 v5; // r13
__int64 i; // r12
int v7; // edx
__int64 v8; // rax
__int64 v9; // rax
unsigned int v10; // ebp
__int64 j; // rbp
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]

v4 = graph_num_nodes();
v5 = graph_get_labelvals(a1);
v13 = graph_num_labelvals(a1);
array_set_cmps(a3, group_cmp, 0LL);
if ( v4 )
{
for ( i = 0LL; i != v4; ++i )
{
stats_cache_node_component(a1, i, &v14);
v16 = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)i);
v15 = v14;
v9 = array_find(a3, &v15, 1LL);
v10 = v9;
if ( v9 == -1 )
{
v7 = v13;
if ( v13 )
{
v8 = 0LL;
while ( *(_DWORD *)(v5 + 4 * v8) != v16 )
{
if ( ++v8 == v13 )
goto LABEL_9;
}
v7 = v8;
}
LABEL_9:
v17 = v7;
v18 = 1;
if ( (unsigned __int8)array_insert_sorted(a3, &v15, 1LL, 0LL) == 2 )
return 1LL;
}
else
{
if ( (unsigned __int8)array_get(a3, (unsigned int)v9, &v15) )
return 1LL;
++v18;
array_set(a3, v10, &v15);
}
}
}
array_set_cmps(a3, group_size_cmp, 0LL);
array_sort(a3);
if ( a2 <= 1 )
return 0LL;
for ( j = 1LL; j != a2; ++j )
{
v18 = j;
while ( array_remove_by_val(a3, &v15, 1LL) >= 0 )
;
}
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:
i
unsigned long

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


decompiled_code:
double __fastcall stats_pathlength(__int64 a1, unsigned int a2, void *a3)
{
size_t v4; // rbp
void *v5; // rax
double v6; // xmm0_8
double result; // xmm0_8
unsigned int v8[3]; // [rsp+Ch] [rbp-4Ch] BYREF
double v9; // [rsp+18h] [rbp-40h] BYREF
void *src; // [rsp+20h] [rbp-38h] BYREF
double v11; // [rsp+28h] [rbp-30h]
int v12; // [rsp+30h] [rbp-28h]

v8[0] = a2;
v11 = 0.0;
v12 = 0;
v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 8uLL);
src = v5;
if ( !v5 )
return *(double *)&LC1;
*((_QWORD *)v5 + v8[0]) = 0LL;
if ( (unsigned __int8)bfs(a1, v8, 1LL, 0LL, &src, 0LL, bfs_cb, 0LL) )
{
result = *(double *)&LC1;
if ( src )
{
free(src);
result = *(double *)&LC1;
}
}
else
{
v6 = 0.0;
if ( v12 )
v6 = v11 / (double)v12;
v9 = v6;
stats_cache_add(a1, 16LL, 2LL, 8LL);
stats_cache_add(a1, 22LL, 3LL, 8LL);
stats_cache_update(a1, 16LL, v8[0], -1LL, &v9);
stats_cache_update(a1, 22LL, v8[0], -1LL, src);
if ( a3 )
memcpy(a3, src, 8 * v4);
free(src);
result = v9;
}
return result;
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1, unsigned int a2, void *a3)
{
size_t v4; // rbp
void *v5; // rax
double v6; // xmm0_8
double result; // xmm0_8
unsigned int v8[3]; // [rsp+Ch] [rbp-4Ch] BYREF
double v9; // [rsp+18h] [rbp-40h] BYREF
void *src; // [rsp+20h] [rbp-38h] BYREF
double v11; // [rsp+28h] [rbp-30h]
int v12; // [rsp+30h] [rbp-28h]

v8[0] = a2;
v11 = 0.0;
v12 = 0;
v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 8uLL);
src = v5;
if ( !v5 )
return *(double *)&LC1;
*((_QWORD *)v5 + v8[0]) = 0LL;
if ( (unsigned __int8)bfs(a1, v8, 1LL, 0LL, &src, 0LL, bfs_cb, 0LL) )
{
result = *(double *)&LC1;
if ( src )
{
free(src);
result = *(double *)&LC1;
}
}
else
{
v6 = 0.0;
if ( v12 )
v6 = v11 / (double)v12;
v9 = v6;
stats_cache_add(a1, 16LL, 2LL, 8LL);
stats_cache_add(a1, 22LL, 3LL, 8LL);
stats_cache_update(a1, 16LL, v8[0], -1LL, &v9);
stats_cache_update(a1, 22LL, v8[0], -1LL, src);
if ( a3 )
memcpy(a3, src, 8 * v4);
free(src);
result = v9;
}
return result;
}

original_code:
double stats_pathlength(
  graph_t *g,
  uint32_t nidx,
  double *pathlens)
{
  ctx_t ctx;
  double path;
  uint32_t nnodes;
  ctx.pathlens = ((void *)0);
  nnodes = graph_num_nodes(g);
  ctx.tally = 0;
  ctx.count = 0;
  ctx.pathlens = calloc(nnodes,sizeof(double));
  if (ctx.pathlens == ((void *)0)) goto fail;
  ctx.pathlens[nidx] = 0;
  if (bfs(g, &nidx, 1, ((void *)0), &ctx, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
  if (ctx.count == 0) path = 0;
  else path = ctx.tally / ctx.count;
  stats_cache_add(g,
                  STATS_CACHE_NODE_PATHLENGTH,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(double));
  stats_cache_add(g,
                  STATS_CACHE_PAIR_PATHLENGTH,
                  STATS_CACHE_TYPE_PAIR,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_NODE_PATHLENGTH, nidx, -1, &path);
  stats_cache_update(g, STATS_CACHE_PAIR_PATHLENGTH, nidx, -1, ctx.pathlens);
  if (pathlens != ((void *)0)) {
    memcpy(pathlens, ctx.pathlens, nnodes*sizeof(double));
  }
  free(ctx.pathlens);
  return path;
fail:
  if (ctx.pathlens != ((void *)0)) free(ctx.pathlens);
  return -1;
}

canonical_original_code:
double stats_pathlength(struct _graph *g, unsigned int nidx, double *pathlens)
{
  struct _ctx ctx;
  double path;
  unsigned int nnodes;
  ctx.pathlens = ((void *)0);
  nnodes = graph_num_nodes(g);
  ctx.tally = 0;
  ctx.count = 0;
  ctx.pathlens = calloc(nnodes,sizeof(double));
  if (ctx.pathlens == ((void *)0)) goto fail;
  ctx.pathlens[nidx] = 0;
  if (bfs(g, &nidx, 1, ((void *)0), &ctx, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
  if (ctx.count == 0) path = 0;
  else path = ctx.tally / ctx.count;
  stats_cache_add(g,
                  STATS_CACHE_NODE_PATHLENGTH,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(double));
  stats_cache_add(g,
                  STATS_CACHE_PAIR_PATHLENGTH,
                  STATS_CACHE_TYPE_PAIR,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_NODE_PATHLENGTH, nidx, -1, &path);
  stats_cache_update(g, STATS_CACHE_PAIR_PATHLENGTH, nidx, -1, ctx.pathlens);
  if (pathlens != ((void *)0)) {
    memcpy(pathlens, ctx.pathlens, nnodes*sizeof(double));
  }
  free(ctx.pathlens);
  return path;
fail:
  if (ctx.pathlens != ((void *)0)) free(ctx.pathlens);
  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:
nidx
unsigned int

variable_types:
pathlens
double *

variable_types: struct _ctx { double *pathlens; double tally; unsigned int count; }

variable_types: path double


decompiled_code:
double __fastcall stats_avg_pathlength(__int64 a1)
{
int v1; // er13
int v2; // ebp
unsigned int v3; // ebx
double v4; // xmm0_8
double result; // xmm0_8
double v6[6]; // [rsp+8h] [rbp-30h] BYREF

v6[0] = 0.0;
v1 = graph_num_nodes();
if ( v1 )
{
v2 = 0;
v3 = 0;
while ( 1 )
{
v4 = stats_pathlength(a1, v3, 0LL);
if ( v4 < 0.0 )
break;
++v2;
v6[0] = v4 + v6[0];
if ( v1 == ++v3 )
goto LABEL_5;
}
result = *(double *)&LC1;
}
else
{
v2 = 0;
LABEL_5:
v6[0] = v6[0] / (double)v2;
stats_cache_add(a1, 3LL, 0LL, 8LL);
stats_cache_update(a1, 3LL, 0LL, -1LL, v6);
result = v6[0];
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
int v1; // er13
int v2; // ebp
unsigned int v3; // ebx
double v4; // xmm0_8
double result; // xmm0_8
double v6[6]; // [rsp+8h] [rbp-30h] BYREF

v6[0] = 0.0;
v1 = graph_num_nodes();
if ( v1 )
{
v2 = 0;
v3 = 0;
while ( 1 )
{
v4 = func1(a1, v3, 0LL);
if ( v4 < 0.0 )
break;
++v2;
v6[0] = v4 + v6[0];
if ( v1 == ++v3 )
goto LABEL_5;
}
result = *(double *)&LC1;
}
else
{
v2 = 0;
LABEL_5:
v6[0] = v6[0] / (double)v2;
stats_cache_add(a1, 3LL, 0LL, 8LL);
stats_cache_update(a1, 3LL, 0LL, -1LL, v6);
result = v6[0];
}
return result;
}

original_code:
double stats_avg_pathlength(graph_t *g) {
  uint32_t i;
  uint32_t numnodes;
  uint32_t count;
  double avgpath;
  double path;
  avgpath = 0;
  count = 0;
  numnodes = graph_num_nodes(g);
  for (i = 0; i < numnodes; i++) {
    path = stats_pathlength(g, i, ((void *)0));
    if (path < 0) goto fail;
    if (__builtin_isnan (path)) continue;
    count++;
    avgpath += path;
  }
  avgpath /= count;
  stats_cache_add(g,
                  STATS_CACHE_GRAPH_PATHLENGTH,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_GRAPH_PATHLENGTH, 0, -1, &avgpath);
  return avgpath;
fail:
  return -1;
}

canonical_original_code:
double stats_avg_pathlength(struct _graph *g) {
  unsigned int i;
  unsigned int numnodes;
  unsigned int count;
  double avgpath;
  double path;
  avgpath = 0;
  count = 0;
  numnodes = graph_num_nodes(g);
  for (i = 0; i < numnodes; i++) {
    path = stats_pathlength(g, i, ((void *)0));
    if (path < 0) goto fail;
    if (__builtin_isnan (path)) continue;
    count++;
    avgpath += path;
  }
  avgpath /= count;
  stats_cache_add(g,
                  STATS_CACHE_GRAPH_PATHLENGTH,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_GRAPH_PATHLENGTH, 0, -1, &avgpath);
  return avgpath;
fail:
  return -1;
}

variable_types:
i
unsigned int

variable_types:
numnodes
unsigned int

variable_types:
count
unsigned int

variable_types: avgpath double


decompiled_code:
double __fastcall stats_chira(__int64 a1, unsigned int a2, unsigned int *a3)
{
size_t v4; // r14
void *v5; // r12
_DWORD *v6; // r14
void *v7; // rbp
char *v8; // r15
size_t nmemb; // [rsp+8h] [rbp-60h]
void *nmemba; // [rsp+8h] [rbp-60h]
char *v12; // [rsp+18h] [rbp-50h]
double v13[8]; // [rsp+28h] [rbp-40h] BYREF

v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 4uLL);
if ( v5 )
{
nmemb = v4;
v6 = calloc(v4, 4uLL);
if ( v6 )
{
v7 = calloc(a2, 4uLL);
if ( v7 )
{
v8 = (char *)calloc(a2, 8uLL);
if ( v8 )
{
nmemba = calloc(nmemb, 8uLL);
if ( nmemba )
{
v12 = (char *)calloc(a2, 8uLL);
if ( v12 )
{
count_degrees(a1, (__int64)a3, v5, v6);
count_community_sizes(a1, a2, a3, v7);
count_community_edges(a1, a2, (__int64)a3, (__int64)v5, v8);
calc_node_strengths(a1, (__int64)v5, (__int64)v6, (__int64)a3, (__int64)v7, nmemba);
calc_community_strengths(a1, a2, (__int64)a3, (__int64)v7, (__int64)nmemba, v12);
*(_QWORD *)&v13[0] = calc_partition_strength(a1, a2, (__int64)v7, (__int64)v8, (__int64)v12);
stats_cache_add(a1, 14LL, 0LL, 8LL);
stats_cache_update(a1, 14LL, 0LL, -1LL, v13);
free(v5);
free(v6);
free(v7);
free(v8);
free(nmemba);
free(v12);
return v13[0];
}
}
}
else
{
nmemba = 0LL;
}
}
else
{
nmemba = 0LL;
v8 = 0LL;
}
}
else
{
nmemba = 0LL;
v8 = 0LL;
v7 = 0LL;
}
free(v5);
if ( v6 )
free(v6);
}
else
{
nmemba = 0LL;
v8 = 0LL;
v7 = 0LL;
}
if ( v7 )
free(v7);
if ( v8 )
free(v8);
if ( nmemba )
free(nmemba);
return *(double *)&LC2;
}

canonical_decompiled_code:
double __fastcall func5(__int64 a1, unsigned int a2, unsigned int *a3)
{
size_t v4; // r14
void *v5; // r12
_DWORD *v6; // r14
void *v7; // rbp
char *v8; // r15
size_t nmemb; // [rsp+8h] [rbp-60h]
void *nmemba; // [rsp+8h] [rbp-60h]
char *v12; // [rsp+18h] [rbp-50h]
double v13[8]; // [rsp+28h] [rbp-40h] BYREF

v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 4uLL);
if ( v5 )
{
nmemb = v4;
v6 = calloc(v4, 4uLL);
if ( v6 )
{
v7 = calloc(a2, 4uLL);
if ( v7 )
{
v8 = (char *)calloc(a2, 8uLL);
if ( v8 )
{
nmemba = calloc(nmemb, 8uLL);
if ( nmemba )
{
v12 = (char *)calloc(a2, 8uLL);
if ( v12 )
{
func3(a1, (__int64)a3, v5, v6);
func0(a1, a2, a3, v7);
func1(a1, a2, (__int64)a3, (__int64)v5, v8);
func2(a1, (__int64)v5, (__int64)v6, (__int64)a3, (__int64)v7, nmemba);
func4(a1, a2, (__int64)a3, (__int64)v7, (__int64)nmemba, v12);
*(_QWORD *)&v13[0] = calc_partition_strength(a1, a2, (__int64)v7, (__int64)v8, (__int64)v12);
stats_cache_add(a1, 14LL, 0LL, 8LL);
stats_cache_update(a1, 14LL, 0LL, -1LL, v13);
free(v5);
free(v6);
free(v7);
free(v8);
free(nmemba);
free(v12);
return v13[0];
}
}
}
else
{
nmemba = 0LL;
}
}
else
{
nmemba = 0LL;
v8 = 0LL;
}
}
else
{
nmemba = 0LL;
v8 = 0LL;
v7 = 0LL;
}
free(v5);
if ( v6 )
free(v6);
}
else
{
nmemba = 0LL;
v8 = 0LL;
v7 = 0LL;
}
if ( v7 )
free(v7);
if ( v8 )
free(v8);
if ( nmemba )
free(nmemba);
return *(double *)&LC2;
}

original_code:
double stats_chira(graph_t *g, uint32_t ncommunities, uint32_t *communities) {
  uint32_t nnodes;
  uint32_t *indegrees;
  uint32_t *outdegrees;
  uint32_t *comm_sizes;
  double *comm_edges;
  double *node_strengths;
  double *comm_strengths;
  double fitness;
  indegrees = ((void *)0);
  outdegrees = ((void *)0);
  comm_sizes = ((void *)0);
  comm_edges = ((void *)0);
  node_strengths = ((void *)0);
  comm_strengths = ((void *)0);
  nnodes = graph_num_nodes(g);
  indegrees = calloc(nnodes,sizeof(uint32_t));
  if (indegrees == ((void *)0)) goto fail;
  outdegrees = calloc(nnodes,sizeof(uint32_t));
  if (outdegrees == ((void *)0)) goto fail;
  comm_sizes = calloc(ncommunities,sizeof(uint32_t));
  if (comm_sizes == ((void *)0)) goto fail;
  comm_edges = calloc(ncommunities,sizeof(double));
  if (comm_edges == ((void *)0)) goto fail;
  node_strengths = calloc(nnodes,sizeof(double));
  if (node_strengths == ((void *)0)) goto fail;
  comm_strengths = calloc(ncommunities,sizeof(double));
  if (comm_strengths == ((void *)0)) goto fail;
  _count_degrees( g, communities, indegrees, outdegrees);
  _count_community_sizes(g, ncommunities, communities, comm_sizes);
  _count_community_edges(g, ncommunities, communities, indegrees, comm_edges);
  _calc_node_strengths(
    g, indegrees, outdegrees,
    communities, comm_sizes,
    node_strengths);
  _calc_community_strengths(
    g, ncommunities,
    communities, comm_sizes,
    node_strengths, comm_strengths);
  fitness = _calc_partition_strength(
    g, ncommunities, comm_sizes, comm_edges, comm_strengths);
  stats_cache_add(g,
                  STATS_CACHE_CHIRA,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_CHIRA, 0, -1, &fitness);
  free(indegrees);
  free(outdegrees);
  free(comm_sizes);
  free(comm_edges);
  free(node_strengths);
  free(comm_strengths);
  return fitness;
fail:
  if (indegrees != ((void *)0)) free(indegrees);
  if (outdegrees != ((void *)0)) free(outdegrees);
  if (comm_sizes != ((void *)0)) free(comm_sizes);
  if (comm_edges != ((void *)0)) free(comm_edges);
  if (node_strengths != ((void *)0)) free(node_strengths);
  if (comm_strengths != ((void *)0)) free(comm_strengths);
  return -1;
}

canonical_original_code:
double stats_chira(struct _graph *g, unsigned int ncommunities, unsigned int *communities) {
  unsigned int nnodes;
  unsigned int *indegrees;
  unsigned int *outdegrees;
  unsigned int *comm_sizes;
  double *comm_edges;
  double *node_strengths;
  double *comm_strengths;
  double fitness;
  indegrees = ((void *)0);
  outdegrees = ((void *)0);
  comm_sizes = ((void *)0);
  comm_edges = ((void *)0);
  node_strengths = ((void *)0);
  comm_strengths = ((void *)0);
  nnodes = graph_num_nodes(g);
  indegrees = calloc(nnodes,sizeof(unsigned int));
  if (indegrees == ((void *)0)) goto fail;
  outdegrees = calloc(nnodes,sizeof(unsigned int));
  if (outdegrees == ((void *)0)) goto fail;
  comm_sizes = calloc(ncommunities,sizeof(unsigned int));
  if (comm_sizes == ((void *)0)) goto fail;
  comm_edges = calloc(ncommunities,sizeof(double));
  if (comm_edges == ((void *)0)) goto fail;
  node_strengths = calloc(nnodes,sizeof(double));
  if (node_strengths == ((void *)0)) goto fail;
  comm_strengths = calloc(ncommunities,sizeof(double));
  if (comm_strengths == ((void *)0)) goto fail;
  _count_degrees( g, communities, indegrees, outdegrees);
  _count_community_sizes(g, ncommunities, communities, comm_sizes);
  _count_community_edges(g, ncommunities, communities, indegrees, comm_edges);
  _calc_node_strengths(
    g, indegrees, outdegrees,
    communities, comm_sizes,
    node_strengths);
  _calc_community_strengths(
    g, ncommunities,
    communities, comm_sizes,
    node_strengths, comm_strengths);
  fitness = _calc_partition_strength(
    g, ncommunities, comm_sizes, comm_edges, comm_strengths);
  stats_cache_add(g,
                  STATS_CACHE_CHIRA,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_CHIRA, 0, -1, &fitness);
  free(indegrees);
  free(outdegrees);
  free(comm_sizes);
  free(comm_edges);
  free(node_strengths);
  free(comm_strengths);
  return fitness;
fail:
  if (indegrees != ((void *)0)) free(indegrees);
  if (outdegrees != ((void *)0)) free(outdegrees);
  if (comm_sizes != ((void *)0)) free(comm_sizes);
  if (comm_edges != ((void *)0)) free(comm_edges);
  if (node_strengths != ((void *)0)) free(node_strengths);
  if (comm_strengths != ((void *)0)) free(comm_strengths);
  return -1;
}

variable_types:
ncommunities
unsigned int

variable_types:
communities
unsigned int *

variable_types:
indegrees
unsigned int *

variable_types:
outdegrees
unsigned int *

variable_types: fitness double


decompiled_code:
__int64 __fastcall graph_seed(__int64 a1, __int64 a2, unsigned int *a3, unsigned int a4, char a5, __int64 a6)
{
size_t v9; // rbx
unsigned int *v10; // rax
unsigned int v11; // ebp
__int64 i; // rax
char v14[8]; // [rsp+0h] [rbp-48h] BYREF
void *ptr; // [rsp+8h] [rbp-40h]

v14[0] = a5;
v9 = (unsigned int)graph_num_nodes();
ptr = calloc(v9, 1uLL);
if ( !ptr )
return 1;
if ( a4 )
{
v10 = a3;
do
*((_BYTE *)ptr + *v10++) = 1;
while ( v10 != &a3[a4] );
}
if ( !(unsigned __int8)bfs(a1, a3, a4, 0LL, v14, 0LL, bfs_cb, 0LL) )
{
v11 = graph_mask(a1, a2, ptr);
if ( !(_BYTE)v11 )
{
if ( !a6 )
goto LABEL_7;
if ( v9 )
{
for ( i = 0LL; i != v9; ++i )
*((_BYTE *)ptr + i) = *((_BYTE *)ptr + i) == 0;
}
if ( !(unsigned __int8)graph_mask(a1, a6, ptr) )
goto LABEL_7;
}
}
v11 = 1;
if ( ptr )
LABEL_7:
free(ptr);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned int *a3, unsigned int a4, char a5, __int64 a6)
{
size_t v9; // rbx
unsigned int *v10; // rax
unsigned int v11; // ebp
__int64 i; // rax
char v14[8]; // [rsp+0h] [rbp-48h] BYREF
void *ptr; // [rsp+8h] [rbp-40h]

v14[0] = a5;
v9 = (unsigned int)graph_num_nodes();
ptr = calloc(v9, 1uLL);
if ( !ptr )
return 1;
if ( a4 )
{
v10 = a3;
do
*((_BYTE *)ptr + *v10++) = 1;
while ( v10 != &a3[a4] );
}
if ( !(unsigned __int8)bfs(a1, a3, a4, 0LL, v14, 0LL, bfs_cb, 0LL) )
{
v11 = graph_mask(a1, a2, ptr);
if ( !(_BYTE)v11 )
{
if ( !a6 )
goto LABEL_7;
if ( v9 )
{
for ( i = 0LL; i != v9; ++i )
*((_BYTE *)ptr + i) = *((_BYTE *)ptr + i) == 0;
}
if ( !(unsigned __int8)graph_mask(a1, a6, ptr) )
goto LABEL_7;
}
}
v11 = 1;
if ( ptr )
LABEL_7:
free(ptr);
return v11;
}

original_code:
uint8_t graph_seed(
  graph_t *gin,
  graph_t *gout,
  uint32_t *seeds,
  uint32_t nseeds,
  uint8_t depth,
  graph_t *grem) {
  ctx_t ctx;
  uint64_t i;
  uint32_t nnodes;
  nnodes = graph_num_nodes(gin);
  ctx.maxdepth = depth;
  ctx.nodemask = calloc(nnodes, 1);
  if (ctx.nodemask == ((void *)0)) goto fail;
  for (i = 0; i < nseeds; i++) ctx.nodemask[seeds[i]] = 1;
  if (bfs(gin, seeds, nseeds, ((void *)0), &ctx, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
  if (graph_mask(gin, gout, ctx.nodemask)) goto fail;
  if (grem) {
    for (i = 0; i < nnodes; i++) ctx.nodemask[i] = !ctx.nodemask[i];
    if (graph_mask(gin, grem, ctx.nodemask)) goto fail;
  }
  free(ctx.nodemask);
  return 0;
fail:
  if (ctx.nodemask != ((void *)0)) free(ctx.nodemask);
  return 1;
}

canonical_original_code:
unsigned char graph_seed(struct _graph *gin, struct _graph *gout, unsigned int *seeds, unsigned int nseeds, unsigned char depth, struct _graph *grem) {
  struct __ctx ctx;
  unsigned long i;
  unsigned int nnodes;
  nnodes = graph_num_nodes(gin);
  ctx.maxdepth = depth;
  ctx.nodemask = calloc(nnodes, 1);
  if (ctx.nodemask == ((void *)0)) goto fail;
  for (i = 0; i < nseeds; i++) ctx.nodemask[seeds[i]] = 1;
  if (bfs(gin, seeds, nseeds, ((void *)0), &ctx, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
  if (graph_mask(gin, gout, ctx.nodemask)) goto fail;
  if (grem) {
    for (i = 0; i < nnodes; i++) ctx.nodemask[i] = !ctx.nodemask[i];
    if (graph_mask(gin, grem, ctx.nodemask)) goto fail;
  }
  free(ctx.nodemask);
  return 0;
fail:
  if (ctx.nodemask != ((void *)0)) free(ctx.nodemask);
  return 1;
}

variable_types:
gout
struct _graph *

variable_types:
seeds
unsigned int *

variable_types:
nseeds
unsigned int

variable_types:
depth
unsigned char

variable_types:
grem
struct _graph *

variable_types: struct __ctx { unsigned char maxdepth; unsigned char *nodemask; }

variable_types:
i
unsigned long

variable_types:
nnodes
unsigned int


decompiled_code:
__int64 __fastcall graph_create_smallworld(__int64 a1, __int64 a2, unsigned __int16 a3, double a4)
{
__int64 v4; // rbp
unsigned __int16 v5; // r13
unsigned __int64 v6; // rbx
unsigned __int64 v7; // r13
__int64 i; // r14
unsigned __int64 v9; // rbx
int v10; // eax
float v11; // xmm0_4
unsigned __int64 v12; // r15
__int64 j; // rbx
int v14; // eax
unsigned int v15; // er14
__m128d v16; // xmm0
double v17; // xmm2_8
__m128d v18; // xmm2
unsigned int v19; // esi
float v20; // xmm0_4
int v21; // er12
__int64 v22; // rbp
unsigned __int8 v25; // [rsp+13h] [rbp-A5h]
int v26; // [rsp+14h] [rbp-A4h]
double v27; // [rsp+20h] [rbp-98h]
unsigned __int64 v28; // [rsp+28h] [rbp-90h]
char v29[136]; // [rsp+30h] [rbp-88h] BYREF

v4 = a1;
v26 = a2;
if ( !(_DWORD)a2 )
goto LABEL_34;
v5 = a3;
if ( !a1 || a4 > 1.0 || a4 < 0.0 || !a3 )
goto LABEL_34;
if ( (a3 & 1) != 0 )
v5 = a3 + 1;
v25 = graph_create(a1, a2, 0LL);
if ( !v25 )
{
v6 = 0LL;
do
{
mk_label((__int64)v29);
++v6;
}
while ( v6 < (unsigned int)a2 );
v7 = (unsigned __int16)((v5 >> 1) + 1);
for ( i = 0LL; ; ++i )
{
if ( v7 > i + 1 )
{
v9 = i + 1;
do
{
v10 = rand();
v11 = (double)v10 / 2147483647.0 + (double)v10 / 2147483647.0 - 1.0;
if ( (unsigned __int8)graph_add_edge(a1, (unsigned int)i, v9 % (unsigned int)a2, v11) )
goto LABEL_34;
++v9;
}
while ( v7 > v9 );
}
++v7;
if ( i + 1 >= (unsigned __int64)(unsigned int)a2 )
break;
}
v12 = 0LL;
v28 = (unsigned int)a2;
do
{
v21 = graph_num_neighbours(a1, (unsigned int)v12);
v22 = graph_get_neighbours(a1, (unsigned int)v12);
if ( v21 )
{
for ( j = 0LL; j != v21; ++j )
{
if ( *(unsigned int *)(v22 + 4 * j) <= v12 && (double)rand() / 2147483647.0 <= a4 )
{
v14 = rand();
v27 = (double)v14 / 2147483647.0 + (double)v14 / 2147483647.0 - 1.0;
v15 = *(_DWORD *)(v22 + 4 * j);
if ( (unsigned __int8)graph_remove_edge(a1, (unsigned int)v12, v15) )
{
v4 = a1;
goto LABEL_34;
}
do
{
v16.m128d_f64[0] = (double)rand() / 2147483647.0 * (double)v26;
v17 = v16.m128d_f64[0];
if ( COERCE_DOUBLE(LC7 & *(_QWORD *)&v16.m128d_f64[0]) < 4.503599627370496e15 )
{
v18.m128d_f64[0] = (double)(int)v16.m128d_f64[0];
*(_QWORD *)&v17 = ~LC7 & *(_QWORD *)&v16.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v18.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v18, v16) & LC3));
}
v19 = (int)v17;
}
while ( v15 == (int)v17
|| (int)v17 == v12
|| (unsigned __int8)graph_are_neighbours(a1, (unsigned int)v12, v19) );
v20 = v27;
if ( (unsigned __int8)graph_add_edge(a1, (unsigned int)v12, v19, v20) )
{
v4 = a1;
goto LABEL_34;
}
}
}
}
++v12;
}
while ( v12 < v28 );
}
else
{
LABEL_34:
graph_free(v4);
v25 = 1;
}
return v25;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int16 a3, double a4)
{
__int64 v4; // rbp
unsigned __int16 v5; // r13
unsigned __int64 v6; // rbx
unsigned __int64 v7; // r13
__int64 i; // r14
unsigned __int64 v9; // rbx
int v10; // eax
float v11; // xmm0_4
unsigned __int64 v12; // r15
__int64 j; // rbx
int v14; // eax
unsigned int v15; // er14
__m128d v16; // xmm0
double v17; // xmm2_8
__m128d v18; // xmm2
unsigned int v19; // esi
float v20; // xmm0_4
int v21; // er12
__int64 v22; // rbp
unsigned __int8 v25; // [rsp+13h] [rbp-A5h]
int v26; // [rsp+14h] [rbp-A4h]
double v27; // [rsp+20h] [rbp-98h]
unsigned __int64 v28; // [rsp+28h] [rbp-90h]
char v29[136]; // [rsp+30h] [rbp-88h] BYREF

v4 = a1;
v26 = a2;
if ( !(_DWORD)a2 )
goto LABEL_34;
v5 = a3;
if ( !a1 || a4 > 1.0 || a4 < 0.0 || !a3 )
goto LABEL_34;
if ( (a3 & 1) != 0 )
v5 = a3 + 1;
v25 = graph_create(a1, a2, 0LL);
if ( !v25 )
{
v6 = 0LL;
do
{
func0((__int64)v29);
++v6;
}
while ( v6 < (unsigned int)a2 );
v7 = (unsigned __int16)((v5 >> 1) + 1);
for ( i = 0LL; ; ++i )
{
if ( v7 > i + 1 )
{
v9 = i + 1;
do
{
v10 = rand();
v11 = (double)v10 / 2147483647.0 + (double)v10 / 2147483647.0 - 1.0;
if ( (unsigned __int8)graph_add_edge(a1, (unsigned int)i, v9 % (unsigned int)a2, v11) )
goto LABEL_34;
++v9;
}
while ( v7 > v9 );
}
++v7;
if ( i + 1 >= (unsigned __int64)(unsigned int)a2 )
break;
}
v12 = 0LL;
v28 = (unsigned int)a2;
do
{
v21 = graph_num_neighbours(a1, (unsigned int)v12);
v22 = graph_get_neighbours(a1, (unsigned int)v12);
if ( v21 )
{
for ( j = 0LL; j != v21; ++j )
{
if ( *(unsigned int *)(v22 + 4 * j) <= v12 && (double)rand() / 2147483647.0 <= a4 )
{
v14 = rand();
v27 = (double)v14 / 2147483647.0 + (double)v14 / 2147483647.0 - 1.0;
v15 = *(_DWORD *)(v22 + 4 * j);
if ( (unsigned __int8)graph_remove_edge(a1, (unsigned int)v12, v15) )
{
v4 = a1;
goto LABEL_34;
}
do
{
v16.m128d_f64[0] = (double)rand() / 2147483647.0 * (double)v26;
v17 = v16.m128d_f64[0];
if ( COERCE_DOUBLE(LC7 & *(_QWORD *)&v16.m128d_f64[0]) < 4.503599627370496e15 )
{
v18.m128d_f64[0] = (double)(int)v16.m128d_f64[0];
*(_QWORD *)&v17 = ~LC7 & *(_QWORD *)&v16.m128d_f64[0] | COERCE_UNSIGNED_INT64(
v18.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v18, v16) & LC3));
}
v19 = (int)v17;
}
while ( v15 == (int)v17
|| (int)v17 == v12
|| (unsigned __int8)graph_are_neighbours(a1, (unsigned int)v12, v19) );
v20 = v27;
if ( (unsigned __int8)graph_add_edge(a1, (unsigned int)v12, v19, v20) )
{
v4 = a1;
goto LABEL_34;
}
}
}
}
++v12;
}
while ( v12 < v28 );
}
else
{
LABEL_34:
graph_free(v4);
v25 = 1;
}
return v25;
}

original_code:
uint8_t graph_create_smallworld(
  graph_t *g, uint32_t nnodes, double p, uint16_t k) {
  uint64_t i;
  uint64_t j;
  uint32_t oldnbr;
  uint32_t newnbr;
  uint32_t nnbrs;
  uint32_t *nbrs;
  double wt;
  graph_label_t lbl;
  if (g == ((void *)0)) goto fail;
  if (nnodes == 0) goto fail;
  if (p > 1.0) goto fail;
  if (p < 0.0) goto fail;
  if (k == 0) goto fail;
  if (k % 2)
    k ++;
  if (graph_create(g, nnodes, 0)) goto fail;
  for (i = 0; i < nnodes; i++) {
    _mk_label(&lbl);
  }
  for (i = 0; i < nnodes; i++) {
    for (j = i+1; j < (i + 1 + k/2); j++) {
      wt = -1.0 + 2.0*((double)rand() / 2147483647);
      if (graph_add_edge(g, i, (j % nnodes), wt)) goto fail;
    }
  }
  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;
      if (((double)rand() / 2147483647) > p)
        continue;
      wt = -1.0 + 2.0*((double)rand() / 2147483647);
      oldnbr = nbrs[j];
      if (graph_remove_edge(g, i, oldnbr)) goto fail;
      while (1) {
        newnbr = floor(nnodes * ((double)rand() / 2147483647));
        if (newnbr == i) continue;
        if (newnbr == oldnbr) continue;
        if (graph_are_neighbours(g, i, newnbr)) continue;
        break;
      }
      if (graph_add_edge(g, i, newnbr, wt)) goto fail;
    }
  }
  return 0;
fail:
  graph_free(g);
  return 1;
}

canonical_original_code:
unsigned char graph_create_smallworld(struct _graph *g, unsigned int nnodes, double p, unsigned short k) {
  unsigned long i;
  unsigned long j;
  unsigned int oldnbr;
  unsigned int newnbr;
  unsigned int nnbrs;
  unsigned int *nbrs;
  double wt;
  struct _graph_label lbl;
  if (g == ((void *)0)) goto fail;
  if (nnodes == 0) goto fail;
  if (p > 1.0) goto fail;
  if (p < 0.0) goto fail;
  if (k == 0) goto fail;
  if (k % 2)
    k ++;
  if (graph_create(g, nnodes, 0)) goto fail;
  for (i = 0; i < nnodes; i++) {
    _mk_label(&lbl);
  }
  for (i = 0; i < nnodes; i++) {
    for (j = i+1; j < (i + 1 + k/2); j++) {
      wt = -1.0 + 2.0*((double)rand() / 2147483647);
      if (graph_add_edge(g, i, (j % nnodes), wt)) goto fail;
    }
  }
  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;
      if (((double)rand() / 2147483647) > p)
        continue;
      wt = -1.0 + 2.0*((double)rand() / 2147483647);
      oldnbr = nbrs[j];
      if (graph_remove_edge(g, i, oldnbr)) goto fail;
      while (1) {
        newnbr = floor(nnodes * ((double)rand() / 2147483647));
        if (newnbr == i) continue;
        if (newnbr == oldnbr) continue;
        if (graph_are_neighbours(g, i, newnbr)) continue;
        break;
      }
      if (graph_add_edge(g, i, newnbr, wt)) goto fail;
    }
  }
  return 0;
fail:
  graph_free(g);
  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: p double

variable_types:
k
unsigned short

variable_types:
j
unsigned long

variable_types:
oldnbr
unsigned int

variable_types:
newnbr
unsigned int

variable_types:
nnbrs
unsigned int

variable_types:
nbrs
unsigned int *

variable_types: wt double

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


decompiled_code:
__int64 __fastcall dimorder_parse(__int64 a1, const char **a2, unsigned __int8 *a3, unsigned __int8 a4)
{
unsigned __int8 v5; // bp
unsigned __int8 v6; // r12
unsigned __int8 v7; // r15
__int64 result; // rax
unsigned __int8 v9; // al
const char **v10; // rbp
unsigned __int8 *v11; // r13
const char *v12; // rbx
unsigned __int8 v13; // al
unsigned __int8 v14; // dl
unsigned __int8 v15; // al
__int64 v16; // rax
__int64 v17; // [rsp+0h] [rbp-48h]
unsigned __int8 v18; // [rsp+Ch] [rbp-3Ch]

v5 = a4;
v18 = a4;
v6 = a4;
v7 = analyze_num_dims();
result = 1LL;
if ( v7 >= v5 )
{
v9 = v5;
if ( v5 )
{
v10 = a2;
v11 = a3;
v17 = (__int64)&a2[(unsigned __int8)(v9 - 1) + 1];
while ( 1 )
{
v12 = *v10;
if ( strlen(*v10) != 1 )
return 1LL;
if ( ((*_ctype_b_loc())[*v12] & 0x800) == 0 )
return 1LL;
v13 = atoi(v12);
*v11 = v13;
if ( v13 >= v7 )
break;
++v10;
++v11;
if ( v10 == (const char **)v17 )
goto LABEL_8;
}
result = 1LL;
}
else
{
LABEL_8:
v14 = 0;
result = 0LL;
if ( v7 > v18 )
{
do
{
v16 = 0LL;
if ( !v6 )
goto LABEL_11;
while ( a3[v16] != v14 )
{
if ( v6 <= (unsigned __int8)++v16 )
goto LABEL_11;
}
if ( (unsigned __int8)v16 >= v6 )
LABEL_11:
a3[v6++] = v14;
v15 = ++v14;
if ( v6 >= v14 )
v15 = v6;
}
while ( v7 > v15 );
result = 0LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char **a2, unsigned __int8 *a3, unsigned __int8 a4)
{
unsigned __int8 v5; // bp
unsigned __int8 v6; // r12
unsigned __int8 v7; // r15
__int64 result; // rax
unsigned __int8 v9; // al
const char **v10; // rbp
unsigned __int8 *v11; // r13
const char *v12; // rbx
unsigned __int8 v13; // al
unsigned __int8 v14; // dl
unsigned __int8 v15; // al
__int64 v16; // rax
__int64 v17; // [rsp+0h] [rbp-48h]
unsigned __int8 v18; // [rsp+Ch] [rbp-3Ch]

v5 = a4;
v18 = a4;
v6 = a4;
v7 = analyze_num_dims();
result = 1LL;
if ( v7 >= v5 )
{
v9 = v5;
if ( v5 )
{
v10 = a2;
v11 = a3;
v17 = (__int64)&a2[(unsigned __int8)(v9 - 1) + 1];
while ( 1 )
{
v12 = *v10;
if ( strlen(*v10) != 1 )
return 1LL;
if ( ((*_ctype_b_loc())[*v12] & 0x800) == 0 )
return 1LL;
v13 = atoi(v12);
*v11 = v13;
if ( v13 >= v7 )
break;
++v10;
++v11;
if ( v10 == (const char **)v17 )
goto LABEL_8;
}
result = 1LL;
}
else
{
LABEL_8:
v14 = 0;
result = 0LL;
if ( v7 > v18 )
{
do
{
v16 = 0LL;
if ( !v6 )
goto LABEL_11;
while ( a3[v16] != v14 )
{
if ( v6 <= (unsigned __int8)++v16 )
goto LABEL_11;
}
if ( (unsigned __int8)v16 >= v6 )
LABEL_11:
a3[v6++] = v14;
v15 = ++v14;
if ( v6 >= v14 )
v15 = v6;
}
while ( v7 > v15 );
result = 0LL;
}
}
}
return result;
}

original_code:
uint8_t dimorder_parse(
  dsr_t *hdr,
  char *order[],
  uint8_t *dims,
  uint8_t orderlen)
{
  uint8_t i,j;
  uint8_t ndims;
  ndims = analyze_num_dims(hdr);
  if (orderlen > ndims) goto fail;
  for (i = 0; i < orderlen; i++) {
    if (strlen(order[i]) != 1) goto fail;
    if (!((*__ctype_b_loc ())[(int) ((order[i][0]))] & (unsigned short int) _ISdigit)) goto fail;
    dims[i] = atoi(order[i]);
    if (dims[i] >= ndims) goto fail;
  }
  for (i = 0; orderlen < ndims && i < ndims; i++) {
    for (j = 0; j < orderlen; j++) if (dims[j] == i) break;
    if (j < orderlen) continue;
    dims[orderlen++] = i;
  }
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char dimorder_parse(struct dsr *hdr, char *order[], unsigned char *dims, unsigned char orderlen)
{
  unsigned char i; unsigned char j;
  unsigned char ndims;
  ndims = analyze_num_dims(hdr);
  if (orderlen > ndims) goto fail;
  for (i = 0; i < orderlen; i++) {
    if (strlen(order[i]) != 1) goto fail;
    if (!((*__ctype_b_loc ())[(int) ((order[i][0]))] & (unsigned short) _ISdigit)) goto fail;
    dims[i] = atoi(order[i]);
    if (dims[i] >= ndims) goto fail;
  }
  for (i = 0; orderlen < ndims && i < ndims; i++) {
    for (j = 0; j < orderlen; j++) if (dims[j] == i) break;
    if (j < orderlen) continue;
    dims[orderlen++] = i;
  }
  return 0;
fail:
  return 1;
}

variable_types: struct dsr { struct header_key { unsigned int sizeof_hdr; char data_type[10]; char db_name[18]; unsigned int extents; unsigned short session_error; char regular; char hkey_un0; } hk; struct image_dimension { unsigned short dim[8]; unsigned short unused8; unsigned short unused9; unsigned short unused10; unsigned short unused11; unsigned short unused12; unsigned short unused13; unsigned short unused14; unsigned short datatype; unsigned short bitpix; unsigned short dim_un0; float pixdim[8]; float vox_offset; float funused1; float funused2; float funused3; float cal_max; float cal_min; float compressed; float verified; unsigned int glmax; unsigned int glmin; } dime; struct data_history { char descrip[80]; char aux_file[24]; char orient; char originator[10]; char generated[10]; char scannum[10]; char patient_id[10]; char exp_date[10]; char exp_time[10]; char hist_un0[3]; unsigned int views; unsigned int vols_added; unsigned int start_field; unsigned int field_skip; unsigned int omax; unsigned int omin; unsigned int smax; unsigned int smin; } hist; unsigned char rev; } *

variable_types:
order
char *[]

variable_types:
dims
unsigned char *

variable_types:
orderlen
unsigned char

variable_types:
i
unsigned char

variable_types:
j
unsigned char

variable_types:
ndims
unsigned char

user_defined_types: struct dsr { struct header_key hk; struct image_dimension dime; struct data_history hist; unsigned char rev; }


decompiled_code:
__int64 __fastcall dimorder_next(__int64 a1, __int64 a2, unsigned __int8 *a3)
{
__int64 result; // rax
unsigned __int8 *v5; // rbx
__int64 v6; // r13

result = (unsigned __int8)analyze_num_dims();
if ( (_BYTE)result )
{
v5 = a3;
v6 = (__int64)&a3[(unsigned int)(result - 1) + 1];
do
{
*(_DWORD *)(a2 + 4LL * *v5) = (*(_DWORD *)(a2 + 4LL * *v5) + 1)
% (unsigned int)(unsigned __int16)analyze_dim_size(a1, *v5);
result = *v5;
if ( *(_DWORD *)(a2 + 4 * result) )
break;
++v5;
}
while ( v5 != (unsigned __int8 *)v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, unsigned __int8 *a3)
{
__int64 result; // rax
unsigned __int8 *v5; // rbx
__int64 v6; // r13

result = (unsigned __int8)analyze_num_dims();
if ( (_BYTE)result )
{
v5 = a3;
v6 = (__int64)&a3[(unsigned int)(result - 1) + 1];
do
{
*(_DWORD *)(a2 + 4LL * *v5) = (*(_DWORD *)(a2 + 4LL * *v5) + 1)
% (unsigned int)(unsigned __int16)analyze_dim_size(a1, *v5);
result = *v5;
if ( *(_DWORD *)(a2 + 4 * result) )
break;
++v5;
}
while ( v5 != (unsigned __int8 *)v6 );
}
return result;
}

original_code:
void dimorder_next(dsr_t *hdr, uint32_t *dims, uint8_t *dimorder) {
  uint32_t i;
  uint16_t ndims;
  uint32_t dimsz;
  ndims = analyze_num_dims(hdr);
  for (i = 0; i < ndims; i++) {
    dimsz = analyze_dim_size(hdr, dimorder[i]);
    dims[dimorder[i]] = (dims[dimorder[i]] + 1) % dimsz;
    if (dims[dimorder[i]] != 0) break;
  }
}

canonical_original_code:
void dimorder_next(struct dsr *hdr, unsigned int *dims, unsigned char *dimorder) {
  unsigned int i;
  unsigned short ndims;
  unsigned int dimsz;
  ndims = analyze_num_dims(hdr);
  for (i = 0; i < ndims; i++) {
    dimsz = analyze_dim_size(hdr, dimorder[i]);
    dims[dimorder[i]] = (dims[dimorder[i]] + 1) % dimsz;
    if (dims[dimorder[i]] != 0) break;
  }
}

variable_types:
dims
unsigned int *

variable_types:
dimorder
unsigned char *

variable_types:
i
unsigned int

variable_types:
ndims
unsigned short

variable_types:
dimsz
unsigned int

user_defined_types: struct header_key { unsigned int sizeof_hdr; char data_type[10]; char db_name[18]; unsigned int extents; unsigned short session_error; char regular; char hkey_un0; }

user_defined_types: struct image_dimension { unsigned short dim[8]; unsigned short unused8; unsigned short unused9; unsigned short unused10; unsigned short unused11; unsigned short unused12; unsigned short unused13; unsigned short unused14; unsigned short datatype; unsigned short bitpix; unsigned short dim_un0; float pixdim[8]; float vox_offset; float funused1; float funused2; float funused3; float cal_max; float cal_min; float compressed; float verified; unsigned int glmax; unsigned int glmin; }

user_defined_types: struct data_history { char descrip[80]; char aux_file[24]; char orient; char originator[10]; char generated[10]; char scannum[10]; char patient_id[10]; char exp_date[10]; char exp_time[10]; char hist_un0[3]; unsigned int views; unsigned int vols_added; unsigned int start_field; unsigned int field_skip; unsigned int omax; unsigned int omin; unsigned int smax; unsigned int smin; }


reverse

original_code:
void reverse(void *src, void *dst, int len) {
  int i;
  uint8_t tmp;
  uint8_t *usrc = (uint8_t *)src;
  uint8_t *udst = (uint8_t *)dst;
  if (src == ((void *)0)) return;
  if (dst == ((void *)0)) return;
  if (len == 0) return;
  for (i = 0; i < len/2; i++) {
    tmp = usrc[i];
    udst[i] = usrc[len-1-i];
    udst[len-1-i] = tmp;
  }
}

canonical_original_code:
void reverse(void *src, void *dst, int len) {
  int i;
  unsigned char tmp;
  unsigned char *usrc = (uint8_t *)src;
  unsigned char *udst = (uint8_t *)dst;
  if (src == ((void *)0)) return;
  if (dst == ((void *)0)) return;
  if (len == 0) return;
  for (i = 0; i < len/2; i++) {
    tmp = usrc[i];
    udst[i] = usrc[len-1-i];
    udst[len-1-i] = tmp;
  }
}

variable_types:
src
void *

variable_types:
dst
void *

variable_types: len int

variable_types: i int

variable_types:
tmp
unsigned char

variable_types:
usrc
unsigned char *

variable_types:
udst
unsigned char *