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


repo: pauldmccarthy/ccnet

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

return_type: double

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


decompiled_code:
__int64 __fastcall stats_cache_node_clustering(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

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

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

variable_types:
nnodes
unsigned int

return_type: unsigned char

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


decompiled_code:
__int64 __fastcall 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 int v4; // er13
char v5; // al
__int64 v6; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

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

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
char v6; // al
__int64 result; // rax
_DWORD *v8; // rax
_DWORD *v9; // r13

v5 = graph_num_nodes();
v6 = stats_cache_check(a1, 20LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v6 == 1 )
return 0LL;
if ( a2 < v5 )
{
v8 = calloc(v5, 4uLL);
v9 = v8;
if ( v8 )
{
stats_num_components(a1, 1LL, 0LL, v8, a4);
*a3 = v9[a2];
free(v9);
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
char v6; // al
__int64 result; // rax
_DWORD *v8; // rax
_DWORD *v9; // r13

v5 = graph_num_nodes();
v6 = stats_cache_check(a1, 20LL, (unsigned int)a2, -1LL, a3);
if ( !a3 || v6 == 1 )
return 0LL;
if ( a2 < v5 )
{
v8 = calloc(v5, 4uLL);
v9 = v8;
if ( v8 )
{
stats_num_components(a1, 1LL, 0LL, v8, a4);
*a3 = v9[a2];
free(v9);
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 int v4; // er13
char v5; // al
__int64 v6; // rbx

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

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

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

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 v2; // rbx
unsigned int v3; // er12
unsigned int v4; // er14
_DWORD *v5; // r13
__int64 i; // rbx
double v8[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = stats_cache_check(a1, 10LL, 0LL, -1LL, v8);
v2 = v8[0];
if ( v1 != 1 )
{
v3 = graph_num_nodes(a1);
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);
}
v2 = stats_modularity(a1, v4, v5);
free(v5);
}
else
{
v2 = *(double *)&LC0;
}
}
return v2;
}

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

v1 = stats_cache_check(a1, 10LL, 0LL, -1LL, v8);
v2 = v8[0];
if ( v1 != 1 )
{
v3 = graph_num_nodes(a1);
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);
}
v2 = stats_modularity(a1, v4, v5);
free(v5);
}
else
{
v2 = *(double *)&LC0;
}
}
return v2;
}

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:
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)
{
char v1; // al
double result; // xmm0_8
__int64 v3[2]; // [rsp+8h] [rbp-10h] BYREF

v1 = stats_cache_check(a1, 12LL, 0LL, -1LL, v3);
result = *(double *)v3;
if ( v1 != 1 )
{
stats_num_intra_edges(a1, v3, *(double *)v3);
result = *(double *)v3;
}
return result;
}

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

v1 = stats_cache_check(a1, 12LL, 0LL, -1LL, v3);
result = *(double *)v3;
if ( v1 != 1 )
{
stats_num_intra_edges(a1, v3, *(double *)v3);
result = *(double *)v3;
}
return result;
}

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 v2; // rbx
unsigned int v3; // er12
unsigned int v4; // er14
_DWORD *v5; // r13
__int64 i; // rbx
double v8[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = stats_cache_check(a1, 14LL, 0LL, -1LL, v8);
v2 = v8[0];
if ( v1 != 1 )
{
v3 = graph_num_nodes(a1);
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);
}
v2 = stats_chira(a1, v4, v5);
free(v5);
}
else
{
v2 = *(double *)&LC0;
}
}
return v2;
}

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

v1 = stats_cache_check(a1, 14LL, 0LL, -1LL, v8);
v2 = v8[0];
if ( v1 != 1 )
{
v3 = graph_num_nodes(a1);
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);
}
v2 = stats_chira(a1, v4, v5);
free(v5);
}
else
{
v2 = *(double *)&LC0;
}
}
return v2;
}

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

variable_types:
nnodes
unsigned int


decompiled_code:
__int64 __fastcall stats_cache_betweenness_centrality(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

v4 = graph_num_nodes(a1);
v5 = stats_cache_check(a1, 18LL, (unsigned int)a2, -1LL, a3);
if ( a3 && v5 != 1 )
{
if ( v4 > a2 )
{
*a3 = stats_betweenness_centrality(a1, (unsigned int)a2);
}
else
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_betweenness_centrality(a1, (unsigned int)v6);
++v6;
}
while ( v4 != v6 );
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

v4 = graph_num_nodes(a1);
v5 = stats_cache_check(a1, 18LL, (unsigned int)a2, -1LL, a3);
if ( a3 && v5 != 1 )
{
if ( v4 > a2 )
{
*a3 = stats_betweenness_centrality(a1, (unsigned int)a2);
}
else
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_betweenness_centrality(a1, (unsigned int)v6);
++v6;
}
while ( v4 != v6 );
}
}
}
return 0LL;
}

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)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

v4 = graph_num_nodes(a1);
v5 = stats_cache_check(a1, 19LL, (unsigned int)a2, -1LL, a3);
if ( a3 && v5 != 1 )
{
if ( v4 > a2 )
{
*a3 = stats_numpaths(a1, (unsigned int)a2, 0LL);
}
else
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_numpaths(a1, (unsigned int)v6, 0LL);
++v6;
}
while ( v4 != v6 );
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

v4 = graph_num_nodes(a1);
v5 = stats_cache_check(a1, 19LL, (unsigned int)a2, -1LL, a3);
if ( a3 && v5 != 1 )
{
if ( v4 > a2 )
{
*a3 = stats_numpaths(a1, (unsigned int)a2, 0LL);
}
else
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_numpaths(a1, (unsigned int)v6, 0LL);
++v6;
}
while ( v4 != v6 );
}
}
}
return 0LL;
}

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)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

v4 = graph_num_nodes(a1);
v5 = stats_cache_check(a1, 21LL, (unsigned int)a2, -1LL, a3);
if ( a3 && v5 != 1 )
{
if ( v4 > a2 )
{
*a3 = stats_avg_edge_distance(a1, (unsigned int)a2);
}
else
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_avg_edge_distance(a1, (unsigned int)v6);
++v6;
}
while ( v4 != v6 );
}
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1, unsigned __int64 a2, double *a3)
{
unsigned int v4; // er13
char v5; // al
__int64 v6; // rbx

v4 = graph_num_nodes(a1);
v5 = stats_cache_check(a1, 21LL, (unsigned int)a2, -1LL, a3);
if ( a3 && v5 != 1 )
{
if ( v4 > a2 )
{
*a3 = stats_avg_edge_distance(a1, (unsigned int)a2);
}
else
{
v6 = 0LL;
if ( v4 )
{
do
{
a3[v6] = stats_avg_edge_distance(a1, (unsigned int)v6);
++v6;
}
while ( v4 != v6 );
}
}
}
return 0LL;
}

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)
{
int v5; // er14
__int64 v6; // r15
__int64 i; // rbx

if ( (unsigned __int8)stats_cache_check(a1, 24LL, a2, -1LL, a3) != 1 )
{
v5 = 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)
{
int v5; // er14
__int64 v6; // r15
__int64 i; // rbx

if ( (unsigned __int8)stats_cache_check(a1, 24LL, a2, -1LL, a3) != 1 )
{
v5 = 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

return_type: int


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

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

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

result = 1LL;
if ( *a1 <= *a2 )
result = (unsigned int)-(*a1 != *a2);
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

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

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

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

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; // edx
__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; // edx
__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

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


decompiled_code:
bool __fastcall array_create(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // edi
void *v5; // rax

v4 = 2;
if ( a3 >= 2 )
v4 = a3;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)a1 = v4;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
v5 = calloc(v4, a2);
*(_QWORD *)(a1 + 16) = v5;
return v5 == 0LL;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // edi
void *v5; // rax

v4 = 2;
if ( a3 >= 2 )
v4 = a3;
*(_DWORD *)(a1 + 4) = 0;
*(_DWORD *)(a1 + 8) = a2;
*(_DWORD *)a1 = v4;
*(_QWORD *)(a1 + 24) = 0LL;
*(_QWORD *)(a1 + 32) = 0LL;
v5 = calloc(v4, a2);
*(_QWORD *)(a1 + 16) = v5;
return v5 == 0LL;
}

original_code:
uint8_t array_create(array_t *array, uint32_t datasz, uint32_t capacity) {
  if (capacity < 2) capacity = 2;
  array->size = 0;
  array->datasz = datasz;
  array->capacity = capacity;
  array->cmp = ((void *)0);
  array->cmpins = ((void *)0);
  array->data = calloc(capacity, datasz);
  if (array->data == ((void *)0)) goto fail;
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char array_create(struct _array *array, unsigned int datasz, unsigned int capacity) {
  if (capacity < 2) capacity = 2;
  array->size = 0;
  array->datasz = datasz;
  array->capacity = capacity;
  array->cmp = ((void *)0);
  array->cmpins = ((void *)0);
  array->data = calloc(capacity, datasz);
  if (array->data == ((void *)0)) goto fail;
  return 0;
fail:
  return 1;
}

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

variable_types:
datasz
unsigned int

variable_types:
capacity
unsigned int


original_code:
void array_set_cmps(
  array_t *array,
  int (*cmp) (const void *a, const void *b),
  int (*cmpins)(const void *a, const void *b)
) {
  if (array == ((void *)0)) return;
  array->cmp = cmp;
  array->cmpins = cmpins;
}

canonical_original_code:
void array_set_cmps(struct _array *array, int (*cmp)(void *a, void *b), int (*cmpins)(void *a, void *b)) {
  if (array == ((void *)0)) return;
  array->cmp = cmp;
  array->cmpins = cmpins;
}

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

variable_types:
cmpins
int (*)(void *a, void *b)

return_type: void


original_code:
void array_free(array_t *array) {
  if (array == ((void *)0)) return;
  if (array->data != ((void *)0)) free(array->data);
  array->capacity = 0;
  array->size = 0;
  array->data = ((void *)0);
  array->cmp = ((void *)0);
  array->cmpins = ((void *)0);
}

canonical_original_code:
void array_free(struct _array *array) {
  if (array == ((void *)0)) return;
  if (array->data != ((void *)0)) free(array->data);
  array->capacity = 0;
  array->size = 0;
  array->data = ((void *)0);
  array->cmp = ((void *)0);
  array->cmpins = ((void *)0);
}


decompiled_code:
void __fastcall array_clear(__int64 a1)
{
if ( a1 )
*(_DWORD *)(a1 + 4) = 0;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
if ( a1 )
*(_DWORD *)(a1 + 4) = 0;
}

original_code:
void array_clear(array_t *array) {
  if (array != ((void *)0)) array->size = 0;
}

canonical_original_code:
void array_clear(struct _array *array) {
  if (array != ((void *)0)) array->size = 0;
}


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

if ( !a1 )
return 1LL;
result = 0LL;
if ( *a1 < a2 )
result = expand((__int64)a1, a2);
return result;
}

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

if ( !a1 )
return 1LL;
result = 0LL;
if ( *a1 < a2 )
result = func0((__int64)a1, a2);
return result;
}

original_code:
uint8_t array_expand(array_t *array, uint32_t capacity) {
  if (array == ((void *)0)) goto fail;
  if (array->capacity >= capacity) return 0;
  return _expand(array, capacity);
fail:
  return 1;
}

canonical_original_code:
unsigned char array_expand(struct _array *array, unsigned int capacity) {
  if (array == ((void *)0)) goto fail;
  if (array->capacity >= capacity) return 0;
  return _expand(array, capacity);
fail:
  return 1;
}


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

result = 1LL;
if ( *(_DWORD *)a1 > a2 )
{
memcpy(a3, (const void *)(*(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * a2), *(unsigned int *)(a1 + 8));
result = 0LL;
}
return result;
}

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

result = 1LL;
if ( *(_DWORD *)a1 > a2 )
{
memcpy(a3, (const void *)(*(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * a2), *(unsigned int *)(a1 + 8));
result = 0LL;
}
return result;
}

original_code:
uint8_t array_get(array_t *array, uint32_t idx, void *data) {
  if (idx >= array->capacity) return 1;
  memcpy(data, (array->data)+(idx*(array->datasz)), array->datasz);
  return 0;
}

canonical_original_code:
unsigned char array_get(struct _array *array, unsigned int idx, void *data) {
  if (idx >= array->capacity) return 1;
  memcpy(data, (array->data)+(idx*(array->datasz)), array->datasz);
  return 0;
}

variable_types:
idx
unsigned int

variable_types:
data
void *


decompiled_code:
__int64 __fastcall array_getd(__int64 a1, unsigned int a2)
{
__int64 result; // rax

if ( *(_DWORD *)a1 <= a2 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * a2;
return result;
}

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

if ( *(_DWORD *)a1 <= a2 )
result = 0LL;
else
result = *(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * a2;
return result;
}

original_code:
void * array_getd(array_t *array, uint32_t idx) {
  if (idx >= array->capacity) return ((void *)0);
  return (array->data)+(idx*(array->datasz));
}

canonical_original_code:
void *array_getd(struct _array *array, unsigned int idx) {
  if (idx >= array->capacity) return ((void *)0);
  return (array->data)+(idx*(array->datasz));
}


decompiled_code:
void *__fastcall array_set(__int64 a1, unsigned int a2, const void *a3)
{
void *result; // rax

if ( *(_DWORD *)a1 > a2 )
{
result = memcpy((void *)(*(_QWORD *)(a1 + 16) + a2 * *(_DWORD *)(a1 + 8)), a3, *(unsigned int *)(a1 + 8));
if ( *(_DWORD *)(a1 + 4) <= a2 )
*(_DWORD *)(a1 + 4) = a2 + 1;
}
return result;
}

canonical_decompiled_code:
void *__fastcall func8(__int64 a1, unsigned int a2, const void *a3)
{
void *result; // rax

if ( *(_DWORD *)a1 > a2 )
{
result = memcpy((void *)(*(_QWORD *)(a1 + 16) + a2 * *(_DWORD *)(a1 + 8)), a3, *(unsigned int *)(a1 + 8));
if ( *(_DWORD *)(a1 + 4) <= a2 )
*(_DWORD *)(a1 + 4) = a2 + 1;
}
return result;
}

original_code:
void array_set(array_t *array, uint32_t idx, void *value) {
  if (idx >= array->capacity) return;
  memcpy(array->data + (idx*(array->datasz)), value, array->datasz);
  if (idx >= array->size) array->size = idx+1;
}

canonical_original_code:
void array_set(struct _array *array, unsigned int idx, void *value) {
  if (idx >= array->capacity) return;
  memcpy(array->data + (idx*(array->datasz)), value, array->datasz);
  if (idx >= array->size) array->size = idx+1;
}

variable_types:
value
void *


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

if ( a2 )
{
if ( a1 )
result = memcpy(*(void **)(a1 + 16), a2, (unsigned int)(*(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 4)));
}
return result;
}

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

if ( a2 )
{
if ( a1 )
result = memcpy(*(void **)(a1 + 16), a2, (unsigned int)(*(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 4)));
}
return result;
}

original_code:
void array_set_all(array_t *array, void *value) {
  if (array == ((void *)0)) return;
  if (value == ((void *)0)) return;
  memcpy(array->data, value, (array->size) * (array->datasz));
}

canonical_original_code:
void array_set_all(struct _array *array, void *value) {
  if (array == ((void *)0)) return;
  if (value == ((void *)0)) return;
  memcpy(array->data, value, (array->size) * (array->datasz));
}


decompiled_code:
__int64 __fastcall array_find(__int64 a1, const void *a2, char a3)
{
int (*v3)(const void *, const void *); // r8
size_t v4; // rax
void *v5; // rax
__int64 result; // rax
size_t nmemb[2]; // [rsp+0h] [rbp-10h] BYREF

if ( !a2 )
return -1LL;
if ( !a1 )
return -1LL;
v3 = *(int (**)(const void *, const void *))(a1 + 24);
if ( !v3 )
return -1LL;
v4 = *(unsigned int *)(a1 + 4);
nmemb[0] = v4;
if ( a3 )
v5 = bsearch(a2, *(const void **)(a1 + 16), v4, *(unsigned int *)(a1 + 8), v3);
else
v5 = lfind(a2, *(const void **)(a1 + 16), nmemb, *(unsigned int *)(a1 + 8), v3);
if ( v5 )
result = ((__int64)v5 - *(_QWORD *)(a1 + 16)) / *(unsigned int *)(a1 + 8);
else
result = -1LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const void *a2, char a3)
{
int (*v3)(const void *, const void *); // r8
size_t v4; // rax
void *v5; // rax
__int64 result; // rax
size_t nmemb[2]; // [rsp+0h] [rbp-10h] BYREF

if ( !a2 )
return -1LL;
if ( !a1 )
return -1LL;
v3 = *(int (**)(const void *, const void *))(a1 + 24);
if ( !v3 )
return -1LL;
v4 = *(unsigned int *)(a1 + 4);
nmemb[0] = v4;
if ( a3 )
v5 = bsearch(a2, *(const void **)(a1 + 16), v4, *(unsigned int *)(a1 + 8), v3);
else
v5 = lfind(a2, *(const void **)(a1 + 16), nmemb, *(unsigned int *)(a1 + 8), v3);
if ( v5 )
result = ((__int64)v5 - *(_QWORD *)(a1 + 16)) / *(unsigned int *)(a1 + 8);
else
result = -1LL;
return result;
}

original_code:
int64_t array_find(array_t *a, void *val, uint8_t is_sorted) {
  uint8_t *elem;
  size_t sz;
  if (a == ((void *)0)) return -1;
  if (val == ((void *)0)) return -1;
  if (a->cmp == ((void *)0)) return -1;
  sz = a->size;
  if (is_sorted) elem = bsearch(val, a->data, a->size, a->datasz, a->cmp);
  else elem = lfind( val, a->data, &sz, a->datasz, a->cmp);
  if (elem == ((void *)0)) return -1;
  return (elem - a->data) / a->datasz;
}

canonical_original_code:
long array_find(struct _array *a, void *val, unsigned char is_sorted) {
  unsigned char *elem;
  unsigned long sz;
  if (a == ((void *)0)) return -1;
  if (val == ((void *)0)) return -1;
  if (a->cmp == ((void *)0)) return -1;
  sz = a->size;
  if (is_sorted) elem = bsearch(val, a->data, a->size, a->datasz, a->cmp);
  else elem = lfind( val, a->data, &sz, a->datasz, a->cmp);
  if (elem == ((void *)0)) return -1;
  return (elem - a->data) / a->datasz;
}

variable_types:
val
void *

variable_types:
elem
unsigned char *

variable_types:
sz
unsigned long

return_type: long


original_code:
uint32_t array_count(array_t *array, void *value) {
  uint64_t i;
  uint32_t count;
  void *value2;
  if (array == ((void *)0)) return 0;
  if (array->cmp == ((void *)0)) return 0;
  count = 0;
  for (i = 0; i < array->size; i++) {
    value2 = array->data + i*(array->datasz);
    if (array->cmp(value, value2) == 0) count++;
  }
  return count;
}

canonical_original_code:
unsigned int array_count(struct _array *array, void *value) {
  unsigned long i;
  unsigned int count;
  void *value2;
  if (array == ((void *)0)) return 0;
  if (array->cmp == ((void *)0)) return 0;
  count = 0;
  for (i = 0; i < array->size; i++) {
    value2 = array->data + i*(array->datasz);
    if (array->cmp(value, value2) == 0) count++;
  }
  return count;
}

variable_types:
i
unsigned long

variable_types:
count
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall array_append(_DWORD *a1, const void *a2)
{
__int64 result; // rax
char v3; // dl

if ( !a1 )
return 1LL;
if ( a1[1] != *a1 || (v3 = expand((__int64)a1, 0), result = 1LL, !v3) )
{
array_set((__int64)a1, a1[1], a2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1, const void *a2)
{
__int64 result; // rax
char v3; // dl

if ( !a1 )
return 1LL;
if ( a1[1] != *a1 || (v3 = func0((__int64)a1, 0), result = 1LL, !v3) )
{
func8((__int64)a1, a1[1], a2);
result = 0LL;
}
return result;
}

original_code:
uint8_t array_append(array_t *array, void *value) {
  if (array == ((void *)0)) goto fail;
  if (array->size == array->capacity) {
    if (_expand(array, 0)) goto fail;
  }
  array_set(array, array->size, value);
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char array_append(struct _array *array, void *value) {
  if (array == ((void *)0)) goto fail;
  if (array->size == array->capacity) {
    if (_expand(array, 0)) goto fail;
  }
  array_set(array, array->size, value);
  return 0;
fail:
  return 1;
}


decompiled_code:
__int64 __fastcall array_insert(__int64 a1, unsigned int a2, const void *a3)
{
__int64 result; // rax
unsigned int v5; // edx
char v6; // dl

if ( !a3 )
return 1LL;
if ( !a1 )
return 1LL;
if ( *(_DWORD *)(a1 + 4) != *(_DWORD *)a1 || (v6 = expand(a1, 0), result = 1LL, !v6) )
{
result = 1LL;
if ( *(_DWORD *)a1 > a2 )
{
v5 = *(_DWORD *)(a1 + 4);
if ( v5 > a2 )
{
memmove(
(void *)(*(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) + a2 * *(_DWORD *)(a1 + 8)),
(const void *)(*(_QWORD *)(a1 + 16) + a2 * *(_DWORD *)(a1 + 8)),
*(_DWORD *)(a1 + 8) * (v5 - a2));
++*(_DWORD *)(a1 + 4);
}
array_set(a1, a2, a3);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2, const void *a3)
{
__int64 result; // rax
unsigned int v5; // edx
char v6; // dl

if ( !a3 )
return 1LL;
if ( !a1 )
return 1LL;
if ( *(_DWORD *)(a1 + 4) != *(_DWORD *)a1 || (v6 = func0(a1, 0), result = 1LL, !v6) )
{
result = 1LL;
if ( *(_DWORD *)a1 > a2 )
{
v5 = *(_DWORD *)(a1 + 4);
if ( v5 > a2 )
{
memmove(
(void *)(*(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) + a2 * *(_DWORD *)(a1 + 8)),
(const void *)(*(_QWORD *)(a1 + 16) + a2 * *(_DWORD *)(a1 + 8)),
*(_DWORD *)(a1 + 8) * (v5 - a2));
++*(_DWORD *)(a1 + 4);
}
func8(a1, a2, a3);
result = 0LL;
}
}
return result;
}

original_code:
uint8_t array_insert(array_t *array, uint32_t idx, void *val) {
  uint8_t *src;
  uint8_t *dst;
  uint32_t sz;
  if (array == ((void *)0)) goto fail;
  if (val == ((void *)0)) goto fail;
  if (array->size == array->capacity) {
    if (_expand(array, 0)) goto fail;
  }
  if (idx >= array->capacity) goto fail;
  if (idx < array->size) {
    sz = (array->size - idx) * (array->datasz);
    src = array->data + idx * (array->datasz);
    dst = array->data + (idx+1) * (array->datasz);
    memmove(dst, src, sz);
    array->size ++;
  }
  array_set(array, idx, val);
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char array_insert(struct _array *array, unsigned int idx, void *val) {
  unsigned char *src;
  unsigned char *dst;
  unsigned int sz;
  if (array == ((void *)0)) goto fail;
  if (val == ((void *)0)) goto fail;
  if (array->size == array->capacity) {
    if (_expand(array, 0)) goto fail;
  }
  if (idx >= array->capacity) goto fail;
  if (idx < array->size) {
    sz = (array->size - idx) * (array->datasz);
    src = array->data + idx * (array->datasz);
    dst = array->data + (idx+1) * (array->datasz);
    memmove(dst, src, sz);
    array->size ++;
  }
  array_set(array, idx, val);
  return 0;
fail:
  return 1;
}

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types:
sz
unsigned int


decompiled_code:
__int64 __fastcall array_insert_sorted(__int64 a1, const void *a2, char a3, _DWORD *a4)
{
char v4; // r15
__int64 v7; // rbp
__int64 v8; // rax
__int64 result; // rax
int v10; // eax

if ( !a1 )
return 2LL;
v4 = a3;
if ( *(_QWORD *)(a1 + 24) )
{
if ( !a4 )
goto LABEL_5;
}
else
{
if ( !*(_QWORD *)(a1 + 32) )
return 2LL;
if ( !a4 )
goto LABEL_10;
}
*a4 = 0;
LABEL_5:
if ( !*(_QWORD *)(a1 + 32) )
{
v7 = 0LL;
if ( *(_DWORD *)(a1 + 4) )
{
while ( 1 )
{
v10 = (*(__int64 (__fastcall **)(const void *, __int64))(a1 + 24))(
a2,
*(_QWORD *)(a1 + 16) + v7 * *(unsigned int *)(a1 + 8));
if ( v10 < 0 )
break;
if ( !v10 && a3 )
goto LABEL_13;
if ( *(unsigned int *)(a1 + 4) <= ++v7 )
goto LABEL_25;
}
}
goto LABEL_25;
}
LABEL_10:
v8 = bsearch_insert(a2, *(_QWORD *)(a1 + 16), *(unsigned int *)(a1 + 4), *(unsigned int *)(a1 + 8));
if ( !v8 )
{
LODWORD(v7) = 0;
LABEL_25:
result = array_insert(a1, v7, a2);
if ( (_BYTE)result )
return 2LL;
if ( a4 )
*a4 = v7;
return result;
}
LODWORD(v7) = (v8 - *(_QWORD *)(a1 + 16)) / *(unsigned int *)(a1 + 8) + 1;
if ( (*(unsigned int (__fastcall **)(const void *, __int64, __int64))(a1 + 24))(
a2,
v8,
(v8 - *(_QWORD *)(a1 + 16)) % *(unsigned int *)(a1 + 8))
|| !v4 )
{
goto LABEL_25;
}
LABEL_13:
result = 1LL;
if ( a4 )
*a4 = v7 - 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const void *a2, char a3, _DWORD *a4)
{
char v4; // r15
__int64 v7; // rbp
__int64 v8; // rax
__int64 result; // rax
int v10; // eax

if ( !a1 )
return 2LL;
v4 = a3;
if ( *(_QWORD *)(a1 + 24) )
{
if ( !a4 )
goto LABEL_5;
}
else
{
if ( !*(_QWORD *)(a1 + 32) )
return 2LL;
if ( !a4 )
goto LABEL_10;
}
*a4 = 0;
LABEL_5:
if ( !*(_QWORD *)(a1 + 32) )
{
v7 = 0LL;
if ( *(_DWORD *)(a1 + 4) )
{
while ( 1 )
{
v10 = (*(__int64 (__fastcall **)(const void *, __int64))(a1 + 24))(
a2,
*(_QWORD *)(a1 + 16) + v7 * *(unsigned int *)(a1 + 8));
if ( v10 < 0 )
break;
if ( !v10 && a3 )
goto LABEL_13;
if ( *(unsigned int *)(a1 + 4) <= ++v7 )
goto LABEL_25;
}
}
goto LABEL_25;
}
LABEL_10:
v8 = bsearch_insert(a2, *(_QWORD *)(a1 + 16), *(unsigned int *)(a1 + 4), *(unsigned int *)(a1 + 8));
if ( !v8 )
{
LODWORD(v7) = 0;
LABEL_25:
result = func13(a1, v7, a2);
if ( (_BYTE)result )
return 2LL;
if ( a4 )
*a4 = v7;
return result;
}
LODWORD(v7) = (v8 - *(_QWORD *)(a1 + 16)) / *(unsigned int *)(a1 + 8) + 1;
if ( (*(unsigned int (__fastcall **)(const void *, __int64, __int64))(a1 + 24))(
a2,
v8,
(v8 - *(_QWORD *)(a1 + 16)) % *(unsigned int *)(a1 + 8))
|| !v4 )
{
goto LABEL_25;
}
LABEL_13:
result = 1LL;
if ( a4 )
*a4 = v7 - 1;
return result;
}

original_code:
uint8_t array_insert_sorted(
  array_t *a, void *val, uint8_t unique, uint32_t *idx) {
  int64_t i;
  int cmpval;
  uint8_t *elem;
  cmpval = 1;
  if ( a == ((void *)0)) goto fail;
  if ( a->cmp == ((void *)0)
    && a->cmpins == ((void *)0)) goto fail;
  if (idx != ((void *)0)) *idx = 0;
  if (a->cmpins) {
    elem = bsearch_insert(val, a->data, a->size, a->datasz, a->cmpins);
    if (elem == ((void *)0)) {
      i = 0;
      cmpval = -1;
    }
    else {
      i = ((elem - a->data) / a->datasz) + 1;
      cmpval = a->cmp(val, elem);
    }
  }
  else {
    for (i = 0; i < a->size; i++) {
      elem = a->data + i*(a->datasz);
      cmpval = a->cmp(val, elem);
      if (cmpval < 0) break;
      if (cmpval == 0 && unique) break;
    }
  }
  if (cmpval == 0 && unique) {
    if (idx != ((void *)0)) (*idx) = i - 1;
    return 1;
  }
  if (array_insert(a, i, val)) goto fail;
  if (idx != ((void *)0)) *idx = i;
  return 0;
fail:
  return 2;
}

canonical_original_code:
unsigned char array_insert_sorted(struct _array *a, void *val, unsigned char unique, unsigned int *idx) {
  long i;
  int cmpval;
  unsigned char *elem;
  cmpval = 1;
  if ( a == ((void *)0)) goto fail;
  if ( a->cmp == ((void *)0)
    && a->cmpins == ((void *)0)) goto fail;
  if (idx != ((void *)0)) *idx = 0;
  if (a->cmpins) {
    elem = bsearch_insert(val, a->data, a->size, a->datasz, a->cmpins);
    if (elem == ((void *)0)) {
      i = 0;
      cmpval = -1;
    }
    else {
      i = ((elem - a->data) / a->datasz) + 1;
      cmpval = a->cmp(val, elem);
    }
  }
  else {
    for (i = 0; i < a->size; i++) {
      elem = a->data + i*(a->datasz);
      cmpval = a->cmp(val, elem);
      if (cmpval < 0) break;
      if (cmpval == 0 && unique) break;
    }
  }
  if (cmpval == 0 && unique) {
    if (idx != ((void *)0)) (*idx) = i - 1;
    return 1;
  }
  if (array_insert(a, i, val)) goto fail;
  if (idx != ((void *)0)) *idx = i;
  return 0;
fail:
  return 2;
}

variable_types:
unique
unsigned char

variable_types:
idx
unsigned int *

variable_types: i long

variable_types: cmpval int


decompiled_code:
void __fastcall array_sort(__int64 a1)
{
int (*v1)(const void *, const void *); // rcx

if ( a1 )
{
v1 = *(int (**)(const void *, const void *))(a1 + 24);
if ( v1 )
qsort(*(void **)(a1 + 16), *(unsigned int *)(a1 + 4), *(unsigned int *)(a1 + 8), v1);
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1)
{
int (*v1)(const void *, const void *); // rcx

if ( a1 )
{
v1 = *(int (**)(const void *, const void *))(a1 + 24);
if ( v1 )
qsort(*(void **)(a1 + 16), *(unsigned int *)(a1 + 4), *(unsigned int *)(a1 + 8), v1);
}
}

original_code:
void array_sort(array_t *array) {
  if (array == ((void *)0)) return;
  if (array->cmp == ((void *)0)) return;
  qsort(array->data, array->size, array->datasz, array->cmp);
}

canonical_original_code:
void array_sort(struct _array *array) {
  if (array == ((void *)0)) return;
  if (array->cmp == ((void *)0)) return;
  qsort(array->data, array->size, array->datasz, array->cmp);
}

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


decompiled_code:
void *__fastcall array_remove_by_idx(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx
int v3; // er8
__int64 v4; // rcx
void *result; // rax

if ( a1 )
{
v2 = *(_DWORD *)(a1 + 4);
if ( v2 > a2 )
{
v3 = *(_DWORD *)(a1 + 8);
v4 = *(_QWORD *)(a1 + 16);
*(_DWORD *)(a1 + 4) = v2 - 1;
result = memmove((void *)(v4 + v3 * (a2 + 1) - v3), (const void *)(v4 + v3 * (a2 + 1)), v3 * (v2 - a2));
}
}
return result;
}

canonical_decompiled_code:
void *__fastcall func16(__int64 a1, unsigned int a2)
{
unsigned int v2; // edx
int v3; // er8
__int64 v4; // rcx
void *result; // rax

if ( a1 )
{
v2 = *(_DWORD *)(a1 + 4);
if ( v2 > a2 )
{
v3 = *(_DWORD *)(a1 + 8);
v4 = *(_QWORD *)(a1 + 16);
*(_DWORD *)(a1 + 4) = v2 - 1;
result = memmove((void *)(v4 + v3 * (a2 + 1) - v3), (const void *)(v4 + v3 * (a2 + 1)), v3 * (v2 - a2));
}
}
return result;
}

original_code:
void array_remove_by_idx(array_t *array, uint32_t idx) {
  uint8_t *src;
  uint8_t *dst;
  uint32_t sz;
  if (array == ((void *)0)) return;
  if (idx >= array->size) return;
  sz = (array->size - idx) * (array->datasz);
  src = array->data + (idx+1) * (array->datasz);
  dst = array->data + idx * (array->datasz);
  array->size --;
  memmove(dst, src, sz);
}

canonical_original_code:
void array_remove_by_idx(struct _array *array, unsigned int idx) {
  unsigned char *src;
  unsigned char *dst;
  unsigned int sz;
  if (array == ((void *)0)) return;
  if (idx >= array->size) return;
  sz = (array->size - idx) * (array->datasz);
  src = array->data + (idx+1) * (array->datasz);
  dst = array->data + idx * (array->datasz);
  array->size --;
  memmove(dst, src, sz);
}


decompiled_code:
__int64 __fastcall array_remove_by_val(__int64 a1, const void *a2, char a3)
{
unsigned int v3; // eax
unsigned int v4; // ebx

v3 = array_find(a1, a2, a3);
if ( v3 == -1 )
return -1LL;
v4 = v3;
array_remove_by_idx(a1, v3);
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, const void *a2, char a3)
{
unsigned int v3; // eax
unsigned int v4; // ebx

v3 = func10(a1, a2, a3);
if ( v3 == -1 )
return -1LL;
v4 = v3;
func16(a1, v3);
return v4;
}

original_code:
int64_t array_remove_by_val(array_t *array, void *val, uint8_t is_sorted) {
  uint32_t idx;
  idx = array_find(array, val, is_sorted);
  if (idx == -1) return -1;
  array_remove_by_idx(array, idx);
  return idx;
}

canonical_original_code:
long array_remove_by_val(struct _array *array, void *val, unsigned char is_sorted) {
  unsigned int idx;
  idx = array_find(array, val, is_sorted);
  if (idx == -1) return -1;
  array_remove_by_idx(array, idx);
  return idx;
}


decompiled_code:
__int64 __fastcall graph_mask(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // ebx
unsigned int v6; // eax
__int64 v7[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v8; // [rsp+10h] [rbp-38h]
__int64 v9; // [rsp+18h] [rbp-30h]
__int64 v10; // [rsp+20h] [rbp-28h]

v7[0] = 0LL;
v7[1] = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
if ( !(unsigned __int8)array_create(v7, 8LL, 100LL)
&& (v6 = graph_num_nodes(a1), !(unsigned __int8)create_node_mapping((__int64)v7, a3, v6))
&& !(unsigned __int8)graph_create(a2, HIDWORD(v7[0]), 0LL)
&& !(unsigned __int8)copy_nodelabels(a1, a2, (__int64)v7)
&& (v4 = copy_edges(a1, a2, (__int64)v7), !(_BYTE)v4)
|| (v4 = 1, v8) )
{
array_free(v7);
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
unsigned int v4; // ebx
unsigned int v6; // eax
__int64 v7[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v8; // [rsp+10h] [rbp-38h]
__int64 v9; // [rsp+18h] [rbp-30h]
__int64 v10; // [rsp+20h] [rbp-28h]

v7[0] = 0LL;
v7[1] = 0LL;
v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
if ( !(unsigned __int8)array_create(v7, 8LL, 100LL)
&& (v6 = graph_num_nodes(a1), !(unsigned __int8)func0((__int64)v7, a3, v6))
&& !(unsigned __int8)graph_create(a2, HIDWORD(v7[0]), 0LL)
&& !(unsigned __int8)func1(a1, a2, (__int64)v7)
&& (v4 = func2(a1, a2, (__int64)v7), !(_BYTE)v4)
|| (v4 = 1, v8) )
{
array_free(v7);
}
return v4;
}

original_code:
uint8_t graph_mask(graph_t *gin, graph_t *gout, uint8_t *mask) {
  array_t nodemap;
  memset(&nodemap, 0, sizeof(nodemap));
  if (array_create(&nodemap, sizeof(nodemap_t), 100)) goto fail;
  if (_create_node_mapping(&nodemap, mask, graph_num_nodes(gin))) goto fail;
  if (graph_create(gout, nodemap.size, 0)) goto fail;
  if (_copy_nodelabels(gin, gout, &nodemap)) goto fail;
  if (_copy_edges(gin, gout, &nodemap)) goto fail;
  array_free(&nodemap);
  return 0;
fail:
  if (nodemap.data != ((void *)0)) array_free(&nodemap);
  return 1;
}

canonical_original_code:
unsigned char graph_mask(struct _graph *gin, struct _graph *gout, unsigned char *mask) {
  struct _array nodemap;
  memset(&nodemap, 0, sizeof(nodemap));
  if (array_create(&nodemap, sizeof(nodemap_t), 100)) goto fail;
  if (_create_node_mapping(&nodemap, mask, graph_num_nodes(gin))) goto fail;
  if (graph_create(gout, nodemap.size, 0)) goto fail;
  if (_copy_nodelabels(gin, gout, &nodemap)) goto fail;
  if (_copy_edges(gin, gout, &nodemap)) goto fail;
  array_free(&nodemap);
  return 0;
fail:
  if (nodemap.data != ((void *)0)) array_free(&nodemap);
  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:
gout
struct _graph *

variable_types:
mask
unsigned char *


decompiled_code:
__int64 __fastcall graph_remove(__int64 a1, __int64 a2, unsigned int *a3, int a4)
{
unsigned int v6; // eax
_BYTE *v7; // rax
_BYTE *v8; // rbx
unsigned int *v9; // rax
unsigned int v10; // ebp

v6 = graph_num_nodes(a1);
v7 = calloc(v6, 1uLL);
if ( !v7 )
return 1;
v8 = v7;
if ( a4 )
{
v9 = a3;
do
v8[*v9++] = 1;
while ( v9 != &a3[a4] );
}
v10 = graph_mask(a1, a2, (__int64)v8);
free(v8);
return v10;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int *a3, int a4)
{
unsigned int v6; // eax
_BYTE *v7; // rax
_BYTE *v8; // rbx
unsigned int *v9; // rax
unsigned int v10; // ebp

v6 = graph_num_nodes(a1);
v7 = calloc(v6, 1uLL);
if ( !v7 )
return 1;
v8 = v7;
if ( a4 )
{
v9 = a3;
do
v8[*v9++] = 1;
while ( v9 != &a3[a4] );
}
v10 = func3(a1, a2, (__int64)v8);
free(v8);
return v10;
}

original_code:
uint8_t graph_remove(
  graph_t *gin, graph_t *gout, uint32_t *nodes, uint32_t nnodes) {
  uint64_t i;
  uint32_t nginnodes;
  uint8_t *mask;
  uint8_t result;
  mask = ((void *)0);
  nginnodes = graph_num_nodes(gin);
  mask = calloc(nginnodes, sizeof(uint8_t));
  if (mask == ((void *)0)) goto fail;
  for (i = 0; i < nnodes; i++) mask[nodes[i]] = 1;
  result = graph_mask(gin, gout, mask);
  free(mask);
  return result;
fail:
  if (mask != ((void *)0)) free(mask);
  return 1;
}

canonical_original_code:
unsigned char graph_remove(struct _graph *gin, struct _graph *gout, unsigned int *nodes, unsigned int nnodes) {
  unsigned long i;
  unsigned int nginnodes;
  unsigned char *mask;
  unsigned char result;
  mask = ((void *)0);
  nginnodes = graph_num_nodes(gin);
  mask = calloc(nginnodes, sizeof(unsigned char));
  if (mask == ((void *)0)) goto fail;
  for (i = 0; i < nnodes; i++) mask[nodes[i]] = 1;
  result = graph_mask(gin, gout, mask);
  free(mask);
  return result;
fail:
  if (mask != ((void *)0)) free(mask);
  return 1;
}

variable_types:
nodes
unsigned int *

variable_types:
nnodes
unsigned int

variable_types:
nginnodes
unsigned int

variable_types:
result
unsigned char


decompiled_code:
bool __fastcall stack_create(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // edi
void *v5; // rax

v4 = 4;
if ( a3 >= 4 )
v4 = a3;
*(_DWORD *)(a1 + 16) = v4;
*(_DWORD *)(a1 + 12) = a2;
*(_DWORD *)(a1 + 8) = 0;
v5 = calloc(v4, a2);
*(_QWORD *)a1 = v5;
return v5 == 0LL;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
unsigned int v4; // edi
void *v5; // rax

v4 = 4;
if ( a3 >= 4 )
v4 = a3;
*(_DWORD *)(a1 + 16) = v4;
*(_DWORD *)(a1 + 12) = a2;
*(_DWORD *)(a1 + 8) = 0;
v5 = calloc(v4, a2);
*(_QWORD *)a1 = v5;
return v5 == 0LL;
}

original_code:
uint8_t stack_create(cstack_t *stack, uint32_t elemsz, uint32_t capacity) {
  if (capacity < 4) capacity = 4;
  stack->capacity = capacity;
  stack->elemsz = elemsz;
  stack->size = 0;
  stack->data = calloc(capacity, elemsz);
  if (stack->data == ((void *)0)) goto fail;
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char stack_create(struct _stack *stack, unsigned int elemsz, unsigned int capacity) {
  if (capacity < 4) capacity = 4;
  stack->capacity = capacity;
  stack->elemsz = elemsz;
  stack->size = 0;
  stack->data = calloc(capacity, elemsz);
  if (stack->data == ((void *)0)) goto fail;
  return 0;
fail:
  return 1;
}

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

variable_types:
elemsz
unsigned int

variable_types:
capacity
unsigned int


decompiled_code:
void __fastcall stack_free(void **a1)
{
void *v1; // rdi

if ( a1 )
{
v1 = *a1;
if ( v1 )
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func2(void **a1)
{
void *v1; // rdi

if ( a1 )
{
v1 = *a1;
if ( v1 )
free(v1);
}
}

original_code:
void stack_free(cstack_t *stack) {
  if (stack != ((void *)0) && stack->data != ((void *)0))
    free(stack->data);
}

canonical_original_code:
void stack_free(struct _stack *stack) {
  if (stack != ((void *)0) && stack->data != ((void *)0))
    free(stack->data);
}

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


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

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
result = *(_QWORD *)a1 + (unsigned int)(*(_DWORD *)(a1 + 12) * (v1 - 1));
else
result = 0LL;
return result;
}

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

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
if ( v1 )
result = *(_QWORD *)a1 + (unsigned int)(*(_DWORD *)(a1 + 12) * (v1 - 1));
else
result = 0LL;
return result;
}

original_code:
void * stack_peek(cstack_t *stack) {
  void *val;
  uint32_t off;
  if (stack == ((void *)0)) return ((void *)0);
  if (stack->size == 0) return ((void *)0);
  off = (stack->size - 1) * (stack->elemsz);
  val = stack->data + off;
  return val;
}

canonical_original_code:
void *stack_peek(struct _stack *stack) {
  void *val;
  unsigned int off;
  if (stack == ((void *)0)) return ((void *)0);
  if (stack->size == 0) return ((void *)0);
  off = (stack->size - 1) * (stack->elemsz);
  val = stack->data + off;
  return val;
}

variable_types:
val
void *

variable_types:
off
unsigned int


decompiled_code:
__int64 __fastcall stack_pop(__int64 a1)
{
int v1; // ebp
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
result = stack_peek(a1);
*(_DWORD *)(a1 + 8) = v1 - 1;
return result;
}

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

if ( !a1 )
return 0LL;
v1 = *(_DWORD *)(a1 + 8);
if ( !v1 )
return 0LL;
result = func3(a1);
*(_DWORD *)(a1 + 8) = v1 - 1;
return result;
}

original_code:
void * stack_pop(cstack_t *stack) {
  void *val;
  if (stack == ((void *)0)) return ((void *)0);
  if (stack->size == 0) return ((void *)0);
  val = stack_peek(stack);
  stack->size --;
  return val;
}

canonical_original_code:
void *stack_pop(struct _stack *stack) {
  void *val;
  if (stack == ((void *)0)) return ((void *)0);
  if (stack->size == 0) return ((void *)0);
  val = stack_peek(stack);
  stack->size --;
  return val;
}


decompiled_code:
__int64 __fastcall stack_push(__int64 a1, const void *a2)
{
__int64 result; // rax
char v3; // dl

if ( !a1 )
return 1LL;
if ( *(_DWORD *)(a1 + 8) != *(_DWORD *)(a1 + 16) || (v3 = expand(a1, 0), result = 1LL, !v3) )
{
memcpy(
(void *)(*(_QWORD *)a1 + (unsigned int)(*(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 12))),
a2,
*(unsigned int *)(a1 + 12));
++*(_DWORD *)(a1 + 8);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const void *a2)
{
__int64 result; // rax
char v3; // dl

if ( !a1 )
return 1LL;
if ( *(_DWORD *)(a1 + 8) != *(_DWORD *)(a1 + 16) || (v3 = func0(a1, 0), result = 1LL, !v3) )
{
memcpy(
(void *)(*(_QWORD *)a1 + (unsigned int)(*(_DWORD *)(a1 + 8) * *(_DWORD *)(a1 + 12))),
a2,
*(unsigned int *)(a1 + 12));
++*(_DWORD *)(a1 + 8);
result = 0LL;
}
return result;
}

original_code:
uint8_t stack_push(cstack_t *stack, void *elem) {
  uint32_t off;
  if (stack == ((void *)0)) goto fail;
  if (stack->size == stack->capacity) {
    if (_expand(stack, 0)) goto fail;
  }
  off = (stack->size) * (stack->elemsz);
  memcpy(stack->data + off, elem, stack->elemsz);
  stack->size++;
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char stack_push(struct _stack *stack, void *elem) {
  unsigned int off;
  if (stack == ((void *)0)) goto fail;
  if (stack->size == stack->capacity) {
    if (_expand(stack, 0)) goto fail;
  }
  off = (stack->size) * (stack->elemsz);
  memcpy(stack->data + off, elem, stack->elemsz);
  stack->size++;
  return 0;
fail:
  return 1;
}

variable_types:
elem
void *


original_code:
void get_suffix(char *name, char *suf) {
  int64_t i;
  uint32_t len;
  uint32_t suf_len;
  int64_t suf_start;
  if (name == ((void *)0)) return;
  if (suf == ((void *)0)) return;
  suf_start = -1;
  len = strlen(name);
  for (i = len-1; i >= 0; i--) {
    if (name[i] == '.') {
      suf_start = i+1;
      break;
    }
  }
  if (suf_start == -1 || suf_start == len) {
    suf[0] = '\0';
    return;
  }
  suf_len = len - suf_start;
  for (i = 0; i < suf_len; i++)
    suf[i] = name[suf_start + i];
  suf[suf_len] = '\0';
}

canonical_original_code:
void get_suffix(char *name, char *suf) {
  long i;
  unsigned int len;
  unsigned int suf_len;
  long suf_start;
  if (name == ((void *)0)) return;
  if (suf == ((void *)0)) return;
  suf_start = -1;
  len = strlen(name);
  for (i = len-1; i >= 0; i--) {
    if (name[i] == '.') {
      suf_start = i+1;
      break;
    }
  }
  if (suf_start == -1 || suf_start == len) {
    suf[0] = '\0';
    return;
  }
  suf_len = len - suf_start;
  for (i = 0; i < suf_len; i++)
    suf[i] = name[suf_start + i];
  suf[suf_len] = '\0';
}

variable_types:
name
char *

variable_types:
suf
char *

variable_types:
len
unsigned int


decompiled_code:
char *__fastcall join_path(const char *a1, const char *a2)
{
int v2; // ebx
int v3; // eax
char *v4; // rax
char *v5; // rbx

v2 = strlen(a1);
v3 = strlen(a2);
v4 = (char *)malloc((unsigned int)(v2 + v3 + 2));
v5 = v4;
if ( v4 )
sprintf(v4, "%s/%s", a1, a2);
return v5;
}

canonical_decompiled_code:
char *__fastcall func1(const char *a1, const char *a2)
{
int v2; // ebx
int v3; // eax
char *v4; // rax
char *v5; // rbx

v2 = strlen(a1);
v3 = strlen(a2);
v4 = (char *)malloc((unsigned int)(v2 + v3 + 2));
v5 = v4;
if ( v4 )
sprintf(v4, "%s/%s", a1, a2);
return v5;
}

original_code:
char * join_path(char *path, char *name) {
  uint32_t len;
  char *joined;
  joined = ((void *)0);
  len = strlen(path) + strlen(name) + 2;
  joined = malloc(len);
  if (joined == ((void *)0)) goto fail;
  sprintf(joined, "%s/%s", path, name);
  return joined;
fail:
  if (joined != ((void *)0)) free(joined);
  return ((void *)0);
}

canonical_original_code:
char *join_path(char *path, char *name) {
  unsigned int len;
  char *joined;
  joined = ((void *)0);
  len = strlen(path) + strlen(name) + 2;
  joined = malloc(len);
  if (joined == ((void *)0)) goto fail;
  sprintf(joined, "%s/%s", path, name);
  return joined;
fail:
  if (joined != ((void *)0)) free(joined);
  return ((void *)0);
}

variable_types:
path
char *

variable_types:
joined
char *

return_type: char *


dirname

decompiled_code:
char *__fastcall dirname(char *src, char *dest)
{
char *result; // rax
signed __int64 v3; // rbx

result = strrchr(src, 47);
if ( result )
{
v3 = result - src;
result = strncpy(dest, src, result - src + 1);
dest[v3 + 1] = 0;
}
else
{
*dest = 0;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func2(char *src, char *dest)
{
char *result; // rax
signed __int64 v3; // rbx

result = strrchr(src, 47);
if ( result )
{
v3 = result - src;
result = strncpy(dest, src, result - src + 1);
dest[v3 + 1] = 0;
}
else
{
*dest = 0;
}
return result;
}

original_code:
void dirname(char *path, char *dir) {
  char *bn;
  bn = strrchr(path, '/');
  if (bn == ((void *)0)) dir[0] = '\0';
  else {
    strncpy(dir, path, bn - path + 1);
    dir[bn - path + 1] = '\0';
  }
}

variable_types:
dir
char *

variable_types:
bn
char *


basename

decompiled_code:
const char *__fastcall basename(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func3(const char *a1)
{
char *v2; // rax
char *v3; // rdi
bool v4; // zf
const char *result; // rax

v2 = strrchr(a1, 47);
v3 = v2 + 1;
v4 = v2 == 0LL;
result = a1;
if ( !v4 )
result = v3;
return result;
}

original_code:
char * basename(char *path) {
  char *bn;
  bn = strrchr(path, '/');
  if (bn == ((void *)0)) return path;
  else return bn + 1;
}

canonical_original_code:
char *basename(char *path) {
  char *bn;
  bn = strrchr(path, '/');
  if (bn == ((void *)0)) return path;
  else return bn + 1;
}


decompiled_code:
void __fastcall get_prefix(char *s, _BYTE *a2)
{
_BYTE *v2; // rbp
const char *v3; // r13
unsigned __int16 v4; // r12
char *v5; // rdx
char *v6; // r12
signed __int64 v7; // rcx
__int64 v8; // rax

if ( a2 )
{
v2 = a2;
if ( s )
{
v3 = basename(s);
v4 = strlen(s);
v5 = strrchr(v3, 46);
v6 = &s[v4];
if ( !v5 )
v5 = v6;
v7 = v5 - s;
v8 = 0LL;
if ( s < v5 )
{
do
{
a2[v8] = s[v8];
++v8;
}
while ( v8 != v7 );
v2 = &a2[v7];
}
*v2 = 0;
}
}
}

original_code:
void get_prefix(char *name, char *pref) {
  uint16_t len;
  char *bn;
  char *pref_end;
  if (name == ((void *)0)) return;
  if (pref == ((void *)0)) return;
  pref_end = ((void *)0);
  bn = basename(name);
  len = strlen(name);
  pref_end = strrchr(bn, '.');
  if (pref_end == ((void *)0)) pref_end = name+len;
  for (; name < pref_end; name++,pref++) *pref = *name;
  *pref = '\0';
}

canonical_original_code:
void get_prefix(char *name, char *pref) {
  unsigned short len;
  char *bn;
  char *pref_end;
  if (name == ((void *)0)) return;
  if (pref == ((void *)0)) return;
  pref_end = ((void *)0);
  bn = basename(name);
  len = strlen(name);
  pref_end = strrchr(bn, '.');
  if (pref_end == ((void *)0)) pref_end = name+len;
  for (; name < pref_end; name++,pref++) *pref = *name;
  *pref = '\0';
}

variable_types:
pref
char *

variable_types:
len
unsigned short


decompiled_code:
char *__fastcall set_suffix(char *s, char *a2)
{
size_t v2; // r13
_BYTE *v3; // rbp
_BYTE *v4; // r13
int v5; // ebx
int v6; // eax
char *v7; // rax
char *v8; // rbx

if ( !a2 || !s )
return 0LL;
v2 = (int)(strlen(s) + 1);
v3 = malloc(v2);
if ( !v3 )
return 0LL;
v4 = malloc(v2);
if ( !v4
|| (get_prefix(s, v3),
get_suffix(s, v4),
v5 = strlen(v3),
v6 = strlen(a2),
v7 = (char *)malloc(v5 + v6 + 2),
(v8 = v7) == 0LL) )
{
free(v3);
if ( v4 )
free(v4);
return 0LL;
}
sprintf(v7, "%s.%s", v3, a2);
free(v3);
free(v4);
return v8;
}

canonical_decompiled_code:
char *__fastcall func5(char *s, char *a2)
{
size_t v2; // r13
_BYTE *v3; // rbp
_BYTE *v4; // r13
int v5; // ebx
int v6; // eax
char *v7; // rax
char *v8; // rbx

if ( !a2 || !s )
return 0LL;
v2 = (int)(strlen(s) + 1);
v3 = malloc(v2);
if ( !v3 )
return 0LL;
v4 = malloc(v2);
if ( !v4
|| (func4(s, v3),
func0(s, v4),
v5 = strlen(v3),
v6 = strlen(a2),
v7 = (char *)malloc(v5 + v6 + 2),
(v8 = v7) == 0LL) )
{
free(v3);
if ( v4 )
free(v4);
return 0LL;
}
sprintf(v7, "%s.%s", v3, a2);
free(v3);
free(v4);
return v8;
}

original_code:
char * set_suffix(char *oldname, char *suffix) {
  int len;
  char *newname;
  char *oldprefix;
  char *oldsuffix;
  newname = ((void *)0);
  oldprefix = ((void *)0);
  oldsuffix = ((void *)0);
  if (oldname == ((void *)0)) return ((void *)0);
  if (suffix == ((void *)0)) return ((void *)0);
  len = strlen(oldname);
  oldprefix = malloc(len+1);
  if (oldprefix == ((void *)0)) goto fail;
  oldsuffix = malloc(len+1);
  if (oldsuffix == ((void *)0)) goto fail;
  get_prefix(oldname, oldprefix);
  get_suffix(oldname, oldsuffix);
  len = strlen(oldprefix) + strlen(suffix) + 2;
  newname = malloc(len);
  if (newname == ((void *)0)) goto fail;
  sprintf(newname, "%s.%s", oldprefix, suffix);
  free(oldprefix);
  free(oldsuffix);
  return newname;
fail:
  if (oldprefix != ((void *)0)) free(oldprefix);
  if (oldsuffix != ((void *)0)) free(oldsuffix);
  if (newname != ((void *)0)) free(newname);
  return ((void *)0);
}

canonical_original_code:
char *set_suffix(char *oldname, char *suffix) {
  int len;
  char *newname;
  char *oldprefix;
  char *oldsuffix;
  newname = ((void *)0);
  oldprefix = ((void *)0);
  oldsuffix = ((void *)0);
  if (oldname == ((void *)0)) return ((void *)0);
  if (suffix == ((void *)0)) return ((void *)0);
  len = strlen(oldname);
  oldprefix = malloc(len+1);
  if (oldprefix == ((void *)0)) goto fail;
  oldsuffix = malloc(len+1);
  if (oldsuffix == ((void *)0)) goto fail;
  get_prefix(oldname, oldprefix);
  get_suffix(oldname, oldsuffix);
  len = strlen(oldprefix) + strlen(suffix) + 2;
  newname = malloc(len);
  if (newname == ((void *)0)) goto fail;
  sprintf(newname, "%s.%s", oldprefix, suffix);
  free(oldprefix);
  free(oldsuffix);
  return newname;
fail:
  if (oldprefix != ((void *)0)) free(oldprefix);
  if (oldsuffix != ((void *)0)) free(oldsuffix);
  if (newname != ((void *)0)) free(newname);
  return ((void *)0);
}

variable_types:
oldname
char *

variable_types:
suffix
char *

variable_types: len int

variable_types:
newname
char *

variable_types:
oldprefix
char *

variable_types:
oldsuffix
char *


decompiled_code:
bool __fastcall graph_create_ncut(__int64 fd, struct sockaddr *addr, __int64 a3)
{
unsigned int v4; // eax
char v5; // dl
bool result; // al
socklen_t v7; // edx

v4 = analyze_num_vals(addr);
v5 = graph_create(fd, v4, 0LL);
result = 1;
if ( !v5 )
{
v7 = label(fd, (__int64)addr, a3);
result = 1;
if ( !(_BYTE)v7 )
result = (unsigned __int8)connect(fd, addr, v7) != 0;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 fd, struct sockaddr *addr, __int64 a3)
{
unsigned int v4; // eax
char v5; // dl
bool result; // al
socklen_t v7; // edx

v4 = analyze_num_vals(addr);
v5 = graph_create(fd, v4, 0LL);
result = 1;
if ( !v5 )
{
v7 = func0(fd, (__int64)addr, a3);
result = 1;
if ( !(_BYTE)v7 )
result = (unsigned __int8)func2(fd, addr, v7) != 0;
}
return result;
}

original_code:
uint8_t graph_create_ncut(
  graph_t *g,
  dsr_t *hdr,
  uint8_t *img,
  double si,
  double sx,
  double rad,
  double thres) {
  uint32_t nnodes;
  nnodes = analyze_num_vals(hdr);
  if (graph_create(g, nnodes, 0)) goto fail;
  if (_label(g, hdr, img)) goto fail;
  if (_connect(g, si, sx, rad, thres)) goto fail;
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_create_ncut(struct _graph *g, struct dsr *hdr, unsigned char *img, double si, double sx, double rad, double thres) {
  unsigned int nnodes;
  nnodes = analyze_num_vals(hdr);
  if (graph_create(g, nnodes, 0)) goto fail;
  if (_label(g, hdr, img)) goto fail;
  if (_connect(g, si, sx, rad, thres)) goto fail;
  return 0;
fail:
  return 1;
}

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

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

variable_types:
img
unsigned char *

variable_types: si double

variable_types: sx double

variable_types: rad double

variable_types: thres double

variable_types:
nnodes
unsigned int

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