decompiled_code:
double __fastcall stats_avg_local_efficiency(__int64 a1)
{
int v1; // er13
__int64 v2; // rbx
double result; // xmm0_8
double v4; // [rsp+0h] [rbp-38h] BYREF
double v5[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = graph_num_nodes();
v4 = 0.0;
if ( v1 )
{
v2 = 0LL;
while ( !(unsigned __int8)stats_cache_node_local_efficiency(a1, v2, v5) )
{
v4 = v4 + v5[0];
if ( ++v2 == v1 )
goto LABEL_5;
}
result = *(double *)&LC0;
}
else
{
LABEL_5:
v4 = v4 / (double)v1;
stats_cache_add(a1, 9LL, 0LL, 8LL);
stats_cache_update(a1, 9LL, 0LL, -1LL, &v4);
result = v4;
}
return result;
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
int v1; // er13
__int64 v2; // rbx
double result; // xmm0_8
double v4; // [rsp+0h] [rbp-38h] BYREF
double v5[6]; // [rsp+8h] [rbp-30h] BYREF

v1 = graph_num_nodes();
v4 = 0.0;
if ( v1 )
{
v2 = 0LL;
while ( !(unsigned __int8)stats_cache_node_local_efficiency(a1, v2, v5) )
{
v4 = v4 + v5[0];
if ( ++v2 == v1 )
goto LABEL_5;
}
result = *(double *)&LC0;
}
else
{
LABEL_5:
v4 = v4 / (double)v1;
stats_cache_add(a1, 9LL, 0LL, 8LL);
stats_cache_update(a1, 9LL, 0LL, -1LL, &v4);
result = v4;
}
return result;
}

original_code:
double stats_avg_local_efficiency(graph_t *g) {
  uint64_t i;
  uint32_t nnodes;
  double loceff;
  double loceff_tally;
  nnodes = graph_num_nodes(g);
  loceff_tally = 0;
  for (i = 0; i < nnodes; i++) {
    if (stats_cache_node_local_efficiency(g, i, &loceff)) goto fail;
    loceff_tally += loceff;
  }
  loceff_tally /= nnodes;
  stats_cache_add(g,
                  STATS_CACHE_LOCAL_EFFICIENCY,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_LOCAL_EFFICIENCY, 0, -1, &loceff_tally);
  return loceff_tally;
fail:
  return -1;
}

canonical_original_code:
double stats_avg_local_efficiency(struct _graph *g) {
  unsigned long i;
  unsigned int nnodes;
  double loceff;
  double loceff_tally;
  nnodes = graph_num_nodes(g);
  loceff_tally = 0;
  for (i = 0; i < nnodes; i++) {
    if (stats_cache_node_local_efficiency(g, i, &loceff)) goto fail;
    loceff_tally += loceff;
  }
  loceff_tally /= nnodes;
  stats_cache_add(g,
                  STATS_CACHE_LOCAL_EFFICIENCY,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_LOCAL_EFFICIENCY, 0, -1, &loceff_tally);
  return loceff_tally;
fail:
  return -1;
}

variable_types:
i
unsigned long

variable_types: loceff double


repo: pauldmccarthy/ccnet

decompiled_code:
double __fastcall stats_sub_efficiency(__int64 a1, int a2, __int64 a3)
{
unsigned int v4; // eax
unsigned int v5; // ebp
unsigned int v6; // eax
double v8; // [rsp+8h] [rbp-40h]
double v9; // [rsp+10h] [rbp-38h] BYREF
unsigned int v10[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v4 = graph_num_nodes();
v10[0] = 0;
if ( v4 )
{
v5 = v4;
v8 = 0.0;
v6 = 0;
while ( 1 )
{
if ( !a3 || !*(_BYTE *)(a3 + v6) )
{
v9 = 0.0;
if ( (unsigned __int8)bfs(a1, v10, 1LL, a3, &v9, 0LL, bfs_cb, 0LL) )
return *(double *)&LC0;
if ( v9 < 0.0 )
return *(double *)&LC0;
v8 = v9 + v8;
}
v6 = v10[0] + 1;
v10[0] = v6;
if ( v6 >= v5 )
return v8 / (double)((a2 - 1) * a2);
}
}
v8 = 0.0;
return v8 / (double)((a2 - 1) * a2);
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, int a2, __int64 a3)
{
unsigned int v4; // eax
unsigned int v5; // ebp
unsigned int v6; // eax
double v8; // [rsp+8h] [rbp-40h]
double v9; // [rsp+10h] [rbp-38h] BYREF
unsigned int v10[11]; // [rsp+1Ch] [rbp-2Ch] BYREF

v4 = graph_num_nodes();
v10[0] = 0;
if ( v4 )
{
v5 = v4;
v8 = 0.0;
v6 = 0;
while ( 1 )
{
if ( !a3 || !*(_BYTE *)(a3 + v6) )
{
v9 = 0.0;
if ( (unsigned __int8)bfs(a1, v10, 1LL, a3, &v9, 0LL, bfs_cb, 0LL) )
return *(double *)&LC0;
if ( v9 < 0.0 )
return *(double *)&LC0;
v8 = v9 + v8;
}
v6 = v10[0] + 1;
v10[0] = v6;
if ( v6 >= v5 )
return v8 / (double)((a2 - 1) * a2);
}
}
v8 = 0.0;
return v8 / (double)((a2 - 1) * a2);
}

original_code:
double stats_sub_efficiency(graph_t *g, uint32_t nnodes, uint8_t *mask) {
  uint32_t i;
  uint32_t gnnodes;
  double invsum;
  double inv;
  double effic;
  invsum = 0;
  gnnodes = graph_num_nodes(g);
  for (i = 0; i < gnnodes; i++) {
    if (mask && mask[i]) continue;
    inv = 0;
    if (bfs(g, &i, 1, mask, &inv, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
    if (inv < 0) goto fail;
    invsum += inv;
  }
  effic = invsum / (nnodes*(nnodes-1));
  return effic;
fail:
  return -1;
}

canonical_original_code:
double stats_sub_efficiency(struct _graph *g, unsigned int nnodes, unsigned char *mask) {
  unsigned int i;
  unsigned int gnnodes;
  double invsum;
  double inv;
  double effic;
  invsum = 0;
  gnnodes = graph_num_nodes(g);
  for (i = 0; i < gnnodes; i++) {
    if (mask && mask[i]) continue;
    inv = 0;
    if (bfs(g, &i, 1, mask, &inv, ((void *)0), _bfs_cb, ((void *)0))) goto fail;
    if (inv < 0) goto fail;
    invsum += inv;
  }
  effic = invsum / (nnodes*(nnodes-1));
  return effic;
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:
nnodes
unsigned int

variable_types:
mask
unsigned char *

variable_types:
i
unsigned int

variable_types:
gnnodes
unsigned int

variable_types: invsum double

variable_types: inv double

variable_types: effic double

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:
double __fastcall stats_local_efficiency(__int64 a1, unsigned int a2)
{
unsigned int v2; // er15
unsigned int v3; // er13
__int64 v4; // rax
double result; // xmm0_8
unsigned int *v6; // r14
char *v7; // rax
_BYTE *v8; // rbx
char *v9; // rdx
char *v10; // r15
unsigned int *v11; // rax
double v12[8]; // [rsp+8h] [rbp-40h] BYREF

v2 = graph_num_nodes();
v3 = graph_num_neighbours(a1, a2);
v4 = graph_get_neighbours(a1, a2);
result = 0.0;
if ( v3 > 1 )
{
v6 = (unsigned int *)v4;
v7 = (char *)malloc(v2);
v8 = v7;
if ( v7 )
{
if ( v2 )
{
v9 = v7;
v10 = &v7[v2];
do
*v9++ = 1;
while ( v9 != v10 );
}
v11 = v6;
do
v8[*v11++] = 0;
while ( v11 != &v6[v3] );
v12[0] = stats_sub_efficiency(a1, v3, (__int64)v8);
free(v8);
stats_cache_add(a1, 17LL, 2LL, 8LL);
stats_cache_update(a1, 17LL, a2, -1LL, v12);
result = v12[0];
}
else
{
result = *(double *)&LC0;
}
}
return result;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1, unsigned int a2)
{
unsigned int v2; // er15
unsigned int v3; // er13
__int64 v4; // rax
double result; // xmm0_8
unsigned int *v6; // r14
char *v7; // rax
_BYTE *v8; // rbx
char *v9; // rdx
char *v10; // r15
unsigned int *v11; // rax
double v12[8]; // [rsp+8h] [rbp-40h] BYREF

v2 = graph_num_nodes();
v3 = graph_num_neighbours(a1, a2);
v4 = graph_get_neighbours(a1, a2);
result = 0.0;
if ( v3 > 1 )
{
v6 = (unsigned int *)v4;
v7 = (char *)malloc(v2);
v8 = v7;
if ( v7 )
{
if ( v2 )
{
v9 = v7;
v10 = &v7[v2];
do
*v9++ = 1;
while ( v9 != v10 );
}
v11 = v6;
do
v8[*v11++] = 0;
while ( v11 != &v6[v3] );
v12[0] = func2(a1, v3, (__int64)v8);
free(v8);
stats_cache_add(a1, 17LL, 2LL, 8LL);
stats_cache_update(a1, 17LL, a2, -1LL, v12);
result = v12[0];
}
else
{
result = *(double *)&LC0;
}
}
return result;
}

original_code:
double stats_local_efficiency(graph_t *g, uint32_t nidx) {
  uint32_t i;
  uint32_t numnodes;
  uint32_t numnbrs;
  uint32_t *nbrs;
  uint8_t *subgraphmask;
  double effic;
  subgraphmask = ((void *)0);
  numnodes = graph_num_nodes( g);
  numnbrs = graph_num_neighbours(g, nidx);
  nbrs = graph_get_neighbours(g, nidx);
  if (numnbrs == 0 || numnbrs == 1) return 0.0;
  subgraphmask = malloc(numnodes*sizeof(uint8_t));
  if (subgraphmask == ((void *)0)) goto fail;
  for (i = 0; i < numnodes; i++) subgraphmask[i] = 1;
  for (i = 0; i < numnbrs; i++) subgraphmask[nbrs[i]] = 0;
  effic = stats_sub_efficiency(g, numnbrs, subgraphmask);
  free(subgraphmask);
  stats_cache_add(g,
                  STATS_CACHE_NODE_LOCAL_EFFICIENCY,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_NODE_LOCAL_EFFICIENCY, nidx, -1, &effic);
  return effic;
fail:
  if (subgraphmask != ((void *)0)) free(subgraphmask);
  return -1;
}

canonical_original_code:
double stats_local_efficiency(struct _graph *g, unsigned int nidx) {
  unsigned int i;
  unsigned int numnodes;
  unsigned int numnbrs;
  unsigned int *nbrs;
  unsigned char *subgraphmask;
  double effic;
  subgraphmask = ((void *)0);
  numnodes = graph_num_nodes( g);
  numnbrs = graph_num_neighbours(g, nidx);
  nbrs = graph_get_neighbours(g, nidx);
  if (numnbrs == 0 || numnbrs == 1) return 0.0;
  subgraphmask = malloc(numnodes*sizeof(unsigned char));
  if (subgraphmask == ((void *)0)) goto fail;
  for (i = 0; i < numnodes; i++) subgraphmask[i] = 1;
  for (i = 0; i < numnbrs; i++) subgraphmask[nbrs[i]] = 0;
  effic = stats_sub_efficiency(g, numnbrs, subgraphmask);
  free(subgraphmask);
  stats_cache_add(g,
                  STATS_CACHE_NODE_LOCAL_EFFICIENCY,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_NODE_LOCAL_EFFICIENCY, nidx, -1, &effic);
  return effic;
fail:
  if (subgraphmask != ((void *)0)) free(subgraphmask);
  return -1;
}

variable_types:
nidx
unsigned int

variable_types:
numnodes
unsigned int

variable_types:
numnbrs
unsigned int

variable_types:
nbrs
unsigned int *

variable_types:
subgraphmask
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 graph_relabel(__int64 a1, __int64 a2, __int64 a3, char a4)
{
int v5; // er14
char v6; // dl
__int64 result; // rax
__int64 v8; // rbp
unsigned int v9; // er13
unsigned int v10; // er13
unsigned int v11; // er13
const __m128i *v12; // rax
float v13; // [rsp+Ch] [rbp-BCh]
float v15; // [rsp+20h] [rbp-A8h]
double v16; // [rsp+20h] [rbp-A8h]
float v17; // [rsp+28h] [rbp-A0h]
double v18; // [rsp+28h] [rbp-A0h]
unsigned int v19; // [rsp+34h] [rbp-94h] BYREF
unsigned int v20; // [rsp+38h] [rbp-90h]
unsigned int v21; // [rsp+3Ch] [rbp-8Ch]
__int128 v22[8]; // [rsp+40h] [rbp-88h] BYREF

v5 = graph_num_nodes();
v13 = analyze_pixdim_size(a2, 0LL);
v15 = analyze_pixdim_size(a2, 1LL);
v17 = analyze_pixdim_size(a2, 2LL);
v6 = analyze_num_dims(a2);
result = 1LL;
if ( v6 == 3 )
{
if ( v5 )
{
v16 = v15;
v18 = v17;
v8 = 0LL;
while ( 1 )
{
v12 = (const __m128i *)graph_get_nodelabel(a1, (unsigned int)v8);
if ( !v12 )
return 1LL;
v22[0] = (__int128)_mm_loadu_si128(v12);
v22[1] = (__int128)_mm_loadu_si128(v12 + 1);
v22[2] = (__int128)_mm_loadu_si128(v12 + 2);
v22[3] = (__int128)_mm_loadu_si128(v12 + 3);
v22[4] = (__int128)_mm_loadu_si128(v12 + 4);
if ( a4 )
{
v19 = (int)round(*((float *)v22 + 1) / v13);
v20 = (int)round(*((float *)v22 + 2) / v16);
v21 = (int)round(*((float *)v22 + 3) / v18);
}
else
{
v19 = (int)*((float *)v22 + 1);
v20 = (int)*((float *)v22 + 2);
v21 = (int)*((float *)v22 + 3);
}
v9 = v19;
if ( v9 >= (unsigned __int16)analyze_dim_size(a2, 0LL) )
return 1LL;
v10 = v20;
if ( v10 >= (unsigned __int16)analyze_dim_size(a2, 1LL) )
return 1LL;
v11 = v21;
if ( v11 >= (unsigned __int16)analyze_dim_size(a2, 2LL) )
return 1LL;
LODWORD(v22[0]) = (int)analyze_read_val(a2, a3, &v19);
result = graph_set_nodelabel(a1, (unsigned int)v8, v22);
if ( (_BYTE)result )
break;
if ( ++v8 == v5 )
return result;
}
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, char a4)
{
int v5; // er14
char v6; // dl
__int64 result; // rax
__int64 v8; // rbp
unsigned int v9; // er13
unsigned int v10; // er13
unsigned int v11; // er13
const __m128i *v12; // rax
float v13; // [rsp+Ch] [rbp-BCh]
float v15; // [rsp+20h] [rbp-A8h]
double v16; // [rsp+20h] [rbp-A8h]
float v17; // [rsp+28h] [rbp-A0h]
double v18; // [rsp+28h] [rbp-A0h]
unsigned int v19; // [rsp+34h] [rbp-94h] BYREF
unsigned int v20; // [rsp+38h] [rbp-90h]
unsigned int v21; // [rsp+3Ch] [rbp-8Ch]
__int128 v22[8]; // [rsp+40h] [rbp-88h] BYREF

v5 = graph_num_nodes();
v13 = analyze_pixdim_size(a2, 0LL);
v15 = analyze_pixdim_size(a2, 1LL);
v17 = analyze_pixdim_size(a2, 2LL);
v6 = analyze_num_dims(a2);
result = 1LL;
if ( v6 == 3 )
{
if ( v5 )
{
v16 = v15;
v18 = v17;
v8 = 0LL;
while ( 1 )
{
v12 = (const __m128i *)graph_get_nodelabel(a1, (unsigned int)v8);
if ( !v12 )
return 1LL;
v22[0] = (__int128)_mm_loadu_si128(v12);
v22[1] = (__int128)_mm_loadu_si128(v12 + 1);
v22[2] = (__int128)_mm_loadu_si128(v12 + 2);
v22[3] = (__int128)_mm_loadu_si128(v12 + 3);
v22[4] = (__int128)_mm_loadu_si128(v12 + 4);
if ( a4 )
{
v19 = (int)round(*((float *)v22 + 1) / v13);
v20 = (int)round(*((float *)v22 + 2) / v16);
v21 = (int)round(*((float *)v22 + 3) / v18);
}
else
{
v19 = (int)*((float *)v22 + 1);
v20 = (int)*((float *)v22 + 2);
v21 = (int)*((float *)v22 + 3);
}
v9 = v19;
if ( v9 >= (unsigned __int16)analyze_dim_size(a2, 0LL) )
return 1LL;
v10 = v20;
if ( v10 >= (unsigned __int16)analyze_dim_size(a2, 1LL) )
return 1LL;
v11 = v21;
if ( v11 >= (unsigned __int16)analyze_dim_size(a2, 2LL) )
return 1LL;
LODWORD(v22[0]) = (int)analyze_read_val(a2, a3, &v19);
result = graph_set_nodelabel(a1, (unsigned int)v8, v22);
if ( (_BYTE)result )
break;
if ( ++v8 == v5 )
return result;
}
result = 1LL;
}
else
{
result = 0LL;
}
}
return result;
}

original_code:
uint8_t graph_relabel(graph_t *g, dsr_t *hdr, uint8_t *img, uint8_t real) {
  graph_label_t lbl;
  graph_label_t *plbl;
  uint32_t nnodes;
  uint64_t i;
  double xl;
  double yl;
  double zl;
  uint32_t dims[3];
  nnodes = graph_num_nodes(g);
  xl = analyze_pixdim_size(hdr, 0);
  yl = analyze_pixdim_size(hdr, 1);
  zl = analyze_pixdim_size(hdr, 2);
  if (analyze_num_dims(hdr) != 3) goto fail;
  for (i = 0; i < nnodes; i++) {
    plbl = graph_get_nodelabel(g, i);
    if (plbl == ((void *)0)) goto fail;
    memcpy(&lbl, plbl, sizeof(graph_label_t));
    if (real) {
      dims[0] = (uint32_t)(round(lbl.xval / xl));
      dims[1] = (uint32_t)(round(lbl.yval / yl));
      dims[2] = (uint32_t)(round(lbl.zval / zl));
    }
    else {
      dims[0] = (uint32_t)lbl.xval;
      dims[1] = (uint32_t)lbl.yval;
      dims[2] = (uint32_t)lbl.zval;
    }
    if (dims[0] >= analyze_dim_size(hdr, 0)) goto fail;
    if (dims[1] >= analyze_dim_size(hdr, 1)) goto fail;
    if (dims[2] >= analyze_dim_size(hdr, 2)) goto fail;
    lbl.labelval = analyze_read_val(hdr, img, dims);
    if (graph_set_nodelabel(g, i, &lbl)) goto fail;
  }
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_relabel(struct _graph *g, struct dsr *hdr, unsigned char *img, unsigned char real) {
  struct _graph_label lbl;
  struct _graph_label *plbl;
  unsigned int nnodes;
  unsigned long i;
  double xl;
  double yl;
  double zl;
  unsigned int dims[3];
  nnodes = graph_num_nodes(g);
  xl = analyze_pixdim_size(hdr, 0);
  yl = analyze_pixdim_size(hdr, 1);
  zl = analyze_pixdim_size(hdr, 2);
  if (analyze_num_dims(hdr) != 3) goto fail;
  for (i = 0; i < nnodes; i++) {
    plbl = graph_get_nodelabel(g, i);
    if (plbl == ((void *)0)) goto fail;
    memcpy(&lbl, plbl, sizeof(graph_label_t));
    if (real) {
      dims[0] = (unsigned int)(round(lbl.xval / xl));
      dims[1] = (unsigned int)(round(lbl.yval / yl));
      dims[2] = (unsigned int)(round(lbl.zval / zl));
    }
    else {
      dims[0] = (unsigned int)lbl.xval;
      dims[1] = (unsigned int)lbl.yval;
      dims[2] = (unsigned int)lbl.zval;
    }
    if (dims[0] >= analyze_dim_size(hdr, 0)) goto fail;
    if (dims[1] >= analyze_dim_size(hdr, 1)) goto fail;
    if (dims[2] >= analyze_dim_size(hdr, 2)) goto fail;
    lbl.labelval = analyze_read_val(hdr, img, dims);
    if (graph_set_nodelabel(g, i, &lbl)) goto fail;
  }
  return 0;
fail:
  return 1;
}

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

variable_types:
img
unsigned char *

variable_types:
real
unsigned char

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

variable_types: xl double

variable_types: yl double

variable_types: zl double

variable_types:
dims
unsigned int [3]

return_type: unsigned char

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


decompiled_code:
__int64 __fastcall graph_relabel_map(__int64 a1, char *a2)
{
int v2; // ebp
unsigned int v3; // eax
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v7[11]; // [rsp+0h] [rbp-58h] BYREF

v2 = graph_num_nodes();
v7[0] = 0LL;
v7[1] = 0LL;
v7[2] = 0LL;
v7[3] = 0LL;
v7[4] = 0LL;
v3 = load_mapfile(a2, (__int64)v7);
v4 = 1;
if ( !(_BYTE)v3 )
{
v4 = v3;
if ( v2 )
{
v5 = 0LL;
while ( !(unsigned __int8)relabel_node(a1, v5, (__int64)v7) )
{
if ( ++v5 == v2 )
goto LABEL_6;
}
v4 = 1;
}
else
{
LABEL_6:
array_free(v7);
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, char *a2)
{
int v2; // ebp
unsigned int v3; // eax
unsigned int v4; // er13
__int64 v5; // rbx
__int64 v7[11]; // [rsp+0h] [rbp-58h] BYREF

v2 = graph_num_nodes();
v7[0] = 0LL;
v7[1] = 0LL;
v7[2] = 0LL;
v7[3] = 0LL;
v7[4] = 0LL;
v3 = func0(a2, (__int64)v7);
v4 = 1;
if ( !(_BYTE)v3 )
{
v4 = v3;
if ( v2 )
{
v5 = 0LL;
while ( !(unsigned __int8)func2(a1, v5, (__int64)v7) )
{
if ( ++v5 == v2 )
goto LABEL_6;
}
v4 = 1;
}
else
{
LABEL_6:
array_free(v7);
}
}
return v4;
}

original_code:
uint8_t graph_relabel_map(graph_t *g, char *lblmapfile) {
  uint64_t i;
  uint32_t nnodes;
  array_t map;
  nnodes = graph_num_nodes(g);
  memset(&map, 0, sizeof(array_t));
  if (_load_mapfile(lblmapfile, &map))
    goto fail;
  for (i = 0; i < nnodes; i++) {
    if (_relabel_node(g, i, &map))
      goto fail;
  }
  array_free(&map);
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_relabel_map(struct _graph *g, char *lblmapfile) {
  unsigned long i;
  unsigned int nnodes;
  struct _array map;
  nnodes = graph_num_nodes(g);
  memset(&map, 0, sizeof(array_t));
  if (_load_mapfile(lblmapfile, &map))
    goto fail;
  for (i = 0; i < nnodes; i++) {
    if (_relabel_node(g, i, &map))
      goto fail;
  }
  array_free(&map);
  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:
lblmapfile
char *

variable_types:
i
unsigned long

variable_types:
nnodes
unsigned int


decompiled_code:
double __fastcall stats_degree_centrality(__int64 a1, unsigned int a2)
{
int v2; // ebx

v2 = graph_num_nodes();
return (double)(int)graph_num_neighbours(a1, a2) / ((double)v2 - 1.0);
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, unsigned int a2)
{
int v2; // ebx

v2 = graph_num_nodes();
return (double)(int)graph_num_neighbours(a1, a2) / ((double)v2 - 1.0);
}

original_code:
double stats_degree_centrality(graph_t *g, uint32_t nidx) {
  double nnodes;
  double nnbrs;
  nnodes = graph_num_nodes(g);
  nnbrs = graph_num_neighbours(g, nidx);
  return nnbrs / (nnodes-1);
}

canonical_original_code:
double stats_degree_centrality(struct _graph *g, unsigned int nidx) {
  double nnodes;
  double nnbrs;
  nnodes = graph_num_nodes(g);
  nnbrs = graph_num_neighbours(g, nidx);
  return nnbrs / (nnodes-1);
}

variable_types:
nidx
unsigned int

variable_types: nnodes double

variable_types: nnbrs double


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

stats_cache_node_pathlength(a1, a2, v3);
result = *(double *)&LC1;
if ( v3[0] >= 0.0 )
{
result = 0.0;
if ( v3[0] > 0.0 )
result = 1.0 / v3[0];
}
return result;
}

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

stats_cache_node_pathlength(a1, a2, v3);
result = *(double *)&LC1;
if ( v3[0] >= 0.0 )
{
result = 0.0;
if ( v3[0] > 0.0 )
result = 1.0 / v3[0];
}
return result;
}

original_code:
double stats_closeness_centrality(graph_t *g, uint32_t nidx) {
  double closeness;
  double avg_pathlen;
  stats_cache_node_pathlength(g, nidx, &avg_pathlen);
  if (avg_pathlen < 0) return -1;
  if (avg_pathlen > 0) closeness = 1/avg_pathlen;
  else closeness = 0;
  return closeness;
}

canonical_original_code:
double stats_closeness_centrality(struct _graph *g, unsigned int nidx) {
  double closeness;
  double avg_pathlen;
  stats_cache_node_pathlength(g, nidx, &avg_pathlen);
  if (avg_pathlen < 0) return -1;
  if (avg_pathlen > 0) closeness = 1/avg_pathlen;
  else closeness = 0;
  return closeness;
}

variable_types: closeness double


original_code:
void nifti1_reverse_hdr(nifti1_hdr_t *hdr) {
  uint8_t i;
  reverse(&(hdr->sizeof_hdr), &(hdr->sizeof_hdr), sizeof(hdr->sizeof_hdr));
  reverse(&(hdr->extents), &(hdr->extents), sizeof(hdr->extents));
  reverse(&(hdr->session_error),
          &(hdr->session_error),
     sizeof(hdr->session_error));
  for (i = 0; i < 8; i++)
    reverse((hdr->dim)+i, (hdr->dim)+i, sizeof((hdr->dim)[i]));
  reverse(&(hdr->intent_p1), &(hdr->intent_p1), sizeof(hdr->intent_p1));
  reverse(&(hdr->intent_p2), &(hdr->intent_p2), sizeof(hdr->intent_p2));
  reverse(&(hdr->intent_p3), &(hdr->intent_p3), sizeof(hdr->intent_p3));
  reverse(&(hdr->intent_code), &(hdr->intent_code), sizeof(hdr->intent_code));
  reverse(&(hdr->datatype), &(hdr->datatype), sizeof(hdr->datatype));
  reverse(&(hdr->bitpix), &(hdr->bitpix), sizeof(hdr->bitpix));
  reverse(&(hdr->slice_start), &(hdr->slice_start), sizeof(hdr->slice_start));
  for (i = 0; i < 8; i++)
    reverse((hdr->pixdim)+i, (hdr->pixdim)+i, sizeof((hdr->pixdim)[i]));
  reverse(&(hdr->vox_offset), &(hdr->vox_offset), sizeof(hdr->vox_offset));
  reverse(&(hdr->scl_slope), &(hdr->scl_slope), sizeof(hdr->scl_slope));
  reverse(&(hdr->scl_inter), &(hdr->scl_inter), sizeof(hdr->scl_inter));
  reverse(&(hdr->slice_end), &(hdr->slice_end), sizeof(hdr->slice_end));
  reverse(&(hdr->slice_code), &(hdr->slice_code), sizeof(hdr->slice_code));
  reverse(&(hdr->xyzt_units), &(hdr->xyzt_units), sizeof(hdr->xyzt_units));
  reverse(&(hdr->cal_max), &(hdr->cal_max), sizeof(hdr->cal_max));
  reverse(&(hdr->cal_min), &(hdr->cal_min), sizeof(hdr->cal_min));
  reverse(&(hdr->slice_duration),
          &(hdr->slice_duration),
     sizeof(hdr->slice_duration));
  reverse(&(hdr->toffset), &(hdr->toffset), sizeof(hdr->toffset));
  reverse(&(hdr->glmax), &(hdr->glmax), sizeof(hdr->glmax));
  reverse(&(hdr->glmin), &(hdr->glmin), sizeof(hdr->glmin));
  reverse(&(hdr->qform_code), &(hdr->qform_code), sizeof(hdr->qform_code));
  reverse(&(hdr->sform_code), &(hdr->sform_code), sizeof(hdr->sform_code));
  reverse(&(hdr->quatern_b), &(hdr->quatern_b), sizeof(hdr->quatern_b));
  reverse(&(hdr->quatern_c), &(hdr->quatern_c), sizeof(hdr->quatern_c));
  reverse(&(hdr->quatern_d), &(hdr->quatern_d), sizeof(hdr->quatern_d));
  reverse(&(hdr->qoffset_x), &(hdr->qoffset_x), sizeof(hdr->qoffset_x));
  reverse(&(hdr->qoffset_y), &(hdr->qoffset_y), sizeof(hdr->qoffset_y));
  reverse(&(hdr->qoffset_z), &(hdr->qoffset_z), sizeof(hdr->qoffset_z));
  for (i = 0; i < 4; i++)
    reverse((hdr->srow_x)+i, (hdr->srow_x)+i, sizeof((hdr->srow_x)[i]));
    reverse((hdr->srow_y)+i, (hdr->srow_y)+i, sizeof((hdr->srow_y)[i]));
    reverse((hdr->srow_z)+i, (hdr->srow_z)+i, sizeof((hdr->srow_z)[i]));
}

canonical_original_code:
void nifti1_reverse_hdr(struct _nifti_hdr *hdr) {
  unsigned char i;
  reverse(&(hdr->sizeof_hdr), &(hdr->sizeof_hdr), sizeof(hdr->sizeof_hdr));
  reverse(&(hdr->extents), &(hdr->extents), sizeof(hdr->extents));
  reverse(&(hdr->session_error),
          &(hdr->session_error),
     sizeof(hdr->session_error));
  for (i = 0; i < 8; i++)
    reverse((hdr->dim)+i, (hdr->dim)+i, sizeof((hdr->dim)[i]));
  reverse(&(hdr->intent_p1), &(hdr->intent_p1), sizeof(hdr->intent_p1));
  reverse(&(hdr->intent_p2), &(hdr->intent_p2), sizeof(hdr->intent_p2));
  reverse(&(hdr->intent_p3), &(hdr->intent_p3), sizeof(hdr->intent_p3));
  reverse(&(hdr->intent_code), &(hdr->intent_code), sizeof(hdr->intent_code));
  reverse(&(hdr->datatype), &(hdr->datatype), sizeof(hdr->datatype));
  reverse(&(hdr->bitpix), &(hdr->bitpix), sizeof(hdr->bitpix));
  reverse(&(hdr->slice_start), &(hdr->slice_start), sizeof(hdr->slice_start));
  for (i = 0; i < 8; i++)
    reverse((hdr->pixdim)+i, (hdr->pixdim)+i, sizeof((hdr->pixdim)[i]));
  reverse(&(hdr->vox_offset), &(hdr->vox_offset), sizeof(hdr->vox_offset));
  reverse(&(hdr->scl_slope), &(hdr->scl_slope), sizeof(hdr->scl_slope));
  reverse(&(hdr->scl_inter), &(hdr->scl_inter), sizeof(hdr->scl_inter));
  reverse(&(hdr->slice_end), &(hdr->slice_end), sizeof(hdr->slice_end));
  reverse(&(hdr->slice_code), &(hdr->slice_code), sizeof(hdr->slice_code));
  reverse(&(hdr->xyzt_units), &(hdr->xyzt_units), sizeof(hdr->xyzt_units));
  reverse(&(hdr->cal_max), &(hdr->cal_max), sizeof(hdr->cal_max));
  reverse(&(hdr->cal_min), &(hdr->cal_min), sizeof(hdr->cal_min));
  reverse(&(hdr->slice_duration),
          &(hdr->slice_duration),
     sizeof(hdr->slice_duration));
  reverse(&(hdr->toffset), &(hdr->toffset), sizeof(hdr->toffset));
  reverse(&(hdr->glmax), &(hdr->glmax), sizeof(hdr->glmax));
  reverse(&(hdr->glmin), &(hdr->glmin), sizeof(hdr->glmin));
  reverse(&(hdr->qform_code), &(hdr->qform_code), sizeof(hdr->qform_code));
  reverse(&(hdr->sform_code), &(hdr->sform_code), sizeof(hdr->sform_code));
  reverse(&(hdr->quatern_b), &(hdr->quatern_b), sizeof(hdr->quatern_b));
  reverse(&(hdr->quatern_c), &(hdr->quatern_c), sizeof(hdr->quatern_c));
  reverse(&(hdr->quatern_d), &(hdr->quatern_d), sizeof(hdr->quatern_d));
  reverse(&(hdr->qoffset_x), &(hdr->qoffset_x), sizeof(hdr->qoffset_x));
  reverse(&(hdr->qoffset_y), &(hdr->qoffset_y), sizeof(hdr->qoffset_y));
  reverse(&(hdr->qoffset_z), &(hdr->qoffset_z), sizeof(hdr->qoffset_z));
  for (i = 0; i < 4; i++)
    reverse((hdr->srow_x)+i, (hdr->srow_x)+i, sizeof((hdr->srow_x)[i]));
    reverse((hdr->srow_y)+i, (hdr->srow_y)+i, sizeof((hdr->srow_y)[i]));
    reverse((hdr->srow_z)+i, (hdr->srow_z)+i, sizeof((hdr->srow_z)[i]));
}

variable_types: struct _nifti_hdr { unsigned int sizeof_hdr; char data_type[10]; char db_name[18]; unsigned int extents; unsigned short session_error; char regular; char dim_info; unsigned short dim[8]; float intent_p1; float intent_p2; float intent_p3; unsigned short intent_code; unsigned short datatype; unsigned short bitpix; unsigned short slice_start; float pixdim[8]; float vox_offset; float scl_slope; float scl_inter; unsigned short slice_end; char slice_code; char xyzt_units; float cal_max; float cal_min; float slice_duration; float toffset; unsigned int glmax; unsigned int glmin; char descrip[80]; char aux_file[24]; unsigned short qform_code; unsigned short sform_code; float quatern_b; float quatern_c; float quatern_d; float qoffset_x; float qoffset_y; float qoffset_z; float srow_x[4]; float srow_y[4]; float srow_z[4]; char intent_name[16]; char magic[4]; unsigned char extension[4]; unsigned char rev; } *

variable_types:
i
unsigned char

return_type: void


original_code:
uint8_t nifti1_to_analyze(nifti1_hdr_t *nhdr, dsr_t *ahdr) {
  if (nhdr->datatype > 256) return 1;
  memset(ahdr, 0, sizeof(dsr_t));
  ahdr->hk.sizeof_hdr = 348;
  ahdr->rev = nhdr->rev;
  memcpy(ahdr->hk.data_type, nhdr->data_type, sizeof(ahdr->hk.data_type));
  memcpy(ahdr->hk.db_name, nhdr->db_name, sizeof(ahdr->hk.db_name));
  ahdr->hk.extents = 16384;
  ahdr->hk.regular = 'r';
  ahdr->hk.hkey_un0 = '0';
  memcpy(ahdr->dime.dim, nhdr->dim, sizeof(ahdr->dime.dim));
  memcpy(ahdr->dime.pixdim, nhdr->pixdim, sizeof(ahdr->dime.pixdim));
  ahdr->dime.datatype = nhdr->datatype;
  ahdr->dime.cal_min = nhdr->cal_min;
  ahdr->dime.cal_max = nhdr->cal_max;
  ahdr->dime.glmin = nhdr->glmin;
  ahdr->dime.glmax = nhdr->glmax;
  ahdr->dime.bitpix = nhdr->bitpix;
  memcpy(ahdr->hist.descrip, nhdr->descrip, sizeof(ahdr->hist.descrip));
  memcpy(ahdr->hist.aux_file, nhdr->aux_file, sizeof(ahdr->hist.aux_file));
  return 0;
}

canonical_original_code:
unsigned char nifti1_to_analyze(struct _nifti_hdr *nhdr, struct dsr *ahdr) {
  if (nhdr->datatype > 256) return 1;
  memset(ahdr, 0, sizeof(dsr_t));
  ahdr->hk.sizeof_hdr = 348;
  ahdr->rev = nhdr->rev;
  memcpy(ahdr->hk.data_type, nhdr->data_type, sizeof(ahdr->hk.data_type));
  memcpy(ahdr->hk.db_name, nhdr->db_name, sizeof(ahdr->hk.db_name));
  ahdr->hk.extents = 16384;
  ahdr->hk.regular = 'r';
  ahdr->hk.hkey_un0 = '0';
  memcpy(ahdr->dime.dim, nhdr->dim, sizeof(ahdr->dime.dim));
  memcpy(ahdr->dime.pixdim, nhdr->pixdim, sizeof(ahdr->dime.pixdim));
  ahdr->dime.datatype = nhdr->datatype;
  ahdr->dime.cal_min = nhdr->cal_min;
  ahdr->dime.cal_max = nhdr->cal_max;
  ahdr->dime.glmin = nhdr->glmin;
  ahdr->dime.glmax = nhdr->glmax;
  ahdr->dime.bitpix = nhdr->bitpix;
  memcpy(ahdr->hist.descrip, nhdr->descrip, sizeof(ahdr->hist.descrip));
  memcpy(ahdr->hist.aux_file, nhdr->aux_file, sizeof(ahdr->hist.aux_file));
  return 0;
}

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

user_defined_types: struct _nifti_hdr { unsigned int sizeof_hdr; char data_type[10]; char db_name[18]; unsigned int extents; unsigned short session_error; char regular; char dim_info; unsigned short dim[8]; float intent_p1; float intent_p2; float intent_p3; unsigned short intent_code; unsigned short datatype; unsigned short bitpix; unsigned short slice_start; float pixdim[8]; float vox_offset; float scl_slope; float scl_inter; unsigned short slice_end; char slice_code; char xyzt_units; float cal_max; float cal_min; float slice_duration; float toffset; unsigned int glmax; unsigned int glmin; char descrip[80]; char aux_file[24]; unsigned short qform_code; unsigned short sform_code; float quatern_b; float quatern_c; float quatern_d; float qoffset_x; float qoffset_y; float qoffset_z; float srow_x[4]; float srow_y[4]; float srow_z[4]; char intent_name[16]; char magic[4]; unsigned char extension[4]; unsigned char rev; }


original_code:
uint8_t graph_create_scalefree(
  graph_t *g, uint32_t nnodes, uint16_t m, uint16_t m0) {
  uint64_t i;
  uint64_t j;
  uint32_t n;
  double prob;
  uint64_t tot_deg;
  double wt;
  graph_label_t lbl;
  if (g == ((void *)0)) goto fail;
  if (nnodes == 0) goto fail;
  if (m == 0) goto fail;
  if (m0 == 0) goto fail;
  if (m > m0) goto fail;
  if (graph_create(g, nnodes, 0)) goto fail;
  for (i = 0; i < nnodes; i++) {
    _mk_label(&lbl);
    graph_set_nodelabel(g, i, &lbl);
  }
  tot_deg = (m0*m0) - m0;
  for (i = 0; i < m0; i++) {
    for (j = i+1; j < m0; j++) {
      wt = -1.0 + 2.0*((double)rand() / 2147483647);
      if (graph_add_edge(g, i, j, wt)) goto fail;
    }
  }
  for (i = m0; i < nnodes; i++) {
    j = 0;
    while (j < m) {
      n = floor(i * ((double)rand() / 2147483647));
      prob = (double)graph_num_neighbours(g, n) / tot_deg;
      if (((double)rand() / 2147483647) > prob)
        continue;
      wt = -1.0 + 2.0*((double)rand() / 2147483647);
      if (graph_add_edge(g, i, n, wt))
        goto fail;
      j += 1;
      tot_deg += 2;
    }
  }
  return 0;
fail:
  graph_free(g);
  return 1;
}

canonical_original_code:
unsigned char graph_create_scalefree(struct _graph *g, unsigned int nnodes, unsigned short m, unsigned short m0) {
  unsigned long i;
  unsigned long j;
  unsigned int n;
  double prob;
  unsigned long tot_deg;
  double wt;
  struct _graph_label lbl;
  if (g == ((void *)0)) goto fail;
  if (nnodes == 0) goto fail;
  if (m == 0) goto fail;
  if (m0 == 0) goto fail;
  if (m > m0) goto fail;
  if (graph_create(g, nnodes, 0)) goto fail;
  for (i = 0; i < nnodes; i++) {
    _mk_label(&lbl);
    graph_set_nodelabel(g, i, &lbl);
  }
  tot_deg = (m0*m0) - m0;
  for (i = 0; i < m0; i++) {
    for (j = i+1; j < m0; j++) {
      wt = -1.0 + 2.0*((double)rand() / 2147483647);
      if (graph_add_edge(g, i, j, wt)) goto fail;
    }
  }
  for (i = m0; i < nnodes; i++) {
    j = 0;
    while (j < m) {
      n = floor(i * ((double)rand() / 2147483647));
      prob = (double)graph_num_neighbours(g, n) / tot_deg;
      if (((double)rand() / 2147483647) > prob)
        continue;
      wt = -1.0 + 2.0*((double)rand() / 2147483647);
      if (graph_add_edge(g, i, n, wt))
        goto fail;
      j += 1;
      tot_deg += 2;
    }
  }
  return 0;
fail:
  graph_free(g);
  return 1;
}

variable_types:
m
unsigned short

variable_types:
j
unsigned long

variable_types:
n
unsigned int

variable_types: prob double

variable_types: wt double

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


decompiled_code:
__int64 __fastcall graph_init_edge_betweenness(__int64 a1)
{
stats_edge_betweenness(a1, 0LL, 0LL);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
stats_edge_betweenness(a1, 0LL, 0LL);
return 0LL;
}

original_code:
uint8_t graph_init_edge_betweenness(graph_t *g) {
  stats_edge_betweenness(g, 0, ((void *)0));
  return 0;
}

canonical_original_code:
unsigned char graph_init_edge_betweenness(struct _graph *g) {
  stats_edge_betweenness(g, 0, ((void *)0));
  return 0;
}

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


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

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

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

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

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

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

variable_types:
betw
double *

variable_types:
edges
struct _array *

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

variable_types:
nnbrs
unsigned int

variable_types:
nbrs
unsigned int *

variable_types: max double


decompiled_code:
__int64 __fastcall graph_recalculate_edge_betweenness(__int64 a1, unsigned int *a2)
{
size_t v2; // r14
_DWORD *v3; // rax
_DWORD *v4; // r13
int v5; // er15
__int64 i; // rbx
int v7; // eax
int v9; // [rsp+Ch] [rbp-3Ch]

v2 = (unsigned int)graph_num_nodes();
v3 = calloc(v2, 4uLL);
if ( !v3 )
return 1LL;
v4 = v3;
stats_cache_node_component(a1, -1LL, v3);
v5 = v4[*a2];
v9 = v4[a2[1]];
if ( v2 )
{
for ( i = 0LL; i != v2; ++i )
{
if ( *a2 != i && a2[1] != i )
{
v7 = v4[i];
if ( v5 == v7 || v9 == v7 )
{
stats_pathlength(a1, (unsigned int)i, 0LL);
stats_numpaths(a1, (unsigned int)i, 0LL);
}
}
}
}
stats_pathlength(a1, *a2, 0LL);
stats_pathlength(a1, a2[1], 0LL);
stats_numpaths(a1, *a2, 0LL);
stats_numpaths(a1, a2[1], 0LL);
stats_edge_betweenness(a1, *a2, 0LL);
if ( v5 != v9 )
stats_edge_betweenness(a1, a2[1], 0LL);
free(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
size_t v2; // r14
_DWORD *v3; // rax
_DWORD *v4; // r13
int v5; // er15
__int64 i; // rbx
int v7; // eax
int v9; // [rsp+Ch] [rbp-3Ch]

v2 = (unsigned int)graph_num_nodes();
v3 = calloc(v2, 4uLL);
if ( !v3 )
return 1LL;
v4 = v3;
stats_cache_node_component(a1, -1LL, v3);
v5 = v4[*a2];
v9 = v4[a2[1]];
if ( v2 )
{
for ( i = 0LL; i != v2; ++i )
{
if ( *a2 != i && a2[1] != i )
{
v7 = v4[i];
if ( v5 == v7 || v9 == v7 )
{
stats_pathlength(a1, (unsigned int)i, 0LL);
stats_numpaths(a1, (unsigned int)i, 0LL);
}
}
}
}
stats_pathlength(a1, *a2, 0LL);
stats_pathlength(a1, a2[1], 0LL);
stats_numpaths(a1, *a2, 0LL);
stats_numpaths(a1, a2[1], 0LL);
stats_edge_betweenness(a1, *a2, 0LL);
if ( v5 != v9 )
stats_edge_betweenness(a1, a2[1], 0LL);
free(v4);
return 0LL;
}

original_code:
uint8_t graph_recalculate_edge_betweenness(graph_t *g, graph_edge_t *edge) {
  uint64_t i;
  uint32_t nnodes;
  double icmp;
  double ucmp;
  double vcmp;
  uint32_t *components;
  components = ((void *)0);
  nnodes = graph_num_nodes(g);
  components = calloc(nnodes,sizeof(uint32_t));
  if (components == ((void *)0)) goto fail;
  stats_cache_node_component(g, -1, components);
  ucmp = components[edge->u];
  vcmp = components[edge->v];
  for (i = 0; i < nnodes; i++) {
    if (i == edge->u || i == edge->v) continue;
    icmp = components[i];
    if (icmp == ucmp || icmp == vcmp) {
      stats_pathlength(g, i, ((void *)0));
      stats_numpaths( g, i, ((void *)0));
    }
  }
  stats_pathlength(g, edge->u, ((void *)0));
  stats_pathlength(g, edge->v, ((void *)0));
  stats_numpaths( g, edge->u, ((void *)0));
  stats_numpaths( g, edge->v, ((void *)0));
  stats_edge_betweenness(g, edge->u, ((void *)0));
  if (ucmp != vcmp)
    stats_edge_betweenness(g, edge->v, ((void *)0));
  free(components);
  return 0;
fail:
  if (components != ((void *)0)) free(components);
  return 1;
}

canonical_original_code:
unsigned char graph_recalculate_edge_betweenness(struct _graph *g, struct _graph_edge *edge) {
  unsigned long i;
  unsigned int nnodes;
  double icmp;
  double ucmp;
  double vcmp;
  unsigned int *components;
  components = ((void *)0);
  nnodes = graph_num_nodes(g);
  components = calloc(nnodes,sizeof(unsigned int));
  if (components == ((void *)0)) goto fail;
  stats_cache_node_component(g, -1, components);
  ucmp = components[edge->u];
  vcmp = components[edge->v];
  for (i = 0; i < nnodes; i++) {
    if (i == edge->u || i == edge->v) continue;
    icmp = components[i];
    if (icmp == ucmp || icmp == vcmp) {
      stats_pathlength(g, i, ((void *)0));
      stats_numpaths( g, i, ((void *)0));
    }
  }
  stats_pathlength(g, edge->u, ((void *)0));
  stats_pathlength(g, edge->v, ((void *)0));
  stats_numpaths( g, edge->u, ((void *)0));
  stats_numpaths( g, edge->v, ((void *)0));
  stats_edge_betweenness(g, edge->u, ((void *)0));
  if (ucmp != vcmp)
    stats_edge_betweenness(g, edge->v, ((void *)0));
  free(components);
  return 0;
fail:
  if (components != ((void *)0)) free(components);
  return 1;
}

variable_types:
i
unsigned long

variable_types:
nnodes
unsigned int

variable_types: icmp double

variable_types: ucmp double

variable_types: vcmp double

variable_types:
components
unsigned int *

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


decompiled_code:
bool __fastcall graph_are_connected(__int64 a1, unsigned int *a2, unsigned int a3)
{
size_t v4; // r15
void *v5; // rax
void *v6; // rbp
void *v7; // rbx
unsigned int *v8; // rax
__int64 v9; // rbx
bool result; // al
void *ptr[8]; // [rsp+8h] [rbp-40h] BYREF

ptr[0] = 0LL;
v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 1uLL);
if ( v5 )
{
v6 = v5;
v7 = calloc(v4, 1uLL);
ptr[0] = v7;
if ( v7 )
{
memset(v6, 1, v4);
if ( a3 )
{
v8 = a2;
do
*((_BYTE *)v6 + *v8++) = 0;
while ( v8 != &a2[a3] );
*((_BYTE *)v7 + *a2) = 1;
if ( !(unsigned __int8)bfs(a1, a2, 1LL, v6, ptr, 0LL, bfs_cb, 0LL) )
{
v9 = 0LL;
while ( *((_BYTE *)ptr[0] + a2[v9]) )
{
if ( ++v9 == a3 )
{
v9 = a3;
goto LABEL_11;
}
}
goto LABEL_11;
}
}
else
{
*((_BYTE *)v7 + *a2) = 1;
v9 = 0LL;
if ( !(unsigned __int8)bfs(a1, a2, 1LL, v6, ptr, 0LL, bfs_cb, 0LL) )
{
LABEL_11:
free(v6);
free(ptr[0]);
return v9 == a3;
}
}
}
free(v6);
}
result = 1;
if ( ptr[0] )
{
free(ptr[0]);
result = 1;
}
return result;
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1, unsigned int *a2, unsigned int a3)
{
size_t v4; // r15
void *v5; // rax
void *v6; // rbp
void *v7; // rbx
unsigned int *v8; // rax
__int64 v9; // rbx
bool result; // al
void *ptr[8]; // [rsp+8h] [rbp-40h] BYREF

ptr[0] = 0LL;
v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 1uLL);
if ( v5 )
{
v6 = v5;
v7 = calloc(v4, 1uLL);
ptr[0] = v7;
if ( v7 )
{
memset(v6, 1, v4);
if ( a3 )
{
v8 = a2;
do
*((_BYTE *)v6 + *v8++) = 0;
while ( v8 != &a2[a3] );
*((_BYTE *)v7 + *a2) = 1;
if ( !(unsigned __int8)bfs(a1, a2, 1LL, v6, ptr, 0LL, bfs_cb, 0LL) )
{
v9 = 0LL;
while ( *((_BYTE *)ptr[0] + a2[v9]) )
{
if ( ++v9 == a3 )
{
v9 = a3;
goto LABEL_11;
}
}
goto LABEL_11;
}
}
else
{
*((_BYTE *)v7 + *a2) = 1;
v9 = 0LL;
if ( !(unsigned __int8)bfs(a1, a2, 1LL, v6, ptr, 0LL, bfs_cb, 0LL) )
{
LABEL_11:
free(v6);
free(ptr[0]);
return v9 == a3;
}
}
}
free(v6);
}
result = 1;
if ( ptr[0] )
{
free(ptr[0]);
result = 1;
}
return result;
}

original_code:
uint8_t graph_are_connected(graph_t *g, uint32_t *group, uint32_t ngroup) {
  uint8_t *mask;
  uint32_t nnodes;
  uint64_t i;
  ctx_t ctx;
  mask = ((void *)0);
  ctx.visited = ((void *)0);
  nnodes = graph_num_nodes(g);
  mask = calloc(nnodes, sizeof(uint8_t));
  if (mask == ((void *)0)) goto fail;
  ctx.visited = calloc(nnodes, sizeof(uint8_t));
  if (ctx.visited == ((void *)0)) goto fail;
  memset(mask, 1, nnodes);
  for (i = 0; i < ngroup; i++)
    mask[group[i]] = 0;
  ctx.visited[group[0]] = 1;
  if (bfs(g, group, 1, mask, &ctx, ((void *)0), &_bfs_cb, ((void *)0)))
    goto fail;
  for (i = 0; i < ngroup; i++)
    if (!ctx.visited[group[i]])
      break;
  free(mask);
  free(ctx.visited);
  return (i == ngroup) ? 1 : 0;
fail:
  if (mask != ((void *)0)) free(mask);
  if (ctx.visited != ((void *)0)) free(ctx.visited);
  return 1;
}

canonical_original_code:
unsigned char graph_are_connected(struct _graph *g, unsigned int *group, unsigned int ngroup) {
  unsigned char *mask;
  unsigned int nnodes;
  unsigned long i;
  struct _ctx ctx;
  mask = ((void *)0);
  ctx.visited = ((void *)0);
  nnodes = graph_num_nodes(g);
  mask = calloc(nnodes, sizeof(unsigned char));
  if (mask == ((void *)0)) goto fail;
  ctx.visited = calloc(nnodes, sizeof(unsigned char));
  if (ctx.visited == ((void *)0)) goto fail;
  memset(mask, 1, nnodes);
  for (i = 0; i < ngroup; i++)
    mask[group[i]] = 0;
  ctx.visited[group[0]] = 1;
  if (bfs(g, group, 1, mask, &ctx, ((void *)0), &_bfs_cb, ((void *)0)))
    goto fail;
  for (i = 0; i < ngroup; i++)
    if (!ctx.visited[group[i]])
      break;
  free(mask);
  free(ctx.visited);
  return (i == ngroup) ? 1 : 0;
fail:
  if (mask != ((void *)0)) free(mask);
  if (ctx.visited != ((void *)0)) free(ctx.visited);
  return 1;
}

variable_types:
group
unsigned int *

variable_types:
ngroup
unsigned int

variable_types:
mask
unsigned char *

variable_types:
ctx
struct _ctx { unsigned char *visited; }


decompiled_code:
__int64 __fastcall graph_connect(__int64 a1, unsigned int *a2, signed int a3)
{
__int64 v4; // rbx
__int64 v5; // rax
double v7; // [rsp+8h] [rbp-30h]

printf(" ");
do
{
if ( graph_are_connected(a1, a2, a3) )
return 0LL;
v7 = (double)a3 / 2147483647.0;
v4 = (unsigned int)(int)((double)rand() * v7);
do
v5 = (unsigned int)(int)((double)rand() * v7);
while ( v4 == v5 );
}
while ( !(unsigned __int8)graph_add_edge(a1, a2[v4], a2[v5], 1.0) );
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2, signed int a3)
{
__int64 v4; // rbx
__int64 v5; // rax
double v7; // [rsp+8h] [rbp-30h]

printf(" ");
do
{
if ( func1(a1, a2, a3) )
return 0LL;
v7 = (double)a3 / 2147483647.0;
v4 = (unsigned int)(int)((double)rand() * v7);
do
v5 = (unsigned int)(int)((double)rand() * v7);
while ( v4 == v5 );
}
while ( !(unsigned __int8)graph_add_edge(a1, a2[v4], a2[v5], 1.0) );
return 1LL;
}

original_code:
uint8_t graph_connect(graph_t *g, uint32_t *group, uint32_t ngroup) {
  uint64_t i;
  uint64_t j;
  printf("              ");
  while (!graph_are_connected(g, group, ngroup)) {
    i = (uint32_t)(rand() * ((double)ngroup / 2147483647));
    j = i;
    while (j == i)
      j = (uint32_t)(rand() * ((double)ngroup / 2147483647));
    if (graph_add_edge(g, group[i], group[j], 1))
      goto fail;
  }
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_connect(struct _graph *g, unsigned int *group, unsigned int ngroup) {
  unsigned long i;
  unsigned long j;
  printf("              ");
  while (!graph_are_connected(g, group, ngroup)) {
    i = (unsigned int)(rand() * ((double)ngroup / 2147483647));
    j = i;
    while (j == i)
      j = (unsigned int)(rand() * ((double)ngroup / 2147483647));
    if (graph_add_edge(g, group[i], group[j], 1))
      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:
j
unsigned long


decompiled_code:
__int64 __fastcall graph_connect_from(__int64 a1, __int64 a2, unsigned int *a3, unsigned int a4)
{
unsigned __int64 v4; // r13
unsigned int *v5; // r12
unsigned int *v6; // rbp
unsigned __int64 v7; // r15
unsigned __int64 v8; // rbx

v4 = a4;
if ( !a4 )
return 0LL;
v5 = a3;
v6 = a3;
v7 = 0LL;
do
{
while ( ++v7 < v4 )
{
v8 = v7;
do
{
if ( (unsigned __int8)graph_are_neighbours(a2, *v6, v5[v8])
&& (unsigned __int8)graph_add_edge(a1, *v6, v5[v8], 1.0) )
{
return 1LL;
}
++v8;
}
while ( v8 < v4 );
++v6;
}
++v6;
}
while ( v7 != v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int *a3, unsigned int a4)
{
unsigned __int64 v4; // r13
unsigned int *v5; // r12
unsigned int *v6; // rbp
unsigned __int64 v7; // r15
unsigned __int64 v8; // rbx

v4 = a4;
if ( !a4 )
return 0LL;
v5 = a3;
v6 = a3;
v7 = 0LL;
do
{
while ( ++v7 < v4 )
{
v8 = v7;
do
{
if ( (unsigned __int8)graph_are_neighbours(a2, *v6, v5[v8])
&& (unsigned __int8)graph_add_edge(a1, *v6, v5[v8], 1.0) )
{
return 1LL;
}
++v8;
}
while ( v8 < v4 );
++v6;
}
++v6;
}
while ( v7 != v4 );
return 0LL;
}

original_code:
uint8_t graph_connect_from(
  graph_t *g, graph_t *src, uint32_t *group, uint32_t ngroup) {
  uint64_t i;
  uint64_t j;
  for (i = 0; i < ngroup; i++) {
    for (j = i+1; j < ngroup; j++) {
      if (graph_are_neighbours(src, group[i], group[j])) {
        if (graph_add_edge(g, group[i], group[j], 1.0))
          goto fail;
      }
    }
  }
  return 0;
fail:
  return 1;
}

canonical_original_code:
unsigned char graph_connect_from(struct _graph *g, struct _graph *src, unsigned int *group, unsigned int ngroup) {
  unsigned long i;
  unsigned long j;
  for (i = 0; i < ngroup; i++) {
    for (j = i+1; j < ngroup; j++) {
      if (graph_are_neighbours(src, group[i], group[j])) {
        if (graph_add_edge(g, group[i], group[j], 1.0))
          goto fail;
      }
    }
  }
  return 0;
fail:
  return 1;
}

variable_types:
src
struct _graph *


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

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

variable_types:
nclusters
unsigned int

variable_types: internal double

variable_types: external double

variable_types: sizerange double

variable_types:
ni
unsigned long

variable_types:
nj
unsigned long

variable_types:
ci
unsigned long

variable_types:
cj
unsigned long

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

variable_types:
nci
unsigned long

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

variable_types:
sz
unsigned int

variable_types:
tmp
unsigned int


decompiled_code:
__int64 __fastcall graph_create_clustered_by_degree(__int64 a1, signed int a2, signed int a3, double a4, double a5, double a6)
{
double v8; // r15
double v9; // rbx
double v10; // xmm1_8
double v12; // [rsp+8h] [rbp-50h]
double v13; // [rsp+8h] [rbp-50h]
double v14; // [rsp+10h] [rbp-48h]

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, signed int a2, signed int a3, double a4, double a5, double a6)
{
double v8; // r15
double v9; // rbx
double v10; // xmm1_8
double v12; // [rsp+8h] [rbp-50h]
double v13; // [rsp+8h] [rbp-50h]
double v14; // [rsp+10h] [rbp-48h]

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

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

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

variable_types:
nnodes
unsigned int

variable_types: intdegree double

variable_types: extdegree double

variable_types: clustsz double

variable_types: maxintra double

variable_types: maxinter double

variable_types: nintra double

variable_types: ninter double

variable_types: intdens double

variable_types: extdens double


decompiled_code:
__int64 __fastcall graph_create_clustered_by_total(__int64 a1, signed int a2, signed int a3, double a4, double a5, double a6)
{
__int64 result; // rax
double v9; // r15
double v10; // xmm1_8
double v11; // [rsp+10h] [rbp-48h]
double v12; // [rsp+18h] [rbp-40h]

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, signed int a2, signed int a3, double a4, double a5, double a6)
{
__int64 result; // rax
double v9; // r15
double v10; // xmm1_8
double v11; // [rsp+10h] [rbp-48h]
double v12; // [rsp+18h] [rbp-40h]

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

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

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

variable_types: 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:
nclusters
unsigned int

variable_types: internal double

variable_types: total double

variable_types: sizerange double

variable_types: external double


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

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

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

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

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

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

variable_types:
gout
struct _graph *

variable_types:
size
unsigned int

variable_types: prop double

variable_types:
components
unsigned int *

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

variable_types:
i
unsigned long

variable_types:
s
unsigned int


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

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

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

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

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

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

variable_types: threshold double

variable_types:
absval
unsigned char

variable_types:
reverse
unsigned char


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

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

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

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

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

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

variable_types:
nedges
unsigned int

variable_types:
flags
unsigned int

variable_types:
opt
void *

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

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

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

variable_types:
nnodes
unsigned int

variable_types:
space
double *


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

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

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

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

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

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

variable_types: 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:
cmplimit
unsigned int

variable_types:
igndis
unsigned int

variable_types:
ncmps
unsigned long

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


decompiled_code:
__int64 __fastcall graph_threshold_modularity(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, void (__fastcall *a6)(char *), unsigned __int8 (__fastcall *a7)(char *, void *, char *, char *), unsigned __int8 (__fastcall *a8)(char *, char *))
{
unsigned int v11; // er15
void *v12; // r13
unsigned int v13; // ebp
void *v14; // rdi
void *v15; // rdi
void *v17; // rax
void *v18; // rax
__int64 v19; // r15
__int64 v20; // r14
double v21; // xmm0_8
double v22; // [rsp+0h] [rbp-2B8h]
void *ptr; // [rsp+8h] [rbp-2B0h]
char v24[128]; // [rsp+20h] [rbp-298h] BYREF
__int64 v25; // [rsp+A0h] [rbp-218h]
char v26[16]; // [rsp+130h] [rbp-188h] BYREF
char v27[16]; // [rsp+140h] [rbp-178h] BYREF
__int64 v28; // [rsp+150h] [rbp-168h]
char v29[328]; // [rsp+170h] [rbp-148h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, unsigned int a3, __int64 a4, __int64 a5, void (__fastcall *a6)(char *), unsigned __int8 (__fastcall *a7)(char *, void *, char *, char *), unsigned __int8 (__fastcall *a8)(char *, char *))
{
unsigned int v11; // er15
void *v12; // r13
unsigned int v13; // ebp
void *v14; // rdi
void *v15; // rdi
void *v17; // rax
void *v18; // rax
__int64 v19; // r15
__int64 v20; // r14
double v21; // xmm0_8
double v22; // [rsp+0h] [rbp-2B8h]
void *ptr; // [rsp+8h] [rbp-2B0h]
char v24[128]; // [rsp+20h] [rbp-298h] BYREF
__int64 v25; // [rsp+A0h] [rbp-218h]
char v26[16]; // [rsp+130h] [rbp-188h] BYREF
char v27[16]; // [rsp+140h] [rbp-178h] BYREF
__int64 v28; // [rsp+150h] [rbp-168h]
char v29[328]; // [rsp+170h] [rbp-148h] BYREF

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

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

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

variable_types:
edgelimit
unsigned int

variable_types:
i
unsigned long

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: mod double

variable_types: maxmod double

variable_types:
ncmps
unsigned int

variable_types:
components
unsigned int *

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