decompiled_code:
__int64 __fastcall graph_pathlength(__int64 a1, int a2, int a3, __int64 a4)
{
__int64 v5; // rdx
__int64 v6; // rdx
int v7; // [rsp+Ch] [rbp-9Ch] BYREF
int v8[2]; // [rsp+10h] [rbp-98h] BYREF
unsigned int v9; // [rsp+18h] [rbp-90h]
char v10[40]; // [rsp+20h] [rbp-88h] BYREF
char v11[40]; // [rsp+48h] [rbp-60h] BYREF
char v12[40]; // [rsp+70h] [rbp-38h] BYREF
__int64 v13; // [rsp+98h] [rbp-10h]

v7 = a2;
v8[0] = a2;
v8[1] = a3;
v9 = 0;
v13 = a4;
if ( (unsigned __int8)array_create(v10, 4LL, 50LL) )
return 0LL;
if ( (unsigned __int8)array_create(v11, 4LL, 50LL) )
return 0LL;
if ( (unsigned __int8)array_create(v12, 4LL, 10LL) )
return 0LL;
array_append(v12, 0LL);
if ( (unsigned __int8)bfs(a1, &v7, 1LL, 0LL, v8) )
return 0LL;
array_free(v10, &v7, bfs_cb);
array_free(v11, &v7, v5);
array_free(v12, &v7, v6);
return v9;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3, __int64 a4)
{
__int64 v5; // rdx
__int64 v6; // rdx
int v7; // [rsp+Ch] [rbp-9Ch] BYREF
int v8[2]; // [rsp+10h] [rbp-98h] BYREF
unsigned int v9; // [rsp+18h] [rbp-90h]
char v10[40]; // [rsp+20h] [rbp-88h] BYREF
char v11[40]; // [rsp+48h] [rbp-60h] BYREF
char v12[40]; // [rsp+70h] [rbp-38h] BYREF
__int64 v13; // [rsp+98h] [rbp-10h]

v7 = a2;
v8[0] = a2;
v8[1] = a3;
v9 = 0;
v13 = a4;
if ( (unsigned __int8)array_create(v10, 4LL, 50LL) )
return 0LL;
if ( (unsigned __int8)array_create(v11, 4LL, 50LL) )
return 0LL;
if ( (unsigned __int8)array_create(v12, 4LL, 10LL) )
return 0LL;
array_append(v12, 0LL);
if ( (unsigned __int8)bfs(a1, &v7, 1LL, 0LL, v8) )
return 0LL;
array_free(v10, &v7, bfs_cb);
array_free(v11, &v7, v5);
array_free(v12, &v7, v6);
return v9;
}

original_code:
uint32_t graph_pathlength(
  graph_t *g, uint32_t u, uint32_t v, array_t *path) {
  ctx_t context;
  context.src = u;
  context.dest = v;
  context.pathlength = 0;
  context.path = path;
  if (array_create(&(context.nodes), sizeof(uint32_t), 50)) goto fail;
  if (array_create(&(context.parents), sizeof(uint32_t), 50)) goto fail;
  if (array_create(&(context.offsets), sizeof(uint32_t), 10)) goto fail;
  array_append(&(context.offsets), 0);
  if (bfs(g, &u, 1, ((void *)0), &context, &context, _bfs_cb, _expand_cb))
    goto fail;
  array_free(&(context.nodes));
  array_free(&(context.parents));
  array_free(&(context.offsets));
  return context.pathlength;
fail:
  return 0;
}

canonical_original_code:
unsigned int graph_pathlength(struct _graph *g, unsigned int u, unsigned int v, struct _array *path) {
  struct _ctx context;
  context.src = u;
  context.dest = v;
  context.pathlength = 0;
  context.path = path;
  if (array_create(&(context.nodes), sizeof(unsigned int), 50)) goto fail;
  if (array_create(&(context.parents), sizeof(unsigned int), 50)) goto fail;
  if (array_create(&(context.offsets), sizeof(unsigned int), 10)) goto fail;
  array_append(&(context.offsets), 0);
  if (bfs(g, &u, 1, ((void *)0), &context, &context, _bfs_cb, _expand_cb))
    goto fail;
  array_free(&(context.nodes));
  array_free(&(context.parents));
  array_free(&(context.offsets));
  return context.pathlength;
fail:
  return 0;
}

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

variable_types:
u
unsigned int

variable_types:
v
unsigned int

variable_types:
path
struct _array *

variable_types: struct _ctx { unsigned int src; unsigned int dest; unsigned int pathlength; 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); } nodes; struct _array parents; struct _array offsets; struct _array *path; }

return_type: unsigned int

user_defined_types: struct _ctx { unsigned int src; unsigned int dest; unsigned int pathlength; struct _array nodes; struct _array parents; struct _array offsets; struct _array *path; }


repo: pauldmccarthy/ccnet

decompiled_code:
__int64 __fastcall stats_num_components(__int64 a1, unsigned int a2, __int64 a3, void *a4)
{
size_t v6; // rbp
void *v7; // rax
_BYTE *v8; // r8
int v9; // ecx
__int64 v10; // rbx
size_t v11; // rbx
__int64 v12; // r8
__int64 v13; // rdx
char *v14; // r8
__int64 result; // rax
__int64 v16; // r8
int v17; // [rsp+8h] [rbp-70h]
int v18; // [rsp+18h] [rbp-60h] BYREF
int v19; // [rsp+1Ch] [rbp-5Ch] BYREF
void *ptr; // [rsp+20h] [rbp-58h] BYREF
void *src; // [rsp+28h] [rbp-50h]
__int64 v22; // [rsp+30h] [rbp-48h] BYREF

ptr = 0LL;
src = 0LL;
v22 = 0LL;
v6 = (unsigned int)graph_num_nodes();
if ( a3 )
array_clear(a3);
ptr = calloc(v6, 1uLL);
if ( !ptr )
goto LABEL_22;
v7 = calloc(v6, 4uLL);
v8 = ptr;
src = v7;
if ( !v7 )
goto LABEL_21;
v9 = v22;
if ( !v6 )
{
v19 = v22;
stats_cache_add(a1, 5LL, 0LL, 4LL, ptr);
stats_cache_add(a1, 20LL, 2LL, 4LL, v16);
stats_cache_update(a1, 5LL, 0LL, -1LL, &v19);
LABEL_18:
free(ptr);
free(src);
return (unsigned int)v22;
}
v10 = 0LL;
while ( 1 )
{
if ( v8[v10] )
goto LABEL_13;
HIDWORD(v22) = 1;
*((_DWORD *)src + v10) = v9;
v18 = v10;
v8[v10] = 1;
if ( (unsigned __int8)bfs(a1, &v18, 1LL, 0LL, &ptr, 0LL, bfs_cb, 0LL) )
break;
v9 = v22;
if ( HIDWORD(v22) >= a2 )
{
v9 = v22 + 1;
LODWORD(v22) = v22 + 1;
if ( a3 )
{
array_append(a3, (char *)&v22 + 4);
v9 = v22;
}
}
LABEL_13:
if ( v6 == ++v10 )
{
if ( a4 )
{
v17 = v9;
memcpy(a4, src, 4 * v6);
v9 = v17;
}
v19 = v9;
v11 = 0LL;
stats_cache_add(a1, 5LL, 0LL, 4LL, v8);
stats_cache_add(a1, 20LL, 2LL, 4LL, v12);
stats_cache_update(a1, 5LL, 0LL, -1LL, &v19);
do
{
v13 = (unsigned int)v11;
v14 = (char *)src + 4 * v11++;
stats_cache_update(a1, 20LL, v13, -1LL, v14);
}
while ( v6 > v11 );
goto LABEL_18;
}
v8 = ptr;
}
v8 = ptr;
if ( !ptr )
goto LABEL_22;
LABEL_21:
free(v8);
LABEL_22:
result = 0LL;
if ( src )
{
free(src);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, __int64 a3, void *a4)
{
size_t v6; // rbp
void *v7; // rax
_BYTE *v8; // r8
int v9; // ecx
__int64 v10; // rbx
size_t v11; // rbx
__int64 v12; // r8
__int64 v13; // rdx
char *v14; // r8
__int64 result; // rax
__int64 v16; // r8
int v17; // [rsp+8h] [rbp-70h]
int v18; // [rsp+18h] [rbp-60h] BYREF
int v19; // [rsp+1Ch] [rbp-5Ch] BYREF
void *ptr; // [rsp+20h] [rbp-58h] BYREF
void *src; // [rsp+28h] [rbp-50h]
__int64 v22; // [rsp+30h] [rbp-48h] BYREF

ptr = 0LL;
src = 0LL;
v22 = 0LL;
v6 = (unsigned int)graph_num_nodes();
if ( a3 )
array_clear(a3);
ptr = calloc(v6, 1uLL);
if ( !ptr )
goto LABEL_22;
v7 = calloc(v6, 4uLL);
v8 = ptr;
src = v7;
if ( !v7 )
goto LABEL_21;
v9 = v22;
if ( !v6 )
{
v19 = v22;
stats_cache_add(a1, 5LL, 0LL, 4LL, ptr);
stats_cache_add(a1, 20LL, 2LL, 4LL, v16);
stats_cache_update(a1, 5LL, 0LL, -1LL, &v19);
LABEL_18:
free(ptr);
free(src);
return (unsigned int)v22;
}
v10 = 0LL;
while ( 1 )
{
if ( v8[v10] )
goto LABEL_13;
HIDWORD(v22) = 1;
*((_DWORD *)src + v10) = v9;
v18 = v10;
v8[v10] = 1;
if ( (unsigned __int8)bfs(a1, &v18, 1LL, 0LL, &ptr, 0LL, bfs_cb, 0LL) )
break;
v9 = v22;
if ( HIDWORD(v22) >= a2 )
{
v9 = v22 + 1;
LODWORD(v22) = v22 + 1;
if ( a3 )
{
array_append(a3, (char *)&v22 + 4);
v9 = v22;
}
}
LABEL_13:
if ( v6 == ++v10 )
{
if ( a4 )
{
v17 = v9;
memcpy(a4, src, 4 * v6);
v9 = v17;
}
v19 = v9;
v11 = 0LL;
stats_cache_add(a1, 5LL, 0LL, 4LL, v8);
stats_cache_add(a1, 20LL, 2LL, 4LL, v12);
stats_cache_update(a1, 5LL, 0LL, -1LL, &v19);
do
{
v13 = (unsigned int)v11;
v14 = (char *)src + 4 * v11++;
stats_cache_update(a1, 20LL, v13, -1LL, v14);
}
while ( v6 > v11 );
goto LABEL_18;
}
v8 = ptr;
}
v8 = ptr;
if ( !ptr )
goto LABEL_22;
LABEL_21:
free(v8);
LABEL_22:
result = 0LL;
if ( src )
{
free(src);
result = 0LL;
}
return result;
}

original_code:
uint32_t stats_num_components(
  graph_t *g, uint32_t sz, array_t *sizes, uint32_t *cmpnums) {
  uint64_t i;
  uint32_t root;
  uint32_t numnodes;
  uint32_t cmpnum;
  ctx_t ctx;
  ctx.visited = ((void *)0);
  ctx.component = ((void *)0);
  ctx.cmpnum = 0;
  ctx.size = 0;
  numnodes = graph_num_nodes(g);
  if (sizes != ((void *)0)) array_clear(sizes);
  ctx.visited = calloc(numnodes, sizeof(uint8_t));
  if (ctx.visited == ((void *)0)) goto fail;
  ctx.component = calloc(numnodes, sizeof(uint32_t));
  if (ctx.component == ((void *)0)) goto fail;
  for (i = 0; i < numnodes; i++) {
    if (ctx.visited[i]) continue;
    ctx.size = 1;
    ctx.component[i] = ctx.cmpnum;
    root = i;
    ctx.visited[i] = 1;
    if (bfs(g, &root, 1, ((void *)0), &ctx, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
    if (ctx.size < sz) continue;
    ctx.cmpnum++;
    if (sizes != ((void *)0)) array_append(sizes, &(ctx.size));
  }
  if (cmpnums != ((void *)0))
    memcpy(cmpnums, ctx.component, numnodes*sizeof(uint32_t));
  cmpnum = ctx.cmpnum;
  stats_cache_add(g,
                  STATS_CACHE_NUM_COMPONENTS,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(uint32_t));
  stats_cache_add(g,
                  STATS_CACHE_NODE_COMPONENT,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(uint32_t));
  stats_cache_update(g, STATS_CACHE_NUM_COMPONENTS, 0, -1, &cmpnum);
  for (i = 0; i < numnodes; i++){
    stats_cache_update(g, STATS_CACHE_NODE_COMPONENT, i, -1, ctx.component+i);
  }
  free(ctx.visited);
  free(ctx.component);
  return ctx.cmpnum;
fail:
  if (ctx.visited != ((void *)0)) free(ctx.visited);
  if (ctx.component != ((void *)0)) free(ctx.component);
  return 0;
}

canonical_original_code:
unsigned int stats_num_components(struct _graph *g, unsigned int sz, struct _array *sizes, unsigned int *cmpnums) {
  unsigned long i;
  unsigned int root;
  unsigned int numnodes;
  unsigned int cmpnum;
  struct _ctx ctx;
  ctx.visited = ((void *)0);
  ctx.component = ((void *)0);
  ctx.cmpnum = 0;
  ctx.size = 0;
  numnodes = graph_num_nodes(g);
  if (sizes != ((void *)0)) array_clear(sizes);
  ctx.visited = calloc(numnodes, sizeof(unsigned char));
  if (ctx.visited == ((void *)0)) goto fail;
  ctx.component = calloc(numnodes, sizeof(unsigned int));
  if (ctx.component == ((void *)0)) goto fail;
  for (i = 0; i < numnodes; i++) {
    if (ctx.visited[i]) continue;
    ctx.size = 1;
    ctx.component[i] = ctx.cmpnum;
    root = i;
    ctx.visited[i] = 1;
    if (bfs(g, &root, 1, ((void *)0), &ctx, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
    if (ctx.size < sz) continue;
    ctx.cmpnum++;
    if (sizes != ((void *)0)) array_append(sizes, &(ctx.size));
  }
  if (cmpnums != ((void *)0))
    memcpy(cmpnums, ctx.component, numnodes*sizeof(unsigned int));
  cmpnum = ctx.cmpnum;
  stats_cache_add(g,
                  STATS_CACHE_NUM_COMPONENTS,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(unsigned int));
  stats_cache_add(g,
                  STATS_CACHE_NODE_COMPONENT,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(unsigned int));
  stats_cache_update(g, STATS_CACHE_NUM_COMPONENTS, 0, -1, &cmpnum);
  for (i = 0; i < numnodes; i++){
    stats_cache_update(g, STATS_CACHE_NODE_COMPONENT, i, -1, ctx.component+i);
  }
  free(ctx.visited);
  free(ctx.component);
  return ctx.cmpnum;
fail:
  if (ctx.visited != ((void *)0)) free(ctx.visited);
  if (ctx.component != ((void *)0)) free(ctx.component);
  return 0;
}

variable_types:
sz
unsigned int

variable_types:
sizes
struct _array *

variable_types:
cmpnums
unsigned int *

variable_types:
i
unsigned long

variable_types:
root
unsigned int

variable_types:
numnodes
unsigned int

variable_types:
cmpnum
unsigned int

variable_types: struct _ctx { unsigned char *visited; unsigned int *component; unsigned int cmpnum; unsigned int size; }

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 _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:
double __fastcall stats_component_span(__int64 a1, unsigned int a2)
{
unsigned __int64 v3; // r12
unsigned __int64 v4; // r14
bool i; // zf
unsigned __int64 v6; // rbx
double v7; // [rsp+8h] [rbp-70h]
unsigned int v8; // [rsp+18h] [rbp-60h] BYREF
unsigned int v9; // [rsp+1Ch] [rbp-5Ch] BYREF
char v10[4]; // [rsp+20h] [rbp-58h] BYREF
unsigned int v11; // [rsp+24h] [rbp-54h]
__int64 v12; // [rsp+30h] [rbp-48h]

v12 = 0LL;
if ( !(unsigned __int8)array_create(v10, 4LL, 100LL) && !(unsigned __int8)graph_get_component(a1, a2, v10) )
{
v3 = v11;
if ( v11 )
{
v4 = 0LL;
v7 = *(double *)&LC0;
do
{
for ( i = ++v4 == v3; v4 < v3; i = v4 == v3 )
{
v6 = v4;
do
{
array_get(v10, (unsigned int)(v4 - 1), &v8);
array_get(v10, (unsigned int)v6++, &v9);
v7 = fmax(stats_edge_distance(a1, v8, v9), v7);
}
while ( v6 < v3 );
++v4;
}
}
while ( !i );
}
else
{
v7 = *(double *)&LC0;
}
goto LABEL_3;
}
v7 = *(double *)&LC0;
if ( v12 )
LABEL_3:
array_free(v10);
return v7;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, unsigned int a2)
{
unsigned __int64 v3; // r12
unsigned __int64 v4; // r14
bool i; // zf
unsigned __int64 v6; // rbx
double v7; // [rsp+8h] [rbp-70h]
unsigned int v8; // [rsp+18h] [rbp-60h] BYREF
unsigned int v9; // [rsp+1Ch] [rbp-5Ch] BYREF
char v10[4]; // [rsp+20h] [rbp-58h] BYREF
unsigned int v11; // [rsp+24h] [rbp-54h]
__int64 v12; // [rsp+30h] [rbp-48h]

v12 = 0LL;
if ( !(unsigned __int8)array_create(v10, 4LL, 100LL) && !(unsigned __int8)graph_get_component(a1, a2, v10) )
{
v3 = v11;
if ( v11 )
{
v4 = 0LL;
v7 = *(double *)&LC0;
do
{
for ( i = ++v4 == v3; v4 < v3; i = v4 == v3 )
{
v6 = v4;
do
{
array_get(v10, (unsigned int)(v4 - 1), &v8);
array_get(v10, (unsigned int)v6++, &v9);
v7 = fmax(stats_edge_distance(a1, v8, v9), v7);
}
while ( v6 < v3 );
++v4;
}
}
while ( !i );
}
else
{
v7 = *(double *)&LC0;
}
goto LABEL_3;
}
v7 = *(double *)&LC0;
if ( v12 )
LABEL_3:
array_free(v10);
return v7;
}

original_code:
double stats_component_span(graph_t *g, uint32_t cmp) {
  uint64_t i;
  uint64_t j;
  uint32_t ni;
  uint32_t nj;
  uint32_t cmpsz;
  double dist;
  double maxdist;
  array_t nodes;
  nodes.data = ((void *)0);
  maxdist = -1.0;
  if (array_create(&nodes, sizeof(uint32_t), 100)) goto fail;
  if (graph_get_component(g, cmp, &nodes)) goto fail;
  cmpsz = nodes.size;
  for (i = 0; i < cmpsz; i++) {
    for (j = i+1; j < cmpsz; j++) {
      array_get(&nodes, i, &ni);
      array_get(&nodes, j, &nj);
      dist = stats_edge_distance(g, ni, nj);
      if (dist > maxdist) maxdist = dist;
    }
  }
  array_free(&nodes);
  return maxdist;
fail:
  if (nodes.data != ((void *)0)) array_free(&nodes);
  return -1.0;
}

canonical_original_code:
double stats_component_span(struct _graph *g, unsigned int cmp) {
  unsigned long i;
  unsigned long j;
  unsigned int ni;
  unsigned int nj;
  unsigned int cmpsz;
  double dist;
  double maxdist;
  struct _array nodes;
  nodes.data = ((void *)0);
  maxdist = -1.0;
  if (array_create(&nodes, sizeof(unsigned int), 100)) goto fail;
  if (graph_get_component(g, cmp, &nodes)) goto fail;
  cmpsz = nodes.size;
  for (i = 0; i < cmpsz; i++) {
    for (j = i+1; j < cmpsz; j++) {
      array_get(&nodes, i, &ni);
      array_get(&nodes, j, &nj);
      dist = stats_edge_distance(g, ni, nj);
      if (dist > maxdist) maxdist = dist;
    }
  }
  array_free(&nodes);
  return maxdist;
fail:
  if (nodes.data != ((void *)0)) array_free(&nodes);
  return -1.0;
}

variable_types:
cmp
unsigned int

variable_types:
j
unsigned long

variable_types:
ni
unsigned int

variable_types:
nj
unsigned int

variable_types:
cmpsz
unsigned int

variable_types: dist double

variable_types: maxdist double

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

return_type: double


decompiled_code:
__int64 __fastcall stats_largest_component(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r8
unsigned int v3; // [rsp+0h] [rbp-4Ch] BYREF
__int128 v4; // [rsp+4h] [rbp-48h] BYREF
__int128 v5; // [rsp+14h] [rbp-38h]
__int64 v6; // [rsp+24h] [rbp-28h]

v4 = 0LL;
v6 = 0LL;
v5 = 0LL;
if ( (unsigned __int8)array_create(&v4, 4LL, 10LL)
|| (array_set_cmps(&v4, &compare_u32, &compare_u32_insert),
stats_num_components(a1, 0, (__int64)&v4, 0LL),
array_sort(&v4),
(unsigned __int8)array_get(&v4, (unsigned int)(DWORD1(v4) - 1), &v3)) )
{
if ( (_QWORD)v5 )
array_free(&v4);
result = 0LL;
}
else
{
stats_cache_add(a1, 6LL, 0LL, 4LL, v2);
stats_cache_update(a1, 6LL, 0LL, -1LL, &v3);
array_free(&v4);
result = v3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
__int64 v2; // r8
unsigned int v3; // [rsp+0h] [rbp-4Ch] BYREF
__int128 v4; // [rsp+4h] [rbp-48h] BYREF
__int128 v5; // [rsp+14h] [rbp-38h]
__int64 v6; // [rsp+24h] [rbp-28h]

v4 = 0LL;
v6 = 0LL;
v5 = 0LL;
if ( (unsigned __int8)array_create(&v4, 4LL, 10LL)
|| (array_set_cmps(&v4, &compare_u32, &compare_u32_insert),
func1(a1, 0, (__int64)&v4, 0LL),
array_sort(&v4),
(unsigned __int8)array_get(&v4, (unsigned int)(DWORD1(v4) - 1), &v3)) )
{
if ( (_QWORD)v5 )
array_free(&v4);
result = 0LL;
}
else
{
stats_cache_add(a1, 6LL, 0LL, 4LL, v2);
stats_cache_update(a1, 6LL, 0LL, -1LL, &v3);
array_free(&v4);
result = v3;
}
return result;
}

original_code:
uint32_t stats_largest_component(graph_t *g) {
  uint32_t lcmp;
  array_t sizes;
  memset(&sizes, 0, sizeof(sizes));
  if (array_create(&sizes, sizeof(uint32_t), 10)) goto fail;
  array_set_cmps(&sizes, &compare_u32, &compare_u32_insert);
  stats_num_components(g, 0, &sizes, ((void *)0));
  array_sort(&sizes);
  if (array_get(&sizes, sizes.size - 1, &lcmp)) goto fail;
  stats_cache_add(g,
                  STATS_CACHE_LARGEST_COMPONENT,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(uint32_t));
  stats_cache_update(g, STATS_CACHE_LARGEST_COMPONENT, 0, -1, &lcmp);
  array_free(&sizes);
  return lcmp;
fail:
  if (sizes.data != ((void *)0)) array_free(&sizes);
  return 0;
}

canonical_original_code:
unsigned int stats_largest_component(struct _graph *g) {
  unsigned int lcmp;
  struct _array sizes;
  memset(&sizes, 0, sizeof(sizes));
  if (array_create(&sizes, sizeof(unsigned int), 10)) goto fail;
  array_set_cmps(&sizes, &compare_u32, &compare_u32_insert);
  stats_num_components(g, 0, &sizes, ((void *)0));
  array_sort(&sizes);
  if (array_get(&sizes, sizes.size - 1, &lcmp)) goto fail;
  stats_cache_add(g,
                  STATS_CACHE_LARGEST_COMPONENT,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(unsigned int));
  stats_cache_update(g, STATS_CACHE_LARGEST_COMPONENT, 0, -1, &lcmp);
  array_free(&sizes);
  return lcmp;
fail:
  if (sizes.data != ((void *)0)) array_free(&sizes);
  return 0;
}

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

variable_types:
lcmp
unsigned int


decompiled_code:
__int64 __fastcall analyze_open_volume(char *a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp
__int64 result; // rax
_QWORD *v5; // r8
__int64 v6; // rbx
void *v7; // rdi
void *ptr; // [rsp+Ah] [rbp-20h] BYREF

*(_OWORD *)a2 = 0LL;
*(_OWORD *)(a2 + 16) = 0LL;
ptr = 0LL;
v2 = list_files_constprop_0(a1, (void ***)&ptr);
v3 = v2;
if ( v2 <= 0 )
{
v5 = ptr;
if ( !ptr )
return 1LL;
if ( !v2 )
goto LABEL_11;
goto LABEL_7;
}
if ( v2 == 1 )
{
if ( !(unsigned __int8)4d_to_volume(*(char **)ptr, (unsigned __int16 *)a2) )
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}
LABEL_6:
v5 = ptr;
if ( !ptr )
return 1LL;
LABEL_7:
v6 = 0LL;
do
{
v7 = (void *)v5[v6];
if ( v7 )
{
free(v7);
v5 = ptr;
}
++v6;
}
while ( v3 > (unsigned int)v6 );
LABEL_11:
free(v5);
return 1LL;
}
result = 3d_to_volume((__int64)ptr, v2, (unsigned __int16 *)a2);
if ( (_BYTE)result )
goto LABEL_6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebp
__int64 result; // rax
_QWORD *v5; // r8
__int64 v6; // rbx
void *v7; // rdi
void *ptr; // [rsp+Ah] [rbp-20h] BYREF

*(_OWORD *)a2 = 0LL;
*(_OWORD *)(a2 + 16) = 0LL;
ptr = 0LL;
v2 = func3(a1, (void ***)&ptr);
v3 = v2;
if ( v2 <= 0 )
{
v5 = ptr;
if ( !ptr )
return 1LL;
if ( !v2 )
goto LABEL_11;
goto LABEL_7;
}
if ( v2 == 1 )
{
if ( !(unsigned __int8)4dfunc2(*(char **)ptr, (unsigned __int16 *)a2) )
{
free(*(void **)ptr);
free(ptr);
return 0LL;
}
LABEL_6:
v5 = ptr;
if ( !ptr )
return 1LL;
LABEL_7:
v6 = 0LL;
do
{
v7 = (void *)v5[v6];
if ( v7 )
{
free(v7);
v5 = ptr;
}
++v6;
}
while ( v3 > (unsigned int)v6 );
LABEL_11:
free(v5);
return 1LL;
}
result = 3dfunc2((__int64)ptr, v2, (unsigned __int16 *)a2);
if ( (_BYTE)result )
goto LABEL_6;
return result;
}

original_code:
uint8_t analyze_open_volume(char *path, analyze_volume_t *vol) {
  uint32_t i;
  char **files;
  int32_t nfiles;
  nfiles = 0;
  files = ((void *)0);
  memset(vol, 0, sizeof(analyze_volume_t));
  nfiles = _list_files(path, &files);
  if (nfiles <= 0) goto fail;
  if (nfiles == 1) {
    if (_4d_to_volume(files[0], vol)) goto fail;
    free(files[0]);
    free(files);
  }
  else {
    if (_3d_to_volume(files, nfiles, vol)) goto fail;
  }
  return 0;
fail:
  if (files != ((void *)0)) {
    for (i = 0; i < nfiles; i++) {
      if (files[i] != ((void *)0))
        free(files[i]);
    }
    free(files);
  }
  return 1;
}

canonical_original_code:
unsigned char analyze_open_volume(char *path, struct __analyze_volume *vol) {
  unsigned int i;
  char **files;
  int nfiles;
  nfiles = 0;
  files = ((void *)0);
  memset(vol, 0, sizeof(analyze_volume_t));
  nfiles = _list_files(path, &files);
  if (nfiles <= 0) goto fail;
  if (nfiles == 1) {
    if (_4d_to_volume(files[0], vol)) goto fail;
    free(files[0]);
    free(files);
  }
  else {
    if (_3d_to_volume(files, nfiles, vol)) goto fail;
  }
  return 0;
fail:
  if (files != ((void *)0)) {
    for (i = 0; i < nfiles; i++) {
      if (files[i] != ((void *)0))
        free(files[i]);
    }
    free(files);
  }
  return 1;
}

variable_types:
path
char *

variable_types: struct __analyze_volume { unsigned short nimgs; char **files; 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; } *hdrs; unsigned char **imgs; } *

variable_types:
i
unsigned int

variable_types:
files
char **

variable_types: nfiles int

return_type: unsigned char

user_defined_types: struct __analyze_volume { unsigned short nimgs; char **files; struct dsr *hdrs; unsigned char **imgs; }

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


original_code:
void analyze_free_volume(analyze_volume_t *vol) {
  uint32_t i;
  if (vol == ((void *)0)) return;
  if (vol->hdrs == ((void *)0)) return;
  if (vol->imgs == ((void *)0)) return;
  if (vol->files == ((void *)0)) return;
  if (vol->nimgs == 0) return;
  for (i = 0; i < vol->nimgs; i++) {
    free(vol->imgs[i]);
    free(vol->files[i]);
  }
  free(vol->hdrs);
  free(vol->imgs);
  free(vol->files);
}

canonical_original_code:
void analyze_free_volume(struct __analyze_volume *vol) {
  unsigned int i;
  if (vol == ((void *)0)) return;
  if (vol->hdrs == ((void *)0)) return;
  if (vol->imgs == ((void *)0)) return;
  if (vol->files == ((void *)0)) return;
  if (vol->nimgs == 0) return;
  for (i = 0; i < vol->nimgs; i++) {
    free(vol->imgs[i]);
    free(vol->files[i]);
  }
  free(vol->hdrs);
  free(vol->imgs);
  free(vol->files);
}

return_type: void

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


original_code:
uint8_t analyze_read_timeseries(
  analyze_volume_t *vol,
  uint32_t x,
  uint32_t y,
  uint32_t z,
  double *timeseries) {
  uint64_t i;
  uint32_t idx[4];
  idx[0] = x;
  idx[1] = y;
  idx[2] = z;
  idx[3] = 0;
  for (i = 0; i < vol->nimgs; i++) {
    timeseries[i] = analyze_read_val(&(vol->hdrs[i]), vol->imgs[i], idx);
  }
  return 0;
}

canonical_original_code:
unsigned char analyze_read_timeseries(struct __analyze_volume *vol, unsigned int x, unsigned int y, unsigned int z, double *timeseries) {
  unsigned long i;
  unsigned int idx[4];
  idx[0] = x;
  idx[1] = y;
  idx[2] = z;
  idx[3] = 0;
  for (i = 0; i < vol->nimgs; i++) {
    timeseries[i] = analyze_read_val(&(vol->hdrs[i]), vol->imgs[i], idx);
  }
  return 0;
}

variable_types:
x
unsigned int

variable_types:
y
unsigned int

variable_types:
z
unsigned int

variable_types:
timeseries
double *

variable_types:
i
unsigned long

variable_types:
idx
unsigned int [4]


decompiled_code:
__int64 __fastcall analyze_read_timeseries_by_idx(__int64 a1, __int64 a2, __int64 a3)
{
int v5[14]; // [rsp+0h] [rbp-38h] BYREF

analyze_get_indices(*(_QWORD *)(a1 + 16), a2, v5);
return analyze_read_timeseries((unsigned __int16 *)a1, v5[0], v5[1], v5[2], a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
int v5[14]; // [rsp+0h] [rbp-38h] BYREF

analyze_get_indices(*(_QWORD *)(a1 + 16), a2, v5);
return func6((unsigned __int16 *)a1, v5[0], v5[1], v5[2], a3);
}

original_code:
uint8_t analyze_read_timeseries_by_idx(
  analyze_volume_t *vol, uint32_t idx, double *timeseries) {
  uint32_t dims[5];
  analyze_get_indices(vol->hdrs, idx, dims);
  return analyze_read_timeseries(vol, dims[0], dims[1], dims[2], timeseries);
}

canonical_original_code:
unsigned char analyze_read_timeseries_by_idx(struct __analyze_volume *vol, unsigned int idx, double *timeseries) {
  unsigned int dims[5];
  analyze_get_indices(vol->hdrs, idx, dims);
  return analyze_read_timeseries(vol, dims[0], dims[1], dims[2], timeseries);
}

variable_types:
idx
unsigned int

variable_types:
dims
unsigned int [5]


decompiled_code:
double __fastcall stats_num_intra_edges(__int64 a1, double *a2)
{
unsigned int v2; // eax
unsigned __int64 v3; // rbp
__int64 v4; // r14
__int64 v5; // r12
_DWORD *v6; // r13
__int64 v7; // rbx
unsigned __int64 v8; // rsi
double result; // xmm0_8
__int64 v10; // [rsp+0h] [rbp-58h]
double v12; // [rsp+10h] [rbp-48h] BYREF
double v13[8]; // [rsp+18h] [rbp-40h] BYREF

if ( (unsigned int)graph_num_labelvals() <= 1 )
{
if ( a2 )
*a2 = 0.0;
result = (double)(int)graph_num_edges(a1);
}
else
{
v12 = 0.0;
v13[0] = 0.0;
v2 = graph_num_nodes(a1);
v10 = v2;
if ( v2 )
{
v3 = 0LL;
while ( 1 )
{
v4 = (unsigned int)graph_num_neighbours(a1, (unsigned int)v3);
v5 = graph_get_neighbours(a1, (unsigned int)v3);
v6 = (_DWORD *)graph_get_nodelabel(a1, (unsigned int)v3);
if ( v4 )
break;
LABEL_11:
if ( ++v3 == v10 )
goto LABEL_12;
}
v7 = 0LL;
while ( 1 )
{
v8 = *(unsigned int *)(v5 + 4 * v7);
if ( v8 < v3 )
goto LABEL_7;
if ( *v6 == *(_DWORD *)graph_get_nodelabel(a1, v8) )
{
++v7;
v12 = v12 + 1.0;
if ( v7 == v4 )
goto LABEL_11;
}
else
{
v13[0] = v13[0] + 1.0;
LABEL_7:
if ( ++v7 == v4 )
goto LABEL_11;
}
}
}
LABEL_12:
stats_cache_add(a1, 11LL, 0LL, 8LL);
stats_cache_add(a1, 12LL, 0LL, 8LL);
stats_cache_update(a1, 11LL, 0LL, -1LL, &v12);
stats_cache_update(a1, 12LL, 0LL, -1LL, v13);
if ( a2 )
*a2 = v13[0];
result = v12;
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, double *a2)
{
unsigned int v2; // eax
unsigned __int64 v3; // rbp
__int64 v4; // r14
__int64 v5; // r12
_DWORD *v6; // r13
__int64 v7; // rbx
unsigned __int64 v8; // rsi
double result; // xmm0_8
__int64 v10; // [rsp+0h] [rbp-58h]
double v12; // [rsp+10h] [rbp-48h] BYREF
double v13[8]; // [rsp+18h] [rbp-40h] BYREF

if ( (unsigned int)graph_num_labelvals() <= 1 )
{
if ( a2 )
*a2 = 0.0;
result = (double)(int)graph_num_edges(a1);
}
else
{
v12 = 0.0;
v13[0] = 0.0;
v2 = graph_num_nodes(a1);
v10 = v2;
if ( v2 )
{
v3 = 0LL;
while ( 1 )
{
v4 = (unsigned int)graph_num_neighbours(a1, (unsigned int)v3);
v5 = graph_get_neighbours(a1, (unsigned int)v3);
v6 = (_DWORD *)graph_get_nodelabel(a1, (unsigned int)v3);
if ( v4 )
break;
LABEL_11:
if ( ++v3 == v10 )
goto LABEL_12;
}
v7 = 0LL;
while ( 1 )
{
v8 = *(unsigned int *)(v5 + 4 * v7);
if ( v8 < v3 )
goto LABEL_7;
if ( *v6 == *(_DWORD *)graph_get_nodelabel(a1, v8) )
{
++v7;
v12 = v12 + 1.0;
if ( v7 == v4 )
goto LABEL_11;
}
else
{
v13[0] = v13[0] + 1.0;
LABEL_7:
if ( ++v7 == v4 )
goto LABEL_11;
}
}
}
LABEL_12:
stats_cache_add(a1, 11LL, 0LL, 8LL);
stats_cache_add(a1, 12LL, 0LL, 8LL);
stats_cache_update(a1, 11LL, 0LL, -1LL, &v12);
stats_cache_update(a1, 12LL, 0LL, -1LL, v13);
if ( a2 )
*a2 = v13[0];
result = v12;
}
return result;
}

original_code:
double stats_num_intra_edges(graph_t *g, double *inter_out) {
  uint64_t i;
  uint64_t j;
  uint32_t nnodes;
  uint32_t nnbrs;
  uint32_t *nbrs;
  graph_label_t *ilbl;
  graph_label_t *jlbl;
  double intra;
  double inter;
  if (graph_num_labelvals(g) <= 1) {
    if (inter_out != ((void *)0)) *inter_out = 0;
    return graph_num_edges(g);
  }
  intra = 0;
  inter = 0;
  nnodes = graph_num_nodes(g);
  for (i = 0; i < nnodes; i++) {
    nnbrs = graph_num_neighbours(g, i);
    nbrs = graph_get_neighbours(g, i);
    ilbl = graph_get_nodelabel( g, i);
    for (j = 0; j < nnbrs; j++) {
      if (i > nbrs[j]) continue;
      jlbl = graph_get_nodelabel(g, nbrs[j]);
      if (ilbl->labelval == jlbl->labelval) intra ++;
      else inter ++;
    }
  }
  stats_cache_add(g,
                  STATS_CACHE_INTRA_EDGES,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_add(g,
                  STATS_CACHE_INTER_EDGES,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_INTRA_EDGES, 0, -1, &intra);
  stats_cache_update(g, STATS_CACHE_INTER_EDGES, 0, -1, &inter);
  if (inter_out != ((void *)0)) *inter_out = inter;
  return intra;
}

canonical_original_code:
double stats_num_intra_edges(struct _graph *g, double *inter_out) {
  unsigned long i;
  unsigned long j;
  unsigned int nnodes;
  unsigned int nnbrs;
  unsigned int *nbrs;
  struct _graph_label *ilbl;
  struct _graph_label *jlbl;
  double intra;
  double inter;
  if (graph_num_labelvals(g) <= 1) {
    if (inter_out != ((void *)0)) *inter_out = 0;
    return graph_num_edges(g);
  }
  intra = 0;
  inter = 0;
  nnodes = graph_num_nodes(g);
  for (i = 0; i < nnodes; i++) {
    nnbrs = graph_num_neighbours(g, i);
    nbrs = graph_get_neighbours(g, i);
    ilbl = graph_get_nodelabel( g, i);
    for (j = 0; j < nnbrs; j++) {
      if (i > nbrs[j]) continue;
      jlbl = graph_get_nodelabel(g, nbrs[j]);
      if (ilbl->labelval == jlbl->labelval) intra ++;
      else inter ++;
    }
  }
  stats_cache_add(g,
                  STATS_CACHE_INTRA_EDGES,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_add(g,
                  STATS_CACHE_INTER_EDGES,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_INTRA_EDGES, 0, -1, &intra);
  stats_cache_update(g, STATS_CACHE_INTER_EDGES, 0, -1, &inter);
  if (inter_out != ((void *)0)) *inter_out = inter;
  return intra;
}

variable_types:
j
unsigned long

variable_types:
nnodes
unsigned int

variable_types:
nnbrs
unsigned int

variable_types:
nbrs
unsigned int *

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

variable_types: intra double

variable_types: inter double


decompiled_code:
void __fastcall stats_edge_distance(__int64 a1, __int64 a2, unsigned int a3)
{
float *v4; // rbx
float *v5; // rax
float v6; // xmm1_4

v4 = (float *)graph_get_nodelabel(a1, a2);
v5 = (float *)graph_get_nodelabel(a1, a3);
if ( v4 )
{
if ( v5 )
{
v6 = v4[3] - v5[3];
pow(
(float)(v4[1] - v5[1]) * (float)(v4[1] - v5[1]) + (float)(v4[2] - v5[2]) * (float)(v4[2] - v5[2]) + v6 * v6,
0.5);
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, __int64 a2, unsigned int a3)
{
float *v4; // rbx
float *v5; // rax
float v6; // xmm1_4

v4 = (float *)graph_get_nodelabel(a1, a2);
v5 = (float *)graph_get_nodelabel(a1, a3);
if ( v4 )
{
if ( v5 )
{
v6 = v4[3] - v5[3];
pow(
(float)(v4[1] - v5[1]) * (float)(v4[1] - v5[1]) + (float)(v4[2] - v5[2]) * (float)(v4[2] - v5[2]) + v6 * v6,
0.5);
}
}
}

original_code:
double stats_edge_distance(graph_t *g, uint32_t u, uint32_t v) {
  double dist;
  double dx;
  double dy;
  double dz;
  graph_label_t *lu;
  graph_label_t *lv;
  lu = graph_get_nodelabel(g, u);
  lv = graph_get_nodelabel(g, v);
  if (lu == ((void *)0)) return -1.0;
  if (lv == ((void *)0)) return -1.0;
  dx = lu->xval - lv->xval;
  dy = lu->yval - lv->yval;
  dz = lu->zval - lv->zval;
  dist = pow((dx*dx) + (dy*dy) + (dz*dz), 0.5);
  return dist;
}

canonical_original_code:
double stats_edge_distance(struct _graph *g, unsigned int u, unsigned int v) {
  double dist;
  double dx;
  double dy;
  double dz;
  struct _graph_label *lu;
  struct _graph_label *lv;
  lu = graph_get_nodelabel(g, u);
  lv = graph_get_nodelabel(g, v);
  if (lu == ((void *)0)) return -1.0;
  if (lv == ((void *)0)) return -1.0;
  dx = lu->xval - lv->xval;
  dy = lu->yval - lv->yval;
  dz = lu->zval - lv->zval;
  dist = pow((dx*dx) + (dy*dy) + (dz*dz), 0.5);
  return dist;
}

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:
u
unsigned int

variable_types:
v
unsigned int

variable_types: dist double

variable_types: dx double

variable_types: dy double

variable_types: dz double

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


decompiled_code:
double __fastcall stats_avg_edge_distance(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // r14
__int64 v6; // rbx
unsigned int v7; // edx
double v9[6]; // [rsp+8h] [rbp-30h] BYREF

v9[0] = 0.0;
v3 = (unsigned int)graph_num_neighbours(a1, a2);
v4 = graph_get_neighbours(a1, (unsigned int)a2);
if ( v3 )
{
v5 = v4;
v6 = 0LL;
do
{
v7 = *(_DWORD *)(v5 + 4 * v6++);
stats_edge_distance(a1, (unsigned int)a2, v7);
a3 = a3 + v9[0];
v9[0] = a3;
}
while ( v6 != v3 );
}
else
{
a3 = v9[0];
}
v9[0] = a3 / (double)(int)v3;
stats_cache_add(a1, 21LL, 2LL, 8LL);
stats_cache_update(a1, 21LL, (unsigned int)a2, -1LL, v9);
return v9[0];
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, __int64 a2, double a3)
{
__int64 v3; // r12
__int64 v4; // rax
__int64 v5; // r14
__int64 v6; // rbx
unsigned int v7; // edx
double v9[6]; // [rsp+8h] [rbp-30h] BYREF

v9[0] = 0.0;
v3 = (unsigned int)graph_num_neighbours(a1, a2);
v4 = graph_get_neighbours(a1, (unsigned int)a2);
if ( v3 )
{
v5 = v4;
v6 = 0LL;
do
{
v7 = *(_DWORD *)(v5 + 4 * v6++);
func1(a1, (unsigned int)a2, v7);
a3 = a3 + v9[0];
v9[0] = a3;
}
while ( v6 != v3 );
}
else
{
a3 = v9[0];
}
v9[0] = a3 / (double)(int)v3;
stats_cache_add(a1, 21LL, 2LL, 8LL);
stats_cache_update(a1, 21LL, (unsigned int)a2, -1LL, v9);
return v9[0];
}

original_code:
double stats_avg_edge_distance(graph_t *g, uint32_t u) {
  uint64_t i;
  uint32_t nnbrs;
  uint32_t *nbrs;
  double avg;
  avg = 0;
  nnbrs = graph_num_neighbours(g, u);
  nbrs = graph_get_neighbours(g, u);
  for (i = 0; i < nnbrs; i++) {
    avg += stats_edge_distance(g, u, nbrs[i]);
  }
  avg /= nnbrs;
  stats_cache_add(g,
                  STATS_CACHE_NODE_EDGEDIST,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_NODE_EDGEDIST, u, -1, &avg);
  return avg;
}

canonical_original_code:
double stats_avg_edge_distance(struct _graph *g, unsigned int u) {
  unsigned long i;
  unsigned int nnbrs;
  unsigned int *nbrs;
  double avg;
  avg = 0;
  nnbrs = graph_num_neighbours(g, u);
  nbrs = graph_get_neighbours(g, u);
  for (i = 0; i < nnbrs; i++) {
    avg += stats_edge_distance(g, u, nbrs[i]);
  }
  avg /= nnbrs;
  stats_cache_add(g,
                  STATS_CACHE_NODE_EDGEDIST,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_NODE_EDGEDIST, u, -1, &avg);
  return avg;
}

variable_types:
i
unsigned long

variable_types: avg double


decompiled_code:
bool __fastcall graph_add_event_listener(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax

v2 = id_counter;
*a2 = id_counter;
id_counter = v2 + 1;
return (unsigned __int8)array_append(a1 + 152) != 0;
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1, _QWORD *a2)
{
__int64 v2; // rax

v2 = id_counter;
*a2 = id_counter;
id_counter = v2 + 1;
return (unsigned __int8)array_append(a1 + 152) != 0;
}

original_code:
uint8_t graph_add_event_listener(graph_t *g, graph_event_listener_t *l) {
  l->id = _id_counter ++;
  if (array_append(&g->event_listeners, l)) return 1;
  return 0;
}

canonical_original_code:
unsigned char graph_add_event_listener(struct _graph *g, struct _graph_event_listener *l) {
  l->id = _id_counter ++;
  if (array_append(&g->event_listeners, l)) return 1;
  return 0;
}

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


decompiled_code:
__int64 __fastcall graph_remove_event_listener(__int64 a1, __int64 a2)
{
return array_remove_by_val(a1 + 152, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
return array_remove_by_val(a1 + 152, a2, 0LL);
}

original_code:
void graph_remove_event_listener(graph_t *g, graph_event_listener_t *l) {
  array_remove_by_val(&g->event_listeners, l, 0);
}

canonical_original_code:
void graph_remove_event_listener(struct _graph *g, struct _graph_event_listener *l) {
  array_remove_by_val(&g->event_listeners, l, 0);
}

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


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

if ( !a2 )
return fire_edge_added(a1, a3);
if ( a2 == 1 )
result = fire_edge_removed(a1, (unsigned int *)a3);
return result;
}

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

if ( !a2 )
return func0(a1, a3);
if ( a2 == 1 )
result = func1(a1, (unsigned int *)a3);
return result;
}

original_code:
void graph_event_fire(graph_t *g, graph_event_t type, void *ctx) {
  switch(type) {
    case GRAPH_EVENT_EDGE_ADDED: _fire_edge_added( g, ctx); break;
    case GRAPH_EVENT_EDGE_REMOVED: _fire_edge_removed(g, ctx); break;
  }
}

canonical_original_code:
void graph_event_fire(struct _graph *g, enum graph_event_t type, void *ctx) {
  switch(type) {
    case GRAPH_EVENT_EDGE_ADDED: _fire_edge_added( g, ctx); break;
    case GRAPH_EVENT_EDGE_REMOVED: _fire_edge_removed(g, ctx); break;
  }
}

variable_types: enum graph_event_t { GRAPH_EVENT_EDGE_ADDED=0, GRAPH_EVENT_EDGE_REMOVED=1 }

variable_types:
ctx
void *


decompiled_code:
_BOOL8 __fastcall graph_compare_event_listeners(_QWORD *a1, _QWORD *a2)
{
return *a1 != *a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(_QWORD *a1, _QWORD *a2)
{
return *a1 != *a2;
}

original_code:
int graph_compare_event_listeners(const void *a, const void *b) {
  graph_event_listener_t *gela;
  graph_event_listener_t *gelb;
  gela = (graph_event_listener_t *)a;
  gelb = (graph_event_listener_t *)b;
  if (gela->id == gelb->id) return 0;
  return 1;
}

canonical_original_code:
int graph_compare_event_listeners(void *a, void *b) {
  struct _graph_event_listener *gela;
  struct _graph_event_listener *gelb;
  gela = (struct _graph_event_listener *)a;
  gelb = (struct _graph_event_listener *)b;
  if (gela->id == gelb->id) return 0;
  return 1;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types: struct _graph_event_listener { unsigned long id; void *ctx; void (*edge_added)(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, 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); } *

return_type: int


decompiled_code:
__int64 __fastcall stats_cache_approx_clustering(__int64 a1, unsigned int a2)
{
__int64 result; // rax
double v3[4]; // [rsp+8h] [rbp-20h] BYREF

result = stats_cache_check(a1, 1LL, 0LL, -1LL, v3);
if ( (_BYTE)result != 1 )
result = stats_approx_clustering(a1, a2, v3[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
__int64 result; // rax
double v3[4]; // [rsp+8h] [rbp-20h] BYREF

result = stats_cache_check(a1, 1LL, 0LL, -1LL, v3);
if ( (_BYTE)result != 1 )
result = stats_approx_clustering(a1, a2, v3[0]);
return result;
}

original_code:
double stats_cache_approx_clustering(graph_t *g, uint32_t ntriples) {
  double clust;
  if (stats_cache_check(g, STATS_CACHE_APPROX_CLUSTERING, 0, -1, &clust) == 1)
    return clust;
  return stats_approx_clustering(g, ntriples);
}

canonical_original_code:
double stats_cache_approx_clustering(struct _graph *g, unsigned int ntriples) {
  double clust;
  if (stats_cache_check(g, STATS_CACHE_APPROX_CLUSTERING, 0, -1, &clust) == 1)
    return clust;
  return stats_approx_clustering(g, ntriples);
}

variable_types:
ntriples
unsigned int

variable_types: clust double


decompiled_code:
__int64 __fastcall stats_cache_graph_clustering(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 2LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_avg_clustering(a1, v2[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 2LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_avg_clustering(a1, v2[0]);
return result;
}

original_code:
double stats_cache_graph_clustering(graph_t *g) {
  double clust;
  if (stats_cache_check(g, STATS_CACHE_GRAPH_CLUSTERING, 0, -1, &clust) == 1)
    return clust;
  return stats_avg_clustering(g);
}

canonical_original_code:
double stats_cache_graph_clustering(struct _graph *g) {
  double clust;
  if (stats_cache_check(g, STATS_CACHE_GRAPH_CLUSTERING, 0, -1, &clust) == 1)
    return clust;
  return stats_avg_clustering(g);
}

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


decompiled_code:
__int64 __fastcall stats_cache_node_clustering(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned __int64 v4; // r13
char v5; // al
__int64 v6; // rbx
__int64 result; // rax
double v8; // xmm0_8

v4 = (unsigned int)graph_num_nodes();
v5 = stats_cache_check(a1, 15LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v5 == 1 )
return 0LL;
if ( v4 <= a2 )
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_clustering(a1, (unsigned int)v6);
++v6;
}
while ( v4 != v6 );
}
return 0LL;
}
v8 = stats_clustering(a1, (unsigned int)a2);
result = 0LL;
*a3 = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned __int64 v4; // r13
char v5; // al
__int64 v6; // rbx
__int64 result; // rax
double v8; // xmm0_8

v4 = (unsigned int)graph_num_nodes();
v5 = stats_cache_check(a1, 15LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v5 == 1 )
return 0LL;
if ( v4 <= a2 )
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_clustering(a1, (unsigned int)v6);
++v6;
}
while ( v4 != v6 );
}
return 0LL;
}
v8 = stats_clustering(a1, (unsigned int)a2);
result = 0LL;
*a3 = v8;
return result;
}

original_code:
uint8_t stats_cache_node_clustering(graph_t *g, int64_t n, double *data) {
  uint64_t i;
  uint32_t nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_CLUSTERING, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_clustering(g, i);
      }
    }
    else {
      *data = stats_clustering(g, n);
    }
  }
  return 0;
}

canonical_original_code:
unsigned char stats_cache_node_clustering(struct _graph *g, long n, double *data) {
  unsigned long i;
  unsigned int nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_CLUSTERING, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_clustering(g, i);
      }
    }
    else {
      *data = stats_clustering(g, n);
    }
  }
  return 0;
}

variable_types: n long

variable_types:
data
double *

variable_types:
nnodes
unsigned int


decompiled_code:
__int64 __fastcall stats_cache_graph_pathlength(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 3LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_avg_pathlength(a1, v2[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 3LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_avg_pathlength(a1, v2[0]);
return result;
}

original_code:
double stats_cache_graph_pathlength(graph_t *g) {
  double path;
  if (stats_cache_check(g, STATS_CACHE_GRAPH_PATHLENGTH, 0, -1, &path) == 1)
    return path;
  return stats_avg_pathlength(g);
}

canonical_original_code:
double stats_cache_graph_pathlength(struct _graph *g) {
  double path;
  if (stats_cache_check(g, STATS_CACHE_GRAPH_PATHLENGTH, 0, -1, &path) == 1)
    return path;
  return stats_avg_pathlength(g);
}

variable_types: path double


decompiled_code:
__int64 __fastcall stats_cache_node_pathlength(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned __int64 v4; // r13
char v5; // al
__int64 v6; // rbx
__int64 result; // rax
double v8; // xmm0_8

v4 = (unsigned int)graph_num_nodes();
v5 = stats_cache_check(a1, 16LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v5 == 1 )
return 0LL;
if ( v4 <= a2 )
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_pathlength(a1, (unsigned int)v6, 0LL);
++v6;
}
while ( v4 != v6 );
}
return 0LL;
}
v8 = stats_pathlength(a1, (unsigned int)a2, 0LL);
result = 0LL;
*a3 = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned __int64 v4; // r13
char v5; // al
__int64 v6; // rbx
__int64 result; // rax
double v8; // xmm0_8

v4 = (unsigned int)graph_num_nodes();
v5 = stats_cache_check(a1, 16LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v5 == 1 )
return 0LL;
if ( v4 <= a2 )
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_pathlength(a1, (unsigned int)v6, 0LL);
++v6;
}
while ( v4 != v6 );
}
return 0LL;
}
v8 = stats_pathlength(a1, (unsigned int)a2, 0LL);
result = 0LL;
*a3 = v8;
return result;
}

original_code:
uint8_t stats_cache_node_pathlength(graph_t *g, int64_t n, double *data) {
  uint64_t i;
  uint32_t nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_PATHLENGTH, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_pathlength(g, i, ((void *)0));
      }
    }
    else {
      *data = stats_pathlength(g, n, ((void *)0));
    }
  }
  return 0;
}

canonical_original_code:
unsigned char stats_cache_node_pathlength(struct _graph *g, long n, double *data) {
  unsigned long i;
  unsigned int nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_PATHLENGTH, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_pathlength(g, i, ((void *)0));
      }
    }
    else {
      *data = stats_pathlength(g, n, ((void *)0));
    }
  }
  return 0;
}


decompiled_code:
__int64 __fastcall stats_cache_pair_pathlength(__int64 a1, unsigned int a2, __int64 a3)
{
if ( (unsigned __int8)stats_cache_check(a1, 22LL, a2, -1LL, a3) != 1 )
stats_pathlength(a1, a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, unsigned int a2, __int64 a3)
{
if ( (unsigned __int8)stats_cache_check(a1, 22LL, a2, -1LL, a3) != 1 )
stats_pathlength(a1, a2, a3);
return 0LL;
}

original_code:
uint8_t stats_cache_pair_pathlength(graph_t *g, uint32_t n, double *paths) {
  if (stats_cache_check(g, STATS_CACHE_PAIR_PATHLENGTH, n, -1, paths) == 1)
    return 0;
  stats_pathlength(g, n, paths);
  return 0;
}

canonical_original_code:
unsigned char stats_cache_pair_pathlength(struct _graph *g, unsigned int n, double *paths) {
  if (stats_cache_check(g, STATS_CACHE_PAIR_PATHLENGTH, n, -1, paths) == 1)
    return 0;
  stats_pathlength(g, n, paths);
  return 0;
}

variable_types:
n
unsigned int

variable_types:
paths
double *


decompiled_code:
__int64 __fastcall stats_cache_assortativity(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 4LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_assortativity(a1, v2[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 4LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_assortativity(a1, v2[0]);
return result;
}

original_code:
double stats_cache_assortativity(graph_t *g) {
  double r;
  if (stats_cache_check(g, STATS_CACHE_ASSORTATIVITY, 0, -1, &r) == 1)
    return r;
  return stats_assortativity(g);
}

canonical_original_code:
double stats_cache_assortativity(struct _graph *g) {
  double r;
  if (stats_cache_check(g, STATS_CACHE_ASSORTATIVITY, 0, -1, &r) == 1)
    return r;
  return stats_assortativity(g);
}

variable_types: r double


decompiled_code:
double __fastcall stats_cache_num_components(__int64 a1)
{
char v1; // al
double result; // xmm0_8
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = stats_cache_check(a1, 5LL, 0LL, -1LL, v3);
result = v3[0];
if ( v1 != 1 )
result = (double)(int)stats_num_components(a1, 1LL, 0LL, 0LL, v3[0]);
return result;
}

canonical_decompiled_code:
double __fastcall func7(__int64 a1)
{
char v1; // al
double result; // xmm0_8
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = stats_cache_check(a1, 5LL, 0LL, -1LL, v3);
result = v3[0];
if ( v1 != 1 )
result = (double)(int)stats_num_components(a1, 1LL, 0LL, 0LL, v3[0]);
return result;
}

original_code:
double stats_cache_num_components(graph_t *g) {
  double ncmps;
  if (stats_cache_check(g, STATS_CACHE_NUM_COMPONENTS, 0, -1, &ncmps) == 1)
    return ncmps;
  return stats_num_components(g, 1, ((void *)0), ((void *)0));
}

canonical_original_code:
double stats_cache_num_components(struct _graph *g) {
  double ncmps;
  if (stats_cache_check(g, STATS_CACHE_NUM_COMPONENTS, 0, -1, &ncmps) == 1)
    return ncmps;
  return stats_num_components(g, 1, ((void *)0), ((void *)0));
}

variable_types: ncmps double


decompiled_code:
double __fastcall stats_cache_largest_component(__int64 a1)
{
char v1; // al
double result; // xmm0_8
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = stats_cache_check(a1, 6LL, 0LL, -1LL, v3);
result = v3[0];
if ( v1 != 1 )
result = (double)(int)stats_largest_component(a1, v3[0]);
return result;
}

canonical_decompiled_code:
double __fastcall func8(__int64 a1)
{
char v1; // al
double result; // xmm0_8
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = stats_cache_check(a1, 6LL, 0LL, -1LL, v3);
result = v3[0];
if ( v1 != 1 )
result = (double)(int)stats_largest_component(a1, v3[0]);
return result;
}

original_code:
double stats_cache_largest_component(graph_t *g) {
  double lcmp;
  if (stats_cache_check(g, STATS_CACHE_LARGEST_COMPONENT, 0, -1, &lcmp) == 1)
    return lcmp;
  return stats_largest_component(g);
}

canonical_original_code:
double stats_cache_largest_component(struct _graph *g) {
  double lcmp;
  if (stats_cache_check(g, STATS_CACHE_LARGEST_COMPONENT, 0, -1, &lcmp) == 1)
    return lcmp;
  return stats_largest_component(g);
}

variable_types: lcmp double


decompiled_code:
__int64 __fastcall stats_cache_node_component(__int64 a1, unsigned __int64 a2, _DWORD *a3, double a4)
{
unsigned int v5; // er13
__int64 result; // rax
_DWORD *v7; // rax
_DWORD *v8; // r13

v5 = graph_num_nodes();
if ( (unsigned __int8)stats_cache_check(a1, 20LL, (unsigned int)a2, -1LL, a3) == 1 || !a3 )
return 0LL;
if ( a2 < v5 )
{
v7 = calloc(v5, 4uLL);
v8 = v7;
if ( v7 )
{
stats_num_components(a1, 1LL, 0LL, v7, a4);
*a3 = v8[a2];
free(v8);
result = 0LL;
}
else
{
result = 1LL;
}
}
else
{
stats_num_components(a1, 1LL, 0LL, a3, a4);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, unsigned __int64 a2, _DWORD *a3, double a4)
{
unsigned int v5; // er13
__int64 result; // rax
_DWORD *v7; // rax
_DWORD *v8; // r13

v5 = graph_num_nodes();
if ( (unsigned __int8)stats_cache_check(a1, 20LL, (unsigned int)a2, -1LL, a3) == 1 || !a3 )
return 0LL;
if ( a2 < v5 )
{
v7 = calloc(v5, 4uLL);
v8 = v7;
if ( v7 )
{
stats_num_components(a1, 1LL, 0LL, v7, a4);
*a3 = v8[a2];
free(v8);
result = 0LL;
}
else
{
result = 1LL;
}
}
else
{
stats_num_components(a1, 1LL, 0LL, a3, a4);
result = 0LL;
}
return result;
}

original_code:
uint8_t stats_cache_node_component(graph_t *g, int64_t n, uint32_t *data) {
  uint32_t nnodes;
  uint32_t *components;
  components = ((void *)0);
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_COMPONENT, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      stats_num_components(g, 1, ((void *)0), data);
    }
    else {
      components = calloc(nnodes,sizeof(uint32_t));
      if (components == ((void *)0)) goto fail;
      stats_num_components(g, 1, ((void *)0), components);
      *data = components[n];
      free(components);
      components = ((void *)0);
    }
  }
  return 0;
fail:
  if (components != ((void *)0)) free(components);
  return 1;
}

canonical_original_code:
unsigned char stats_cache_node_component(struct _graph *g, long n, unsigned int *data) {
  unsigned int nnodes;
  unsigned int *components;
  components = ((void *)0);
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_COMPONENT, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      stats_num_components(g, 1, ((void *)0), data);
    }
    else {
      components = calloc(nnodes,sizeof(unsigned int));
      if (components == ((void *)0)) goto fail;
      stats_num_components(g, 1, ((void *)0), components);
      *data = components[n];
      free(components);
      components = ((void *)0);
    }
  }
  return 0;
fail:
  if (components != ((void *)0)) free(components);
  return 1;
}

variable_types:
data
unsigned int *

variable_types:
components
unsigned int *


decompiled_code:
double __fastcall stats_cache_connected(__int64 a1)
{
char v1; // al
double result; // xmm0_8
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = stats_cache_check(a1, 7LL, 0LL, -1LL, v3);
result = v3[0];
if ( v1 != 1 )
result = (double)(int)stats_connected(a1, v3[0]);
return result;
}

canonical_decompiled_code:
double __fastcall func10(__int64 a1)
{
char v1; // al
double result; // xmm0_8
double v3[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = stats_cache_check(a1, 7LL, 0LL, -1LL, v3);
result = v3[0];
if ( v1 != 1 )
result = (double)(int)stats_connected(a1, v3[0]);
return result;
}

original_code:
double stats_cache_connected(graph_t *g) {
  double connected;
  if (stats_cache_check(g, STATS_CACHE_CONNECTED, 0, -1, &connected) == 1)
    return connected;
  return stats_connected(g);
}

canonical_original_code:
double stats_cache_connected(struct _graph *g) {
  double connected;
  if (stats_cache_check(g, STATS_CACHE_CONNECTED, 0, -1, &connected) == 1)
    return connected;
  return stats_connected(g);
}

variable_types: connected double


decompiled_code:
__int64 __fastcall stats_cache_global_efficiency(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 8LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_global_efficiency(a1, v2[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 8LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_global_efficiency(a1, v2[0]);
return result;
}

original_code:
double stats_cache_global_efficiency(graph_t *g) {
  double eff;
  if (stats_cache_check(g, STATS_CACHE_GLOBAL_EFFICIENCY, 0, -1, &eff) == 1)
    return eff;
  return stats_global_efficiency(g);
}

canonical_original_code:
double stats_cache_global_efficiency(struct _graph *g) {
  double eff;
  if (stats_cache_check(g, STATS_CACHE_GLOBAL_EFFICIENCY, 0, -1, &eff) == 1)
    return eff;
  return stats_global_efficiency(g);
}

variable_types: eff double


decompiled_code:
__int64 __fastcall stats_cache_local_efficiency(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 9LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_avg_local_efficiency(a1, v2[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 9LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_avg_local_efficiency(a1, v2[0]);
return result;
}

original_code:
double stats_cache_local_efficiency(graph_t *g) {
  double eff;
  if (stats_cache_check(g, STATS_CACHE_LOCAL_EFFICIENCY, 0, -1, &eff) == 1)
    return eff;
  return stats_avg_local_efficiency(g);
}

canonical_original_code:
double stats_cache_local_efficiency(struct _graph *g) {
  double eff;
  if (stats_cache_check(g, STATS_CACHE_LOCAL_EFFICIENCY, 0, -1, &eff) == 1)
    return eff;
  return stats_avg_local_efficiency(g);
}


decompiled_code:
__int64 __fastcall stats_cache_node_local_efficiency(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned __int64 v4; // r13
char v5; // al
__int64 v6; // rbx
__int64 result; // rax
double v8; // xmm0_8

v4 = (unsigned int)graph_num_nodes();
v5 = stats_cache_check(a1, 17LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v5 == 1 )
return 0LL;
if ( v4 <= a2 )
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_local_efficiency(a1, (unsigned int)v6);
++v6;
}
while ( v4 != v6 );
}
return 0LL;
}
v8 = stats_local_efficiency(a1, (unsigned int)a2);
result = 0LL;
*a3 = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned __int64 v4; // r13
char v5; // al
__int64 v6; // rbx
__int64 result; // rax
double v8; // xmm0_8

v4 = (unsigned int)graph_num_nodes();
v5 = stats_cache_check(a1, 17LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v5 == 1 )
return 0LL;
if ( v4 <= a2 )
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_local_efficiency(a1, (unsigned int)v6);
++v6;
}
while ( v4 != v6 );
}
return 0LL;
}
v8 = stats_local_efficiency(a1, (unsigned int)a2);
result = 0LL;
*a3 = v8;
return result;
}

original_code:
uint8_t stats_cache_node_local_efficiency(
  graph_t *g, int64_t n, double *data) {
  int64_t i;
  uint32_t nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_LOCAL_EFFICIENCY, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_local_efficiency(g, i);
      }
    }
    else {
      *data = stats_local_efficiency(g, n);
    }
  }
  return 0;
}

canonical_original_code:
unsigned char stats_cache_node_local_efficiency(struct _graph *g, long n, double *data) {
  long i;
  unsigned int nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_LOCAL_EFFICIENCY, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_local_efficiency(g, i);
      }
    }
    else {
      *data = stats_local_efficiency(g, n);
    }
  }
  return 0;
}

variable_types: i long


decompiled_code:
double __fastcall stats_cache_modularity(__int64 a1)
{
char v1; // al
double result; // xmm0_8
size_t v3; // r12
unsigned int v4; // er14
_DWORD *v5; // r13
__int64 i; // rbx
double v7; // [rsp+8h] [rbp-40h]
double v8[6]; // [rsp+18h] [rbp-30h] BYREF

v1 = stats_cache_check(a1, 10LL, 0LL, -1LL, v8);
result = v8[0];
if ( v1 != 1 )
{
v3 = (unsigned int)graph_num_nodes(a1, v8[0]);
v4 = graph_num_labelvals(a1);
v5 = calloc(v3, 4uLL);
if ( v5 )
{
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
v5[i] = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)i);
}
v7 = stats_modularity(a1, v4, v5);
free(v5);
result = v7;
}
else
{
result = *(double *)&LC0;
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func14(__int64 a1)
{
char v1; // al
double result; // xmm0_8
size_t v3; // r12
unsigned int v4; // er14
_DWORD *v5; // r13
__int64 i; // rbx
double v7; // [rsp+8h] [rbp-40h]
double v8[6]; // [rsp+18h] [rbp-30h] BYREF

v1 = stats_cache_check(a1, 10LL, 0LL, -1LL, v8);
result = v8[0];
if ( v1 != 1 )
{
v3 = (unsigned int)graph_num_nodes(a1, v8[0]);
v4 = graph_num_labelvals(a1);
v5 = calloc(v3, 4uLL);
if ( v5 )
{
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
v5[i] = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)i);
}
v7 = stats_modularity(a1, v4, v5);
free(v5);
result = v7;
}
else
{
result = *(double *)&LC0;
}
}
return result;
}

original_code:
double stats_cache_modularity(graph_t *g) {
  double mod;
  uint32_t *comms;
  uint64_t i;
  uint32_t nnodes;
  uint32_t ncomms;
  comms = ((void *)0);
  if (stats_cache_check(g, STATS_CACHE_MODULARITY, 0, -1, &mod) == 1)
    return mod;
  nnodes = graph_num_nodes( g);
  ncomms = graph_num_labelvals(g);
  comms = calloc(nnodes,sizeof(uint32_t));
  if (comms == ((void *)0)) goto fail;
  for (i = 0; i < nnodes; i++)
    comms[i] = graph_get_nodelabel(g, i)->labelval;
  mod = stats_modularity(g, ncomms, comms);
  free(comms);
  return mod;
fail:
  if (comms != ((void *)0)) free(comms);
  return 0xFF;
}

canonical_original_code:
double stats_cache_modularity(struct _graph *g) {
  double mod;
  unsigned int *comms;
  unsigned long i;
  unsigned int nnodes;
  unsigned int ncomms;
  comms = ((void *)0);
  if (stats_cache_check(g, STATS_CACHE_MODULARITY, 0, -1, &mod) == 1)
    return mod;
  nnodes = graph_num_nodes( g);
  ncomms = graph_num_labelvals(g);
  comms = calloc(nnodes,sizeof(unsigned int));
  if (comms == ((void *)0)) goto fail;
  for (i = 0; i < nnodes; i++)
    comms[i] = graph_get_nodelabel(g, i)->labelval;
  mod = stats_modularity(g, ncomms, comms);
  free(comms);
  return mod;
fail:
  if (comms != ((void *)0)) free(comms);
  return 0xFF;
}

variable_types: mod double

variable_types:
comms
unsigned int *

variable_types:
i
unsigned long

variable_types:
ncomms
unsigned int


decompiled_code:
__int64 __fastcall stats_cache_intra_edges(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 11LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_num_intra_edges(a1, 0LL, v2[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 11LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_num_intra_edges(a1, 0LL, v2[0]);
return result;
}

original_code:
double stats_cache_intra_edges(graph_t *g) {
  double intra;
  if (stats_cache_check(g, STATS_CACHE_INTRA_EDGES, 0, -1, &intra) == 1)
    return intra;
  return stats_num_intra_edges(g, ((void *)0));
}

canonical_original_code:
double stats_cache_intra_edges(struct _graph *g) {
  double intra;
  if (stats_cache_check(g, STATS_CACHE_INTRA_EDGES, 0, -1, &intra) == 1)
    return intra;
  return stats_num_intra_edges(g, ((void *)0));
}

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

variable_types: intra double


decompiled_code:
double __fastcall stats_cache_inter_edges(__int64 a1, double a2)
{
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned __int8)stats_cache_check(a1, 12LL, 0LL, -1LL, v3) != 1 )
stats_num_intra_edges(a1, v3, a2);
return *(double *)v3;
}

canonical_decompiled_code:
double __fastcall func16(__int64 a1, double a2)
{
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned __int8)stats_cache_check(a1, 12LL, 0LL, -1LL, v3) != 1 )
stats_num_intra_edges(a1, v3, a2);
return *(double *)v3;
}

original_code:
double stats_cache_inter_edges(graph_t *g) {
  double inter;
  if (stats_cache_check(g, STATS_CACHE_INTER_EDGES, 0, -1, &inter) == 1)
    return inter;
  stats_num_intra_edges(g, &inter);
  return inter;
}

canonical_original_code:
double stats_cache_inter_edges(struct _graph *g) {
  double inter;
  if (stats_cache_check(g, STATS_CACHE_INTER_EDGES, 0, -1, &inter) == 1)
    return inter;
  stats_num_intra_edges(g, &inter);
  return inter;
}

variable_types: inter double


decompiled_code:
__int64 __fastcall stats_cache_max_degree(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 13LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_max_degree(a1, v2[0]);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1)
{
__int64 result; // rax
double v2[2]; // [rsp+8h] [rbp-10h] BYREF

result = stats_cache_check(a1, 13LL, 0LL, -1LL, v2);
if ( (_BYTE)result != 1 )
result = stats_max_degree(a1, v2[0]);
return result;
}

original_code:
double stats_cache_max_degree(graph_t *g) {
  double maxdeg;
  if (stats_cache_check(g, STATS_CACHE_MAX_DEGREE, 0, -1, &maxdeg) == 1)
    return maxdeg;
  maxdeg = stats_max_degree(g);
  return maxdeg;
}

canonical_original_code:
double stats_cache_max_degree(struct _graph *g) {
  double maxdeg;
  if (stats_cache_check(g, STATS_CACHE_MAX_DEGREE, 0, -1, &maxdeg) == 1)
    return maxdeg;
  maxdeg = stats_max_degree(g);
  return maxdeg;
}

variable_types: maxdeg double


decompiled_code:
double __fastcall stats_cache_chira(__int64 a1)
{
char v1; // al
double result; // xmm0_8
size_t v3; // r12
unsigned int v4; // er14
_DWORD *v5; // r13
__int64 i; // rbx
double v7; // [rsp+8h] [rbp-40h]
double v8[6]; // [rsp+18h] [rbp-30h] BYREF

v1 = stats_cache_check(a1, 14LL, 0LL, -1LL, v8);
result = v8[0];
if ( v1 != 1 )
{
v3 = (unsigned int)graph_num_nodes(a1, v8[0]);
v4 = graph_num_labelvals(a1);
v5 = calloc(v3, 4uLL);
if ( v5 )
{
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
v5[i] = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)i);
}
v7 = stats_chira(a1, v4, v5);
free(v5);
result = v7;
}
else
{
result = *(double *)&LC0;
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func18(__int64 a1)
{
char v1; // al
double result; // xmm0_8
size_t v3; // r12
unsigned int v4; // er14
_DWORD *v5; // r13
__int64 i; // rbx
double v7; // [rsp+8h] [rbp-40h]
double v8[6]; // [rsp+18h] [rbp-30h] BYREF

v1 = stats_cache_check(a1, 14LL, 0LL, -1LL, v8);
result = v8[0];
if ( v1 != 1 )
{
v3 = (unsigned int)graph_num_nodes(a1, v8[0]);
v4 = graph_num_labelvals(a1);
v5 = calloc(v3, 4uLL);
if ( v5 )
{
if ( v3 )
{
for ( i = 0LL; i != v3; ++i )
v5[i] = *(_DWORD *)graph_get_nodelabel(a1, (unsigned int)i);
}
v7 = stats_chira(a1, v4, v5);
free(v5);
result = v7;
}
else
{
result = *(double *)&LC0;
}
}
return result;
}

original_code:
double stats_cache_chira(graph_t *g) {
  double mod;
  uint32_t *comms;
  uint64_t i;
  uint32_t nnodes;
  uint32_t ncomms;
  comms = ((void *)0);
  if (stats_cache_check(g, STATS_CACHE_CHIRA, 0, -1, &mod) == 1)
    return mod;
  nnodes = graph_num_nodes( g);
  ncomms = graph_num_labelvals(g);
  comms = calloc(nnodes,sizeof(uint32_t));
  if (comms == ((void *)0)) goto fail;
  for (i = 0; i < nnodes; i++)
    comms[i] = graph_get_nodelabel(g, i)->labelval;
  mod = stats_chira(g, ncomms, comms);
  free(comms);
  return mod;
fail:
  if (comms != ((void *)0)) free(comms);
  return 0xFF;
}

canonical_original_code:
double stats_cache_chira(struct _graph *g) {
  double mod;
  unsigned int *comms;
  unsigned long i;
  unsigned int nnodes;
  unsigned int ncomms;
  comms = ((void *)0);
  if (stats_cache_check(g, STATS_CACHE_CHIRA, 0, -1, &mod) == 1)
    return mod;
  nnodes = graph_num_nodes( g);
  ncomms = graph_num_labelvals(g);
  comms = calloc(nnodes,sizeof(unsigned int));
  if (comms == ((void *)0)) goto fail;
  for (i = 0; i < nnodes; i++)
    comms[i] = graph_get_nodelabel(g, i)->labelval;
  mod = stats_chira(g, ncomms, comms);
  free(comms);
  return mod;
fail:
  if (comms != ((void *)0)) free(comms);
  return 0xFF;
}

variable_types:
nnodes
unsigned int


decompiled_code:
__int64 __fastcall stats_cache_betweenness_centrality(__int64 a1, unsigned __int64 a2, double *a3, double a4)
{
unsigned __int64 v5; // r13
char v6; // al
__int64 v7; // rbx
__int64 result; // rax
double v9; // xmm0_8

v5 = (unsigned int)graph_num_nodes(a1, a4);
v6 = stats_cache_check(a1, 18LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v6 == 1 )
return 0LL;
if ( v5 <= a2 )
{
v7 = 0LL;
if ( v5 )
{
do
{
a3[v7] = stats_betweenness_centrality(a1, (unsigned int)v7);
++v7;
}
while ( v5 != v7 );
}
return 0LL;
}
v9 = stats_betweenness_centrality(a1, (unsigned int)a2);
result = 0LL;
*a3 = v9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned __int64 a2, double *a3, double a4)
{
unsigned __int64 v5; // r13
char v6; // al
__int64 v7; // rbx
__int64 result; // rax
double v9; // xmm0_8

v5 = (unsigned int)graph_num_nodes(a1, a4);
v6 = stats_cache_check(a1, 18LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v6 == 1 )
return 0LL;
if ( v5 <= a2 )
{
v7 = 0LL;
if ( v5 )
{
do
{
a3[v7] = stats_betweenness_centrality(a1, (unsigned int)v7);
++v7;
}
while ( v5 != v7 );
}
return 0LL;
}
v9 = stats_betweenness_centrality(a1, (unsigned int)a2);
result = 0LL;
*a3 = v9;
return result;
}

original_code:
uint8_t stats_cache_betweenness_centrality(
  graph_t *g, int64_t n, double *data) {
  uint64_t i;
  uint32_t nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(
      g, STATS_CACHE_BETWEENNESS_CENTRALITY, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_betweenness_centrality(g, i);
      }
    }
    else {
      *data = stats_betweenness_centrality(g, n);
    }
  }
  return 0;
}

canonical_original_code:
unsigned char stats_cache_betweenness_centrality(struct _graph *g, long n, double *data) {
  unsigned long i;
  unsigned int nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(
      g, STATS_CACHE_BETWEENNESS_CENTRALITY, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_betweenness_centrality(g, i);
      }
    }
    else {
      *data = stats_betweenness_centrality(g, n);
    }
  }
  return 0;
}

variable_types: n long

variable_types:
data
double *


decompiled_code:
__int64 __fastcall stats_cache_node_numpaths(__int64 a1, unsigned __int64 a2, double *a3, double a4)
{
unsigned __int64 v5; // r13
char v6; // al
__int64 v7; // rbx
__int64 result; // rax
double v9; // xmm0_8

v5 = (unsigned int)graph_num_nodes(a1, a4);
v6 = stats_cache_check(a1, 19LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v6 == 1 )
return 0LL;
if ( v5 <= a2 )
{
v7 = 0LL;
if ( v5 )
{
do
{
a3[v7] = stats_numpaths(a1, (unsigned int)v7, 0LL);
++v7;
}
while ( v5 != v7 );
}
return 0LL;
}
v9 = stats_numpaths(a1, (unsigned int)a2, 0LL);
result = 0LL;
*a3 = v9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, unsigned __int64 a2, double *a3, double a4)
{
unsigned __int64 v5; // r13
char v6; // al
__int64 v7; // rbx
__int64 result; // rax
double v9; // xmm0_8

v5 = (unsigned int)graph_num_nodes(a1, a4);
v6 = stats_cache_check(a1, 19LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v6 == 1 )
return 0LL;
if ( v5 <= a2 )
{
v7 = 0LL;
if ( v5 )
{
do
{
a3[v7] = stats_numpaths(a1, (unsigned int)v7, 0LL);
++v7;
}
while ( v5 != v7 );
}
return 0LL;
}
v9 = stats_numpaths(a1, (unsigned int)a2, 0LL);
result = 0LL;
*a3 = v9;
return result;
}

original_code:
uint8_t stats_cache_node_numpaths(graph_t *g, int64_t n, double *data) {
  uint64_t i;
  uint32_t nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_NUMPATHS, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_numpaths(g, i, ((void *)0));
      }
    }
    else {
      *data = stats_numpaths(g, n, ((void *)0));
    }
  }
  return 0;
}

canonical_original_code:
unsigned char stats_cache_node_numpaths(struct _graph *g, long n, double *data) {
  unsigned long i;
  unsigned int nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_NUMPATHS, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_numpaths(g, i, ((void *)0));
      }
    }
    else {
      *data = stats_numpaths(g, n, ((void *)0));
    }
  }
  return 0;
}


decompiled_code:
__int64 __fastcall stats_cache_node_edgedist(__int64 a1, unsigned __int64 a2, double *a3, double a4)
{
unsigned __int64 v5; // r13
char v6; // al
__int64 v7; // rbx
__int64 result; // rax
double v9; // xmm0_8

v5 = (unsigned int)graph_num_nodes(a1, a4);
v6 = stats_cache_check(a1, 21LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v6 == 1 )
return 0LL;
if ( v5 <= a2 )
{
v7 = 0LL;
if ( v5 )
{
do
{
a3[v7] = stats_avg_edge_distance(a1, (unsigned int)v7);
++v7;
}
while ( v5 != v7 );
}
return 0LL;
}
v9 = stats_avg_edge_distance(a1, (unsigned int)a2);
result = 0LL;
*a3 = v9;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned __int64 a2, double *a3, double a4)
{
unsigned __int64 v5; // r13
char v6; // al
__int64 v7; // rbx
__int64 result; // rax
double v9; // xmm0_8

v5 = (unsigned int)graph_num_nodes(a1, a4);
v6 = stats_cache_check(a1, 21LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v6 == 1 )
return 0LL;
if ( v5 <= a2 )
{
v7 = 0LL;
if ( v5 )
{
do
{
a3[v7] = stats_avg_edge_distance(a1, (unsigned int)v7);
++v7;
}
while ( v5 != v7 );
}
return 0LL;
}
v9 = stats_avg_edge_distance(a1, (unsigned int)a2);
result = 0LL;
*a3 = v9;
return result;
}

original_code:
uint8_t stats_cache_node_edgedist(graph_t *g, int64_t n, double *data) {
  uint64_t i;
  uint32_t nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_EDGEDIST, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_avg_edge_distance(g, i);
      }
    }
    else {
      *data = stats_avg_edge_distance(g, n);
    }
  }
  return 0;
}

canonical_original_code:
unsigned char stats_cache_node_edgedist(struct _graph *g, long n, double *data) {
  unsigned long i;
  unsigned int nnodes;
  nnodes = graph_num_nodes(g);
  if (stats_cache_check(g, STATS_CACHE_NODE_EDGEDIST, n, -1, data) == 1)
    return 0;
  if (data != ((void *)0)) {
    if (n < 0 || n >= nnodes) {
      for (i = 0; i < nnodes; i++) {
        data[i] = stats_avg_edge_distance(g, i);
      }
    }
    else {
      *data = stats_avg_edge_distance(g, n);
    }
  }
  return 0;
}


decompiled_code:
__int64 __fastcall stats_cache_pair_numpaths(__int64 a1, unsigned int a2, __int64 a3)
{
if ( (unsigned __int8)stats_cache_check(a1, 23LL, a2, -1LL, a3) != 1 )
stats_numpaths(a1, a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, unsigned int a2, __int64 a3)
{
if ( (unsigned __int8)stats_cache_check(a1, 23LL, a2, -1LL, a3) != 1 )
stats_numpaths(a1, a2, a3);
return 0LL;
}

original_code:
uint8_t stats_cache_pair_numpaths(graph_t *g, uint32_t n, double *paths) {
  if (stats_cache_check(g, STATS_CACHE_PAIR_NUMPATHS, n, -1, paths) == 1)
    return 0;
  stats_numpaths(g, n, paths);
  return 0;
}

canonical_original_code:
unsigned char stats_cache_pair_numpaths(struct _graph *g, unsigned int n, double *paths) {
  if (stats_cache_check(g, STATS_CACHE_PAIR_NUMPATHS, n, -1, paths) == 1)
    return 0;
  stats_numpaths(g, n, paths);
  return 0;
}

variable_types:
n
unsigned int

variable_types:
paths
double *


decompiled_code:
__int64 __fastcall stats_cache_edge_pathsharing(__int64 a1, unsigned int a2, __int64 a3, double a4)
{
__int64 v5; // r14
__int64 v6; // r15
__int64 i; // rbx

if ( (unsigned __int8)stats_cache_check(a1, 24LL, a2, -1LL, a3) != 1 )
{
v5 = (unsigned int)graph_num_neighbours(a1, a2);
v6 = graph_get_neighbours(a1, a2);
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
{
stats_edge_pathsharing(a1, a2, *(unsigned int *)(v6 + 4 * i));
if ( a3 )
*(double *)(a3 + 8 * i) = a4;
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, unsigned int a2, __int64 a3, double a4)
{
__int64 v5; // r14
__int64 v6; // r15
__int64 i; // rbx

if ( (unsigned __int8)stats_cache_check(a1, 24LL, a2, -1LL, a3) != 1 )
{
v5 = (unsigned int)graph_num_neighbours(a1, a2);
v6 = graph_get_neighbours(a1, a2);
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
{
stats_edge_pathsharing(a1, a2, *(unsigned int *)(v6 + 4 * i));
if ( a3 )
*(double *)(a3 + 8 * i) = a4;
}
}
}
return 0LL;
}

original_code:
uint8_t stats_cache_edge_pathsharing(graph_t *g, uint32_t n, double *ps) {
  uint64_t i;
  uint32_t nnbrs;
  uint32_t *nbrs;
  double tmp;
  if (stats_cache_check(g, STATS_CACHE_EDGE_PATHSHARING, n, -1, ps) == 1)
    return 0;
  nnbrs = graph_num_neighbours(g, n);
  nbrs = graph_get_neighbours(g, n);
  for (i = 0; i < nnbrs; i++) {
    tmp = stats_edge_pathsharing(g, n, nbrs[i]);
    if (ps != ((void *)0)) ps[i] = tmp;
  }
  return 0;
}

canonical_original_code:
unsigned char stats_cache_edge_pathsharing(struct _graph *g, unsigned int n, double *ps) {
  unsigned long i;
  unsigned int nnbrs;
  unsigned int *nbrs;
  double tmp;
  if (stats_cache_check(g, STATS_CACHE_EDGE_PATHSHARING, n, -1, ps) == 1)
    return 0;
  nnbrs = graph_num_neighbours(g, n);
  nbrs = graph_get_neighbours(g, n);
  for (i = 0; i < nnbrs; i++) {
    tmp = stats_edge_pathsharing(g, n, nbrs[i]);
    if (ps != ((void *)0)) ps[i] = tmp;
  }
  return 0;
}

variable_types:
ps
double *

variable_types:
nnbrs
unsigned int

variable_types:
nbrs
unsigned int *

variable_types: tmp double


decompiled_code:
__int64 __fastcall stats_cache_edge_betweenness(__int64 a1, unsigned int a2, __int64 a3)
{
if ( (unsigned __int8)stats_cache_check(a1, 25LL, a2, -1LL, a3) != 1 )
stats_edge_betweenness(a1, a2, a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, unsigned int a2, __int64 a3)
{
if ( (unsigned __int8)stats_cache_check(a1, 25LL, a2, -1LL, a3) != 1 )
stats_edge_betweenness(a1, a2, a3);
return 0LL;
}

original_code:
uint8_t stats_cache_edge_betweenness(graph_t *g, uint32_t n, double *eb) {
  if (stats_cache_check(g, STATS_CACHE_EDGE_BETWEENNESS, n, -1, eb) == 1)
    return 0;
  stats_edge_betweenness(g, n, eb);
  return 0;
}

canonical_original_code:
unsigned char stats_cache_edge_betweenness(struct _graph *g, unsigned int n, double *eb) {
  if (stats_cache_check(g, STATS_CACHE_EDGE_BETWEENNESS, n, -1, eb) == 1)
    return 0;
  stats_edge_betweenness(g, n, eb);
  return 0;
}

variable_types:
eb
double *


decompiled_code:
__int64 __fastcall compare_u32(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 1LL;
if ( *a1 <= *a2 )
result = (unsigned int)-(*a1 != *a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 1LL;
if ( *a1 <= *a2 )
result = (unsigned int)-(*a1 != *a2);
return result;
}

original_code:
int compare_u32(const void *a, const void *b) {
  uint32_t ia;
  uint32_t ib;
  ia = *(uint32_t *)a;
  ib = *(uint32_t *)b;
  if (ia > ib) return 1;
  if (ia == ib) return 0;
  return -1;
}

canonical_original_code:
int compare_u32(void *a, void *b) {
  unsigned int ia;
  unsigned int ib;
  ia = *(unsigned int *)a;
  ib = *(unsigned int *)b;
  if (ia > ib) return 1;
  if (ia == ib) return 0;
  return -1;
}

variable_types:
a
void *

variable_types:
b
void *

variable_types:
ia
unsigned int

variable_types:
ib
unsigned int


decompiled_code:
__int64 __fastcall compare_double(double *a1, double *a2)
{
__int64 result; // rax

result = 1LL;
if ( *a1 <= *a2 )
{
if ( *a1 == *a2 )
LODWORD(result) = 0;
result = (unsigned int)-(int)result;
}
return result;
}

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

result = 1LL;
if ( *a1 <= *a2 )
{
if ( *a1 == *a2 )
LODWORD(result) = 0;
result = (unsigned int)-(int)result;
}
return result;
}

original_code:
int compare_double(const void *a, const void *b) {
  double da;
  double db;
  da = *(double *)a;
  db = *(double *)b;
  if (da > db) return 1;
  if (da == db) return 0;
  return -1;
}

canonical_original_code:
int compare_double(void *a, void *b) {
  double da;
  double db;
  da = *(double *)a;
  db = *(double *)b;
  if (da > db) return 1;
  if (da == db) return 0;
  return -1;
}

variable_types: da double

variable_types: db double


decompiled_code:
__int64 __fastcall compare_str_numeric(const char *a1, const char *a2)
{
double v3; // [rsp+0h] [rbp-18h] BYREF
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = atof(a1);
v4[0] = atof(a2);
return compare_double(&v3, v4);
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
double v3; // [rsp+0h] [rbp-18h] BYREF
double v4[2]; // [rsp+8h] [rbp-10h] BYREF

v3 = atof(a1);
v4[0] = atof(a2);
return func1(&v3, v4);
}

original_code:
int compare_str_numeric(const void *a, const void *b) {
  char *sa;
  char *sb;
  double da;
  double db;
  sa = (char *)a;
  sb = (char *)b;
  da = atof(sa);
  db = atof(sb);
  return compare_double(&da, &db);
}

canonical_original_code:
int compare_str_numeric(void *a, void *b) {
  char *sa;
  char *sb;
  double da;
  double db;
  sa = (char *)a;
  sb = (char *)b;
  da = atof(sa);
  db = atof(sb);
  return compare_double(&da, &db);
}

variable_types:
sa
char *

variable_types:
sb
char *


decompiled_code:
__int64 __fastcall compare_insert(__int64 a1, __int64 a2, __int64 a3, __int64 (*a4)(void))
{
int v6; // er8
__int64 result; // rax

if ( a1 )
{
v6 = a4();
result = 0xFFFFFFFFLL;
if ( v6 >= 0 )
{
if ( last_0 == a2 )
result = 0LL;
else
result = ((int (__fastcall *)(__int64, __int64))a4)(a1, a2 + a3) >= 0;
}
}
else
{
last_0 = a2;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, __int64 (*a4)(void))
{
int v6; // er8
__int64 result; // rax

if ( a1 )
{
v6 = a4();
result = 0xFFFFFFFFLL;
if ( v6 >= 0 )
{
if ( last_0 == a2 )
result = 0LL;
else
result = ((int (__fastcall *)(__int64, __int64))a4)(a1, a2 + a3) >= 0;
}
}
else
{
last_0 = a2;
result = 0LL;
}
return result;
}

original_code:
int compare_insert(
  const void *a,
  const void *b,
  const size_t sz,
  int (*cmp)(const void *, const void *)) {
  static const void *last;
  const char *cb;
  int abcmp;
  if (a == ((void *)0)) {
    last = b;
    return 0;
  }
  cb = b;
  abcmp = cmp(a, b);
  if (abcmp >= 0) {
    if (b == last) return 0;
    if (cmp(a, cb+sz) < 0) return 0;
  }
  else if (abcmp < 0)
    return -1;
  return 1;
}

canonical_original_code:
int compare_insert(void *a, void *b, unsigned long sz, int (*cmp)(void *, void *)) {
  static void *last;
  char *cb;
  int abcmp;
  if (a == ((void *)0)) {
    last = b;
    return 0;
  }
  cb = b;
  abcmp = cmp(a, b);
  if (abcmp >= 0) {
    if (b == last) return 0;
    if (cmp(a, cb+sz) < 0) return 0;
  }
  else if (abcmp < 0)
    return -1;
  return 1;
}

variable_types:
sz
unsigned long

variable_types:
cmp
int (*)(void *, void *)

variable_types:
last
void *

variable_types:
cb
char *

variable_types: abcmp int


decompiled_code:
__int64 __fastcall compare_u32_insert(__int64 a1, __int64 a2)
{
return compare_insert(a1, a2, 4LL, (__int64 (*)(void))compare_u32);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return func3(a1, a2, 4LL, (__int64 (*)(void))compare_u32);
}

original_code:
int compare_u32_insert(const void *a, const void *b) {
  return compare_insert(a, b, sizeof(uint32_t), compare_u32);
}

canonical_original_code:
int compare_u32_insert(void *a, void *b) {
  return compare_insert(a, b, sizeof(unsigned int), compare_u32);
}


decompiled_code:
void *__fastcall bsearch_insert(void *key, void *base, size_t nmemb, size_t size, __compar_fn_t compar)
{
compare_insert(0LL, (__int64)base + size * (nmemb - 1), 0LL, 0LL);
return bsearch(key, base, nmemb, size, compar);
}

canonical_decompiled_code:
void *__fastcall func5(void *key, void *base, size_t nmemb, size_t size, __compar_fn_t compar)
{
func3(0LL, (__int64)base + size * (nmemb - 1), 0LL, 0LL);
return bsearch(key, base, nmemb, size, compar);
}

original_code:
void *bsearch_insert(
  const void *key,
  const void *base,
  size_t nmemb,
  size_t size,
  int (*compar)(const void *, const void *)) {
  const char *cbase;
  const void *last;
  cbase = base;
  last = cbase + ((nmemb-1)*size);
  compare_insert(((void *)0), last, 0, ((void *)0));
  return bsearch(key, base, nmemb, size, compar);
}

canonical_original_code:
void *bsearch_insert(void *key, void *base, unsigned long nmemb, unsigned long size, int (*compar)(void *, void *)) {
  char *cbase;
  void *last;
  cbase = base;
  last = cbase + ((nmemb-1)*size);
  compare_insert(((void *)0), last, 0, ((void *)0));
  return bsearch(key, base, nmemb, size, compar);
}

variable_types:
key
void *

variable_types:
base
void *

variable_types:
nmemb
unsigned long

variable_types:
size
unsigned long

variable_types:
compar
int (*)(void *, void *)

variable_types:
cbase
char *

return_type: void *


bfs

original_code:
uint8_t bfs(
  graph_t *g,
  uint32_t *roots,
  uint32_t nroots,
  uint8_t *subgraphmask,
  void *lvl_context,
  void *edge_context,
  uint8_t (*lvl_callback) (
    bfs_state_t *state,
    void *context),
  uint8_t (*edge_callback) (
    expand_state_t *state,
    void *context))
{
  uint64_t i;
  bfs_state_t state;
  array_t tmp;
  array_t nextlevel;
  uint8_t *visited;
  uint32_t numnodes;
  visited = ((void *)0);
  nextlevel.data = ((void *)0);
  state.thislevel.data = ((void *)0);
  numnodes = graph_num_nodes(g);
  if (array_create(&(state.thislevel), sizeof(uint32_t), numnodes/4))
    goto fail;
  if (array_create(&nextlevel, sizeof(uint32_t), numnodes/4))
    goto fail;
  visited = calloc(numnodes, sizeof(uint8_t));
  if (visited == ((void *)0)) goto fail;
  if (subgraphmask != ((void *)0))
    memcpy(visited, subgraphmask, numnodes*sizeof(uint8_t));
  for (i = 0; i < nroots; i++) {
    array_append(&(state.thislevel), &(roots[i]));
    visited[roots[i]] = 1;
  }
  state.depth = 0;
  state.visited = visited;
  do {
    array_clear(&nextlevel);
    if (state.depth > 0)
      if (lvl_callback != ((void *)0) && lvl_callback(&state, lvl_context))
        break;
    if (expand(
      g,
      &(state.thislevel),
      &nextlevel,
      visited,
      edge_context,
      edge_callback)) break;
    state.depth++;
    memcpy(&tmp, &(state.thislevel), sizeof(array_t));
    memcpy(&(state.thislevel), &nextlevel, sizeof(array_t));
    memcpy(&nextlevel, &tmp, sizeof(array_t));
  } while (state.thislevel.size != 0);
  array_free(&(state.thislevel));
  array_free(&nextlevel);
  free(visited);
  return 0;
fail:
  array_free(&(state.thislevel));
  array_free(&nextlevel);
  if (visited != ((void *)0)) free(visited);
  return 1;
}

canonical_original_code:
unsigned char bfs(struct _graph *g, unsigned int *roots, unsigned int nroots, unsigned char *subgraphmask, void *lvl_context, void *edge_context, unsigned char (*lvl_callback)(struct _bfs_state *state, void *context), unsigned char (*edge_callback)(struct _expand_state *state, void *context))
{
  unsigned long i;
  struct _bfs_state state;
  struct _array tmp;
  struct _array nextlevel;
  unsigned char *visited;
  unsigned int numnodes;
  visited = ((void *)0);
  nextlevel.data = ((void *)0);
  state.thislevel.data = ((void *)0);
  numnodes = graph_num_nodes(g);
  if (array_create(&(state.thislevel), sizeof(unsigned int), numnodes/4))
    goto fail;
  if (array_create(&nextlevel, sizeof(unsigned int), numnodes/4))
    goto fail;
  visited = calloc(numnodes, sizeof(unsigned char));
  if (visited == ((void *)0)) goto fail;
  if (subgraphmask != ((void *)0))
    memcpy(visited, subgraphmask, numnodes*sizeof(unsigned char));
  for (i = 0; i < nroots; i++) {
    array_append(&(state.thislevel), &(roots[i]));
    visited[roots[i]] = 1;
  }
  state.depth = 0;
  state.visited = visited;
  do {
    array_clear(&nextlevel);
    if (state.depth > 0)
      if (lvl_callback != ((void *)0) && lvl_callback(&state, lvl_context))
        break;
    if (expand(
      g,
      &(state.thislevel),
      &nextlevel,
      visited,
      edge_context,
      edge_callback)) break;
    state.depth++;
    memcpy(&tmp, &(state.thislevel), sizeof(array_t));
    memcpy(&(state.thislevel), &nextlevel, sizeof(array_t));
    memcpy(&nextlevel, &tmp, sizeof(array_t));
  } while (state.thislevel.size != 0);
  array_free(&(state.thislevel));
  array_free(&nextlevel);
  free(visited);
  return 0;
fail:
  array_free(&(state.thislevel));
  array_free(&nextlevel);
  if (visited != ((void *)0)) free(visited);
  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:
roots
unsigned int *

variable_types:
nroots
unsigned int

variable_types:
subgraphmask
unsigned char *

variable_types: unsigned char (*)(struct _bfs_state { unsigned int depth; struct _array thislevel; unsigned char *visited; } *state, void *context)

variable_types: unsigned char (*)(struct _expand_state { unsigned int parent; unsigned int child; unsigned char visited; } *state, void *context)

variable_types:
i
unsigned long

variable_types: struct _bfs_state { unsigned int depth; 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); } thislevel; unsigned char *visited; }

variable_types:
visited
unsigned char *

variable_types:
numnodes
unsigned int


expand

decompiled_code:
__int64 __fastcall expand(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebx
int v3; // eax
double v4; // xmm0_8
__int64 result; // rax
__m128d v6; // xmm3
__m128d v7; // xmm1
void *v8; // rax

v2 = a2;
v3 = *(_DWORD *)a1;
if ( !a2 )
{
v4 = (double)v3 * 1.2;
if ( COERCE_DOUBLE(*(_QWORD *)&v4 & LC2) < 4.503599627370496e15 )
{
v6.m128d_f64[0] = (double)v3 * 1.2;
v7.m128d_f64[0] = (double)(int)v4;
*(_QWORD *)&v4 = COERCE_UNSIGNED_INT64(v7.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v6, v7) & LC3)) | ~LC2 & *(_QWORD *)&v4;
}
v2 = (int)v4;
}
if ( v2 <= v3 )
return 1LL;
v8 = realloc(*(void **)(a1 + 16), *(_DWORD *)(a1 + 8) * v2);
if ( !v8 )
return 1LL;
*(_QWORD *)(a1 + 16) = v8;
result = 0LL;
*(_DWORD *)a1 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned int v2; // ebx
int v3; // eax
double v4; // xmm0_8
__int64 result; // rax
__m128d v6; // xmm3
__m128d v7; // xmm1
void *v8; // rax

v2 = a2;
v3 = *(_DWORD *)a1;
if ( !a2 )
{
v4 = (double)v3 * 1.2;
if ( COERCE_DOUBLE(*(_QWORD *)&v4 & LC2) < 4.503599627370496e15 )
{
v6.m128d_f64[0] = (double)v3 * 1.2;
v7.m128d_f64[0] = (double)(int)v4;
*(_QWORD *)&v4 = COERCE_UNSIGNED_INT64(v7.m128d_f64[0] + COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v6, v7) & LC3)) | ~LC2 & *(_QWORD *)&v4;
}
v2 = (int)v4;
}
if ( v2 <= v3 )
return 1LL;
v8 = realloc(*(void **)(a1 + 16), *(_DWORD *)(a1 + 8) * v2);
if ( !v8 )
return 1LL;
*(_QWORD *)(a1 + 16) = v8;
result = 0LL;
*(_DWORD *)a1 = v2;
return result;
}

original_code:
uint8_t expand(
  graph_t *g,
  array_t *thislevel,
  array_t *nextlevel,
  uint8_t *visited,
  void *context,
  uint8_t (*callback) (
    expand_state_t *state,
    void *context
  ))
{
  uint32_t i;
  uint32_t j;
  uint32_t ni;
  uint32_t nneighbours;
  uint32_t *neighbours;
  expand_state_t state;
  neighbours = ((void *)0);
  for (i = 0; i < thislevel->size; i++) {
    array_get(thislevel, i, &ni);
    nneighbours = graph_num_neighbours(g, ni);
    neighbours = graph_get_neighbours(g, ni);
    for (j = 0; j < nneighbours; j++) {
      if (callback != ((void *)0)) {
        array_get(thislevel, i, &(state.parent));
        state.child = neighbours[j];
        state.visited = visited[neighbours[j]];
        if (callback(&state, context)) {
          i = thislevel->size;
          return 1;
        }
      }
      if (!visited[neighbours[j]]) {
        array_append(nextlevel, &(neighbours[j]));
        visited[neighbours[j]] = 1;
      }
    }
  }
  return 0;
}

canonical_original_code:
unsigned char expand(struct _graph *g, struct _array *thislevel, struct _array *nextlevel, unsigned char *visited, void *context, unsigned char (*callback)(struct _expand_state *state, void *context))
{
  unsigned int i;
  unsigned int j;
  unsigned int ni;
  unsigned int nneighbours;
  unsigned int *neighbours;
  struct _expand_state state;
  neighbours = ((void *)0);
  for (i = 0; i < thislevel->size; i++) {
    array_get(thislevel, i, &ni);
    nneighbours = graph_num_neighbours(g, ni);
    neighbours = graph_get_neighbours(g, ni);
    for (j = 0; j < nneighbours; j++) {
      if (callback != ((void *)0)) {
        array_get(thislevel, i, &(state.parent));
        state.child = neighbours[j];
        state.visited = visited[neighbours[j]];
        if (callback(&state, context)) {
          i = thislevel->size;
          return 1;
        }
      }
      if (!visited[neighbours[j]]) {
        array_append(nextlevel, &(neighbours[j]));
        visited[neighbours[j]] = 1;
      }
    }
  }
  return 0;
}

variable_types:
thislevel
struct _array *

variable_types:
nextlevel
struct _array *

variable_types:
context
void *

variable_types:
i
unsigned int

variable_types:
j
unsigned int

variable_types:
ni
unsigned int

variable_types:
nneighbours
unsigned int

variable_types:
neighbours
unsigned int *

variable_types: struct _expand_state { unsigned int parent; unsigned int child; unsigned char visited; }