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

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

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

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

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

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

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

variable_types:
nidx
unsigned int

variable_types:
pathlens
double *

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

variable_types: path double


repo: pauldmccarthy/ccnet

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

v8[0] = 0.0;
v1 = graph_num_nodes();
if ( v1 )
{
v2 = v1;
v3 = 0;
for ( i = 0; i != v2; ++i )
{
v5 = stats_pathlength(a1, i, 0LL);
if ( v5 < 0.0 )
return *(double *)&LC1;
++v3;
v8[0] = v5 + v8[0];
}
v7 = (double)v3;
}
else
{
v7 = 0.0;
}
v8[0] = v8[0] / v7;
stats_cache_add(a1, 3LL, 0LL, 8LL);
stats_cache_update(a1, 3LL, 0LL, -1LL, v8);
return v8[0];
}

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

v8[0] = 0.0;
v1 = graph_num_nodes();
if ( v1 )
{
v2 = v1;
v3 = 0;
for ( i = 0; i != v2; ++i )
{
v5 = func1(a1, i, 0LL);
if ( v5 < 0.0 )
return *(double *)&LC1;
++v3;
v8[0] = v5 + v8[0];
}
v7 = (double)v3;
}
else
{
v7 = 0.0;
}
v8[0] = v8[0] / v7;
stats_cache_add(a1, 3LL, 0LL, 8LL);
stats_cache_update(a1, 3LL, 0LL, -1LL, v8);
return v8[0];
}

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

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

variable_types:
i
unsigned int

variable_types:
numnodes
unsigned int

variable_types:
count
unsigned int

variable_types: avgpath double

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

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


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

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

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

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

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

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

variable_types:
ncommunities
unsigned int

variable_types:
communities
unsigned int *

variable_types:
nnodes
unsigned int

variable_types:
indegrees
unsigned int *

variable_types:
outdegrees
unsigned int *

variable_types: fitness double


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

v17[0] = a5;
v9 = (unsigned int)graph_num_nodes();
v10 = calloc(v9, 1uLL);
ptr = v10;
if ( v10 )
{
if ( a4 )
{
v11 = v10;
v12 = a3;
while ( 1 )
{
v13 = *v12++;
v11[v13] = 1;
if ( v12 == &a3[a4] )
break;
v11 = ptr;
}
}
if ( !(unsigned __int8)((__int64 (__fastcall *)(__int64, unsigned int *, _QWORD, _QWORD, char *, _QWORD, bool (__fastcall *)(_DWORD *, unsigned __int8 *), _QWORD))bfs)(
a1,
a3,
a4,
0LL,
v17,
0LL,
bfs_cb,
0LL) )
{
v14 = graph_mask(a1, a2, ptr);
if ( !(_BYTE)v14 )
{
if ( !a6 )
goto LABEL_16;
v16 = 0LL;
if ( v9 )
{
do
{
*((_BYTE *)ptr + v16) = *((_BYTE *)ptr + v16) == 0;
++v16;
}
while ( v9 != v16 );
}
if ( !(unsigned __int8)graph_mask(a1, a6, ptr) )
{
LABEL_16:
free(ptr);
return v14;
}
}
}
if ( ptr )
free(ptr);
}
return 1;
}

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

v17[0] = a5;
v9 = (unsigned int)graph_num_nodes();
v10 = calloc(v9, 1uLL);
ptr = v10;
if ( v10 )
{
if ( a4 )
{
v11 = v10;
v12 = a3;
while ( 1 )
{
v13 = *v12++;
v11[v13] = 1;
if ( v12 == &a3[a4] )
break;
v11 = ptr;
}
}
if ( !(unsigned __int8)((__int64 (__fastcall *)(__int64, unsigned int *, _QWORD, _QWORD, char *, _QWORD, bool (__fastcall *)(_DWORD *, unsigned __int8 *), _QWORD))bfs)(
a1,
a3,
a4,
0LL,
v17,
0LL,
bfs_cb,
0LL) )
{
v14 = graph_mask(a1, a2, ptr);
if ( !(_BYTE)v14 )
{
if ( !a6 )
goto LABEL_16;
v16 = 0LL;
if ( v9 )
{
do
{
*((_BYTE *)ptr + v16) = *((_BYTE *)ptr + v16) == 0;
++v16;
}
while ( v9 != v16 );
}
if ( !(unsigned __int8)graph_mask(a1, a6, ptr) )
{
LABEL_16:
free(ptr);
return v14;
}
}
}
if ( ptr )
free(ptr);
}
return 1;
}

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

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

variable_types:
gout
struct _graph *

variable_types:
seeds
unsigned int *

variable_types:
nseeds
unsigned int

variable_types:
depth
unsigned char

variable_types:
grem
struct _graph *

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

variable_types:
i
unsigned long

return_type: unsigned char


decompiled_code:
__int64 __fastcall graph_create_smallworld(__int64 a1, __int64 a2, unsigned __int16 a3, double a4)
{
unsigned __int16 v4; // r13
unsigned int v5; // er14
unsigned __int64 v6; // rbp
unsigned __int64 v7; // r13
unsigned __int64 v8; // rbp
int v9; // eax
float v10; // xmm0_4
unsigned __int64 v12; // rbp
unsigned int v13; // er15
__int64 v14; // r13
__int64 v15; // rax
__int64 v16; // r15
int v17; // eax
__m128d v18; // xmm0
__m128d v19; // xmm2
unsigned int v20; // er8
float v21; // xmm0_4
unsigned __int64 v23; // [rsp+8h] [rbp-B0h]
__int64 v24; // [rsp+8h] [rbp-B0h]
unsigned int v25; // [rsp+14h] [rbp-A4h]
unsigned int v26; // [rsp+20h] [rbp-98h]
double v27; // [rsp+28h] [rbp-90h]
char v28[136]; // [rsp+30h] [rbp-88h] BYREF

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

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

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

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

variable_types: p double

variable_types:
k
unsigned short

variable_types:
j
unsigned long

variable_types:
oldnbr
unsigned int

variable_types:
newnbr
unsigned int

variable_types:
nnbrs
unsigned int

variable_types:
nbrs
unsigned int *

variable_types: wt double

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


decompiled_code:
__int64 __fastcall dimorder_parse(__int64 a1, const char **a2, unsigned __int8 *a3, unsigned __int8 a4)
{
unsigned __int8 v4; // r15
unsigned __int8 v5; // r13
unsigned __int8 *v6; // rbp
const char **v7; // rbx
unsigned __int8 v8; // al
unsigned __int8 v9; // r12
__int64 v10; // r15
unsigned __int8 v11; // al
const char *v12; // r14
unsigned __int8 v14; // dl
unsigned __int8 *v15; // rax
unsigned __int8 v16; // al
__int64 v17; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, const char **a2, unsigned __int8 *a3, unsigned __int8 a4)
{
unsigned __int8 v4; // r15
unsigned __int8 v5; // r13
unsigned __int8 *v6; // rbp
const char **v7; // rbx
unsigned __int8 v8; // al
unsigned __int8 v9; // r12
__int64 v10; // r15
unsigned __int8 v11; // al
const char *v12; // r14
unsigned __int8 v14; // dl
unsigned __int8 *v15; // rax
unsigned __int8 v16; // al
__int64 v17; // rax

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

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

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

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

variable_types:
order
char *[]

variable_types:
dims
unsigned char *

variable_types:
orderlen
unsigned char

variable_types:
i
unsigned char

variable_types:
j
unsigned char

variable_types:
ndims
unsigned char

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


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

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

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

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

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

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

variable_types:
dims
unsigned int *

variable_types:
dimorder
unsigned char *

variable_types:
i
unsigned int

variable_types:
ndims
unsigned short

variable_types:
dimsz
unsigned int

return_type: void

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

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

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


reverse

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

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

variable_types:
src
void *

variable_types:
dst
void *

variable_types: len int

variable_types: i int

variable_types:
tmp
unsigned char

variable_types:
usrc
unsigned char *

variable_types:
udst
unsigned char *


decompiled_code:
double __fastcall stats_numpaths(__int64 a1, int a2, void *a3)
{
size_t v4; // rbx
void *v5; // rax
_QWORD *v6; // r12
double result; // xmm0_8
unsigned int v8; // [rsp+Ch] [rbp-4Ch] BYREF
int v9; // [rsp+10h] [rbp-48h] BYREF
double v10; // [rsp+18h] [rbp-40h] BYREF
void *src; // [rsp+20h] [rbp-38h]
void *ptr; // [rsp+28h] [rbp-30h]

v8 = a2;
v9 = a2;
v10 = 0.0;
ptr = 0LL;
v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 8uLL);
src = v5;
if ( v5 )
{
v6 = v5;
ptr = calloc(v4, 1uLL);
if ( !ptr )
goto LABEL_9;
v6[v8] = LC0;
if ( !(unsigned __int8)bfs(a1, &v8, 1LL, 0LL, &v9) )
{
if ( a3 )
memcpy(a3, src, 8 * v4);
stats_cache_add(a1, 19LL, 2LL, 8LL);
stats_cache_add(a1, 23LL, 3LL, 8LL);
stats_cache_update(a1, 19LL, v8, -1LL, &v10);
stats_cache_update(a1, 23LL, v8, -1LL, src);
free(src);
free(ptr);
return v10;
}
v6 = src;
if ( src )
LABEL_9:
free(v6);
}
result = 0.0;
if ( ptr )
{
free(ptr);
result = 0.0;
}
return result;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1, int a2, void *a3)
{
size_t v4; // rbx
void *v5; // rax
_QWORD *v6; // r12
double result; // xmm0_8
unsigned int v8; // [rsp+Ch] [rbp-4Ch] BYREF
int v9; // [rsp+10h] [rbp-48h] BYREF
double v10; // [rsp+18h] [rbp-40h] BYREF
void *src; // [rsp+20h] [rbp-38h]
void *ptr; // [rsp+28h] [rbp-30h]

v8 = a2;
v9 = a2;
v10 = 0.0;
ptr = 0LL;
v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 8uLL);
src = v5;
if ( v5 )
{
v6 = v5;
ptr = calloc(v4, 1uLL);
if ( !ptr )
goto LABEL_9;
v6[v8] = LC0;
if ( !(unsigned __int8)bfs(a1, &v8, 1LL, 0LL, &v9) )
{
if ( a3 )
memcpy(a3, src, 8 * v4);
stats_cache_add(a1, 19LL, 2LL, 8LL);
stats_cache_add(a1, 23LL, 3LL, 8LL);
stats_cache_update(a1, 19LL, v8, -1LL, &v10);
stats_cache_update(a1, 23LL, v8, -1LL, src);
free(src);
free(ptr);
return v10;
}
v6 = src;
if ( src )
LABEL_9:
free(v6);
}
result = 0.0;
if ( ptr )
{
free(ptr);
result = 0.0;
}
return result;
}

original_code:
double stats_numpaths(graph_t *g, uint32_t nidx, double *numpaths) {
  bfs_ctx_t ctx;
  uint32_t nnodes;
  ctx.root = nidx;
  ctx.total = 0;
  ctx.numpaths = ((void *)0);
  ctx.visited = ((void *)0);
  nnodes = graph_num_nodes(g);
  ctx.numpaths = calloc(nnodes, sizeof(double));
  if (ctx.numpaths == ((void *)0)) goto fail;
  ctx.visited = calloc(nnodes, sizeof(uint8_t));
  if (ctx.visited == ((void *)0)) goto fail;
  ctx.numpaths[nidx] = 1;
  if (bfs(g, &nidx, 1, ((void *)0), &ctx, &ctx, _bfs_cb, _exp_cb)) goto fail;
  if (numpaths != ((void *)0))
    memcpy(numpaths, ctx.numpaths, nnodes*sizeof(double));
  stats_cache_add(g,
                  STATS_CACHE_NODE_NUMPATHS,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(double));
  stats_cache_add(g,
                  STATS_CACHE_PAIR_NUMPATHS,
                  STATS_CACHE_TYPE_PAIR,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_NODE_NUMPATHS, nidx, -1, &(ctx.total));
  stats_cache_update(g, STATS_CACHE_PAIR_NUMPATHS, nidx, -1, ctx.numpaths);
  free(ctx.numpaths);
  free(ctx.visited);
  return ctx.total;
fail:
  if (ctx.numpaths != ((void *)0)) free(ctx.numpaths);
  if (ctx.visited != ((void *)0)) free(ctx.visited);
  return 0;
}

canonical_original_code:
double stats_numpaths(struct _graph *g, unsigned int nidx, double *numpaths) {
  struct _bfs_ctx ctx;
  unsigned int nnodes;
  ctx.root = nidx;
  ctx.total = 0;
  ctx.numpaths = ((void *)0);
  ctx.visited = ((void *)0);
  nnodes = graph_num_nodes(g);
  ctx.numpaths = calloc(nnodes, sizeof(double));
  if (ctx.numpaths == ((void *)0)) goto fail;
  ctx.visited = calloc(nnodes, sizeof(unsigned char));
  if (ctx.visited == ((void *)0)) goto fail;
  ctx.numpaths[nidx] = 1;
  if (bfs(g, &nidx, 1, ((void *)0), &ctx, &ctx, _bfs_cb, _exp_cb)) goto fail;
  if (numpaths != ((void *)0))
    memcpy(numpaths, ctx.numpaths, nnodes*sizeof(double));
  stats_cache_add(g,
                  STATS_CACHE_NODE_NUMPATHS,
                  STATS_CACHE_TYPE_NODE,
                  sizeof(double));
  stats_cache_add(g,
                  STATS_CACHE_PAIR_NUMPATHS,
                  STATS_CACHE_TYPE_PAIR,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_NODE_NUMPATHS, nidx, -1, &(ctx.total));
  stats_cache_update(g, STATS_CACHE_PAIR_NUMPATHS, nidx, -1, ctx.numpaths);
  free(ctx.numpaths);
  free(ctx.visited);
  return ctx.total;
fail:
  if (ctx.numpaths != ((void *)0)) free(ctx.numpaths);
  if (ctx.visited != ((void *)0)) free(ctx.visited);
  return 0;
}

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

variable_types:
nidx
unsigned int

variable_types:
numpaths
double *

variable_types: struct _bfs_ctx { unsigned int root; double total; double *numpaths; unsigned char *visited; }

variable_types:
nnodes
unsigned int


decompiled_code:
double __fastcall stats_edge_pathsharing(__int64 a1, unsigned int a2, unsigned int a3)
{
double result; // xmm0_8
unsigned int v6; // er14
__int64 v7; // rbx
__int64 v8; // r13
__int64 v9; // r14
__int64 i; // r14
_DWORD *v11; // r13
__int64 v12; // rsi
int v13; // [rsp+0h] [rbp-80h]
double v14; // [rsp+8h] [rbp-78h]
double v15; // [rsp+10h] [rbp-70h]
__int64 v16; // [rsp+18h] [rbp-68h]
__int64 v17; // [rsp+20h] [rbp-60h]
__int64 v18; // [rsp+30h] [rbp-50h]
double v19[8]; // [rsp+40h] [rbp-40h] BYREF

if ( a2 == a3 )
return 0.0;
result = 0.0;
if ( (unsigned __int8)((__int64 (*)(void))graph_are_neighbours)() )
{
v13 = graph_num_neighbours(a1, a2, 0.0);
v6 = graph_num_neighbours(a1, a3, 0.0);
v7 = graph_get_neighbours(a1, a2);
v17 = graph_get_neighbours(a1, a3);
v18 = graph_get_weights(a1, a2);
v8 = graph_get_weights(a1, a3);
v16 = v6;
v15 = (double)(int)(v6 * v13);
if ( v6 )
{
v9 = 0LL;
v14 = 0.0;
do
{
if ( *(_DWORD *)(v17 + 4 * v9) == a2 || (unsigned __int8)graph_are_neighbours(a1, a2) )
v14 = *(float *)(v8 + 4 * v9) + v14;
++v9;
}
while ( v9 != v16 );
}
else
{
v14 = 0.0;
}
if ( v13 )
{
for ( i = 0LL; i != v13; ++i )
{
if ( *(_DWORD *)(v7 + 4 * i) != a3 )
{
if ( (unsigned __int8)graph_are_neighbours(a1, a3) )
v14 = *(float *)(v18 + 4 * i) + v14;
if ( v16 )
{
v11 = (_DWORD *)v17;
do
{
if ( *v11 != a2 )
{
v12 = *(unsigned int *)(v7 + 4 * i);
if ( *v11 == (_DWORD)v12 )
{
v15 = v15 - 1.0;
}
else if ( (unsigned __int8)graph_are_neighbours(a1, v12) )
{
v14 = graph_get_weight(a1, *(unsigned int *)(v7 + 4 * i), (unsigned int)*v11) + v14;
}
}
++v11;
}
while ( (_DWORD *)(v17 + 4 * v16) != v11 );
}
}
}
}
v19[0] = v14 / v15;
stats_cache_add(a1, 24LL, 4LL, 8LL);
stats_cache_update(a1, 24LL, a2, a3, v19);
result = v19[0];
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3)
{
double result; // xmm0_8
unsigned int v6; // er14
__int64 v7; // rbx
__int64 v8; // r13
__int64 v9; // r14
__int64 i; // r14
_DWORD *v11; // r13
__int64 v12; // rsi
int v13; // [rsp+0h] [rbp-80h]
double v14; // [rsp+8h] [rbp-78h]
double v15; // [rsp+10h] [rbp-70h]
__int64 v16; // [rsp+18h] [rbp-68h]
__int64 v17; // [rsp+20h] [rbp-60h]
__int64 v18; // [rsp+30h] [rbp-50h]
double v19[8]; // [rsp+40h] [rbp-40h] BYREF

if ( a2 == a3 )
return 0.0;
result = 0.0;
if ( (unsigned __int8)((__int64 (*)(void))graph_are_neighbours)() )
{
v13 = graph_num_neighbours(a1, a2, 0.0);
v6 = graph_num_neighbours(a1, a3, 0.0);
v7 = graph_get_neighbours(a1, a2);
v17 = graph_get_neighbours(a1, a3);
v18 = graph_get_weights(a1, a2);
v8 = graph_get_weights(a1, a3);
v16 = v6;
v15 = (double)(int)(v6 * v13);
if ( v6 )
{
v9 = 0LL;
v14 = 0.0;
do
{
if ( *(_DWORD *)(v17 + 4 * v9) == a2 || (unsigned __int8)graph_are_neighbours(a1, a2) )
v14 = *(float *)(v8 + 4 * v9) + v14;
++v9;
}
while ( v9 != v16 );
}
else
{
v14 = 0.0;
}
if ( v13 )
{
for ( i = 0LL; i != v13; ++i )
{
if ( *(_DWORD *)(v7 + 4 * i) != a3 )
{
if ( (unsigned __int8)graph_are_neighbours(a1, a3) )
v14 = *(float *)(v18 + 4 * i) + v14;
if ( v16 )
{
v11 = (_DWORD *)v17;
do
{
if ( *v11 != a2 )
{
v12 = *(unsigned int *)(v7 + 4 * i);
if ( *v11 == (_DWORD)v12 )
{
v15 = v15 - 1.0;
}
else if ( (unsigned __int8)graph_are_neighbours(a1, v12) )
{
v14 = graph_get_weight(a1, *(unsigned int *)(v7 + 4 * i), (unsigned int)*v11) + v14;
}
}
++v11;
}
while ( (_DWORD *)(v17 + 4 * v16) != v11 );
}
}
}
}
v19[0] = v14 / v15;
stats_cache_add(a1, 24LL, 4LL, 8LL);
stats_cache_update(a1, 24LL, a2, a3, v19);
result = v19[0];
}
return result;
}

original_code:
double stats_edge_pathsharing(graph_t *g, uint32_t u, uint32_t v) {
  uint64_t i;
  uint64_t j;
  uint32_t nunbrs;
  uint32_t nvnbrs;
  uint32_t *unbrs;
  float *uwts;
  uint32_t *vnbrs;
  float *vwts;
  double count;
  double divisor;
  double ps;
  if (u == v) return 0;
  if (!graph_are_neighbours(g, u, v)) return 0;
  nunbrs = graph_num_neighbours(g, u);
  nvnbrs = graph_num_neighbours(g, v);
  unbrs = graph_get_neighbours(g, u);
  vnbrs = graph_get_neighbours(g, v);
  uwts = graph_get_weights (g, u);
  vwts = graph_get_weights (g, v);
  count = 0;
  divisor = (nunbrs) * (nvnbrs);
  for (j = 0; j < nvnbrs; j++) {
    if (vnbrs[j] == u) {count += vwts[j]; continue;}
    if (graph_are_neighbours(g, u, vnbrs[j])) count += vwts[j];
  }
  for (i = 0; i < nunbrs; i++) {
    if (unbrs[i] == v) continue;
    if (graph_are_neighbours(g, v, unbrs[i])) count += uwts[i];
    for (j = 0; j < nvnbrs; j++) {
      if (vnbrs[j] == u) continue;
      if (unbrs[i] == vnbrs[j]) {divisor -= 1; continue;}
      if (graph_are_neighbours(g, unbrs[i], vnbrs[j]))
        count += graph_get_weight(g, unbrs[i], vnbrs[j]);
    }
  }
  ps = count / divisor;
  stats_cache_add(g,
                  STATS_CACHE_EDGE_PATHSHARING,
                  STATS_CACHE_TYPE_EDGE,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_EDGE_PATHSHARING, u, v, &ps);
  return ps;
}

canonical_original_code:
double stats_edge_pathsharing(struct _graph *g, unsigned int u, unsigned int v) {
  unsigned long i;
  unsigned long j;
  unsigned int nunbrs;
  unsigned int nvnbrs;
  unsigned int *unbrs;
  float *uwts;
  unsigned int *vnbrs;
  float *vwts;
  double count;
  double divisor;
  double ps;
  if (u == v) return 0;
  if (!graph_are_neighbours(g, u, v)) return 0;
  nunbrs = graph_num_neighbours(g, u);
  nvnbrs = graph_num_neighbours(g, v);
  unbrs = graph_get_neighbours(g, u);
  vnbrs = graph_get_neighbours(g, v);
  uwts = graph_get_weights (g, u);
  vwts = graph_get_weights (g, v);
  count = 0;
  divisor = (nunbrs) * (nvnbrs);
  for (j = 0; j < nvnbrs; j++) {
    if (vnbrs[j] == u) {count += vwts[j]; continue;}
    if (graph_are_neighbours(g, u, vnbrs[j])) count += vwts[j];
  }
  for (i = 0; i < nunbrs; i++) {
    if (unbrs[i] == v) continue;
    if (graph_are_neighbours(g, v, unbrs[i])) count += uwts[i];
    for (j = 0; j < nvnbrs; j++) {
      if (vnbrs[j] == u) continue;
      if (unbrs[i] == vnbrs[j]) {divisor -= 1; continue;}
      if (graph_are_neighbours(g, unbrs[i], vnbrs[j]))
        count += graph_get_weight(g, unbrs[i], vnbrs[j]);
    }
  }
  ps = count / divisor;
  stats_cache_add(g,
                  STATS_CACHE_EDGE_PATHSHARING,
                  STATS_CACHE_TYPE_EDGE,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_EDGE_PATHSHARING, u, v, &ps);
  return ps;
}

variable_types:
u
unsigned int

variable_types:
v
unsigned int

variable_types:
i
unsigned long

variable_types:
j
unsigned long

variable_types:
nunbrs
unsigned int

variable_types:
nvnbrs
unsigned int

variable_types:
unbrs
unsigned int *

variable_types:
uwts
float *

variable_types:
vnbrs
unsigned int *

variable_types:
vwts
float *

variable_types: count double

variable_types: divisor double

variable_types: ps double


decompiled_code:
__int64 __fastcall graph_get_component(__int64 a1, int a2, __int64 a3)
{
size_t v4; // rbx
void *v5; // rax
void *v6; // rbp
unsigned int v7; // er14
unsigned __int64 v8; // rax
unsigned __int64 v10[6]; // [rsp+8h] [rbp-30h] BYREF

v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 4uLL);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = v5;
v7 = stats_cache_node_component(a1, -1LL, v5);
if ( (_BYTE)v7 )
{
LABEL_8:
free(v6);
return 0xFFFFFFFFLL;
}
v10[0] = 0LL;
if ( v4 )
{
v8 = 0LL;
while ( *((_DWORD *)v6 + v8) != a2 || !(unsigned __int8)array_append(a3, v10) )
{
v8 = v10[0] + 1;
v10[0] = v8;
if ( v4 <= v8 )
goto LABEL_10;
}
goto LABEL_8;
}
LABEL_10:
free(v6);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2, __int64 a3)
{
size_t v4; // rbx
void *v5; // rax
void *v6; // rbp
unsigned int v7; // er14
unsigned __int64 v8; // rax
unsigned __int64 v10[6]; // [rsp+8h] [rbp-30h] BYREF

v4 = (unsigned int)graph_num_nodes();
v5 = calloc(v4, 4uLL);
if ( !v5 )
return 0xFFFFFFFFLL;
v6 = v5;
v7 = stats_cache_node_component(a1, -1LL, v5);
if ( (_BYTE)v7 )
{
LABEL_8:
free(v6);
return 0xFFFFFFFFLL;
}
v10[0] = 0LL;
if ( v4 )
{
v8 = 0LL;
while ( *((_DWORD *)v6 + v8) != a2 || !(unsigned __int8)array_append(a3, v10) )
{
v8 = v10[0] + 1;
v10[0] = v8;
if ( v4 <= v8 )
goto LABEL_10;
}
goto LABEL_8;
}
LABEL_10:
free(v6);
return v7;
}

original_code:
uint8_t graph_get_component(graph_t *g, uint32_t cmp, array_t *nodeids) {
  uint64_t i;
  uint32_t nnodes;
  uint32_t *cmpnums;
  cmpnums = ((void *)0);
  nnodes = graph_num_nodes(g);
  cmpnums = calloc(nnodes, sizeof(uint32_t));
  if (cmpnums == ((void *)0)) goto fail;
  if (stats_cache_node_component(g, -1, cmpnums)) goto fail;
  for (i = 0; i < nnodes; i++) {
    if (cmpnums[i] != cmp) continue;
    if (array_append(nodeids, &i)) goto fail;
  }
  free(cmpnums);
  return 0;
fail:
  if (cmpnums != ((void *)0)) free(cmpnums);
  return -1;
}

canonical_original_code:
unsigned char graph_get_component(struct _graph *g, unsigned int cmp, struct _array *nodeids) {
  unsigned long i;
  unsigned int nnodes;
  unsigned int *cmpnums;
  cmpnums = ((void *)0);
  nnodes = graph_num_nodes(g);
  cmpnums = calloc(nnodes, sizeof(unsigned int));
  if (cmpnums == ((void *)0)) goto fail;
  if (stats_cache_node_component(g, -1, cmpnums)) goto fail;
  for (i = 0; i < nnodes; i++) {
    if (cmpnums[i] != cmp) continue;
    if (array_append(nodeids, &i)) goto fail;
  }
  free(cmpnums);
  return 0;
fail:
  if (cmpnums != ((void *)0)) free(cmpnums);
  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:
cmp
unsigned int

variable_types:
nodeids
struct _array *

variable_types:
cmpnums
unsigned int *


decompiled_code:
double __fastcall stats_assortativity(__int64 a1)
{
unsigned int v1; // er14
int v2; // er13
__int64 v3; // rax
unsigned int *v4; // rbx
__int64 v5; // rbp
__int64 v6; // rsi
int v7; // eax
double v8; // xmm2_8
double v10; // [rsp+0h] [rbp-68h]
double v11; // [rsp+8h] [rbp-60h]
double v12; // [rsp+10h] [rbp-58h]
int v13; // [rsp+18h] [rbp-50h]
int v14; // [rsp+1Ch] [rbp-4Ch]
double v15[8]; // [rsp+28h] [rbp-40h] BYREF

v13 = graph_num_nodes();
v14 = graph_num_edges(a1);
if ( v13 )
{
v1 = 0;
v12 = 0.0;
v11 = 0.0;
v10 = 0.0;
do
{
v2 = graph_num_neighbours(a1, v1);
v3 = graph_get_neighbours(a1, v1);
if ( v2 )
{
v4 = (unsigned int *)v3;
v5 = v3 + 4LL * (unsigned int)(v2 - 1) + 4;
do
{
v6 = *v4;
if ( (unsigned int)v6 > v1 )
{
v7 = graph_num_neighbours(a1, v6);
v10 = (double)(v7 * v2) + v10;
v11 = (double)(v2 + v7) * 0.5 + v11;
v12 = (double)(v2 * v2 + v7 * v7) * 0.5 + v12;
}
++v4;
}
while ( (unsigned int *)v5 != v4 );
}
++v1;
}
while ( v13 != v1 );
}
else
{
v12 = 0.0;
v11 = 0.0;
v10 = 0.0;
}
v8 = v11 / (double)v14 * (v11 / (double)v14);
v15[0] = (v10 / (double)v14 - v8) / (v12 / (double)v14 - v8);
stats_cache_add(a1, 4LL, 0LL, 8LL);
stats_cache_update(a1, 4LL, 0LL, -1LL, v15);
return v15[0];
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
unsigned int v1; // er14
int v2; // er13
__int64 v3; // rax
unsigned int *v4; // rbx
__int64 v5; // rbp
__int64 v6; // rsi
int v7; // eax
double v8; // xmm2_8
double v10; // [rsp+0h] [rbp-68h]
double v11; // [rsp+8h] [rbp-60h]
double v12; // [rsp+10h] [rbp-58h]
int v13; // [rsp+18h] [rbp-50h]
int v14; // [rsp+1Ch] [rbp-4Ch]
double v15[8]; // [rsp+28h] [rbp-40h] BYREF

v13 = graph_num_nodes();
v14 = graph_num_edges(a1);
if ( v13 )
{
v1 = 0;
v12 = 0.0;
v11 = 0.0;
v10 = 0.0;
do
{
v2 = graph_num_neighbours(a1, v1);
v3 = graph_get_neighbours(a1, v1);
if ( v2 )
{
v4 = (unsigned int *)v3;
v5 = v3 + 4LL * (unsigned int)(v2 - 1) + 4;
do
{
v6 = *v4;
if ( (unsigned int)v6 > v1 )
{
v7 = graph_num_neighbours(a1, v6);
v10 = (double)(v7 * v2) + v10;
v11 = (double)(v2 + v7) * 0.5 + v11;
v12 = (double)(v2 * v2 + v7 * v7) * 0.5 + v12;
}
++v4;
}
while ( (unsigned int *)v5 != v4 );
}
++v1;
}
while ( v13 != v1 );
}
else
{
v12 = 0.0;
v11 = 0.0;
v10 = 0.0;
}
v8 = v11 / (double)v14 * (v11 / (double)v14);
v15[0] = (v10 / (double)v14 - v8) / (v12 / (double)v14 - v8);
stats_cache_add(a1, 4LL, 0LL, 8LL);
stats_cache_update(a1, 4LL, 0LL, -1LL, v15);
return v15[0];
}

original_code:
double stats_assortativity(graph_t *g) {
  uint32_t j;
  uint32_t k;
  uint32_t numnodes;
  uint32_t numedges;
  uint32_t *nbrsj;
  uint32_t degj;
  uint32_t degk;
  double r;
  double jkprod;
  double jkhalfsum;
  double jkhalfsumsq;
  jkprod = 0;
  jkhalfsum = 0;
  jkhalfsumsq = 0;
  numnodes = graph_num_nodes(g);
  numedges = graph_num_edges(g);
  for (j = 0; j < numnodes; j++) {
    degj = graph_num_neighbours(g, j);
    nbrsj = graph_get_neighbours(g, j);
    for (k = 0; k < degj; k++) {
      if (nbrsj[k] <= j) continue;
      degk = graph_num_neighbours(g, nbrsj[k]);
      jkprod += degj * degk;
      jkhalfsum += 0.5 * (degj + degk);
      jkhalfsumsq += 0.5 * ((degj * degj) + (degk * degk));
    }
  }
  r = (jkprod / numedges) - (pow(jkhalfsum / numedges, 2));
  r /= (jkhalfsumsq / numedges) - (pow(jkhalfsum / numedges, 2));
  stats_cache_add(g,
                  STATS_CACHE_ASSORTATIVITY,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_ASSORTATIVITY, 0, -1, &r);
  return r;
}

canonical_original_code:
double stats_assortativity(struct _graph *g) {
  unsigned int j;
  unsigned int k;
  unsigned int numnodes;
  unsigned int numedges;
  unsigned int *nbrsj;
  unsigned int degj;
  unsigned int degk;
  double r;
  double jkprod;
  double jkhalfsum;
  double jkhalfsumsq;
  jkprod = 0;
  jkhalfsum = 0;
  jkhalfsumsq = 0;
  numnodes = graph_num_nodes(g);
  numedges = graph_num_edges(g);
  for (j = 0; j < numnodes; j++) {
    degj = graph_num_neighbours(g, j);
    nbrsj = graph_get_neighbours(g, j);
    for (k = 0; k < degj; k++) {
      if (nbrsj[k] <= j) continue;
      degk = graph_num_neighbours(g, nbrsj[k]);
      jkprod += degj * degk;
      jkhalfsum += 0.5 * (degj + degk);
      jkhalfsumsq += 0.5 * ((degj * degj) + (degk * degk));
    }
  }
  r = (jkprod / numedges) - (pow(jkhalfsum / numedges, 2));
  r /= (jkhalfsumsq / numedges) - (pow(jkhalfsum / numedges, 2));
  stats_cache_add(g,
                  STATS_CACHE_ASSORTATIVITY,
                  STATS_CACHE_TYPE_GRAPH,
                  sizeof(double));
  stats_cache_update(g, STATS_CACHE_ASSORTATIVITY, 0, -1, &r);
  return r;
}

variable_types:
j
unsigned int

variable_types:
k
unsigned int

variable_types:
numnodes
unsigned int

variable_types:
numedges
unsigned int

variable_types:
nbrsj
unsigned int *

variable_types:
degj
unsigned int

variable_types:
degk
unsigned int

variable_types: r double

variable_types: jkprod double

variable_types: jkhalfsum double

variable_types: jkhalfsumsq double


expand

decompiled_code:
__int64 __fastcall expand(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, unsigned __int8 (__fastcall *a6)(char *, __int64))
{
unsigned int v9; // er13
int v10; // er12
__int64 v11; // rax
int *v12; // r15
__int64 v13; // r12
int *v14; // rsi
unsigned int v18; // [rsp+20h] [rbp-48h] BYREF
char v19[4]; // [rsp+24h] [rbp-44h] BYREF
unsigned int v20; // [rsp+28h] [rbp-40h]
char v21; // [rsp+2Ch] [rbp-3Ch]

if ( !*(_DWORD *)(a2 + 4) )
return 0LL;
v9 = 0;
while ( 1 )
{
array_get(a2, v9, &v18);
v10 = graph_num_neighbours(a1, v18);
v11 = graph_get_neighbours(a1, v18);
if ( v10 )
break;
LABEL_10:
if ( *(_DWORD *)(a2 + 4) <= ++v9 )
return 0LL;
}
v12 = (int *)v11;
v13 = v11 + 4LL * (unsigned int)(v10 - 1) + 4;
while ( 1 )
{
if ( a6 )
{
array_get(a2, v9, v19);
v20 = *v12;
v21 = *(_BYTE *)(a4 + v20);
if ( a6(v19, a5) )
return 1LL;
}
if ( *(_BYTE *)(a4 + (unsigned int)*v12) )
{
if ( (int *)v13 == ++v12 )
goto LABEL_10;
}
else
{
v14 = v12++;
array_append(a3, v14);
*(_BYTE *)(a4 + (unsigned int)*(v12 - 1)) = 1;
if ( (int *)v13 == v12 )
goto LABEL_10;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, unsigned __int8 (__fastcall *a6)(char *, __int64))
{
unsigned int v9; // er13
int v10; // er12
__int64 v11; // rax
int *v12; // r15
__int64 v13; // r12
int *v14; // rsi
unsigned int v18; // [rsp+20h] [rbp-48h] BYREF
char v19[4]; // [rsp+24h] [rbp-44h] BYREF
unsigned int v20; // [rsp+28h] [rbp-40h]
char v21; // [rsp+2Ch] [rbp-3Ch]

if ( !*(_DWORD *)(a2 + 4) )
return 0LL;
v9 = 0;
while ( 1 )
{
array_get(a2, v9, &v18);
v10 = graph_num_neighbours(a1, v18);
v11 = graph_get_neighbours(a1, v18);
if ( v10 )
break;
LABEL_10:
if ( *(_DWORD *)(a2 + 4) <= ++v9 )
return 0LL;
}
v12 = (int *)v11;
v13 = v11 + 4LL * (unsigned int)(v10 - 1) + 4;
while ( 1 )
{
if ( a6 )
{
array_get(a2, v9, v19);
v20 = *v12;
v21 = *(_BYTE *)(a4 + v20);
if ( a6(v19, a5) )
return 1LL;
}
if ( *(_BYTE *)(a4 + (unsigned int)*v12) )
{
if ( (int *)v13 == ++v12 )
goto LABEL_10;
}
else
{
v14 = v12++;
array_append(a3, v14);
*(_BYTE *)(a4 + (unsigned int)*(v12 - 1)) = 1;
if ( (int *)v13 == v12 )
goto LABEL_10;
}
}
}

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

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

variable_types:
thislevel
struct _array *

variable_types:
nextlevel
struct _array *

variable_types:
visited
unsigned char *

variable_types:
context
void *

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

variable_types:
i
unsigned int

variable_types:
ni
unsigned int

variable_types:
nneighbours
unsigned int

variable_types:
neighbours
unsigned int *


main

canonical_name: main

repo: paulgriffiths/basicnetworking

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx

set_logging(1LL, argv, envp);
chatc_ui_initialize_screen();
chatc_main_loop();
chatc_ui_free_screen();
set_logging(0LL, argv, v3);
return 0;
}

original_code:
int main(void) {
    set_logging(1);
    chatc_ui_initialize_screen();
    chatc_main_loop();
    chatc_ui_free_screen();
    set_logging(0);
    return 0;
}

canonical_original_code:
int main() {
    set_logging(1);
    chatc_ui_initialize_screen();
    chatc_main_loop();
    chatc_ui_free_screen();
    set_logging(0);
    return 0;
}

return_type: int


decompiled_code:
const char *__fastcall trim_line_ending(const char *a1)
{
int v1; // eax
unsigned int v2; // esi
__int64 v3; // rcx
const char *v4; // rax
const char *v5; // rcx

if ( *a1 )
{
v1 = strlen(a1);
v2 = v1 - 1;
if ( v1 - 1 >= 0 )
{
v3 = (__int64)&a1[v1 - 2];
v4 = &a1[v2];
v5 = (const char *)(v3 - v2);
do
{
if ( *v4 != 10 && *v4 != 13 )
break;
*v4-- = 0;
}
while ( v4 != v5 );
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func0(const char *a1)
{
int v1; // eax
unsigned int v2; // esi
__int64 v3; // rcx
const char *v4; // rax
const char *v5; // rcx

if ( *a1 )
{
v1 = strlen(a1);
v2 = v1 - 1;
if ( v1 - 1 >= 0 )
{
v3 = (__int64)&a1[v1 - 2];
v4 = &a1[v2];
v5 = (const char *)(v3 - v2);
do
{
if ( *v4 != 10 && *v4 != 13 )
break;
*v4-- = 0;
}
while ( v4 != v5 );
}
}
return a1;
}

original_code:
char * trim_line_ending(char * buffer) {
    if ( *buffer != '\0' ) {
        int last;
        for ( last = (int) strlen(buffer) - 1;
              last >= 0 && ( buffer[last] == '\n' || buffer[last] == '\r' );
              --last ) {
            buffer[last] = '\0';
        }
    }
    return buffer;
}

canonical_original_code:
char *trim_line_ending(char *buffer) {
    if ( *buffer != '\0' ) {
        int last;
        for ( last = (int) strlen(buffer) - 1;
              last >= 0 && ( buffer[last] == '\n' || buffer[last] == '\r' );
              --last ) {
            buffer[last] = '\0';
        }
    }
    return buffer;
}

variable_types:
buffer
char *

variable_types: last int

return_type: char *


decompiled_code:
const char *__fastcall trim_right(const char *a1)
{
int v2; // ebx
int v3; // ebp
const unsigned __int16 **v4; // rsi
char *v5; // rax
__int64 v6; // rdi

if ( *a1 )
{
v2 = strlen(a1);
v3 = v2 - 1;
if ( v2 - 1 >= 0 )
{
v4 = _ctype_b_loc();
v5 = (char *)&a1[v3];
v6 = (__int64)&a1[v2 - 2 - v3];
do
{
if ( ((*v4)[*v5] & 0x2000) == 0 )
break;
*v5-- = 0;
}
while ( v5 != (char *)v6 );
}
}
return a1;
}

canonical_decompiled_code:
const char *__fastcall func1(const char *a1)
{
int v2; // ebx
int v3; // ebp
const unsigned __int16 **v4; // rsi
char *v5; // rax
__int64 v6; // rdi

if ( *a1 )
{
v2 = strlen(a1);
v3 = v2 - 1;
if ( v2 - 1 >= 0 )
{
v4 = _ctype_b_loc();
v5 = (char *)&a1[v3];
v6 = (__int64)&a1[v2 - 2 - v3];
do
{
if ( ((*v4)[*v5] & 0x2000) == 0 )
break;
*v5-- = 0;
}
while ( v5 != (char *)v6 );
}
}
return a1;
}

original_code:
char * trim_right(char * buffer) {
    if ( *buffer != '\0' ) {
        int last;
        for ( last = (int) strlen(buffer) - 1;
              last >= 0 && ((*__ctype_b_loc ())[(int) ((buffer[last]))] & (unsigned short int) _ISspace);
              --last ) {
            buffer[last] = '\0';
        }
    }
    return buffer;
}

canonical_original_code:
char *trim_right(char *buffer) {
    if ( *buffer != '\0' ) {
        int last;
        for ( last = (int) strlen(buffer) - 1;
              last >= 0 && ((*__ctype_b_loc ())[(int) ((buffer[last]))] & (unsigned short) _ISspace);
              --last ) {
            buffer[last] = '\0';
        }
    }
    return buffer;
}


trim

decompiled_code:
char *__fastcall trim(char *a1)
{
trim_left(a1);
trim_right(a1);
return a1;
}

canonical_decompiled_code:
char *__fastcall func3(char *a1)
{
func2(a1);
func1(a1);
return a1;
}

original_code:
char * trim(char * buffer) {
    (void) trim_left(buffer);
    (void) trim_right(buffer);
    return buffer;
}

canonical_original_code:
char *trim(char *buffer) {
    (void) trim_left(buffer);
    (void) trim_right(buffer);
    return buffer;
}


decompiled_code:
int chatc_ui_free_screen()
{
msgwin_destroy(qword_238);
qword_238 = 0LL;
sliwin_destroy(qword_240);
qword_240 = 0LL;
delwin(mainwin);
mainwin = 0LL;
curs_set(dword_230);
endwin();
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func0()
{
msgwin_destroy(qword_238);
qword_238 = 0LL;
sliwin_destroy(qword_240);
qword_240 = 0LL;
delwin(mainwin);
mainwin = 0LL;
curs_set(dword_230);
endwin();
return wrefresh(stdscr);
}

original_code:
void chatc_ui_free_screen(void) {
    msgwin_destroy(mainwin.msgwin);
    mainwin.msgwin = ((void *)0);
    sliwin_destroy(mainwin.inpwin);
    mainwin.inpwin = ((void *)0);
    delwin(mainwin.window);
    mainwin.window = ((void *)0);
    curs_set(mainwin.old_cursor);
    endwin();
    wrefresh(stdscr);
}

canonical_original_code:
void chatc_ui_free_screen() {
    msgwin_destroy(mainwin.msgwin);
    mainwin.msgwin = ((void *)0);
    sliwin_destroy(mainwin.inpwin);
    mainwin.inpwin = ((void *)0);
    delwin(mainwin.window);
    mainwin.window = ((void *)0);
    curs_set(mainwin.old_cursor);
    endwin();
    wrefresh(stdscr);
}


decompiled_code:
__int64 chatc_term_rows()
{
return (unsigned __int16)word_228;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned __int16)word_228;
}

original_code:
int chatc_term_rows(void) {
    return mainwin.ws.ws_row;
}

canonical_original_code:
int chatc_term_rows() {
    return mainwin.ws.ws_row;
}


decompiled_code:
__int64 chatc_term_cols()
{
return (unsigned __int16)word_22A;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned __int16)word_22A;
}

original_code:
int chatc_term_cols(void) {
    return mainwin.ws.ws_col;
}

canonical_original_code:
int chatc_term_cols() {
    return mainwin.ws.ws_col;
}


decompiled_code:
__int64 chatc_ui_initialize_screen()
{
int v0; // eax
WINDOW *v1; // rdi
unsigned int v2; // er12
__int64 v3; // r13
__int64 v4; // rdx

mainwin = initscr();
if ( !mainwin )
{
perror("chat-client: couldn't initialize screen");
exit(1);
}
if ( ioctl(0, 0x5413uLL, &word_228) == -1 )
{
perror("chat-client: couldn't get terminal size");
exit(1);
}
noecho();
keypad(mainwin, 1);
v0 = curs_set(0);
v1 = stdscr;
dword_230 = v0;
wrefresh(stdscr);
v2 = chatc_term_rows(v1, 0LL, 0LL) - 3;
v3 = (unsigned int)chatc_term_cols();
qword_238 = msgwin_create(mainwin, 0LL, v4, v3, v2);
qword_240 = sliwin_create(mainwin, 0LL, v2, (unsigned int)v3, 3LL);
msgwin_refresh(qword_238);
return sliwin_refresh(qword_240);
}

canonical_decompiled_code:
__int64 func3()
{
int v0; // eax
WINDOW *v1; // rdi
unsigned int v2; // er12
__int64 v3; // r13
__int64 v4; // rdx

mainwin = initscr();
if ( !mainwin )
{
perror("chat-client: couldn't initialize screen");
exit(1);
}
if ( ioctl(0, 0x5413uLL, &word_228) == -1 )
{
perror("chat-client: couldn't get terminal size");
exit(1);
}
noecho();
keypad(mainwin, 1);
v0 = curs_set(0);
v1 = stdscr;
dword_230 = v0;
wrefresh(stdscr);
v2 = func1(v1, 0LL, 0LL) - 3;
v3 = (unsigned int)func2();
qword_238 = msgwin_create(mainwin, 0LL, v4, v3, v2);
qword_240 = sliwin_create(mainwin, 0LL, v2, (unsigned int)v3, 3LL);
msgwin_refresh(qword_238);
return sliwin_refresh(qword_240);
}

original_code:
void chatc_ui_initialize_screen(void) {
    if ( (mainwin.window = initscr()) == ((void *)0) ) {
        perror("chat-client: couldn't initialize screen");
        exit(1);
    }
    if ( ioctl(0, 0x5413, &mainwin.ws) == -1 ) {
        perror("chat-client: couldn't get terminal size");
        exit(1);
    }
    noecho();
    keypad(mainwin.window, 1);
    mainwin.old_cursor = curs_set(0);
    wrefresh(stdscr);
    const int iwh = 3;
    int rows = chatc_term_rows();
    int cols = chatc_term_cols();
    mainwin.msgwin = msgwin_create(mainwin.window, 0, 0, cols, rows - iwh);
    mainwin.inpwin = sliwin_create(mainwin.window, 0, rows - iwh, cols, iwh);
    msgwin_refresh(mainwin.msgwin);
    sliwin_refresh(mainwin.inpwin);
}

canonical_original_code:
void chatc_ui_initialize_screen() {
    if ( (mainwin.window = initscr()) == ((void *)0) ) {
        perror("chat-client: couldn't initialize screen");
        exit(1);
    }
    if ( ioctl(0, 0x5413, &mainwin.ws) == -1 ) {
        perror("chat-client: couldn't get terminal size");
        exit(1);
    }
    noecho();
    keypad(mainwin.window, 1);
    mainwin.old_cursor = curs_set(0);
    wrefresh(stdscr);
    int iwh = 3;
    int rows = chatc_term_rows();
    int cols = chatc_term_cols();
    mainwin.msgwin = msgwin_create(mainwin.window, 0, 0, cols, rows - iwh);
    mainwin.inpwin = sliwin_create(mainwin.window, 0, rows - iwh, cols, iwh);
    msgwin_refresh(mainwin.msgwin);
    sliwin_refresh(mainwin.inpwin);
}

variable_types: iwh int

variable_types: rows int

variable_types: cols int


decompiled_code:
__int64 __fastcall chatc_ui_print_message(__int64 a1)
{
msgwin_print_message(qword_238, a1);
return msgwin_refresh(qword_238);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
msgwin_print_message(qword_238, a1);
return msgwin_refresh(qword_238);
}

original_code:
void chatc_ui_print_message(const char * msg) {
    msgwin_print_message(mainwin.msgwin, msg);
    msgwin_refresh(mainwin.msgwin);
}

canonical_original_code:
void chatc_ui_print_message(char *msg) {
    msgwin_print_message(mainwin.msgwin, msg);
    msgwin_refresh(mainwin.msgwin);
}

variable_types:
msg
char *


decompiled_code:
__int64 chatc_ui_process_input()
{
return sliwin_get_char(qword_240);
}

canonical_decompiled_code:
__int64 func5()
{
return sliwin_get_char(qword_240);
}

original_code:
void chatc_ui_process_input(void) {
    sliwin_get_char(mainwin.inpwin);
}

canonical_original_code:
void chatc_ui_process_input() {
    sliwin_get_char(mainwin.inpwin);
}


decompiled_code:
__int64 chatc_ui_input_ready()
{
return sliwin_message_ready(qword_240);
}

canonical_decompiled_code:
__int64 func6()
{
return sliwin_message_ready(qword_240);
}

original_code:
_Bool chatc_ui_input_ready(void) {
    return sliwin_message_ready(mainwin.inpwin);
}

canonical_original_code:
_Bool chatc_ui_input_ready() {
    return sliwin_message_ready(mainwin.inpwin);
}


decompiled_code:
__int64 chatc_ui_retrieve_input()
{
return sliwin_get_contents(qword_240);
}

canonical_decompiled_code:
__int64 func7()
{
return sliwin_get_contents(qword_240);
}

original_code:
const char * chatc_ui_retrieve_input(void) {
    return sliwin_get_contents(mainwin.inpwin);
}

canonical_original_code:
char *chatc_ui_retrieve_input() {
    return sliwin_get_contents(mainwin.inpwin);
}


decompiled_code:
__int64 chatc_ui_message_used()
{
return sliwin_message_used(qword_240);
}

canonical_decompiled_code:
__int64 func8()
{
return sliwin_message_used(qword_240);
}

original_code:
void chatc_ui_message_used(void) {
    sliwin_message_used(mainwin.inpwin);
}

canonical_original_code:
void chatc_ui_message_used() {
    sliwin_message_used(mainwin.inpwin);
}


decompiled_code:
int __fastcall set_logging(char a1)
{
int result; // eax

result = (unsigned __int8)logging_on;
if ( a1 )
{
if ( !logging_on )
{
log_file = fopen("chat-client.log", "w");
if ( !log_file )
{
perror("chat-client: couldn't open log file");
exit(1);
}
logging_on = 1;
result = fwrite("Starting to log...\n", 1uLL, 0x13uLL, log_file);
}
}
else if ( logging_on )
{
fwrite("Ending logging...\n", 1uLL, 0x12uLL, log_file);
result = fclose(log_file);
logging_on = 0;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(char a1)
{
int result; // eax

result = (unsigned __int8)logging_on;
if ( a1 )
{
if ( !logging_on )
{
log_file = fopen("chat-client.log", "w");
if ( !log_file )
{
perror("chat-client: couldn't open log file");
exit(1);
}
logging_on = 1;
result = fwrite("Starting to log...\n", 1uLL, 0x13uLL, log_file);
}
}
else if ( logging_on )
{
fwrite("Ending logging...\n", 1uLL, 0x12uLL, log_file);
result = fclose(log_file);
logging_on = 0;
}
return result;
}

original_code:
void set_logging(const _Bool status) {
    if ( status && !logging_on ) {
        log_file = fopen(log_file_name, "w");
        if ( !log_file ) {
            perror("chat-client: couldn't open log file");
            exit(1);
        }
        logging_on = 1;
        fprintf(log_file, "Starting to log...\n");
    }
    else if ( !status && logging_on ) {
        fprintf(log_file, "Ending logging...\n");
        fclose(log_file);
        logging_on = 0;
    }
}

canonical_original_code:
void set_logging(_Bool status) {
    if ( status && !logging_on ) {
        log_file = fopen(log_file_name, "w");
        if ( !log_file ) {
            perror("chat-client: couldn't open log file");
            exit(1);
        }
        logging_on = 1;
        fprintf(log_file, "Starting to log...\n");
    }
    else if ( !status && logging_on ) {
        fprintf(log_file, "Ending logging...\n");
        fclose(log_file);
        logging_on = 0;
    }
}


decompiled_code:
int log_msg(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( logging_on )
{
va_start(arg, format);
result = vfprintf(log_file, format, arg);
}
return result;
}

canonical_decompiled_code:
int func1(char *format, ...)
{
int result; // eax
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( logging_on )
{
va_start(arg, format);
result = vfprintf(log_file, format, arg);
}
return result;
}

original_code:
void log_msg(const char * format, ...) {
    if ( logging_on ) {
        va_list ap;
        __builtin_va_start(ap,format);
        vfprintf(log_file, format, ap);
        __builtin_va_end(ap);
    }
}

canonical_original_code:
void log_msg(char *format, ...) {
    if ( logging_on ) {
        __builtin_va_list ap;
        __builtin_va_start(ap,format);
        vfprintf(log_file, format, ap);
        __builtin_va_end(ap);
    }
}

variable_types:
format
char *


decompiled_code:
__int64 chatc_main_loop()
{
__int64 v0; // rax
__int64 v1; // r12
const char *v3; // r14
size_t v4; // rax
char *v5; // r13
const char **v6; // r15
const char *v7; // r14
size_t v8; // rax
const char *v9; // r15
size_t v10; // r13
size_t v11; // rax
char *v12; // rax
const char *v13; // r14
size_t v14; // rax
fd_set vars0; // [rsp+0h] [rbp+0h] BYREF

while ( 1 )
{
memset(&vars0, 0, sizeof(vars0));
vars0.fds_bits[0] |= 1uLL;
if ( select(1, &vars0, 0LL, 0LL, 0LL) == -1 )
break;
if ( (vars0.fds_bits[0] & 1) != 0 )
chatc_ui_process_input();
if ( (unsigned __int8)chatc_ui_input_ready() )
{
v0 = chatc_ui_retrieve_input();
v1 = chatc_parse_message(v0);
switch ( *(_DWORD *)v1 )
{
case 0:
v13 = **(const char ***)(v1 + 8);
v14 = strlen(v13);
v5 = (char *)malloc(v14 + 15);
if ( !v5 )
goto LABEL_17;
sprintf(v5, "[You said: %s]", v13);
goto LABEL_9;
case 1:
v6 = *(const char ***)(v1 + 8);
v7 = *v6;
v8 = strlen(*v6);
v9 = v6[1];
v10 = v8;
v11 = strlen(v9);
v12 = (char *)malloc(v10 + v11 + 20);
v5 = v12;
if ( !v12 )
goto LABEL_17;
sprintf(v12, "[You told '%s': %s]", v7, v9);
goto LABEL_9;
case 2:
v3 = **(const char ***)(v1 + 8);
v4 = strlen(v3);
v5 = (char *)malloc(v4 + 32);
if ( !v5 )
{
LABEL_17:
perror("chat-client: couldn't allocate memory");
exit(1);
}
sprintf(v5, "[You changed your nick to '%s']", v3);
LABEL_9:
chatc_ui_print_message(v5);
free(v5);
goto LABEL_10;
case 3:
chatc_ui_print_message("[Quitting - goodbye!]");
chatc_ui_message_used();
return chatc_free_message(v1);
case 4:
chatc_ui_print_message("[Bad message!]");
chatc_ui_message_used();
chatc_free_message(v1);
continue;
default:
LABEL_10:
chatc_ui_message_used();
chatc_free_message(v1);
break;
}
}
}
perror("chat-client: error calling select()");
exit(1);
}

canonical_decompiled_code:
__int64 func0()
{
__int64 v0; // rax
__int64 v1; // r12
const char *v3; // r14
size_t v4; // rax
char *v5; // r13
const char **v6; // r15
const char *v7; // r14
size_t v8; // rax
const char *v9; // r15
size_t v10; // r13
size_t v11; // rax
char *v12; // rax
const char *v13; // r14
size_t v14; // rax
fd_set vars0; // [rsp+0h] [rbp+0h] BYREF

while ( 1 )
{
memset(&vars0, 0, sizeof(vars0));
vars0.fds_bits[0] |= 1uLL;
if ( select(1, &vars0, 0LL, 0LL, 0LL) == -1 )
break;
if ( (vars0.fds_bits[0] & 1) != 0 )
chatc_ui_process_input();
if ( (unsigned __int8)chatc_ui_input_ready() )
{
v0 = chatc_ui_retrieve_input();
v1 = chatc_parse_message(v0);
switch ( *(_DWORD *)v1 )
{
case 0:
v13 = **(const char ***)(v1 + 8);
v14 = strlen(v13);
v5 = (char *)malloc(v14 + 15);
if ( !v5 )
goto LABEL_17;
sprintf(v5, "[You said: %s]", v13);
goto LABEL_9;
case 1:
v6 = *(const char ***)(v1 + 8);
v7 = *v6;
v8 = strlen(*v6);
v9 = v6[1];
v10 = v8;
v11 = strlen(v9);
v12 = (char *)malloc(v10 + v11 + 20);
v5 = v12;
if ( !v12 )
goto LABEL_17;
sprintf(v12, "[You told '%s': %s]", v7, v9);
goto LABEL_9;
case 2:
v3 = **(const char ***)(v1 + 8);
v4 = strlen(v3);
v5 = (char *)malloc(v4 + 32);
if ( !v5 )
{
LABEL_17:
perror("chat-client: couldn't allocate memory");
exit(1);
}
sprintf(v5, "[You changed your nick to '%s']", v3);
LABEL_9:
chatc_ui_print_message(v5);
free(v5);
goto LABEL_10;
case 3:
chatc_ui_print_message("[Quitting - goodbye!]");
chatc_ui_message_used();
return chatc_free_message(v1);
case 4:
chatc_ui_print_message("[Bad message!]");
chatc_ui_message_used();
chatc_free_message(v1);
continue;
default:
LABEL_10:
chatc_ui_message_used();
chatc_free_message(v1);
break;
}
}
}
perror("chat-client: error calling select()");
exit(1);
}

original_code:
void chatc_main_loop(void) {
    _Bool keep_going = 1;
    while ( keep_going ) {
        fd_set fds;
        do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
        int status = select(0 + 1, &fds, ((void *)0), ((void *)0), ((void *)0));
        if ( status == -1 ) {
            perror("chat-client: error calling select()");
            exit(1);
        }
        if ( ((((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
            chatc_ui_process_input();
        }
        if ( chatc_ui_input_ready() ) {
            const char * text = chatc_ui_retrieve_input();
            struct chat_msg * msg = chatc_parse_message(text);
            char * fmt;
            char * out;
            switch ( msg->msg_id ) {
                case CHAT_MESSAGE_SAY:
                    fmt = "[You said: %s]";
                    out = malloc(strlen(fmt) +
                                 strlen(msg->parameters[0]) + 1);
                    if ( !out ) {
                        perror("chat-client: couldn't allocate memory");
                        exit(1);
                    }
                    sprintf(out, fmt, msg->parameters[0]);
                    chatc_ui_print_message(out);
                    free(out);
                    break;
                case CHAT_MESSAGE_TELL:
                    fmt = "[You told '%s': %s]";
                    out = malloc(strlen(fmt) +
                                 strlen(msg->parameters[0]) +
                                 strlen(msg->parameters[1]) + 1);
                    if ( !out ) {
                        perror("chat-client: couldn't allocate memory");
                        exit(1);
                    }
                    sprintf(out, fmt, msg->parameters[0], msg->parameters[1]);
                    chatc_ui_print_message(out);
                    free(out);
                    break;
                case CHAT_MESSAGE_NICK:
                    fmt = "[You changed your nick to '%s']";
                    out = malloc(strlen(fmt) +
                                 strlen(msg->parameters[0]) + 1);
                    if ( !out ) {
                        perror("chat-client: couldn't allocate memory");
                        exit(1);
                    }
                    sprintf(out, fmt, msg->parameters[0]);
                    chatc_ui_print_message(out);
                    free(out);
                    break;
                case CHAT_MESSAGE_QUIT:
                    chatc_ui_print_message("[Quitting - goodbye!]");
                    keep_going = 0;
                    break;
                case CHAT_MESSAGE_BADMSG:
                    chatc_ui_print_message("[Bad message!]");
                    break;
            }
            chatc_ui_message_used();
            chatc_free_message(msg);
        }
    }
}

canonical_original_code:
void chatc_main_loop() {
    _Bool keep_going = 1;
    while ( keep_going ) {
        struct fd_set fds;
        do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
        ((void) (((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))));
        int status = select(0 + 1, &fds, ((void *)0), ((void *)0), ((void *)0));
        if ( status == -1 ) {
            perror("chat-client: error calling select()");
            exit(1);
        }
        if ( ((((&fds)->__fds_bits)[((0) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((0) % (8 * (int) sizeof (__fd_mask)))))) != 0) ) {
            chatc_ui_process_input();
        }
        if ( chatc_ui_input_ready() ) {
            char *text = chatc_ui_retrieve_input();
            struct chat_msg *msg = chatc_parse_message(text);
            char *fmt;
            char *out;
            switch ( msg->msg_id ) {
                case CHAT_MESSAGE_SAY:
                    fmt = "[You said: %s]";
                    out = malloc(strlen(fmt) +
                                 strlen(msg->parameters[0]) + 1);
                    if ( !out ) {
                        perror("chat-client: couldn't allocate memory");
                        exit(1);
                    }
                    sprintf(out, fmt, msg->parameters[0]);
                    chatc_ui_print_message(out);
                    free(out);
                    break;
                case CHAT_MESSAGE_TELL:
                    fmt = "[You told '%s': %s]";
                    out = malloc(strlen(fmt) +
                                 strlen(msg->parameters[0]) +
                                 strlen(msg->parameters[1]) + 1);
                    if ( !out ) {
                        perror("chat-client: couldn't allocate memory");
                        exit(1);
                    }
                    sprintf(out, fmt, msg->parameters[0], msg->parameters[1]);
                    chatc_ui_print_message(out);
                    free(out);
                    break;
                case CHAT_MESSAGE_NICK:
                    fmt = "[You changed your nick to '%s']";
                    out = malloc(strlen(fmt) +
                                 strlen(msg->parameters[0]) + 1);
                    if ( !out ) {
                        perror("chat-client: couldn't allocate memory");
                        exit(1);
                    }
                    sprintf(out, fmt, msg->parameters[0]);
                    chatc_ui_print_message(out);
                    free(out);
                    break;
                case CHAT_MESSAGE_QUIT:
                    chatc_ui_print_message("[Quitting - goodbye!]");
                    keep_going = 0;
                    break;
                case CHAT_MESSAGE_BADMSG:
                    chatc_ui_print_message("[Bad message!]");
                    break;
            }
            chatc_ui_message_used();
            chatc_free_message(msg);
        }
    }
}

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

variable_types: status int

variable_types:
text
char *

variable_types: struct chat_msg { enum chatc_msg { CHAT_MESSAGE_SAY=0, CHAT_MESSAGE_TELL=1, CHAT_MESSAGE_NICK=2, CHAT_MESSAGE_QUIT=3, CHAT_MESSAGE_BADMSG=4 } msg_id; char **parameters; } *

variable_types:
fmt
char *

variable_types:
out
char *

user_defined_types: struct chat_msg { enum chatc_msg msg_id; char **parameters; }


decompiled_code:
void __fastcall input_buffer_destroy(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void input_buffer_destroy(struct input_buffer * buffer) {
    free(buffer->buffer);
    free(buffer);
}

canonical_original_code:
void input_buffer_destroy(struct input_buffer *buffer) {
    free(buffer->buffer);
    free(buffer);
}

variable_types: struct input_buffer { char *buffer; unsigned long capacity; unsigned long top; } *


decompiled_code:
__int64 __fastcall input_buffer_capacity(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
size_t input_buffer_capacity(const struct input_buffer * buffer) {
    return buffer->capacity;
}

canonical_original_code:
unsigned long input_buffer_capacity(struct input_buffer *buffer) {
    return buffer->capacity;
}

return_type: unsigned long

user_defined_types: struct input_buffer { char *buffer; unsigned long capacity; unsigned long top; }


decompiled_code:
bool __fastcall input_buffer_is_full(__int64 a1)
{
return *(_QWORD *)(a1 + 16) >= *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
bool __fastcall func2(__int64 a1)
{
return *(_QWORD *)(a1 + 16) >= *(_QWORD *)(a1 + 8);
}

original_code:
_Bool input_buffer_is_full(const struct input_buffer * buffer) {
    return buffer->top >= buffer->capacity;
}

canonical_original_code:
_Bool input_buffer_is_full(struct input_buffer *buffer) {
    return buffer->top >= buffer->capacity;
}


decompiled_code:
__int64 __fastcall input_buffer_push(__int64 *a1, char a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( input_buffer_is_full((__int64)a1) )
_assert_fail("input_buffer_is_full(buffer) == false", "input_buffer.c", 0x30u, "input_buffer_push");
result = a1[2];
v3 = *a1;
a1[2] = result + 1;
*(_BYTE *)(v3 + result) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 *a1, char a2)
{
__int64 result; // rax
__int64 v3; // rdx

if ( func2((__int64)a1) )
_assert_fail("input_buffer_is_full(buffer) == false", "input_buffer.c", 0x30u, "input_buffer_push");
result = a1[2];
v3 = *a1;
a1[2] = result + 1;
*(_BYTE *)(v3 + result) = a2;
return result;
}

original_code:
void input_buffer_push(struct input_buffer * buffer, const char c) {
    ((input_buffer_is_full(buffer) == 0) ? (void) (0) : __assert_fail ("input_buffer_is_full(buffer) == false", "input_buffer.c", 48, __extension__ __PRETTY_FUNCTION__));
    buffer->buffer[buffer->top++] = c;
}

canonical_original_code:
void input_buffer_push(struct input_buffer *buffer, char c) {
    ((input_buffer_is_full(buffer) == 0) ? (void) (0) : __assert_fail ("input_buffer_is_full(buffer) == false", "input_buffer.c", 48, __extension__ __PRETTY_FUNCTION__));
    buffer->buffer[buffer->top++] = c;
}

variable_types: c char


decompiled_code:
bool __fastcall input_buffer_is_empty(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

canonical_decompiled_code:
bool __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 16) == 0LL;
}

original_code:
_Bool input_buffer_is_empty(const struct input_buffer * buffer) {
    return buffer->top == 0;
}

canonical_original_code:
_Bool input_buffer_is_empty(struct input_buffer *buffer) {
    return buffer->top == 0;
}


decompiled_code:
__int64 __fastcall input_buffer_pop(_QWORD *a1)
{
__int64 v1; // rax
_BYTE *v2; // rax
unsigned int v3; // er8

if ( input_buffer_is_empty((__int64)a1) )
_assert_fail("input_buffer_is_empty(buffer) == false", "input_buffer.c", 0x35u, "input_buffer_pop");
v1 = a1[2] - 1LL;
a1[2] = v1;
v2 = (_BYTE *)(*a1 + v1);
v3 = (unsigned __int8)*v2;
*v2 = 0;
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
__int64 v1; // rax
_BYTE *v2; // rax
unsigned int v3; // er8

if ( func4((__int64)a1) )
_assert_fail("input_buffer_is_empty(buffer) == false", "input_buffer.c", 0x35u, "input_buffer_pop");
v1 = a1[2] - 1LL;
a1[2] = v1;
v2 = (_BYTE *)(*a1 + v1);
v3 = (unsigned __int8)*v2;
*v2 = 0;
return v3;
}

original_code:
char input_buffer_pop(struct input_buffer * buffer) {
    ((input_buffer_is_empty(buffer) == 0) ? (void) (0) : __assert_fail ("input_buffer_is_empty(buffer) == false", "input_buffer.c", 53, __extension__ __PRETTY_FUNCTION__));
    char c = buffer->buffer[--buffer->top];
    buffer->buffer[buffer->top] = '\0';
    return c;
}

canonical_original_code:
char input_buffer_pop(struct input_buffer *buffer) {
    ((input_buffer_is_empty(buffer) == 0) ? (void) (0) : __assert_fail ("input_buffer_is_empty(buffer) == false", "input_buffer.c", 53, __extension__ __PRETTY_FUNCTION__));
    char c = buffer->buffer[--buffer->top];
    buffer->buffer[buffer->top] = '\0';
    return c;
}

return_type: char


decompiled_code:
void *__fastcall input_buffer_clear(__int64 a1)
{
void *result; // rax

result = memset(*(void **)a1, 0, *(_QWORD *)(a1 + 8) + 1LL);
*(_QWORD *)(a1 + 16) = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func6(__int64 a1)
{
void *result; // rax

result = memset(*(void **)a1, 0, *(_QWORD *)(a1 + 8) + 1LL);
*(_QWORD *)(a1 + 16) = 0LL;
return result;
}

original_code:
void input_buffer_clear(struct input_buffer * buffer) {
    memset(buffer->buffer, 0, buffer->capacity + 1);
    buffer->top = 0;
}

canonical_original_code:
void input_buffer_clear(struct input_buffer *buffer) {
    memset(buffer->buffer, 0, buffer->capacity + 1);
    buffer->top = 0;
}


decompiled_code:
__int64 __fastcall input_buffer_get_buffer(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
const char * input_buffer_get_buffer(struct input_buffer * buffer) {
    return buffer->buffer;
}

canonical_original_code:
char *input_buffer_get_buffer(struct input_buffer *buffer) {
    return buffer->buffer;
}


handler

decompiled_code:
void handler()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
static void handler(int signum) {
    switch (signum) {
        case 15:
        case 2:
            break;
        default:
            break;
    }
}

variable_types: signum int


decompiled_code:
int set_signal_handlers()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)handler;
v1.sa_flags = 0;
sigemptyset(&v1.sa_mask);
if ( sigaction(15, &v1, 0LL) == -1 )
{
perror("chat-client: couldn't set SIGTERM handler");
exit(1);
}
if ( sigaction(2, &v1, 0LL) == -1 )
{
perror("chat-client: couldn't set SIGINT handler");
exit(1);
}
v1.sa_handler = (__sighandler_t)algn_1;
result = sigaction(20, &v1, 0LL);
if ( result == -1 )
{
perror("chat-client: couldn't ignore SIGTSTP");
exit(1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax
struct sigaction v1; // [rsp+0h] [rbp-A8h] BYREF

v1.sa_handler = (__sighandler_t)handler;
v1.sa_flags = 0;
sigemptyset(&v1.sa_mask);
if ( sigaction(15, &v1, 0LL) == -1 )
{
perror("chat-client: couldn't set SIGTERM handler");
exit(1);
}
if ( sigaction(2, &v1, 0LL) == -1 )
{
perror("chat-client: couldn't set SIGINT handler");
exit(1);
}
v1.sa_handler = (__sighandler_t)algn_1;
result = sigaction(20, &v1, 0LL);
if ( result == -1 )
{
perror("chat-client: couldn't ignore SIGTSTP");
exit(1);
}
return result;
}

original_code:
void set_signal_handlers(void) {
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = handler;
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);
    if ( sigaction(15, &sa, ((void *)0)) == -1 ) {
        perror("chat-client: couldn't set SIGTERM handler");
        exit(1);
    }
    if ( sigaction(2, &sa, ((void *)0)) == -1 ) {
        perror("chat-client: couldn't set SIGINT handler");
        exit(1);
    }
    sa.__sigaction_handler.sa_handler = ((__sighandler_t) 1);
    if ( sigaction(20, &sa, ((void *)0)) == -1 ) {
        perror("chat-client: couldn't ignore SIGTSTP");
        exit(1);
    }
}

canonical_original_code:
void set_signal_handlers() {
    struct sigaction sa;
    sa.__sigaction_handler.sa_handler = handler;
    sa.sa_flags = 0;
    sigemptyset(&sa.sa_mask);
    if ( sigaction(15, &sa, ((void *)0)) == -1 ) {
        perror("chat-client: couldn't set SIGTERM handler");
        exit(1);
    }
    if ( sigaction(2, &sa, ((void *)0)) == -1 ) {
        perror("chat-client: couldn't set SIGINT handler");
        exit(1);
    }
    sa.__sigaction_handler.sa_handler = ((void (*)(int)) 1);
    if ( sigaction(20, &sa, ((void *)0)) == -1 ) {
        perror("chat-client: couldn't ignore SIGTSTP");
        exit(1);
    }
}

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


decompiled_code:
void __fastcall free_string_list(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
void **v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
v2 = *v3++;
}
while ( v2 );
}
free(ptr);
}
}

original_code:
static void free_string_list(char ** slist) {
    if ( slist ) {
        size_t i = 0;
        while ( slist[i] ) {
            free(slist[i++]);
        }
        free(slist);
    }
}

canonical_original_code:
static void free_string_list(char **slist) {
    if ( slist ) {
        unsigned long i = 0;
        while ( slist[i] ) {
            free(slist[i++]);
        }
        free(slist);
    }
}

variable_types:
slist
char **

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall translate_message_name(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = "say";
v3 = 0LL;
do
{
if ( !strcasecmp(v2, s2) )
return (unsigned int)known_msgs[6 * v3];
++v3;
v2 = (&off_708)[3 * v3];
}
while ( v2 );
return (unsigned int)known_msgs[6 * v3];
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
const char *v2; // rdi
__int64 v3; // rbx

v2 = "say";
v3 = 0LL;
do
{
if ( !strcasecmp(v2, s2) )
return (unsigned int)known_msgs[6 * v3];
++v3;
v2 = (&off_708)[3 * v3];
}
while ( v2 );
return (unsigned int)known_msgs[6 * v3];
}

original_code:
static enum chatc_msg translate_message_name(const char * msg_name) {
    size_t i = 0;
    while ( known_msgs[i].name ) {
        if ( !strcasecmp(known_msgs[i].name, msg_name) ) {
            return known_msgs[i].msg_id;
        }
        ++i;
    }
    return known_msgs[i].msg_id;
}

canonical_original_code:
static enum chatc_msg translate_message_name(char *msg_name) {
    unsigned long i = 0;
    while ( known_msgs[i].name ) {
        if ( !strcasecmp(known_msgs[i].name, msg_name) ) {
            return known_msgs[i].msg_id;
        }
        ++i;
    }
    return known_msgs[i].msg_id;
}

return_type: enum chatc_msg { CHAT_MESSAGE_SAY=0, CHAT_MESSAGE_TELL=1, CHAT_MESSAGE_NICK=2, CHAT_MESSAGE_QUIT=3, CHAT_MESSAGE_BADMSG=4 }


decompiled_code:
void __fastcall chatc_free_message(void *ptr)
{
free_string_list(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func4(void *ptr)
{
func1(*((void **)ptr + 1));
free(ptr);
}

original_code:
void chatc_free_message(struct chat_msg * msg) {
    free_string_list(msg->parameters);
    free(msg);
}

canonical_original_code:
void chatc_free_message(struct chat_msg *msg) {
    free_string_list(msg->parameters);
    free(msg);
}

user_defined_types: enum chatc_msg { CHAT_MESSAGE_SAY=0, CHAT_MESSAGE_TELL=1, CHAT_MESSAGE_NICK=2, CHAT_MESSAGE_QUIT=3, CHAT_MESSAGE_BADMSG=4 }


repo: paulgriffiths/cdatastruct

decompiled_code:
__int64 __fastcall stack_init(__int64 a1)
{
return sl_list_init(0LL, a1);
}

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

original_code:
stack stack_init(void (*free_func)(void *)) {
    return sl_list_init(((void *)0), free_func);
}

canonical_original_code:
struct sl_list_t *stack_init(void (*free_func)(void *)) {
    return sl_list_init(((void *)0), free_func);
}

return_type: struct sl_list_t { union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; struct sl_list_node_t { void *data; struct sl_list_node_t *next; } *front; unsigned long length; int (*cfunc)(); void (*free_func)(); } *

user_defined_types: struct sl_list_t { union pthread_mutex_t mutex; struct sl_list_node_t *front; unsigned long length; int (*cfunc)(); void (*free_func)(); }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }