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

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

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

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

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

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

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

variable_types:
datasz
unsigned int

variable_types:
capacity
unsigned int


repo: pauldmccarthy/ccnet

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

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

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

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

return_type: void

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:
void __fastcall array_free(_QWORD *a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = (void *)a1[2];
if ( v2 )
free(v2);
*a1 = 0LL;
a1[2] = 0LL;
a1[3] = 0LL;
a1[4] = 0LL;
}
}

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

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


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

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

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

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


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

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

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

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

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

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

return_type: unsigned char


decompiled_code:
__int64 __fastcall array_get(__int64 a1, unsigned int a2, void *a3)
{
if ( *(_DWORD *)a1 <= a2 )
return 1LL;
memcpy(a3, (const void *)(*(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * a2), *(unsigned int *)(a1 + 8));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, void *a3)
{
if ( *(_DWORD *)a1 <= a2 )
return 1LL;
memcpy(a3, (const void *)(*(_QWORD *)(a1 + 16) + *(_DWORD *)(a1 + 8) * a2), *(unsigned int *)(a1 + 8));
return 0LL;
}

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

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

variable_types:
idx
unsigned int

variable_types:
data
void *


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

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

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

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

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

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

return_type: void *


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

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

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

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

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

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

variable_types:
value
void *


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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
val
void *

variable_types:
elem
unsigned char *

variable_types:
sz
unsigned long

return_type: long


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

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

variable_types:
i
unsigned long

variable_types:
count
unsigned int

return_type: unsigned int


decompiled_code:
__int64 __fastcall array_append(_DWORD *a1, const void *a2)
{
unsigned int v3; // esi

if ( !a1 )
return 1LL;
v3 = a1[1];
if ( v3 != *a1 )
{
LABEL_3:
array_set((__int64)a1, v3, a2);
return 0LL;
}
if ( !(unsigned __int8)expand((__int64)a1, 0) )
{
v3 = a1[1];
goto LABEL_3;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(_DWORD *a1, const void *a2)
{
unsigned int v3; // esi

if ( !a1 )
return 1LL;
v3 = a1[1];
if ( v3 != *a1 )
{
LABEL_3:
func8((__int64)a1, v3, a2);
return 0LL;
}
if ( !(unsigned __int8)func0((__int64)a1, 0) )
{
v3 = a1[1];
goto LABEL_3;
}
return 1LL;
}

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

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


decompiled_code:
__int64 __fastcall array_insert(__int64 a1, unsigned int a2, const void *a3)
{
unsigned int v4; // eax
unsigned int v5; // edx

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

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2, const void *a3)
{
unsigned int v4; // eax
unsigned int v5; // edx

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

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

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

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *

variable_types:
sz
unsigned int


decompiled_code:
__int64 __fastcall array_insert_sorted(__int64 a1, const void *a2, char a3, unsigned int *a4)
{
char v4; // r15
__int64 (__fastcall *v7)(const void *, __int64); // rax
__int64 v8; // r8
unsigned int v9; // er15
__int64 v10; // r13
int v11; // eax
__int64 result; // rax
__int64 v13; // rax

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

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const void *a2, char a3, unsigned int *a4)
{
char v4; // r15
__int64 (__fastcall *v7)(const void *, __int64); // rax
__int64 v8; // r8
unsigned int v9; // er15
__int64 v10; // r13
int v11; // eax
__int64 result; // rax
__int64 v13; // rax

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

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

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

variable_types:
unique
unsigned char

variable_types:
idx
unsigned int *

variable_types: i long

variable_types: cmpval int


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

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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

variable_types:
gout
struct _graph *

variable_types:
mask
unsigned char *

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


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

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

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

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

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

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

variable_types:
nodes
unsigned int *

variable_types:
nnodes
unsigned int

variable_types:
nginnodes
unsigned int

variable_types:
result
unsigned char


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

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

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

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

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

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

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

variable_types:
elemsz
unsigned int

variable_types:
capacity
unsigned int


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

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

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

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

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

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

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


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

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

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

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

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

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

variable_types:
val
void *

variable_types:
off
unsigned int


decompiled_code:
__int64 __fastcall stack_pop(__int64 a1)
{
__int64 result; // rax
int v2; // edx

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

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 result; // rax
int v2; // edx

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

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

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


decompiled_code:
__int64 __fastcall stack_push(__int64 a1, const void *a2)
{
int v3; // edi

if ( !a1 )
return 1LL;
v3 = *(_DWORD *)(a1 + 8);
if ( v3 != *(_DWORD *)(a1 + 16) )
{
LABEL_3:
memcpy((void *)(*(_QWORD *)a1 + (unsigned int)(*(_DWORD *)(a1 + 12) * v3)), a2, *(unsigned int *)(a1 + 12));
++*(_DWORD *)(a1 + 8);
return 0LL;
}
if ( !(unsigned __int8)expand_constprop_0(a1) )
{
v3 = *(_DWORD *)(a1 + 8);
goto LABEL_3;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, const void *a2)
{
int v3; // edi

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

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

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

variable_types:
elem
void *


decompiled_code:
void __fastcall get_suffix(const char *a1, _BYTE *a2)
{
int v2; // ecx
__int64 v3; // rax
__int64 v5; // rcx
__int64 i; // rdx

if ( a2 && a1 )
{
v2 = strlen(a1);
v3 = (unsigned int)(v2 - 1);
while ( a1[v3] != 46 )
{
if ( v3-- == 0 )
goto LABEL_6;
}
if ( v2 == v3 + 1 )
{
LABEL_6:
*a2 = 0;
return;
}
v5 = (unsigned int)(v2 - (v3 + 1));
if ( v5 )
{
for ( i = 0LL; i != v5; ++i )
a2[i] = a1[v3 + 1 + i];
}
a2[v5] = 0;
}
}

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

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

variable_types:
name
char *

variable_types:
suf
char *

variable_types:
len
unsigned int


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

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

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

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

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

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

variable_types:
path
char *

variable_types:
joined
char *

return_type: char *


dirname

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

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

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

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

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

variable_types:
dir
char *

variable_types:
bn
char *


basename

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

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

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

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

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

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


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

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

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

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

variable_types:
pref
char *

variable_types:
len
unsigned short


decompiled_code:
char *__fastcall set_suffix(char *s, char *a2)
{
size_t v2; // r14
_BYTE *v3; // r12
_BYTE *v4; // r15
int v5; // ebp
int v6; // eax
char *v7; // rax
char *v8; // r14

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

canonical_decompiled_code:
char *__fastcall func5(char *s, char *a2)
{
size_t v2; // r14
_BYTE *v3; // r12
_BYTE *v4; // r15
int v5; // ebp
int v6; // eax
char *v7; // rax
char *v8; // r14

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

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

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

variable_types:
oldname
char *

variable_types:
suffix
char *

variable_types: len int

variable_types:
newname
char *

variable_types:
oldprefix
char *

variable_types:
oldsuffix
char *


decompiled_code:
bool __fastcall graph_create_ncut(__int64 fd, const struct sockaddr *a2, __int64 a3)
{
unsigned int v4; // eax
bool result; // al
socklen_t v6; // edx

v4 = analyze_num_vals(a2);
if ( (unsigned __int8)graph_create(fd, v4, 0LL) || (unsigned __int8)label(fd, (__int64)a2, a3) )
result = 1;
else
result = (unsigned __int8)connect(fd, a2, v6) != 0;
return result;
}

canonical_decompiled_code:
bool __fastcall func3(__int64 fd, const struct sockaddr *a2, __int64 a3)
{
unsigned int v4; // eax
bool result; // al
socklen_t v6; // edx

v4 = analyze_num_vals(a2);
if ( (unsigned __int8)graph_create(fd, v4, 0LL) || (unsigned __int8)func0(fd, (__int64)a2, a3) )
result = 1;
else
result = (unsigned __int8)func2(fd, a2, v6) != 0;
return result;
}

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

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

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

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

variable_types:
img
unsigned char *

variable_types: si double

variable_types: sx double

variable_types: rad double

variable_types: thres double

variable_types:
nnodes
unsigned int

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


decompiled_code:
double __fastcall stats_avg_local_efficiency(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // r12
__int64 v3; // rbx
double v4; // xmm0_8
double result; // xmm0_8
double v6; // [rsp+0h] [rbp-28h] BYREF
double v7[4]; // [rsp+8h] [rbp-20h] BYREF

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

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
unsigned int v1; // eax
__int64 v2; // r12
__int64 v3; // rbx
double v4; // xmm0_8
double result; // xmm0_8
double v6; // [rsp+0h] [rbp-28h] BYREF
double v7[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

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

variable_types:
i
unsigned long

variable_types: loceff double

return_type: double


decompiled_code:
double __fastcall stats_sub_efficiency(__int64 a1, int a2, __int64 a3)
{
unsigned int v4; // eax
unsigned int v5; // er13
__int64 v6; // rax
double v8; // [rsp+8h] [rbp-40h]
int v9; // [rsp+14h] [rbp-34h] BYREF
double v10[6]; // [rsp+18h] [rbp-30h] BYREF

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

canonical_decompiled_code:
double __fastcall func2(__int64 a1, int a2, __int64 a3)
{
unsigned int v4; // eax
unsigned int v5; // er13
__int64 v6; // rax
double v8; // [rsp+8h] [rbp-40h]
int v9; // [rsp+14h] [rbp-34h] BYREF
double v10[6]; // [rsp+18h] [rbp-30h] BYREF

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

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

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

variable_types:
mask
unsigned char *

variable_types:
i
unsigned int

variable_types:
gnnodes
unsigned int

variable_types: invsum double

variable_types: inv double

variable_types: effic double


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

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

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

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

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

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

variable_types:
nidx
unsigned int

variable_types:
numnodes
unsigned int

variable_types:
numnbrs
unsigned int

variable_types:
nbrs
unsigned int *

variable_types:
subgraphmask
unsigned char *


decompiled_code:
__int64 __fastcall graph_relabel(__int64 a1, __int64 a2, __int64 a3, char a4, __m128i a5)
{
unsigned int v6; // er13
int v7; // ebp
float v8; // er14
double v9; // xmm0_8
float v10; // xmm3_4
__int64 v11; // rbp
unsigned int v12; // er13
unsigned int v13; // er13
unsigned int v14; // er13
const __m128i *v15; // rax
__int64 v18; // [rsp+20h] [rbp-B8h]
double v19; // [rsp+38h] [rbp-A0h]
unsigned int v20; // [rsp+44h] [rbp-94h] BYREF
unsigned int v21; // [rsp+48h] [rbp-90h]
unsigned int v22; // [rsp+4Ch] [rbp-8Ch]
__int128 v23[8]; // [rsp+50h] [rbp-88h] BYREF

v6 = graph_num_nodes();
*(double *)a5.m128i_i64 = analyze_pixdim_size(a2, 0LL);
v7 = _mm_cvtsi128_si32(a5);
*(double *)a5.m128i_i64 = analyze_pixdim_size(a2, 1LL);
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(a5));
v9 = analyze_pixdim_size(a2, 2LL);
if ( (unsigned __int8)analyze_num_dims(a2) != 3 )
return 1LL;
v18 = v6;
if ( v6 )
{
v10 = *(float *)&v7;
v11 = 0LL;
v19 = *(float *)&v9;
while ( 1 )
{
v15 = (const __m128i *)graph_get_nodelabel(a1, (unsigned int)v11);
if ( !v15 )
break;
v23[0] = (__int128)_mm_loadu_si128(v15);
v23[1] = (__int128)_mm_loadu_si128(v15 + 1);
v23[2] = (__int128)_mm_loadu_si128(v15 + 2);
v23[3] = (__int128)_mm_loadu_si128(v15 + 3);
v23[4] = (__int128)_mm_loadu_si128(v15 + 4);
if ( a4 )
{
v20 = (int)round(*((float *)v23 + 1) / v10);
v12 = v20;
v21 = (int)round(*((float *)v23 + 2) / v8);
v22 = (int)round(*((float *)v23 + 3) / v19);
}
else
{
v20 = (int)*((float *)v23 + 1);
v12 = (int)*((float *)v23 + 1);
v21 = (int)*((float *)v23 + 2);
v22 = (int)*((float *)v23 + 3);
}
if ( (unsigned __int16)analyze_dim_size(a2, 0LL) <= v12 )
break;
v13 = v21;
if ( v13 >= (unsigned __int16)analyze_dim_size(a2, 1LL) )
break;
v14 = v22;
if ( v14 >= (unsigned __int16)analyze_dim_size(a2, 2LL) )
break;
LODWORD(v23[0]) = (int)analyze_read_val(a2, a3, &v20);
if ( (unsigned __int8)graph_set_nodelabel(a1, (unsigned int)v11, v23) )
break;
if ( ++v11 == v18 )
return 0LL;
}
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, char a4, __m128i a5)
{
unsigned int v6; // er13
int v7; // ebp
float v8; // er14
double v9; // xmm0_8
float v10; // xmm3_4
__int64 v11; // rbp
unsigned int v12; // er13
unsigned int v13; // er13
unsigned int v14; // er13
const __m128i *v15; // rax
__int64 v18; // [rsp+20h] [rbp-B8h]
double v19; // [rsp+38h] [rbp-A0h]
unsigned int v20; // [rsp+44h] [rbp-94h] BYREF
unsigned int v21; // [rsp+48h] [rbp-90h]
unsigned int v22; // [rsp+4Ch] [rbp-8Ch]
__int128 v23[8]; // [rsp+50h] [rbp-88h] BYREF

v6 = graph_num_nodes();
*(double *)a5.m128i_i64 = analyze_pixdim_size(a2, 0LL);
v7 = _mm_cvtsi128_si32(a5);
*(double *)a5.m128i_i64 = analyze_pixdim_size(a2, 1LL);
v8 = COERCE_FLOAT(_mm_cvtsi128_si32(a5));
v9 = analyze_pixdim_size(a2, 2LL);
if ( (unsigned __int8)analyze_num_dims(a2) != 3 )
return 1LL;
v18 = v6;
if ( v6 )
{
v10 = *(float *)&v7;
v11 = 0LL;
v19 = *(float *)&v9;
while ( 1 )
{
v15 = (const __m128i *)graph_get_nodelabel(a1, (unsigned int)v11);
if ( !v15 )
break;
v23[0] = (__int128)_mm_loadu_si128(v15);
v23[1] = (__int128)_mm_loadu_si128(v15 + 1);
v23[2] = (__int128)_mm_loadu_si128(v15 + 2);
v23[3] = (__int128)_mm_loadu_si128(v15 + 3);
v23[4] = (__int128)_mm_loadu_si128(v15 + 4);
if ( a4 )
{
v20 = (int)round(*((float *)v23 + 1) / v10);
v12 = v20;
v21 = (int)round(*((float *)v23 + 2) / v8);
v22 = (int)round(*((float *)v23 + 3) / v19);
}
else
{
v20 = (int)*((float *)v23 + 1);
v12 = (int)*((float *)v23 + 1);
v21 = (int)*((float *)v23 + 2);
v22 = (int)*((float *)v23 + 3);
}
if ( (unsigned __int16)analyze_dim_size(a2, 0LL) <= v12 )
break;
v13 = v21;
if ( v13 >= (unsigned __int16)analyze_dim_size(a2, 1LL) )
break;
v14 = v22;
if ( v14 >= (unsigned __int16)analyze_dim_size(a2, 2LL) )
break;
LODWORD(v23[0]) = (int)analyze_read_val(a2, a3, &v20);
if ( (unsigned __int8)graph_set_nodelabel(a1, (unsigned int)v11, v23) )
break;
if ( ++v11 == v18 )
return 0LL;
}
return 1LL;
}
return 0LL;
}

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

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

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

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

variable_types:
img
unsigned char *

variable_types:
real
unsigned char

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

variable_types: xl double

variable_types: yl double

variable_types: zl double

variable_types:
dims
unsigned int [3]


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

v8 = 0LL;
v2 = (unsigned int)graph_num_nodes();
v7[0] = 0LL;
v7[1] = 0LL;
v3 = load_mapfile(a2, (__int64)v7);
if ( (_BYTE)v3 )
return 1LL;
v4 = v3;
if ( v2 )
{
v5 = 0LL;
while ( !relabel_node(a1, v5, (__int64)v7) )
{
if ( ++v5 == v2 )
goto LABEL_7;
}
return 1LL;
}
LABEL_7:
array_free(v7);
return v4;
}

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

v8 = 0LL;
v2 = (unsigned int)graph_num_nodes();
v7[0] = 0LL;
v7[1] = 0LL;
v3 = func0(a2, (__int64)v7);
if ( (_BYTE)v3 )
return 1LL;
v4 = v3;
if ( v2 )
{
v5 = 0LL;
while ( !func2(a1, v5, (__int64)v7) )
{
if ( ++v5 == v2 )
goto LABEL_7;
}
return 1LL;
}
LABEL_7:
array_free(v7);
return v4;
}

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

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

variable_types:
lblmapfile
char *

variable_types:
i
unsigned long

variable_types:
nnodes
unsigned int

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


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

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

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

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

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

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

variable_types:
nidx
unsigned int

variable_types: nnodes double

variable_types: nnbrs double


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

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

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

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

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

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

variable_types: closeness double


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

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

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

variable_types:
i
unsigned char


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

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

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

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


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

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

variable_types: 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:
m
unsigned short

variable_types:
j
unsigned long

variable_types:
n
unsigned int

variable_types: prob double

variable_types: wt double

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


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

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

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

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


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

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

variable_types:
betw
double *

variable_types:
edges
struct _array *

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

variable_types:
i
unsigned long

variable_types:
nnbrs
unsigned int

variable_types:
nbrs
unsigned int *

variable_types: max double


decompiled_code:
__int64 __fastcall graph_recalculate_edge_betweenness(__int64 a1, unsigned int *a2)
{
size_t v3; // r14
_DWORD *v4; // rax
_DWORD *v5; // r13
__int64 v6; // rax
int v7; // er15
int v8; // ecx
__int64 v9; // rsi
__int64 v10; // rbx
int v11; // eax
int v13; // [rsp+Ch] [rbp-3Ch]
int v14; // [rsp+Ch] [rbp-3Ch]

v3 = (unsigned int)graph_num_nodes();
v4 = calloc(v3, 4uLL);
if ( !v4 )
return 1LL;
v5 = v4;
stats_cache_node_component(a1, -1LL, v4);
v6 = *a2;
v7 = v5[v6];
v8 = v5[a2[1]];
v9 = v6;
if ( v3 )
{
v10 = 0LL;
while ( 1 )
{
if ( v6 != v10 && a2[1] != v10 )
{
v11 = v5[v10];
if ( v7 == v11 || v8 == v11 )
{
v14 = v8;
stats_pathlength(a1, (unsigned int)v10, 0LL);
stats_numpaths(a1, (unsigned int)v10, 0LL);
v9 = *a2;
v8 = v14;
}
}
if ( v3 == ++v10 )
break;
v6 = (unsigned int)v9;
}
}
v13 = v8;
stats_pathlength(a1, v9, 0LL);
stats_pathlength(a1, a2[1], 0LL);
stats_numpaths(a1, *a2, 0LL);
stats_numpaths(a1, a2[1], 0LL);
stats_edge_betweenness(a1, *a2, 0LL);
if ( v7 != v13 )
stats_edge_betweenness(a1, a2[1], 0LL);
free(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int *a2)
{
size_t v3; // r14
_DWORD *v4; // rax
_DWORD *v5; // r13
__int64 v6; // rax
int v7; // er15
int v8; // ecx
__int64 v9; // rsi
__int64 v10; // rbx
int v11; // eax
int v13; // [rsp+Ch] [rbp-3Ch]
int v14; // [rsp+Ch] [rbp-3Ch]

v3 = (unsigned int)graph_num_nodes();
v4 = calloc(v3, 4uLL);
if ( !v4 )
return 1LL;
v5 = v4;
stats_cache_node_component(a1, -1LL, v4);
v6 = *a2;
v7 = v5[v6];
v8 = v5[a2[1]];
v9 = v6;
if ( v3 )
{
v10 = 0LL;
while ( 1 )
{
if ( v6 != v10 && a2[1] != v10 )
{
v11 = v5[v10];
if ( v7 == v11 || v8 == v11 )
{
v14 = v8;
stats_pathlength(a1, (unsigned int)v10, 0LL);
stats_numpaths(a1, (unsigned int)v10, 0LL);
v9 = *a2;
v8 = v14;
}
}
if ( v3 == ++v10 )
break;
v6 = (unsigned int)v9;
}
}
v13 = v8;
stats_pathlength(a1, v9, 0LL);
stats_pathlength(a1, a2[1], 0LL);
stats_numpaths(a1, *a2, 0LL);
stats_numpaths(a1, a2[1], 0LL);
stats_edge_betweenness(a1, *a2, 0LL);
if ( v7 != v13 )
stats_edge_betweenness(a1, a2[1], 0LL);
free(v5);
return 0LL;
}

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

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

variable_types:
nnodes
unsigned int

variable_types: icmp double

variable_types: ucmp double

variable_types: vcmp double

variable_types:
components
unsigned int *

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


decompiled_code:
__int64 __fastcall graph_are_connected(__int64 a1, unsigned int *a2, unsigned int a3)
{
unsigned int v3; // er12
__int64 v4; // rbx
size_t v5; // r14
void *v6; // rax
void *v7; // rbp
unsigned int *v8; // rax
__int64 v9; // rdx
void *v10; // r13
__int64 v11; // rax
void *ptr[8]; // [rsp+8h] [rbp-40h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int *a2, unsigned int a3)
{
unsigned int v3; // er12
__int64 v4; // rbx
size_t v5; // r14
void *v6; // rax
void *v7; // rbp
unsigned int *v8; // rax
__int64 v9; // rdx
void *v10; // r13
__int64 v11; // rax
void *ptr[8]; // [rsp+8h] [rbp-40h] BYREF

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

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

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

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

variable_types:
ngroup
unsigned int

variable_types:
mask
unsigned char *

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


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

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

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

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

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

canonical_original_code:
unsigned char graph_connect(struct _graph *g, unsigned int *group, unsigned int ngroup) {
  unsigned long i;
  unsigned long j;
  printf("              ");
  while (!graph_are_connected(g, group, ngroup)) {
    i = (unsigned int)(rand() * ((double)ngroup / 2147483647));
    j = i;
    while (j == i)
      j = (unsigned int)(rand() * ((double)ngroup / 2147483647));
    if (graph_add_edge(g, group[i], group[j], 1))
      goto fail;
  }
  return 0;
fail:
  return 1;
}

variable_types:
j
unsigned long


decompiled_code:
__int64 __fastcall graph_connect_from(__int64 a1, __int64 a2, unsigned int *a3, unsigned int a4)
{
unsigned __int64 v4; // r12
unsigned int *v5; // r15
unsigned int *v6; // rbp
__int64 v7; // rbx
unsigned __int64 v9; // [rsp+8h] [rbp-40h]

v4 = a4;
if ( !a4 )
return 0LL;
v5 = a3;
v6 = a3;
v9 = 0LL;
while ( 1 )
{
v7 = ++v9;
if ( v9 < v4 )
break;
LABEL_10:
++v6;
if ( v9 == v4 )
return 0LL;
}
while ( !(unsigned __int8)graph_are_neighbours(a2, *v6, v5[v7])
|| !(unsigned __int8)graph_add_edge(a1, *v6, v5[v7], 1.0) )
{
if ( ++v7 >= v4 )
{
v7 = ++v9;
++v6;
if ( v9 >= v4 )
goto LABEL_10;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, unsigned int *a3, unsigned int a4)
{
unsigned __int64 v4; // r12
unsigned int *v5; // r15
unsigned int *v6; // rbp
__int64 v7; // rbx
unsigned __int64 v9; // [rsp+8h] [rbp-40h]

v4 = a4;
if ( !a4 )
return 0LL;
v5 = a3;
v6 = a3;
v9 = 0LL;
while ( 1 )
{
v7 = ++v9;
if ( v9 < v4 )
break;
LABEL_10:
++v6;
if ( v9 == v4 )
return 0LL;
}
while ( !(unsigned __int8)graph_are_neighbours(a2, *v6, v5[v7])
|| !(unsigned __int8)graph_add_edge(a1, *v6, v5[v7], 1.0) )
{
if ( ++v7 >= v4 )
{
v7 = ++v9;
++v6;
if ( v9 >= v4 )
goto LABEL_10;
}
}
return 1LL;
}

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

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

variable_types:
src
struct _graph *