decompiled_code:
void __fastcall set_parse_double(__int64 a1, __int64 a2)
{
*(_DWORD *)(a1 + 24) = 6;
*(_QWORD *)(a1 + 32) = a2;
}

original_code: void set_parse_double(struct opt_rule *regla, double *data) { (regla)->accion = (PARSE_DOUBLE); regla->data.d_double = data ; }

variable_types:
data
double *


repo: jcarrano/rtfi

original_code: void set_parse_float(struct opt_rule *regla, float *data) { (regla)->accion = (PARSE_FLOAT); regla->data.d_float = data ; }

variable_types: struct opt_rule { char short_id; char *long_id; char *desc; int accion; union { int *d_int; int *d_bool; double *d_double; float *d_float; char **d_str; struct { void *data; int (*callback)(char *, char *, void *, char **); } d_custom; } data; } *

variable_types:
data
float *

return_type: void


original_code: void set_parse_bool(struct opt_rule *regla, int *data) { (regla)->accion = (SET_BOOL); regla->data.d_bool = data ; }

variable_types:
data
int *

user_defined_types: struct opt_rule { char short_id; char *long_id; char *desc; int accion; union { int *d_int; int *d_bool; double *d_double; float *d_float; char **d_str; struct { void *data; int (*callback)(char *, char *, void *, char **); } d_custom; } data; }


decompiled_code:
void __fastcall set_parse_bool_unset(__int64 a1, __int64 a2)
{
*(_DWORD *)(a1 + 24) = 5;
*(_QWORD *)(a1 + 32) = a2;
}

original_code: void set_parse_bool_unset(struct opt_rule *regla, int *data) { (regla)->accion = (UNSET_BOOL); regla->data.d_bool = data ; }


original_code: void set_parse_str(struct opt_rule *regla, char* *data) { (regla)->accion = (PARSE_STR); regla->data.d_str = data ; }

canonical_original_code: void set_parse_str(struct opt_rule *regla, char **data) { (regla)->accion = (PARSE_STR); regla->data.d_str = data ; }

variable_types:
data
char **


decompiled_code:
void __fastcall set_parse_str_nocopy(__int64 a1, __int64 a2)
{
*(_DWORD *)(a1 + 24) = 9;
*(_QWORD *)(a1 + 32) = a2;
}

original_code: void set_parse_str_nocopy(struct opt_rule *regla, char* *data) { (regla)->accion = (PARSE_STR_NOCOPY); regla->data.d_str = data ; }

canonical_original_code: void set_parse_str_nocopy(struct opt_rule *regla, char **data) { (regla)->accion = (PARSE_STR_NOCOPY); regla->data.d_str = data ; }


original_code:
static int vect_continue(struct vector_data *data, char *value, char **endptr)
{
 int ret = -PARSE_OK, i;
 if(*value != '\0')
 {
  for (i = 0; value[i] == data->sep[i] && value[i] != '\0'; i++);
  if (data->sep[i] != '\0')
   ret = -PARSE_BADSYNTAX;
  if (endptr != ((void *)0))
   *endptr = &value[i];
 } else {
  ret = 1;
 }
 return ret;
}

canonical_original_code:
static int vect_continue(struct vector_data *data, char *value, char **endptr)
{
 int ret = -PARSE_OK; int i;
 if(*value != '\0')
 {
  for (i = 0; value[i] == data->sep[i] && value[i] != '\0'; i++);
  if (data->sep[i] != '\0')
   ret = -PARSE_BADSYNTAX;
  if (endptr != ((void *)0))
   *endptr = &value[i];
 } else {
  ret = 1;
 }
 return ret;
}

variable_types: struct vector_data { unsigned long n_elem; char *sep; int type; int ignore_overfl; int ignore_underfl; char *msg; union { double *double_arr; float *float_arr; int *int_arr; char *char_arr; } arr; int *read; } *

variable_types:
value
char *

variable_types:
endptr
char **

variable_types: ret int

variable_types: i int

return_type: int


decompiled_code:
__int64 __fastcall filler_strtot(__int64 a1, int a2, char *a3, char **a4)
{
int v6; // eax
char *v7; // rdx
__int64 result; // rax
int v9; // eax
char v10; // al
char *endptr[6]; // [rsp+8h] [rbp-30h] BYREF

endptr[0] = a3;
if ( (unsigned __int64)a2 < *(_QWORD *)a1 )
{
v9 = *(_DWORD *)(a1 + 16);
if ( v9 == 1 )
{
*(double *)(*(_QWORD *)(a1 + 40) + 8LL * a2) = strtod(a3, endptr);
}
else if ( v9 == 3 )
{
v10 = *a3;
if ( *a3 )
endptr[0] = a3 + 1;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + a2) = v10;
}
else if ( v9 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 40) + 4LL * a2) = (int)(double)(int)strtol(a3, endptr, 0);
}
else
{
*(float *)(*(_QWORD *)(a1 + 40) + 4LL * a2) = strtof(a3, endptr);
}
goto LABEL_7;
}
if ( *(_DWORD *)(a1 + 20) )
{
v6 = *(_DWORD *)(a1 + 16);
if ( v6 == 1 )
{
strtod(a3, endptr);
}
else
{
if ( v6 == 3 )
{
v7 = a3 + 1;
if ( !*a3 )
{
v7 = a3;
result = 1LL;
goto LABEL_9;
}
goto LABEL_8;
}
if ( v6 )
strtol(a3, endptr, 0);
else
strtof(a3, endptr);
}
LABEL_7:
v7 = endptr[0];
result = 1LL;
if ( !*a3 )
{
LABEL_9:
*a4 = v7;
return result;
}
LABEL_8:
result = 2 * (unsigned int)(a3 != v7) - 2;
goto LABEL_9;
}
return 4294967294LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, char *a3, char **a4)
{
int v6; // eax
char *v7; // rdx
__int64 result; // rax
int v9; // eax
char v10; // al
char *endptr[6]; // [rsp+8h] [rbp-30h] BYREF

endptr[0] = a3;
if ( (unsigned __int64)a2 < *(_QWORD *)a1 )
{
v9 = *(_DWORD *)(a1 + 16);
if ( v9 == 1 )
{
*(double *)(*(_QWORD *)(a1 + 40) + 8LL * a2) = strtod(a3, endptr);
}
else if ( v9 == 3 )
{
v10 = *a3;
if ( *a3 )
endptr[0] = a3 + 1;
*(_BYTE *)(*(_QWORD *)(a1 + 40) + a2) = v10;
}
else if ( v9 )
{
*(_DWORD *)(*(_QWORD *)(a1 + 40) + 4LL * a2) = (int)(double)(int)strtol(a3, endptr, 0);
}
else
{
*(float *)(*(_QWORD *)(a1 + 40) + 4LL * a2) = strtof(a3, endptr);
}
goto LABEL_7;
}
if ( *(_DWORD *)(a1 + 20) )
{
v6 = *(_DWORD *)(a1 + 16);
if ( v6 == 1 )
{
strtod(a3, endptr);
}
else
{
if ( v6 == 3 )
{
v7 = a3 + 1;
if ( !*a3 )
{
v7 = a3;
result = 1LL;
goto LABEL_9;
}
goto LABEL_8;
}
if ( v6 )
strtol(a3, endptr, 0);
else
strtof(a3, endptr);
}
LABEL_7:
v7 = endptr[0];
result = 1LL;
if ( !*a3 )
{
LABEL_9:
*a4 = v7;
return result;
}
LABEL_8:
result = 2 * (unsigned int)(a3 != v7) - 2;
goto LABEL_9;
}
return 4294967294LL;
}

original_code:
static int filler_strtot(struct vector_data *data, int i, char *str,
        char **endptr)
{
 char c, *_endptr = str;
 union {
  float fl;
  double dbl;
  int n;
 } d;
 int ins, ret;
 if (i >= data->n_elem) {
  ins = 0;
  if (!data->ignore_overfl) {
   ret = -PARSE_BADSYNTAX;
   goto filler_strtot_end;
  }
 } else {
  ins = 1;
 }
 switch (data->type) {
 case VPARSER_FLOAT:
  d.fl = strtof(str, &_endptr);
  if (ins)
   data->arr.float_arr[i] = d.fl;
  break;
 case VPARSER_DOUBLE:
  d.dbl = strtod(str, &_endptr);
  if (ins)
   data->arr.double_arr[i] = d.dbl;
  break;
 default:
 case VPARSER_INT:
  d.dbl = strtol(str, &_endptr, 0);
  if (ins)
   data->arr.int_arr[i] = d.dbl;
  break;
 case VPARSER_CHAR:
  if((c = str[0]) != '\0')
   _endptr = str + 1;
  if (ins)
   data->arr.char_arr[i] = c;
  break;
 }
 if (*str == '\0') {
  ret = 1;
 } else if (str == _endptr) {
  ret = -PARSE_BADSYNTAX;
 } else {
  ret = -PARSE_OK;
 }
 if (endptr != ((void *)0))
  *endptr = _endptr;
filler_strtot_end:
 return ret;
}

canonical_original_code:
static int filler_strtot(struct vector_data *data, int i, char *str, char **endptr)
{
 char c; char *_endptr = str;
 union { float fl; double dbl; int n; } d;
 int ins; int ret;
 if (i >= data->n_elem) {
  ins = 0;
  if (!data->ignore_overfl) {
   ret = -PARSE_BADSYNTAX;
   goto filler_strtot_end;
  }
 } else {
  ins = 1;
 }
 switch (data->type) {
 case VPARSER_FLOAT:
  d.fl = strtof(str, &_endptr);
  if (ins)
   data->arr.float_arr[i] = d.fl;
  break;
 case VPARSER_DOUBLE:
  d.dbl = strtod(str, &_endptr);
  if (ins)
   data->arr.double_arr[i] = d.dbl;
  break;
 default:
 case VPARSER_INT:
  d.dbl = strtol(str, &_endptr, 0);
  if (ins)
   data->arr.int_arr[i] = d.dbl;
  break;
 case VPARSER_CHAR:
  if((c = str[0]) != '\0')
   _endptr = str + 1;
  if (ins)
   data->arr.char_arr[i] = c;
  break;
 }
 if (*str == '\0') {
  ret = 1;
 } else if (str == _endptr) {
  ret = -PARSE_BADSYNTAX;
 } else {
  ret = -PARSE_OK;
 }
 if (endptr != ((void *)0))
  *endptr = _endptr;
filler_strtot_end:
 return ret;
}

variable_types:
str
char *

variable_types: c char

variable_types:
d
union { float fl; double dbl; int n; }

variable_types: ins int

user_defined_types: struct vector_data { unsigned long n_elem; char *sep; int type; int ignore_overfl; int ignore_underfl; char *msg; union { double *double_arr; float *float_arr; int *int_arr; char *char_arr; } arr; int *read; }


decompiled_code:
__int64 __fastcall vector_parser(__int64 a1, char *a2, __int64 a3, _QWORD *a4)
{
char *v6; // r8
int i; // ebx
__int64 result; // rax
int v9; // er10
__int64 v10; // r12
__int64 v11; // rcx
_DWORD *v12; // rdx
char *v13[6]; // [rsp+8h] [rbp-30h] BYREF

if ( !a2 || !a3 || !valid_vtype(*(_DWORD *)(a3 + 16)) )
{
v11 = 0LL;
result = 4294967293LL;
goto LABEL_17;
}
v6 = a2;
for ( i = 0; ; ++i )
{
result = filler_strtot(a3, i, v6, v13);
LODWORD(v10) = i + 1;
v9 = result;
if ( (_DWORD)result )
break;
result = vect_continue(a3, v13[0], v13);
if ( (_DWORD)result )
break;
v6 = v13[0];
}
if ( (int)result > 0 )
{
if ( (unsigned __int64)(int)v10 >= *(_QWORD *)a3 || *(_DWORD *)(a3 + 24) )
{
v11 = 0LL;
result = 0LL;
goto LABEL_11;
}
result = 4294967294LL;
}
v11 = *(_QWORD *)(a3 + 32);
LABEL_11:
v12 = *(_DWORD **)(a3 + 48);
if ( v12 )
{
if ( v9 < 0 )
LODWORD(v10) = i;
if ( *(_QWORD *)a3 <= (unsigned __int64)(int)v10 )
v10 = *(_QWORD *)a3;
*v12 = v10;
}
LABEL_17:
if ( a4 )
*a4 = v11;
return result;
}

original_code:
int vector_parser(char *key, char *value, void *_data, const char **_msg)
{
 struct vector_data *data = (struct vector_data*)_data;
 int ret = -PARSE_OK, i = 0, vc = -PARSE_OK, fc = -PARSE_OK;
 char *end, *msg = ((void *)0);
 if (value != ((void *)0) && data!=((void *)0) && valid_vtype(data->type)) {
  do {
   vc = filler_strtot(data, i++, value, &end);
   fc = vc;
   if (vc)
    break;
   value = end;
   vc = vect_continue(data, value, &end);
   if (vc)
    break;
   value = end;
  } while (1);
  if (vc > 0 && i < data->n_elem && !data->ignore_underfl)
   vc = -PARSE_BADSYNTAX;
  if (vc < 0) {
   msg = data->msg;
   ret = vc;
  }
  if (data->read != ((void *)0)) {
   if (fc < 0)
    i--;
   *data->read = i > data->n_elem ? data->n_elem : i;
  }
 } else {
  ret = -PARSE_BADCONFIG;
 }
 if(_msg != ((void *)0) )
  *_msg = msg;
 return ret;
}

canonical_original_code:
int vector_parser(char *key, char *value, void *_data, char **_msg)
{
 struct vector_data *data = (struct vector_data*)_data;
 int ret = -PARSE_OK; int i = 0; int vc = -PARSE_OK; int fc = -PARSE_OK;
 char *end; char *msg = ((void *)0);
 if (value != ((void *)0) && data!=((void *)0) && valid_vtype(data->type)) {
  do {
   vc = filler_strtot(data, i++, value, &end);
   fc = vc;
   if (vc)
    break;
   value = end;
   vc = vect_continue(data, value, &end);
   if (vc)
    break;
   value = end;
  } while (1);
  if (vc > 0 && i < data->n_elem && !data->ignore_underfl)
   vc = -PARSE_BADSYNTAX;
  if (vc < 0) {
   msg = data->msg;
   ret = vc;
  }
  if (data->read != ((void *)0)) {
   if (fc < 0)
    i--;
   *data->read = i > data->n_elem ? data->n_elem : i;
  }
 } else {
  ret = -PARSE_BADCONFIG;
 }
 if(_msg != ((void *)0) )
  *_msg = msg;
 return ret;
}

variable_types:
key
char *

variable_types: vc int

variable_types: fc int

variable_types:
end
char *

variable_types:
msg
char *


decompiled_code:
__int64 __fastcall set_vector_parser(__int64 a1, __int64 a2)
{
return set_parse_custom(a1, vector_parser, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
return set_parse_custom(a1, vector_parser, a2);
}

original_code:
extern void set_vector_parser(struct opt_rule *regla, struct vector_data *cfg)
{
 set_parse_custom(regla, vector_parser, cfg);
}

variable_types: struct opt_rule { char short_id; char *long_id; char *desc; int accion; union { int *d_int; int *d_bool; double *d_double; float *d_float; char **d_str; struct { void *data; int (*callback)(char *, char *, void *, char **); } d_custom; } data; } *


decompiled_code:
__int64 __fastcall str_collector(__int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 v3; // rcx
__int64 result; // rax

v3 = *(int *)(a3 + 12);
if ( v3 >= *(_QWORD *)a3 )
{
result = *(unsigned int *)(a3 + 8);
if ( (_DWORD)result )
result = 2LL;
}
else
{
*(_QWORD *)(*(_QWORD *)(a3 + 16) + 8 * v3) = a2;
*(_DWORD *)(a3 + 12) = v3 + 1;
result = 0LL;
}
return result;
}

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

v3 = *(int *)(a3 + 12);
if ( v3 >= *(_QWORD *)a3 )
{
result = *(unsigned int *)(a3 + 8);
if ( (_DWORD)result )
result = 2LL;
}
else
{
*(_QWORD *)(*(_QWORD *)(a3 + 16) + 8 * v3) = a2;
*(_DWORD *)(a3 + 12) = v3 + 1;
result = 0LL;
}
return result;
}

original_code:
int str_collector(int dummy, char *str, void *_cfg)
{
 struct str_coll_data *cfg = (struct str_coll_data*)_cfg;
 int ret = PARSE_OK;
 if (cfg->n < cfg->n_elem) {
  cfg->store[cfg->n] = str;
  cfg->n++;
 } else if (cfg->strict) {
  ret = PARSE_BADSYNTAX;
 }
 return ret;
}

variable_types: dummy int

variable_types: struct str_coll_data { unsigned long n_elem; int strict; int n; char **store; } *


decompiled_code:
__int64 __fastcall str_coll_n_read(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int str_coll_n_read(struct str_coll_data *cd)
{
 return cd->n;
}

user_defined_types: struct str_coll_data { unsigned long n_elem; int strict; int n; char **store; }


decompiled_code:
_BOOL8 __fastcall can_fullscreen(unsigned int a1)
{
return SDL_ListModes(0LL, a1) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(unsigned int a1)
{
return SDL_ListModes(0LL, a1) != 0;
}

original_code:
static int can_fullscreen(int flags)
{
 return SDL_ListModes(((void *)0), flags) != ((SDL_Rect**)(0));
}

canonical_original_code:
static int can_fullscreen(int flags)
{
 return SDL_ListModes(((void *)0), flags) != ((struct SDL_Rect **)(0));
}

variable_types: flags int

user_defined_types: struct SDL_Rect { short x; unsigned short w; }


decompiled_code:
_BOOL8 __fastcall can_freescreen(unsigned int a1)
{
return SDL_ListModes(0LL, a1) == -1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(unsigned int a1)
{
return SDL_ListModes(0LL, a1) == -1;
}

original_code:
static int can_freescreen(int flags)
{
 return SDL_ListModes(((void *)0), flags) == ((SDL_Rect**)(-1));
}

canonical_original_code:
static int can_freescreen(int flags)
{
 return SDL_ListModes(((void *)0), flags) == ((struct SDL_Rect **)(-1));
}


maxmode

decompiled_code:
__int64 __fastcall maxmode(unsigned int a1)
{
return meta_modes(a1, 0, 0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
return func2(a1, 0, 0, 0LL);
}

original_code:
static int maxmode(int flags)
{
 return meta_modes(flags, 0, 0, ((void *)0));
}


decompiled_code:
__int64 __fastcall view_print_modes(unsigned int a1)
{
return meta_modes(a1, 1, 0, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
return func2(a1, 1, 0, 0LL);
}

original_code:
static void view_print_modes(int flags)
{
 meta_modes(flags, 1, 0, ((void *)0));
}


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

meta_modes(a1, 0, a2, &v3);
return v3;
}

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

func2(a1, 0, a2, &v3);
return v3;
}

original_code:
static SDL_Rect *get_mode(int flags, int mode)
{
 SDL_Rect *ret;
 meta_modes(flags, 0, mode, &ret);
 return ret;
}

canonical_original_code:
static struct SDL_Rect *get_mode(int flags, int mode)
{
 struct SDL_Rect *ret;
 meta_modes(flags, 0, mode, &ret);
 return ret;
}

variable_types: mode int

variable_types: struct SDL_Rect { short x; unsigned short w; } *


decompiled_code:
float __fastcall rand_f(__m128i a1)
{
float v2; // [rsp+0h] [rbp-Ch]

v2 = COERCE_FLOAT(_mm_cvtsi128_si32(a1));
return (float)((float)(*(float *)&a1.m128i_i32[1] - v2)
* COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(int)random() * 4.6566129e-10) & LC1))
+ v2;
}

canonical_decompiled_code:
float __fastcall func0(__m128i a1)
{
float v2; // [rsp+0h] [rbp-Ch]

v2 = COERCE_FLOAT(_mm_cvtsi128_si32(a1));
return (float)((float)(*(float *)&a1.m128i_i32[1] - v2)
* COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(int)random() * 4.6566129e-10) & LC1))
+ v2;
}

original_code:
float rand_f(struct limit lim)
{
 return fabsf(((float)random())/2147483647) * (lim.max - lim.min) + lim.min;
}

variable_types:
lim
struct limit { float min; }

return_type: float


main

canonical_name: main

repo: jcarrelli/status-clock

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
struct tm *v4; // rbx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h] BYREF
char *s; // [rsp+18h] [rbp-20h] BYREF

v6 = 0LL;
s = 0LL;
if ( argc )
{
v3 = *argv;
NAME = (__int64)*argv;
if ( argc == 2 )
{
setvbuf(stdout, 0LL, 1, 0LL);
while ( 1 )
{
timer = time(0LL);
v4 = localtime(&timer);
ustrftime(&s, &v6, argv[1], v4);
puts(s);
sleep(60 - v4->tm_sec);
}
}
}
else
{
NAME = (__int64)"clock.c";
v3 = "clock.c";
}
fprintf(stderr, "Usage: %s <format>\n", v3);
exit(1);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // rdx
struct tm *v4; // rbx
time_t timer; // [rsp+8h] [rbp-30h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h] BYREF
char *s; // [rsp+18h] [rbp-20h] BYREF

v6 = 0LL;
s = 0LL;
if ( argc )
{
v3 = *argv;
NAME = (__int64)*argv;
if ( argc == 2 )
{
setvbuf(stdout, 0LL, 1, 0LL);
while ( 1 )
{
timer = time(0LL);
v4 = localtime(&timer);
func8(&s, &v6, argv[1], v4);
puts(s);
sleep(60 - v4->tm_sec);
}
}
}
else
{
NAME = (__int64)"clock.c";
v3 = "clock.c";
}
fprintf(stderr, "Usage: %s <format>\n", v3);
exit(1);
}

original_code:
int main(int argc, char *argv[])
{
        time_t epochtime;
        struct tm *walltime;
        struct str clock = {0, ((void *)0)};
        NAME = argc ? argv[0] : "clock.c";
        if (argc != 2)
                do { fprintf(stderr, "Usage: %s <format>\n", NAME); exit(1); } while (0);
        setvbuf(stdout, ((void *)0), 1, 0);
        while (1) {
                epochtime = time(((void *)0));
                walltime = localtime(&epochtime);
                ustrftime(&clock.buf, &clock.max, argv[1], walltime);
                puts(clock.buf);
                sleep(60 - walltime->tm_sec);
        }
}

canonical_original_code:
int main(int argc, char *argv[])
{
        long epochtime;
        struct tm *walltime;
        struct str clock = {0, ((void *)0)};
        NAME = argc ? argv[0] : "clock.c";
        if (argc != 2)
                do { fprintf(stderr, "Usage: %s <format>\n", NAME); exit(1); } while (0);
        setvbuf(stdout, ((void *)0), 1, 0);
        while (1) {
                epochtime = time(((void *)0));
                walltime = localtime(&epochtime);
                ustrftime(&clock.buf, &clock.max, argv[1], walltime);
                puts(clock.buf);
                sleep(60 - walltime->tm_sec);
        }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: epochtime long

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; } *

variable_types: struct str { unsigned long max; char *buf; }


umalloc

decompiled_code:
void *__fastcall umalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "%s: malloc failed\n", (const char *)NAME);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
{
fprintf(stderr, "%s: malloc failed\n", (const char *)NAME);
exit(1);
}
return result;
}

original_code:
static void *umalloc(size_t size)
{
        void *ptr = malloc(size);
        if (!ptr)
                do { fprintf(stderr, "%s: malloc failed\n", NAME); exit(1); } while (0);
        return ptr;
}

canonical_original_code:
static void *umalloc(unsigned long size)
{
        void *ptr = malloc(size);
        if (!ptr)
                do { fprintf(stderr, "%s: malloc failed\n", NAME); exit(1); } while (0);
        return ptr;
}

variable_types:
size
unsigned long

variable_types:
ptr
void *

return_type: void *


ustrftime

decompiled_code:
size_t __fastcall ustrftime(void **a1, size_t *a2, const char *a3, const struct tm *a4)
{
size_t v8; // rax
void *v9; // rdi
size_t v10; // rbx
size_t v11; // rsi
void *v12; // rax

v8 = strftime(0LL, 0xFFFFFFFFFFFFFFFFLL, a3, a4);
v9 = *a1;
v10 = v8 + 1;
if ( !v9 || (v11 = *a2, v10 = v8 + 1, *a2 < v8 + 1) )
{
free(v9);
v12 = umalloc(v10);
v11 = v10;
*a1 = v12;
v9 = v12;
*a2 = v10;
}
return strftime((char *)v9, v11, a3, a4);
}

canonical_decompiled_code:
size_t __fastcall func8(void **a1, size_t *a2, const char *a3, const struct tm *a4)
{
size_t v8; // rax
void *v9; // rdi
size_t v10; // rbx
size_t v11; // rsi
void *v12; // rax

v8 = strftime(0LL, 0xFFFFFFFFFFFFFFFFLL, a3, a4);
v9 = *a1;
v10 = v8 + 1;
if ( !v9 || (v11 = *a2, v10 = v8 + 1, *a2 < v8 + 1) )
{
free(v9);
v12 = func7(v10);
v11 = v10;
*a1 = v12;
v9 = v12;
*a2 = v10;
}
return strftime((char *)v9, v11, a3, a4);
}

original_code:
size_t ustrftime(char **s, size_t *max, const char *format,
                 const struct tm *tm)
{
        size_t len = strftime(((void *)0), (18446744073709551615UL), format, tm);
        if (!*s || *max < len + 1) {
                free(*s);
                *s = umalloc(len + 1);
                *max = len + 1;
        }
        return strftime(*s, *max, format, tm);
}

canonical_original_code:
unsigned long ustrftime(char **s, unsigned long *max, char *format, struct tm *tm)
{
        unsigned long len = strftime(((void *)0), (18446744073709551615UL), format, tm);
        if (!*s || *max < len + 1) {
                free(*s);
                *s = umalloc(len + 1);
                *max = len + 1;
        }
        return strftime(*s, *max, format, tm);
}

variable_types:
s
char **

variable_types:
max
unsigned long *

variable_types:
format
char *

variable_types:
len
unsigned long

return_type: unsigned long

user_defined_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long __tm_gmtoff; char *__tm_zone; }


yyerror

repo: jcatumba/crc-compiler

decompiled_code:
int __fastcall yyerror(const char *a1)
{
int result; // eax

noerror = 0;
result = strcmp(a1, "syntax error");
if ( result )
result = printf(" Syntax Error in Line : %d : %s\n", yylineno, a1);
return result;
}

canonical_decompiled_code:
int __fastcall func6(const char *a1)
{
int result; // eax

noerror = 0;
result = strcmp(a1, "syntax error");
if ( result )
result = printf(" Syntax Error in Line : %d : %s\n", yylineno, a1);
return result;
}

original_code:
extern void yyerror(char const *msg) {
 noerror=0;
 if(strcmp(msg,"syntax error"))
  printf(" Syntax Error in Line : %d : %s\n",yylineno,msg);
}

canonical_original_code:
extern void yyerror(char *msg) {
 noerror=0;
 if(strcmp(msg,"syntax error"))
  printf(" Syntax Error in Line : %d : %s\n",yylineno,msg);
}

variable_types:
msg
char *


repo: jcatw/quicknet

decompiled_code:
double __fastcall get_node_mass(__int64 a1)
{
return *(double *)(a1 + 24);
}

canonical_decompiled_code:
double __fastcall func0(__int64 a1)
{
return *(double *)(a1 + 24);
}

original_code:
double
get_node_mass (bstreap_item_t *item) {
  return item->node_mass;
}

canonical_original_code:
double get_node_mass(struct bstreap_item *item) {
  return item->node_mass;
}

variable_types: struct bstreap_item { struct node { unsigned long id; unsigned long in_degree; unsigned long out_degree; double lambda; double mu; struct node_list { struct node *node; struct node_list *next; } *adjacency_list; } *node; struct bstreap_item *left; struct bstreap_item *right; double node_mass; double subtree_mass; unsigned long priority; } *

return_type: double

user_defined_types: struct bstreap_item { struct node *node; struct bstreap_item *left; struct bstreap_item *right; double node_mass; double subtree_mass; unsigned long priority; }

user_defined_types: struct node { unsigned long id; unsigned long in_degree; unsigned long out_degree; double lambda; double mu; struct node_list *adjacency_list; }


decompiled_code:
double __fastcall get_subtree_mass(__int64 a1)
{
return *(double *)(a1 + 32);
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
return *(double *)(a1 + 32);
}

original_code:
double
get_subtree_mass (bstreap_item_t *item) {
  return item->subtree_mass;
}

canonical_original_code:
double get_subtree_mass(struct bstreap_item *item) {
  return item->subtree_mass;
}

user_defined_types: struct node_list { struct node *node; struct node_list *next; }


decompiled_code:
unsigned __int64 __fastcall node_mass_priority(__int64 a1)
{
double v1; // xmm0_8
unsigned __int64 result; // rax

v1 = *(double *)(a1 + 24);
if ( v1 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v1 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v1;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1)
{
double v1; // xmm0_8
unsigned __int64 result; // rax

v1 = *(double *)(a1 + 24);
if ( v1 >= 9.223372036854776e18 )
result = (unsigned int)(int)(v1 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
result = (unsigned int)(int)v1;
return result;
}

original_code:
uint64_t
node_mass_priority(bstreap_item_t *item) {
  return (uint64_t) item->node_mass;
}

canonical_original_code:
unsigned long node_mass_priority(struct bstreap_item *item) {
  return (unsigned long) item->node_mass;
}


decompiled_code:
__int64 random_priority()
{
return rand();
}

canonical_decompiled_code:
__int64 func3()
{
return rand();
}

original_code:
uint64_t
random_priority () {
  return rand();
}

canonical_original_code:
unsigned long random_priority() {
  return rand();
}


decompiled_code:
_QWORD *make_bstreap()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

canonical_decompiled_code:
_QWORD *func4()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( result )
{
*result = 0LL;
result[1] = 0LL;
}
return result;
}

original_code:
bstreap_t *
make_bstreap() {
  bstreap_t *b = (bstreap_t*) malloc(sizeof(*b));
  if (!b) return 0;
  b->total_mass = 0.;
  b->root = ((void *)0);
  return b;
}

canonical_original_code:
struct bstreap *make_bstreap() {
  struct bstreap *b = (bstreap_t*) malloc(sizeof(*b));
  if (!b) return 0;
  b->total_mass = 0.;
  b->root = ((void *)0);
  return b;
}

variable_types: struct bstreap { double total_mass; struct bstreap_item { struct node { unsigned long id; unsigned long in_degree; unsigned long out_degree; double lambda; double mu; struct node_list { struct node *node; struct node_list *next; } *adjacency_list; } *node; struct bstreap_item *left; struct bstreap_item *right; double node_mass; double subtree_mass; unsigned long priority; } *root; } *

user_defined_types: struct bstreap { double total_mass; struct bstreap_item *root; }


decompiled_code:
size_t __fastcall bstreap_rotate_left(__int64 a1, __int64 a2, __int64 a3)
{
size_t result; // rax
double v4; // xmm0_8
__int64 v5; // rcx
double v6; // xmm0_8
__int64 v7; // rcx

result = *(_QWORD *)(a2 + 16);
v4 = *(double *)(a2 + 32);
v5 = *(_QWORD *)(result + 8);
*(double *)(result + 32) = v4;
v6 = v4 - *(double *)(result + 24);
*(_QWORD *)(a2 + 16) = v5;
v7 = *(_QWORD *)(result + 16);
*(double *)(a2 + 32) = v6;
if ( v7 )
*(double *)(a2 + 32) = v6 - *(double *)(v7 + 32);
*(_QWORD *)(result + 8) = a2;
if ( a3 )
{
if ( *(_QWORD *)(a3 + 8) == a2 )
{
*(_QWORD *)(a3 + 8) = result;
}
else if ( *(_QWORD *)(a3 + 16) == a2 )
{
*(_QWORD *)(a3 + 16) = result;
}
else
{
result = fwrite("Failed to rotate left.\n", 1uLL, 0x17uLL, stderr);
}
}
else
{
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func6(__int64 a1, __int64 a2, __int64 a3)
{
size_t result; // rax
double v4; // xmm0_8
__int64 v5; // rcx
double v6; // xmm0_8
__int64 v7; // rcx

result = *(_QWORD *)(a2 + 16);
v4 = *(double *)(a2 + 32);
v5 = *(_QWORD *)(result + 8);
*(double *)(result + 32) = v4;
v6 = v4 - *(double *)(result + 24);
*(_QWORD *)(a2 + 16) = v5;
v7 = *(_QWORD *)(result + 16);
*(double *)(a2 + 32) = v6;
if ( v7 )
*(double *)(a2 + 32) = v6 - *(double *)(v7 + 32);
*(_QWORD *)(result + 8) = a2;
if ( a3 )
{
if ( *(_QWORD *)(a3 + 8) == a2 )
{
*(_QWORD *)(a3 + 8) = result;
}
else if ( *(_QWORD *)(a3 + 16) == a2 )
{
*(_QWORD *)(a3 + 16) = result;
}
else
{
result = fwrite("Failed to rotate left.\n", 1uLL, 0x17uLL, stderr);
}
}
else
{
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

original_code:
void bstreap_rotate_left(bstreap_t *bstreap, bstreap_item_t *item, bstreap_item_t *parent) {
  bstreap_item_t *y;
  double full_subtree_mass;
  full_subtree_mass = item->subtree_mass;
  y = item->right;
  y->subtree_mass = full_subtree_mass;
  item->right = y->left;
  item->subtree_mass = full_subtree_mass;
  item->subtree_mass -= y->node_mass;
  if(y->right != ((void *)0)) {
    item->subtree_mass -= y->right->subtree_mass;
  }
  y->left = item;
  if(parent == ((void *)0))
    bstreap->root = y;
  else if(parent->left == item)
    parent->left = y;
  else if(parent->right == item)
    parent->right = y;
  else {
    fprintf(stderr,"Failed to rotate left.\n");
    return;
  }
}

canonical_original_code:
void bstreap_rotate_left(struct bstreap *bstreap, struct bstreap_item *item, struct bstreap_item *parent) {
  struct bstreap_item *y;
  double full_subtree_mass;
  full_subtree_mass = item->subtree_mass;
  y = item->right;
  y->subtree_mass = full_subtree_mass;
  item->right = y->left;
  item->subtree_mass = full_subtree_mass;
  item->subtree_mass -= y->node_mass;
  if(y->right != ((void *)0)) {
    item->subtree_mass -= y->right->subtree_mass;
  }
  y->left = item;
  if(parent == ((void *)0))
    bstreap->root = y;
  else if(parent->left == item)
    parent->left = y;
  else if(parent->right == item)
    parent->right = y;
  else {
    fprintf(stderr,"Failed to rotate left.\n");
    return;
  }
}

variable_types:
item
struct bstreap_item *

variable_types:
parent
struct bstreap_item *


decompiled_code:
size_t __fastcall bstreap_rotate_right(__int64 a1, __int64 a2, __int64 a3)
{
size_t result; // rax
double v4; // xmm0_8
__int64 v5; // rcx
double v6; // xmm0_8
__int64 v7; // rcx

result = *(_QWORD *)(a2 + 8);
v4 = *(double *)(a2 + 32);
v5 = *(_QWORD *)(result + 16);
*(double *)(result + 32) = v4;
v6 = v4 - *(double *)(result + 24);
*(_QWORD *)(a2 + 8) = v5;
v7 = *(_QWORD *)(result + 8);
*(double *)(a2 + 32) = v6;
if ( v7 )
*(double *)(a2 + 32) = v6 - *(double *)(v7 + 32);
*(_QWORD *)(result + 16) = a2;
if ( a3 )
{
if ( *(_QWORD *)(a3 + 8) == a2 )
{
*(_QWORD *)(a3 + 8) = result;
}
else if ( *(_QWORD *)(a3 + 16) == a2 )
{
*(_QWORD *)(a3 + 16) = result;
}
else
{
result = fwrite("Failed to rotate right.\n", 1uLL, 0x18uLL, stderr);
}
}
else
{
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

canonical_decompiled_code:
size_t __fastcall func7(__int64 a1, __int64 a2, __int64 a3)
{
size_t result; // rax
double v4; // xmm0_8
__int64 v5; // rcx
double v6; // xmm0_8
__int64 v7; // rcx

result = *(_QWORD *)(a2 + 8);
v4 = *(double *)(a2 + 32);
v5 = *(_QWORD *)(result + 16);
*(double *)(result + 32) = v4;
v6 = v4 - *(double *)(result + 24);
*(_QWORD *)(a2 + 8) = v5;
v7 = *(_QWORD *)(result + 8);
*(double *)(a2 + 32) = v6;
if ( v7 )
*(double *)(a2 + 32) = v6 - *(double *)(v7 + 32);
*(_QWORD *)(result + 16) = a2;
if ( a3 )
{
if ( *(_QWORD *)(a3 + 8) == a2 )
{
*(_QWORD *)(a3 + 8) = result;
}
else if ( *(_QWORD *)(a3 + 16) == a2 )
{
*(_QWORD *)(a3 + 16) = result;
}
else
{
result = fwrite("Failed to rotate right.\n", 1uLL, 0x18uLL, stderr);
}
}
else
{
*(_QWORD *)(a1 + 8) = result;
}
return result;
}

original_code:
void bstreap_rotate_right(bstreap_t *bstreap, bstreap_item_t *item, bstreap_item_t *parent) {
  bstreap_item_t *y;
  double full_subtree_mass;
  full_subtree_mass = item->subtree_mass;
  y = item->left;
  y->subtree_mass = full_subtree_mass;
  item->left = y->right;
  item->subtree_mass = full_subtree_mass;
  item->subtree_mass -= y->node_mass;
  if(y->left != ((void *)0)) {
    item->subtree_mass -= y->left->subtree_mass;
  }
  y->right = item;
  if(parent == ((void *)0))
    bstreap->root = y;
  else if(parent->left == item)
    parent->left = y;
  else if(parent->right == item)
    parent->right = y;
  else {
    fprintf(stderr,"Failed to rotate right.\n");
    return;
  }
}

canonical_original_code:
void bstreap_rotate_right(struct bstreap *bstreap, struct bstreap_item *item, struct bstreap_item *parent) {
  struct bstreap_item *y;
  double full_subtree_mass;
  full_subtree_mass = item->subtree_mass;
  y = item->left;
  y->subtree_mass = full_subtree_mass;
  item->left = y->right;
  item->subtree_mass = full_subtree_mass;
  item->subtree_mass -= y->node_mass;
  if(y->left != ((void *)0)) {
    item->subtree_mass -= y->left->subtree_mass;
  }
  y->right = item;
  if(parent == ((void *)0))
    bstreap->root = y;
  else if(parent->left == item)
    parent->left = y;
  else if(parent->right == item)
    parent->right = y;
  else {
    fprintf(stderr,"Failed to rotate right.\n");
    return;
  }
}


decompiled_code:
size_t __fastcall bstreap_item_insert(__int64 a1, __int64 a2, __int64 a3, __int64 a4, double (__fastcall *a5)(__int64))
{
__int64 v5; // r14
__int64 v9; // rdx
size_t result; // rax
__int64 v11; // rdx
double v12; // [rsp+8h] [rbp-30h]

v5 = a2;
*(double *)(a3 + 32) = *(double *)(a3 + 32) + *(double *)(a2 + 24);
v12 = a5(a2);
if ( a5(a3) < v12 )
{
v11 = *(_QWORD *)(a3 + 16);
if ( v11 )
{
bstreap_item_insert(a1, a2, v11, a3, a5);
result = *(_QWORD *)(a3 + 40);
if ( *(_QWORD *)(*(_QWORD *)(a3 + 16) + 40LL) <= result )
return result;
}
else
{
*(_QWORD *)(a3 + 16) = a2;
result = *(_QWORD *)(a3 + 40);
if ( *(_QWORD *)(a2 + 40) <= result )
return result;
}
return bstreap_rotate_left(a1, a3, a4);
}
v9 = *(_QWORD *)(a3 + 8);
if ( v9 )
{
bstreap_item_insert(a1, a2, v9, a3, a5);
v5 = *(_QWORD *)(a3 + 8);
}
else
{
*(_QWORD *)(a3 + 8) = a2;
}
result = *(_QWORD *)(a3 + 40);
if ( *(_QWORD *)(v5 + 40) > result )
result = bstreap_rotate_right(a1, a3, a4);
return result;
}

original_code:
void
bstreap_item_insert(bstreap_t *bstreap,
                    bstreap_item_t *item,
                    bstreap_item_t *existing_item,
                    bstreap_item_t *parent,
                    double (*compute_key)(bstreap_item_t*)) {
  existing_item->subtree_mass += item->node_mass;
  if ((*compute_key)(item) <= (*compute_key)(existing_item)) {
    if (existing_item->left == ((void *)0)) {
      existing_item->left = item;
    }
    else {
      bstreap_item_insert(bstreap,
                          item,
                          existing_item->left,
                          existing_item,
                          compute_key);
    }
    if (existing_item->left->priority > existing_item->priority)
      bstreap_rotate_right(bstreap, existing_item, parent);
    return;
  }
  else {
    if(existing_item->right == ((void *)0)) {
      existing_item->right = item;
    }
    else {
      bstreap_item_insert(bstreap,
                          item,
                          existing_item->right,
                          existing_item,
                          compute_key);
    }
    if (existing_item->right->priority > existing_item->priority)
      bstreap_rotate_left(bstreap, existing_item, parent);
    return;
  }
}

canonical_original_code:
void bstreap_item_insert(struct bstreap *bstreap, struct bstreap_item *item, struct bstreap_item *existing_item, struct bstreap_item *parent, double (*compute_key)(struct bstreap_item *)) {
  existing_item->subtree_mass += item->node_mass;
  if ((*compute_key)(item) <= (*compute_key)(existing_item)) {
    if (existing_item->left == ((void *)0)) {
      existing_item->left = item;
    }
    else {
      bstreap_item_insert(bstreap,
                          item,
                          existing_item->left,
                          existing_item,
                          compute_key);
    }
    if (existing_item->left->priority > existing_item->priority)
      bstreap_rotate_right(bstreap, existing_item, parent);
    return;
  }
  else {
    if(existing_item->right == ((void *)0)) {
      existing_item->right = item;
    }
    else {
      bstreap_item_insert(bstreap,
                          item,
                          existing_item->right,
                          existing_item,
                          compute_key);
    }
    if (existing_item->right->priority > existing_item->priority)
      bstreap_rotate_left(bstreap, existing_item, parent);
    return;
  }
}


decompiled_code:
__int64 __fastcall bstreap_insert(__int64 a1, __int64 a2, double (__fastcall *a3)(__int64), __int64 (__fastcall *a4)(double *), double (__fastcall *a5)(__int64))
{
__int64 result; // rax
__int64 v7; // rdx
__int64 v8; // rbp

result = (__int64)make_bstreap_item(a2, a3, a4);
v7 = *(_QWORD *)(a1 + 8);
v8 = result;
if ( v7 )
result = bstreap_item_insert(a1, result, v7, 0LL, a5);
else
*(_QWORD *)(a1 + 8) = result;
*(double *)a1 = *(double *)a1 + *(double *)(v8 + 24);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, double (__fastcall *a3)(__int64), __int64 (__fastcall *a4)(double *), double (__fastcall *a5)(__int64))
{
__int64 result; // rax
__int64 v7; // rdx
__int64 v8; // rbp

result = (__int64)func5(a2, a3, a4);
v7 = *(_QWORD *)(a1 + 8);
v8 = result;
if ( v7 )
result = func8(a1, result, v7, 0LL, a5);
else
*(_QWORD *)(a1 + 8) = result;
*(double *)a1 = *(double *)a1 + *(double *)(v8 + 24);
return result;
}

original_code:
void
bstreap_insert(bstreap_t *bstreap,
               node_t* node,
               double (*compute_mass) (node_t*),
               uint64_t (*compute_priority) (bstreap_item_t*),
               double (*compute_key)(bstreap_item_t*)) {
  bstreap_item_t *bstreap_item;
  bstreap_item = make_bstreap_item(node, compute_mass, compute_priority);
  if(bstreap->root == ((void *)0)) {
    bstreap->root = bstreap_item;
  }
  else {
    bstreap_item_insert(bstreap, bstreap_item, bstreap->root, ((void *)0), compute_key);
  }
  bstreap->total_mass += bstreap_item->node_mass;
}

canonical_original_code:
void bstreap_insert(struct bstreap *bstreap, struct node *node, double (*compute_mass)(struct node *), unsigned long (*compute_priority)(struct bstreap_item *), double (*compute_key)(struct bstreap_item *)) {
  struct bstreap_item *bstreap_item;
  bstreap_item = make_bstreap_item(node, compute_mass, compute_priority);
  if(bstreap->root == ((void *)0)) {
    bstreap->root = bstreap_item;
  }
  else {
    bstreap_item_insert(bstreap, bstreap_item, bstreap->root, ((void *)0), compute_key);
  }
  bstreap->total_mass += bstreap_item->node_mass;
}

variable_types:
node
struct node *

variable_types: unsigned long (*)(struct bstreap_item *)


original_code:
void bstreap_item_splice(bstreap_t *bstreap, bstreap_item_t *item, bstreap_item_t *parent) {
  bstreap_item_t *parent_placeholder;
  while(!(item->left == ((void *)0) && item->right == ((void *)0))) {
    if(item->left == ((void *)0)) {
      parent_placeholder = item->right;
      bstreap_rotate_left(bstreap, item, parent);
      parent = parent_placeholder;
    }
    else if (item->right == ((void *)0)) {
      parent_placeholder = item->left;
      bstreap_rotate_right(bstreap, item, parent);
      parent = parent_placeholder;
    }
    else if (item->left->priority > item->right->priority) {
      parent_placeholder = item->left;
      bstreap_rotate_right(bstreap, item, parent);
      parent = parent_placeholder;
    }
    else {
      parent_placeholder = item->right;
      bstreap_rotate_left(bstreap, item, parent);
      parent = parent_placeholder;
    }
    parent->subtree_mass -= item->node_mass;
  }
  if (bstreap->root == item)
    bstreap->root = ((void *)0);
  else if (parent->left == item) {
    parent->left = ((void *)0);
  }
  else if (parent->right == item) {
    parent->right = ((void *)0);
  }
}

canonical_original_code:
void bstreap_item_splice(struct bstreap *bstreap, struct bstreap_item *item, struct bstreap_item *parent) {
  struct bstreap_item *parent_placeholder;
  while(!(item->left == ((void *)0) && item->right == ((void *)0))) {
    if(item->left == ((void *)0)) {
      parent_placeholder = item->right;
      bstreap_rotate_left(bstreap, item, parent);
      parent = parent_placeholder;
    }
    else if (item->right == ((void *)0)) {
      parent_placeholder = item->left;
      bstreap_rotate_right(bstreap, item, parent);
      parent = parent_placeholder;
    }
    else if (item->left->priority > item->right->priority) {
      parent_placeholder = item->left;
      bstreap_rotate_right(bstreap, item, parent);
      parent = parent_placeholder;
    }
    else {
      parent_placeholder = item->right;
      bstreap_rotate_left(bstreap, item, parent);
      parent = parent_placeholder;
    }
    parent->subtree_mass -= item->node_mass;
  }
  if (bstreap->root == item)
    bstreap->root = ((void *)0);
  else if (parent->left == item) {
    parent->left = ((void *)0);
  }
  else if (parent->right == item) {
    parent->right = ((void *)0);
  }
}


decompiled_code:
__int64 __fastcall bstreap_item_sample(double *a1, __int64 a2, __int64 a3, double a4, double a5)
{
__int64 v6; // rsi
double v7; // xmm3_8
__int64 v8; // rdx
__int64 result; // rax

v6 = *(_QWORD *)(a2 + 8);
v7 = *a1;
if ( v6 )
{
a4 = a4 + *(double *)(v6 + 32);
if ( a4 / v7 > a5 )
{
v8 = a2;
goto LABEL_6;
}
}
if ( (a4 + *(double *)(a2 + 24)) / v7 > a5 )
{
bstreap_item_splice((__int64)a1, a2, a3);
result = a2;
}
else
{
if ( *(_QWORD *)(a2 + 16) )
{
v8 = a2;
v6 = *(_QWORD *)(a2 + 16);
LABEL_6:
result = bstreap_item_sample(a1, v6, v8);
*(double *)(a2 + 32) = *(double *)(a2 + 32) - *(double *)(result + 24);
return result;
}
fwrite("Failed to sample a bstreap node.\n", 1uLL, 0x21uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(double *a1, __int64 a2, __int64 a3, double a4, double a5)
{
__int64 v6; // rsi
double v7; // xmm3_8
__int64 v8; // rdx
__int64 result; // rax

v6 = *(_QWORD *)(a2 + 8);
v7 = *a1;
if ( v6 )
{
a4 = a4 + *(double *)(v6 + 32);
if ( a4 / v7 > a5 )
{
v8 = a2;
goto LABEL_6;
}
}
if ( (a4 + *(double *)(a2 + 24)) / v7 > a5 )
{
func10((__int64)a1, a2, a3);
result = a2;
}
else
{
if ( *(_QWORD *)(a2 + 16) )
{
v8 = a2;
v6 = *(_QWORD *)(a2 + 16);
LABEL_6:
result = func11(a1, v6, v8);
*(double *)(a2 + 32) = *(double *)(a2 + 32) - *(double *)(result + 24);
return result;
}
fwrite("Failed to sample a bstreap node.\n", 1uLL, 0x21uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
bstreap_item_t *
bstreap_item_sample(bstreap_t *bstreap,
                    bstreap_item_t *item,
                    bstreap_item_t *parent,
                    double observed_mass,
                    double uniform_sample) {
  bstreap_item_t *sampled_item;
  if (item->left != ((void *)0)) {
    if (uniform_sample < (observed_mass + item->left->subtree_mass) / bstreap->total_mass) {
      sampled_item = bstreap_item_sample(bstreap, item->left, item, observed_mass, uniform_sample);
      item->subtree_mass -= sampled_item->node_mass;
      return sampled_item;
    }
    observed_mass += item->left->subtree_mass;
  }
  observed_mass += item->node_mass;
  if (uniform_sample < observed_mass / bstreap->total_mass) {
    bstreap_item_splice(bstreap, item, parent);
    return item;
  }
  if (item->right != ((void *)0)) {
    sampled_item = bstreap_item_sample(bstreap, item->right, item, observed_mass, uniform_sample);
    item->subtree_mass -= sampled_item->node_mass;
    return sampled_item;
  }
  fprintf(stderr,"Failed to sample a bstreap node.\n");
  return ((void *)0);
}

canonical_original_code:
struct bstreap_item *bstreap_item_sample(struct bstreap *bstreap, struct bstreap_item *item, struct bstreap_item *parent, double observed_mass, double uniform_sample) {
  struct bstreap_item *sampled_item;
  if (item->left != ((void *)0)) {
    if (uniform_sample < (observed_mass + item->left->subtree_mass) / bstreap->total_mass) {
      sampled_item = bstreap_item_sample(bstreap, item->left, item, observed_mass, uniform_sample);
      item->subtree_mass -= sampled_item->node_mass;
      return sampled_item;
    }
    observed_mass += item->left->subtree_mass;
  }
  observed_mass += item->node_mass;
  if (uniform_sample < observed_mass / bstreap->total_mass) {
    bstreap_item_splice(bstreap, item, parent);
    return item;
  }
  if (item->right != ((void *)0)) {
    sampled_item = bstreap_item_sample(bstreap, item->right, item, observed_mass, uniform_sample);
    item->subtree_mass -= sampled_item->node_mass;
    return sampled_item;
  }
  fprintf(stderr,"Failed to sample a bstreap node.\n");
  return ((void *)0);
}

variable_types: struct bstreap { double total_mass; struct bstreap_item *root; } *

return_type: struct bstreap_item { struct node { unsigned long id; unsigned long in_degree; unsigned long out_degree; double lambda; double mu; struct node_list { struct node *node; struct node_list *next; } *adjacency_list; } *node; struct bstreap_item *left; struct bstreap_item *right; double node_mass; double subtree_mass; unsigned long priority; } *


decompiled_code:
__int64 __fastcall bstreap_sample(double *a1)
{
int v1; // eax
double v2; // r12
double *v3; // rax

v1 = rand();
v2 = a1[1];
if ( v2 != 0.0 )
{
v3 = (double *)bstreap_item_sample(a1, *((_QWORD *)a1 + 1), 0LL, 0.0, (double)v1 / 2147483647.0);
v2 = *v3;
*a1 = *a1 - v3[3];
free(v3);
}
return *(_QWORD *)&v2;
}

original_code:
node_t *
bstreap_sample(bstreap_t* bstreap) {
  bstreap_item_t *sampled_item;
  node_t *sampled_node;
  double uniform_sample;
  uniform_sample = rand() / (double)2147483647;
  if(bstreap->root == ((void *)0))
    return ((void *)0);
  sampled_item = bstreap_item_sample(bstreap, bstreap->root, ((void *)0), 0., uniform_sample);
  sampled_node = sampled_item->node;
  bstreap->total_mass -= sampled_item->node_mass;
  free(sampled_item);
  return sampled_node;
}

canonical_original_code:
struct node *bstreap_sample(struct bstreap *bstreap) {
  struct bstreap_item *sampled_item;
  struct node *sampled_node;
  double uniform_sample;
  uniform_sample = rand() / (double)2147483647;
  if(bstreap->root == ((void *)0))
    return ((void *)0);
  sampled_item = bstreap_item_sample(bstreap, bstreap->root, ((void *)0), 0., uniform_sample);
  sampled_node = sampled_item->node;
  bstreap->total_mass -= sampled_item->node_mass;
  free(sampled_item);
  return sampled_node;
}

variable_types: struct bstreap { double total_mass; struct bstreap_item { struct node *node; struct bstreap_item *left; struct bstreap_item *right; double node_mass; double subtree_mass; unsigned long priority; } *root; } *

variable_types: struct node { unsigned long id; unsigned long in_degree; unsigned long out_degree; double lambda; double mu; struct node_list { struct node *node; struct node_list *next; } *adjacency_list; } *


padding

decompiled_code:
int __fastcall padding(char a1, int a2)
{
int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = putchar(a1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func13(char a1, int a2)
{
int i; // ebx
int result; // eax

if ( a2 > 0 )
{
for ( i = 0; i != a2; ++i )
result = putchar(a1);
}
return result;
}

original_code:
void
padding(char ch, int n) {
  int i;
  for(i=0; i<n; i++)
    putchar(ch);
}

variable_types: ch char

variable_types: n int

variable_types: i int


decompiled_code:
int __fastcall print_bstreap_item(__int64 a1, unsigned int a2)
{
__int64 i; // rbx
int v4; // er12

for ( i = a1; i; i = *(_QWORD *)(i + 8) )
{
v4 = a2++;
print_bstreap_item(*(_QWORD *)(i + 16), a2);
padding(9, v4);
printf("%llu\n", **(_QWORD **)i);
}
padding(9, a2);
return puts("~");
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, unsigned int a2)
{
__int64 i; // rbx
int v4; // er12

for ( i = a1; i; i = *(_QWORD *)(i + 8) )
{
v4 = a2++;
func14(*(_QWORD *)(i + 16), a2);
func13(9, v4);
printf("%llu\n", **(_QWORD **)i);
}
func13(9, a2);
return puts("~");
}

original_code:
void
print_bstreap_item(bstreap_item_t *item, int level) {
  if(item == ((void *)0)) {
    padding('\t', level);
    puts("~");
  }
  else {
    print_bstreap_item(item->right, level + 1);
    padding('\t', level);
    printf("%llu\n", item->node->id);
    print_bstreap_item(item->left, level + 1);
  }
}

canonical_original_code:
void print_bstreap_item(struct bstreap_item *item, int level) {
  if(item == ((void *)0)) {
    padding('\t', level);
    puts("~");
  }
  else {
    print_bstreap_item(item->right, level + 1);
    padding('\t', level);
    printf("%llu\n", item->node->id);
    print_bstreap_item(item->left, level + 1);
  }
}

variable_types: level int


decompiled_code:
int __fastcall print_bstreap(__int64 a1)
{
return print_bstreap_item(*(_QWORD *)(a1 + 8), 0);
}

canonical_decompiled_code:
int __fastcall func15(__int64 a1)
{
return func14(*(_QWORD *)(a1 + 8), 0);
}

original_code:
void
print_bstreap(bstreap_t *bstreap) {
  print_bstreap_item(bstreap->root, 0);
}

canonical_original_code:
void print_bstreap(struct bstreap *bstreap) {
  print_bstreap_item(bstreap->root, 0);
}


decompiled_code:
void __fastcall bstreap_item_free(_QWORD *a1)
{
if ( a1[1] )
bstreap_item_free();
if ( a1[2] )
bstreap_item_free();
free(a1);
}

canonical_decompiled_code:
void __fastcall func16(_QWORD *a1)
{
if ( a1[1] )
func16();
if ( a1[2] )
func16();
free(a1);
}

original_code:
void
bstreap_item_free(bstreap_item_t *item) {
  if(item->left != ((void *)0))
    bstreap_item_free(item->left);
  if(item->right != ((void *)0))
    bstreap_item_free(item->right);
  free(item);
}

canonical_original_code:
void bstreap_item_free(struct bstreap_item *item) {
  if(item->left != ((void *)0))
    bstreap_item_free(item->left);
  if(item->right != ((void *)0))
    bstreap_item_free(item->right);
  free(item);
}


decompiled_code:
void __fastcall bstreap_free(void *ptr)
{
_QWORD *v2; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
bstreap_item_free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
_QWORD *v2; // rdi

v2 = (_QWORD *)*((_QWORD *)ptr + 1);
if ( v2 )
func16(v2);
free(ptr);
}

original_code:
void
bstreap_free(bstreap_t *bstreap) {
  if (bstreap->root != ((void *)0))
    bstreap_item_free(bstreap->root);
  free(bstreap);
}

canonical_original_code:
void bstreap_free(struct bstreap *bstreap) {
  if (bstreap->root != ((void *)0))
    bstreap_item_free(bstreap->root);
  free(bstreap);
}


decompiled_code:
__int64 __fastcall bstreap_in_degree_insert_lnu(__int64 a1, __int64 a2)
{
return bstreap_insert(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_in_degree,
(__int64 (__fastcall *)(double *))random_priority,
get_node_mass);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, __int64 a2)
{
return func9(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_in_degree,
(__int64 (__fastcall *)(double *))random_priority,
get_node_mass);
}

original_code:
void
bstreap_in_degree_insert_lnu(bstreap_t *bstreap, node_t* node) {
  bstreap_insert(bstreap, node, get_linear_in_degree, random_priority, get_node_mass);
}

canonical_original_code:
void bstreap_in_degree_insert_lnu(struct bstreap *bstreap, struct node *node) {
  bstreap_insert(bstreap, node, get_linear_in_degree, random_priority, get_node_mass);
}


decompiled_code:
__int64 __fastcall bstreap_out_degree_insert_lnu(__int64 a1, __int64 a2)
{
return bstreap_insert(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_out_degree,
(__int64 (__fastcall *)(double *))random_priority,
get_node_mass);
}

canonical_decompiled_code:
__int64 __fastcall func23(__int64 a1, __int64 a2)
{
return func9(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_out_degree,
(__int64 (__fastcall *)(double *))random_priority,
get_node_mass);
}

original_code:
void
bstreap_out_degree_insert_lnu(bstreap_t *bstreap, node_t* node) {
  bstreap_insert(bstreap, node, get_linear_out_degree, random_priority, get_node_mass);
}

canonical_original_code:
void bstreap_out_degree_insert_lnu(struct bstreap *bstreap, struct node *node) {
  bstreap_insert(bstreap, node, get_linear_out_degree, random_priority, get_node_mass);
}


decompiled_code:
__int64 __fastcall bstreap_in_degree_insert_lnn(__int64 a1, __int64 a2)
{
return bstreap_insert(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_in_degree,
(__int64 (__fastcall *)(double *))node_mass_priority,
get_node_mass);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, __int64 a2)
{
return func9(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_in_degree,
(__int64 (__fastcall *)(double *))node_mass_priority,
get_node_mass);
}

original_code:
void
bstreap_in_degree_insert_lnn(bstreap_t *bstreap, node_t* node) {
  bstreap_insert(bstreap, node, get_linear_in_degree, node_mass_priority, get_node_mass);
}

canonical_original_code:
void bstreap_in_degree_insert_lnn(struct bstreap *bstreap, struct node *node) {
  bstreap_insert(bstreap, node, get_linear_in_degree, node_mass_priority, get_node_mass);
}


decompiled_code:
__int64 __fastcall bstreap_out_degree_insert_lnn(__int64 a1, __int64 a2)
{
return bstreap_insert(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_out_degree,
(__int64 (__fastcall *)(double *))node_mass_priority,
get_node_mass);
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1, __int64 a2)
{
return func9(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_out_degree,
(__int64 (__fastcall *)(double *))node_mass_priority,
get_node_mass);
}

original_code:
void
bstreap_out_degree_insert_lnn(bstreap_t *bstreap, node_t* node) {
  bstreap_insert(bstreap, node, get_linear_out_degree, node_mass_priority, get_node_mass);
}

canonical_original_code:
void bstreap_out_degree_insert_lnn(struct bstreap *bstreap, struct node *node) {
  bstreap_insert(bstreap, node, get_linear_out_degree, node_mass_priority, get_node_mass);
}


decompiled_code:
__int64 __fastcall bstreap_in_degree_insert_lsu(__int64 a1, __int64 a2)
{
return bstreap_insert(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_in_degree,
(__int64 (__fastcall *)(double *))random_priority,
get_subtree_mass);
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1, __int64 a2)
{
return func9(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_in_degree,
(__int64 (__fastcall *)(double *))random_priority,
get_subtree_mass);
}

original_code:
void
bstreap_in_degree_insert_lsu(bstreap_t *bstreap, node_t* node) {
  bstreap_insert(bstreap, node, get_linear_in_degree, random_priority, get_subtree_mass);
}

canonical_original_code:
void bstreap_in_degree_insert_lsu(struct bstreap *bstreap, struct node *node) {
  bstreap_insert(bstreap, node, get_linear_in_degree, random_priority, get_subtree_mass);
}


decompiled_code:
__int64 __fastcall bstreap_out_degree_insert_lsu(__int64 a1, __int64 a2)
{
return bstreap_insert(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_out_degree,
(__int64 (__fastcall *)(double *))random_priority,
get_subtree_mass);
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1, __int64 a2)
{
return func9(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_out_degree,
(__int64 (__fastcall *)(double *))random_priority,
get_subtree_mass);
}

original_code:
void
bstreap_out_degree_insert_lsu(bstreap_t *bstreap, node_t* node) {
  bstreap_insert(bstreap, node, get_linear_out_degree, random_priority, get_subtree_mass);
}

canonical_original_code:
void bstreap_out_degree_insert_lsu(struct bstreap *bstreap, struct node *node) {
  bstreap_insert(bstreap, node, get_linear_out_degree, random_priority, get_subtree_mass);
}


decompiled_code:
__int64 __fastcall bstreap_in_degree_insert_lsn(__int64 a1, __int64 a2)
{
return bstreap_insert(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_in_degree,
(__int64 (__fastcall *)(double *))node_mass_priority,
get_subtree_mass);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1, __int64 a2)
{
return func9(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_in_degree,
(__int64 (__fastcall *)(double *))node_mass_priority,
get_subtree_mass);
}

original_code:
void
bstreap_in_degree_insert_lsn(bstreap_t *bstreap, node_t* node) {
  bstreap_insert(bstreap, node, get_linear_in_degree, node_mass_priority, get_subtree_mass);
}

canonical_original_code:
void bstreap_in_degree_insert_lsn(struct bstreap *bstreap, struct node *node) {
  bstreap_insert(bstreap, node, get_linear_in_degree, node_mass_priority, get_subtree_mass);
}


decompiled_code:
__int64 __fastcall bstreap_out_degree_insert_lsn(__int64 a1, __int64 a2)
{
return bstreap_insert(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_out_degree,
(__int64 (__fastcall *)(double *))node_mass_priority,
get_subtree_mass);
}

canonical_decompiled_code:
__int64 __fastcall func29(__int64 a1, __int64 a2)
{
return func9(
a1,
a2,
(double (__fastcall *)(__int64))&get_linear_out_degree,
(__int64 (__fastcall *)(double *))node_mass_priority,
get_subtree_mass);
}

original_code:
void
bstreap_out_degree_insert_lsn(bstreap_t *bstreap, node_t* node) {
  bstreap_insert(bstreap, node, get_linear_out_degree, node_mass_priority, get_subtree_mass);
}

canonical_original_code:
void bstreap_out_degree_insert_lsn(struct bstreap *bstreap, struct node *node) {
  bstreap_insert(bstreap, node, get_linear_out_degree, node_mass_priority, get_subtree_mass);
}


decompiled_code:
size_t __fastcall bstreap_item_insert_xnz(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return bstreap_item_insert(a1, a2, a3, a4, get_node_mass);
}

canonical_decompiled_code:
size_t __fastcall func30(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return func8(a1, a2, a3, a4, get_node_mass);
}

original_code:
void bstreap_item_insert_xnz(bstreap_t *bstreap,
                             bstreap_item_t *item,
                             bstreap_item_t *existing_item,
                             bstreap_item_t *parent) {
  bstreap_item_insert(bstreap, item, existing_item, parent, get_node_mass);
}

canonical_original_code:
void bstreap_item_insert_xnz(struct bstreap *bstreap, struct bstreap_item *item, struct bstreap_item *existing_item, struct bstreap_item *parent) {
  bstreap_item_insert(bstreap, item, existing_item, parent, get_node_mass);
}


mean

decompiled_code:
double __fastcall mean(double *a1, __int64 a2)
{
double *v2; // rax
double v3; // xmm0_8

if ( !a2 )
return 0.0 / (double)0;
v2 = &a1[a2];
v3 = 0.0;
do
v3 = v3 + *a1++;
while ( a1 != v2 );
return v3 / (double)(int)a2;
}

canonical_decompiled_code:
double __fastcall func0(double *a1, __int64 a2)
{
double *v2; // rax
double v3; // xmm0_8

if ( !a2 )
return 0.0 / (double)0;
v2 = &a1[a2];
v3 = 0.0;
do
v3 = v3 + *a1++;
while ( a1 != v2 );
return v3 / (double)(int)a2;
}

original_code:
double
mean(double *a, uint64_t n) {
  uint64_t i;
  double total = 0;
  for(i=0;i<n;i++)
    total += a[i];
  return total / (double) n;
}

canonical_original_code:
double mean(double *a, unsigned long n) {
  unsigned long i;
  double total = 0;
  for(i=0;i<n;i++)
    total += a[i];
  return total / (double) n;
}

variable_types:
a
double *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

variable_types: total double


stdev

original_code:
double
stdev(double *a, uint64_t n) {
  uint64_t i;
  double residual;
  double sum_squared_residuals = 0.;
  double mu;
  mu = mean(a,n);
  for(i=0;i<n;i++) {
    residual = a[i] - mu;
    sum_squared_residuals += residual * residual;
  }
  return sqrt(sum_squared_residuals / ((double) (n - 1)));
}

canonical_original_code:
double stdev(double *a, unsigned long n) {
  unsigned long i;
  double residual;
  double sum_squared_residuals = 0.;
  double mu;
  mu = mean(a,n);
  for(i=0;i<n;i++) {
    residual = a[i] - mu;
    sum_squared_residuals += residual * residual;
  }
  return sqrt(sum_squared_residuals / ((double) (n - 1)));
}

variable_types: residual double

variable_types: mu double


randn

decompiled_code:
double __fastcall randn(double a1, double a2)
{
int v2; // ebx
double v3; // xmm0_8
double v5; // [rsp+0h] [rbp-20h]

v2 = 12;
v5 = 0.0;
do
{
v3 = (double)rand() / 2147483647.0 + v5;
v5 = v3;
--v2;
}
while ( v2 );
return (v3 - 6.0) * a2 + a1;
}

canonical_decompiled_code:
double __fastcall func2(double a1, double a2)
{
int v2; // ebx
double v3; // xmm0_8
double v5; // [rsp+0h] [rbp-20h]

v2 = 12;
v5 = 0.0;
do
{
v3 = (double)rand() / 2147483647.0 + v5;
v5 = v3;
--v2;
}
while ( v2 );
return (v3 - 6.0) * a2 + a1;
}

original_code:
double
randn(double mu, double sigma) {
  int i;
  double sum_uniform_samples = 0.;
  double standard_normal_sample;
  double transformed_normal_sample;
  for(i=0;i<12;i++)
    sum_uniform_samples += (rand() / (double)2147483647);
  standard_normal_sample = sum_uniform_samples - 6.;
  transformed_normal_sample = mu + sigma * standard_normal_sample;
  return transformed_normal_sample;
}

variable_types: sigma double


decompiled_code:
double __fastcall sample_fitness_pareto_in(double a1)
{
int v1; // eax

v1 = rand();
return (a1 - 1.0) / pow((double)v1 / 2147483647.0, 1.0 / a1);
}

canonical_decompiled_code:
double __fastcall func4(double a1)
{
int v1; // eax

v1 = rand();
return (a1 - 1.0) / pow((double)v1 / 2147483647.0, 1.0 / a1);
}

original_code:
double
sample_fitness_pareto_in(double lambda, double p) {
  double xm;
  xm = (lambda - 1.);
  return xm / pow((((double) rand()) / 2147483647),1./lambda);
}

variable_types: lambda double

variable_types: p double

variable_types: xm double


decompiled_code:
// attributes: thunk
double __fastcall sample_fitness_pareto_out(double a1)
{
return sample_fitness_pareto_in(a1);
}

canonical_decompiled_code:
double __fastcall func5(double a1)
{
return func4(a1);
}

original_code:
double
sample_fitness_pareto_out(double mu, double p) {
  double xm;
  xm = (mu - 1.);
  return xm / pow((((double) rand()) / 2147483647),1./mu);
}


decompiled_code:
double __fastcall sample_fitness_normal_in(double a1)
{
return fmax(0.0, randn(a1, 0.25 * a1));
}

canonical_decompiled_code:
double __fastcall func6(double a1)
{
return fmax(0.0, randn(a1, 0.25 * a1));
}

original_code:
double
sample_fitness_normal_in(double lambda, double p) {
  double sampled_fitness;
  sampled_fitness = randn(lambda, lambda/4.);
  if(sampled_fitness < 0.)
    sampled_fitness = 0.;
  return sampled_fitness;
}


decompiled_code:
// attributes: thunk
double __fastcall sample_fitness_normal_out(double a1)
{
return sample_fitness_normal_in(a1);
}

canonical_decompiled_code:
double __fastcall func7(double a1)
{
return func6(a1);
}

original_code:
double
sample_fitness_normal_out(double mu, double p) {
  double sampled_fitness;
  sampled_fitness = randn(mu, mu/4.);
  if(sampled_fitness < 0.)
    sampled_fitness = 0.;
  return sampled_fitness;
}


identity

decompiled_code:
void identity()
{
;
}

canonical_decompiled_code:
void func8()
{
;
}

original_code:
double
identity(double x, double p) {
  return x;
}

variable_types: x double


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

result = (double *)malloc(0x30uLL);
if ( result )
{
*(_QWORD *)result = a1;
result[1] = 0.0;
result[2] = 0.0;
result[3] = a2;
result[4] = a3;
result[5] = 0.0;
}
return result;
}

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

result = (double *)malloc(0x30uLL);
if ( result )
{
*(_QWORD *)result = a1;
result[1] = 0.0;
result[2] = 0.0;
result[3] = a2;
result[4] = a3;
result[5] = 0.0;
}
return result;
}

original_code:
node_t *
make_node(uint64_t id, double lambda, double mu) {
  node_t *n = (node_t*) malloc(sizeof(*n));
  if (!n) return 0;
  n->id = id;
  n->in_degree = 0;
  n->out_degree = 0;
  n->lambda = lambda;
  n->mu = mu;
  n->adjacency_list = ((void *)0);
  return n;
}

canonical_original_code:
struct node *make_node(unsigned long id, double lambda, double mu) {
  struct node *n = (node_t*) malloc(sizeof(*n));
  if (!n) return 0;
  n->id = id;
  n->in_degree = 0;
  n->out_degree = 0;
  n->lambda = lambda;
  n->mu = mu;
  n->adjacency_list = ((void *)0);
  return n;
}

variable_types:
id
unsigned long

return_type: struct node { unsigned long id; unsigned long in_degree; unsigned long out_degree; double lambda; double mu; struct node_list { struct node *node; struct node_list *next; } *adjacency_list; } *


decompiled_code:
double __fastcall get_in_degree(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 8);
if ( v1 < 0 )
result = (double)(int)(*(_DWORD *)(a1 + 8) & 1 | (*(_QWORD *)(a1 + 8) >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 8) & 1 | (*(_QWORD *)(a1 + 8) >> 1));
else
result = (double)(int)v1;
return result;
}

canonical_decompiled_code:
double __fastcall func1(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 8);
if ( v1 < 0 )
result = (double)(int)(*(_DWORD *)(a1 + 8) & 1 | (*(_QWORD *)(a1 + 8) >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 8) & 1 | (*(_QWORD *)(a1 + 8) >> 1));
else
result = (double)(int)v1;
return result;
}

original_code:
double get_in_degree(node_t *node) {
  return (double) node->in_degree;
}

canonical_original_code:
double get_in_degree(struct node *node) {
  return (double) node->in_degree;
}

variable_types: struct node { unsigned long id; unsigned long in_degree; unsigned long out_degree; double lambda; double mu; struct node_list { struct node *node; struct node_list *next; } *adjacency_list; } *


decompiled_code:
double __fastcall get_linear_in_degree(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 8);
if ( v1 < 0 )
result = (double)(int)(*(_DWORD *)(a1 + 8) & 1 | (*(_QWORD *)(a1 + 8) >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 8) & 1 | (*(_QWORD *)(a1 + 8) >> 1))
+ *(double *)(a1 + 24);
else
result = (double)(int)v1 + *(double *)(a1 + 24);
return result;
}

canonical_decompiled_code:
double __fastcall func2(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 8);
if ( v1 < 0 )
result = (double)(int)(*(_DWORD *)(a1 + 8) & 1 | (*(_QWORD *)(a1 + 8) >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 8) & 1 | (*(_QWORD *)(a1 + 8) >> 1))
+ *(double *)(a1 + 24);
else
result = (double)(int)v1 + *(double *)(a1 + 24);
return result;
}

original_code:
double get_linear_in_degree(node_t *node) {
  return (double) node->in_degree + node->lambda;
}

canonical_original_code:
double get_linear_in_degree(struct node *node) {
  return (double) node->in_degree + node->lambda;
}


decompiled_code:
double __fastcall get_quadratic_in_degree(__int64 a1)
{
__int64 v1; // rax
__int64 v3; // rdx

v1 = *(_QWORD *)(a1 + 8) * *(_QWORD *)(a1 + 8);
if ( v1 >= 0 )
return (double)(int)v1 + *(double *)(a1 + 24);
v3 = v1 & 1 | ((*(_QWORD *)(a1 + 8) * *(_QWORD *)(a1 + 8)) >> 1);
return (double)(int)v3 + (double)(int)v3 + *(double *)(a1 + 24);
}

original_code:
double get_quadratic_in_degree(node_t *node) {
  return (double) (node->in_degree * node->in_degree) + node->lambda;
}

canonical_original_code:
double get_quadratic_in_degree(struct node *node) {
  return (double) (node->in_degree * node->in_degree) + node->lambda;
}


decompiled_code:
double __fastcall get_out_degree(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 16);
if ( v1 < 0 )
result = (double)(int)(*(_DWORD *)(a1 + 16) & 1 | (*(_QWORD *)(a1 + 16) >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 16) & 1 | (*(_QWORD *)(a1 + 16) >> 1));
else
result = (double)(int)v1;
return result;
}

canonical_decompiled_code:
double __fastcall func4(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 16);
if ( v1 < 0 )
result = (double)(int)(*(_DWORD *)(a1 + 16) & 1 | (*(_QWORD *)(a1 + 16) >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 16) & 1 | (*(_QWORD *)(a1 + 16) >> 1));
else
result = (double)(int)v1;
return result;
}

original_code:
double get_out_degree(node_t *node) {
  return (double) node->out_degree;
}

canonical_original_code:
double get_out_degree(struct node *node) {
  return (double) node->out_degree;
}


decompiled_code:
double __fastcall get_linear_out_degree(__int64 a1)
{
__int64 v1; // rax
double result; // xmm0_8

v1 = *(_QWORD *)(a1 + 16);
if ( v1 < 0 )
result = (double)(int)(*(_DWORD *)(a1 + 16) & 1 | (*(_QWORD *)(a1 + 16) >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 16) & 1 | (*(_QWORD *)(a1 + 16) >> 1))
+ *(double *)(a1 + 32);
else
result = (double)(int)v1 + *(double *)(a1 + 32);
return result;
}

original_code:
double get_linear_out_degree(node_t *node) {
  return (double) node->out_degree + node->mu;
}

canonical_original_code:
double get_linear_out_degree(struct node *node) {
  return (double) node->out_degree + node->mu;
}


decompiled_code:
// attributes: thunk
double __fastcall get_quadratic_out_degree(__int64 a1)
{
return get_linear_out_degree(a1);
}

canonical_decompiled_code:
double __fastcall func6(__int64 a1)
{
return func5(a1);
}

original_code:
double get_quadratic_out_degree(node_t *node) {
  return (double) node->out_degree + node->mu;
}

canonical_original_code:
double get_quadratic_out_degree(struct node *node) {
  return (double) node->out_degree + node->mu;
}


decompiled_code:
void __fastcall node_free(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
node_list_free(v2);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
void *v2; // rdi

v2 = (void *)*((_QWORD *)ptr + 5);
if ( v2 )
func7(v2);
free(ptr);
}

original_code:
void node_free(node_t *node) {
  if(node->adjacency_list != ((void *)0))
    node_list_free(node->adjacency_list);
  free(node);
}

canonical_original_code:
void node_free(struct node *node) {
  if(node->adjacency_list != ((void *)0))
    node_list_free(node->adjacency_list);
  free(node);
}


freeNode

repo: jcchurch/C-Linear-Algebra

decompiled_code:
void __fastcall freeNode(void **a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}
}

original_code:
void freeNode(Node* pN){
   if( pN!=((void *)0) && *pN!=((void *)0) ){
      free(*pN);
      *pN = ((void *)0);
   }
}

canonical_original_code:
void freeNode(struct NodeObj **pN){
   if( pN!=((void *)0) && *pN!=((void *)0) ){
      free(*pN);
      *pN = ((void *)0);
   }
}

variable_types: struct NodeObj { void *data; struct NodeObj *next; struct NodeObj *prev; } **


newList

decompiled_code:
_QWORD *newList()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
if ( !result )
_assert_fail("L!=NULL", "List.c", 0x3Bu, "newList");
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0xFFFFFFFFLL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x20uLL);
if ( !result )
_assert_fail("L!=NULL", "List.c", 0x3Bu, "newList");
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0xFFFFFFFFLL;
return result;
}

original_code:
List newList(void){
 List L = malloc(sizeof(ListObj));
 ((L!=((void *)0)) ? (void) (0) : __assert_fail ("L!=NULL", "List.c", 59, __extension__ __PRETTY_FUNCTION__));
 L->front = ((void *)0);
 L->cursor = ((void *)0);
 L->back = ((void *)0);
 L->numItems = 0;
 L->cursorIndex = -1;
 return L;
}

canonical_original_code:
struct ListObj *newList(){
 struct ListObj *L = malloc(sizeof(ListObj));
 ((L!=((void *)0)) ? (void) (0) : __assert_fail ("L!=NULL", "List.c", 59, __extension__ __PRETTY_FUNCTION__));
 L->front = ((void *)0);
 L->cursor = ((void *)0);
 L->back = ((void *)0);
 L->numItems = 0;
 L->cursorIndex = -1;
 return L;
}

variable_types: struct ListObj { struct NodeObj { void *data; struct NodeObj *next; struct NodeObj *prev; } *front; struct NodeObj *cursor; struct NodeObj *back; int cursorIndex; int numItems; } *

user_defined_types: struct ListObj { struct NodeObj *front; struct NodeObj *cursor; struct NodeObj *back; int cursorIndex; int numItems; }


length

decompiled_code:
__int64 __fastcall length(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
return *(unsigned int *)(a1 + 28);
}

original_code:
int length(List L){
 return L->numItems;
}

canonical_original_code:
int length(struct ListObj *L){
 return L->numItems;
}

user_defined_types: struct NodeObj { void *data; struct NodeObj *next; struct NodeObj *prev; }


decompiled_code:
__int64 __fastcall list_index(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return *(unsigned int *)(a1 + 24);
}

original_code:
int list_index(List L){
 return L->cursorIndex;
}

canonical_original_code:
int list_index(struct ListObj *L){
 return L->cursorIndex;
}


front

decompiled_code:
__int64 __fastcall front(__int64 a1)
{
if ( (int)length(a1) <= 0 )
{
fwrite("List Error: calling front() on list length of 0\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( (int)func2(a1) <= 0 )
{
fwrite("List Error: calling front() on list length of 0\n", 1uLL, 0x30uLL, stderr);
exit(1);
}
return **(_QWORD **)a1;
}

original_code:
void* front(List L){
 if(length(L)<=0 ){
     fprintf(stderr,
            "List Error: calling front() on list length of 0\n");
     exit(1);
   }
   return L->front->data;
}

canonical_original_code:
void *front(struct ListObj *L){
 if(length(L)<=0 ){
     fprintf(stderr,
            "List Error: calling front() on list length of 0\n");
     exit(1);
   }
   return L->front->data;
}


back

decompiled_code:
__int64 __fastcall back(__int64 a1)
{
if ( (int)length(a1) <= 0 )
{
fwrite("List Error: calling back() on list length of 0\n", 1uLL, 0x2FuLL, stderr);
exit(1);
}
return **(_QWORD **)(a1 + 16);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( (int)func2(a1) <= 0 )
{
fwrite("List Error: calling back() on list length of 0\n", 1uLL, 0x2FuLL, stderr);
exit(1);
}
return **(_QWORD **)(a1 + 16);
}

original_code:
void* back(List L){
   if(length(L)<=0){
     fprintf(stderr,
         "List Error: calling back() on list length of 0\n");
     exit(1);
   }
   return L->back->data;
}

canonical_original_code:
void *back(struct ListObj *L){
   if(length(L)<=0){
     fprintf(stderr,
         "List Error: calling back() on list length of 0\n");
     exit(1);
   }
   return L->back->data;
}


get

decompiled_code:
__int64 __fastcall get(__int64 a1)
{
if ( (int)length(a1) <= 0 )
{
fwrite("List Error: calling get() on list length of 0\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
if ( (int)list_index(a1) < 0 )
{
fwrite("List Error: calling get() while there is no cursor present\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
return **(_QWORD **)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
if ( (int)func2(a1) <= 0 )
{
fwrite("List Error: calling get() on list length of 0\n", 1uLL, 0x2EuLL, stderr);
exit(1);
}
if ( (int)func3(a1) < 0 )
{
fwrite("List Error: calling get() while there is no cursor present\n", 1uLL, 0x3BuLL, stderr);
exit(1);
}
return **(_QWORD **)(a1 + 8);
}

original_code:
void* get(List L){
 if(length(L)<=0){
    fprintf(stderr,
     "List Error: calling get() on list length of 0\n");
    exit(1);
   }
    if(list_index(L)<0){
    fprintf(stderr,
     "List Error: calling get() while there is no cursor present\n");
    exit(1);
   }
 return L->cursor->data;
}

canonical_original_code:
void *get(struct ListObj *L){
 if(length(L)<=0){
    fprintf(stderr,
     "List Error: calling get() on list length of 0\n");
    exit(1);
   }
    if(list_index(L)<0){
    fprintf(stderr,
     "List Error: calling get() while there is no cursor present\n");
    exit(1);
   }
 return L->cursor->data;
}


clear

decompiled_code:
__int64 __fastcall clear(__int64 a1)
{
__int64 v2; // rax
__int64 i; // rdi
__int64 result; // rax

if ( (int)length(a1) > 0 )
{
v2 = *(_QWORD *)a1;
*(_QWORD *)(a1 + 8) = *(_QWORD *)a1;
for ( i = *(_QWORD *)(v2 + 8); i; i = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL) )
{
*(_QWORD *)(a1 + 8) = i;
freeNode((void **)(i + 16));
}
freeNode((void **)(a1 + 8));
}
result = 0xFFFFFFFFLL;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_QWORD *)(a1 + 24) = 0xFFFFFFFFLL;
return result;
}

original_code:
void clear(List L){
    if(length(L) > 0){
  L->cursor = L->front;
  while(L->cursor->next != ((void *)0)){
   L->cursor = L->cursor->next;
   freeNode(&L->cursor->prev);
  }
  freeNode(&L->cursor);
 }
 L->front = ((void *)0);
 L->back = ((void *)0);
 L->cursor = ((void *)0);
 L->numItems = 0;
 L->cursorIndex = -1;
}

canonical_original_code:
void clear(struct ListObj *L){
    if(length(L) > 0){
  L->cursor = L->front;
  while(L->cursor->next != ((void *)0)){
   L->cursor = L->cursor->next;
   freeNode(&L->cursor->prev);
  }
  freeNode(&L->cursor);
 }
 L->front = ((void *)0);
 L->back = ((void *)0);
 L->cursor = ((void *)0);
 L->numItems = 0;
 L->cursorIndex = -1;
}


freeList

decompiled_code:
void __fastcall freeList(void **a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
if ( (int)length((__int64)v2) > 0 )
{
clear((__int64)v2);
v2 = *a1;
}
free(v2);
*a1 = 0LL;
}
}
}

original_code:
void freeList(List* pL){
 if(pL!=((void *)0) && *pL!=((void *)0)){
  if(length(*pL) > 0){ clear(*pL); }
  free(*pL);
  *pL = ((void *)0);
 }
}

canonical_original_code:
void freeList(struct ListObj **pL){
 if(pL!=((void *)0) && *pL!=((void *)0)){
  if(length(*pL) > 0){ clear(*pL); }
  free(*pL);
  *pL = ((void *)0);
 }
}

variable_types: struct ListObj { struct NodeObj { void *data; struct NodeObj *next; struct NodeObj *prev; } *front; struct NodeObj *cursor; struct NodeObj *back; int cursorIndex; int numItems; } **


moveNext

decompiled_code:
__int64 __fastcall moveNext(__int64 a1)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8);
if ( result )
{
if ( result == *(_QWORD *)(a1 + 16) )
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 24) = -1;
}
else
{
result = *(_QWORD *)(result + 8);
++*(_DWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
__int64 result; // rax

result = *(_QWORD *)(a1 + 8);
if ( result )
{
if ( result == *(_QWORD *)(a1 + 16) )
{
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 24) = -1;
}
else
{
result = *(_QWORD *)(result + 8);
++*(_DWORD *)(a1 + 24);
*(_QWORD *)(a1 + 8) = result;
}
}
return result;
}

original_code:
void moveNext(List L){
 if(L->cursor != ((void *)0)){
  if(L->cursor != L->back){
   L->cursorIndex++;
   L->cursor = L->cursor->next;
  }
  else if(L->cursor == L->back){
   L->cursor = ((void *)0);
   L->cursorIndex = -1;
  }
 }
}

canonical_original_code:
void moveNext(struct ListObj *L){
 if(L->cursor != ((void *)0)){
  if(L->cursor != L->back){
   L->cursorIndex++;
   L->cursor = L->cursor->next;
  }
  else if(L->cursor == L->back){
   L->cursor = ((void *)0);
   L->cursorIndex = -1;
  }
 }
}


prepend

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

result = (unsigned __int64)newNode(a2);
v3 = *((_DWORD *)a1 + 7);
if ( v3 <= 0 )
{
*a1 = result;
a1[2] = result;
*((_DWORD *)a1 + 7) = v3 + 1;
}
else
{
v4 = *a1;
*(_QWORD *)(v4 + 16) = result;
*(_QWORD *)(result + 8) = v4;
*a1 = result;
result = *((unsigned int *)a1 + 6);
if ( (_DWORD)result != -1 )
{
result = (unsigned int)(result + 1);
*((_DWORD *)a1 + 6) = result;
}
*((_DWORD *)a1 + 7) = v3 + 1;
}
return result;
}

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

result = (unsigned __int64)newNode(a2);
v3 = *((_DWORD *)a1 + 7);
if ( v3 <= 0 )
{
*a1 = result;
a1[2] = result;
*((_DWORD *)a1 + 7) = v3 + 1;
}
else
{
v4 = *a1;
*(_QWORD *)(v4 + 16) = result;
*(_QWORD *)(result + 8) = v4;
*a1 = result;
result = *((unsigned int *)a1 + 6);
if ( (_DWORD)result != -1 )
{
result = (unsigned int)(result + 1);
*((_DWORD *)a1 + 6) = result;
}
*((_DWORD *)a1 + 7) = v3 + 1;
}
return result;
}

original_code:
void prepend(List L, void* data){
 Node newbie = newNode(data);
 if(L->numItems > 0){
  L->front->prev = newbie;
  newbie->next = L->front;
  L->front = newbie;
  if(L->cursorIndex != -1){
   L->cursorIndex++;
  }
 }
 else {
  L->front = newbie;
  L->back = newbie;
 }
 L->numItems++;
}

canonical_original_code:
void prepend(struct ListObj *L, void *data){
 struct NodeObj *newbie = newNode(data);
 if(L->numItems > 0){
  L->front->prev = newbie;
  newbie->next = L->front;
  L->front = newbie;
  if(L->cursorIndex != -1){
   L->cursorIndex++;
  }
 }
 else {
  L->front = newbie;
  L->back = newbie;
 }
 L->numItems++;
}

variable_types:
data
void *

variable_types: struct NodeObj { void *data; struct NodeObj *next; struct NodeObj *prev; } *


deleteFront

decompiled_code:
__int64 __fastcall deleteFront(__int64 a1)
{
__int64 v2; // rdi
__int64 result; // rax

if ( (int)length(a1) <= 0 )
{
fwrite("List Error: calling deleteFront() on list length of 0\n", 1uLL, 0x36uLL, stderr);
exit(1);
}
if ( *(_DWORD *)(a1 + 28) == 1 )
{
freeNode((void **)a1);
}
else
{
v2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = v2;
freeNode((void **)(v2 + 16));
}
result = 0xFFFFFFFFLL;
if ( *(_QWORD *)(a1 + 8) != *(_QWORD *)a1 )
result = (unsigned int)(*(_DWORD *)(a1 + 24) - 1);
--*(_DWORD *)(a1 + 28);
*(_DWORD *)(a1 + 24) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1)
{
__int64 v2; // rdi
__int64 result; // rax

if ( (int)func2(a1) <= 0 )
{
fwrite("List Error: calling deleteFront() on list length of 0\n", 1uLL, 0x36uLL, stderr);
exit(1);
}
if ( *(_DWORD *)(a1 + 28) == 1 )
{
func0((void **)a1);
}
else
{
v2 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = v2;
func0((void **)(v2 + 16));
}
result = 0xFFFFFFFFLL;
if ( *(_QWORD *)(a1 + 8) != *(_QWORD *)a1 )
result = (unsigned int)(*(_DWORD *)(a1 + 24) - 1);
--*(_DWORD *)(a1 + 28);
*(_DWORD *)(a1 + 24) = result;
return result;
}

original_code:
void deleteFront(List L){
 if(length(L) <= 0 ){
     fprintf(stderr,
         "List Error: calling deleteFront() on list length of 0\n");
     exit(1);
    }
    if(L->numItems == 1){
     freeNode(&L->front);
    }
    else{
     L->front = L->front->next;
     freeNode(&L->front->prev);
 }
    if(L->cursor == L->front){
     L->cursorIndex = -1;
    }
    else{
     L->cursorIndex--;
    }
    L->numItems--;
}

canonical_original_code:
void deleteFront(struct ListObj *L){
 if(length(L) <= 0 ){
     fprintf(stderr,
         "List Error: calling deleteFront() on list length of 0\n");
     exit(1);
    }
    if(L->numItems == 1){
     freeNode(&L->front);
    }
    else{
     L->front = L->front->next;
     freeNode(&L->front->prev);
 }
    if(L->cursor == L->front){
     L->cursorIndex = -1;
    }
    else{
     L->cursorIndex--;
    }
    L->numItems--;
}


deleteBack

original_code:
void deleteBack(List L){
 if(length(L) <= 0 ){
     fprintf(stderr,
         "List Error: calling deleteBack() on list length of 0\n");
     exit(1);
    }
    if(L->cursor == L->back){
     L->cursor = ((void *)0);
     L->cursorIndex = -1;
    }
    if(L->numItems > 1){
     L->back = L->back->prev;
  freeNode(&L->back->next);
    }
    else{
     freeNode(&L->back);
    }
    L->numItems--;
}

canonical_original_code:
void deleteBack(struct ListObj *L){
 if(length(L) <= 0 ){
     fprintf(stderr,
         "List Error: calling deleteBack() on list length of 0\n");
     exit(1);
    }
    if(L->cursor == L->back){
     L->cursor = ((void *)0);
     L->cursorIndex = -1;
    }
    if(L->numItems > 1){
     L->back = L->back->prev;
  freeNode(&L->back->next);
    }
    else{
     freeNode(&L->back);
    }
    L->numItems--;
}


delete

original_code:
void delete(List L){
 if(length(L) <= 0 ){
     fprintf(stderr,
         "List Error: calling delete() on list length of 0\n");
     exit(1);
    }
    if(L->numItems == 1){
     deleteFront(L);
    }
    else{
     if(L->cursor == L->front){
      deleteFront(L);
     }
     else if(L->cursor == L->back){
      deleteBack(L);
     }
     else{
      Node temp = L->cursor->prev;
      temp->next = L->cursor->next;
      Node situ = L->cursor->next;
      situ->prev = temp;
      freeNode(&L->cursor);
      L->numItems--;
     }
    }
    L->cursor = ((void *)0);
    L->cursorIndex = -1;
}

canonical_original_code:
void delete(struct ListObj *L){
 if(length(L) <= 0 ){
     fprintf(stderr,
         "List Error: calling delete() on list length of 0\n");
     exit(1);
    }
    if(L->numItems == 1){
     deleteFront(L);
    }
    else{
     if(L->cursor == L->front){
      deleteFront(L);
     }
     else if(L->cursor == L->back){
      deleteBack(L);
     }
     else{
      struct NodeObj *temp = L->cursor->prev;
      temp->next = L->cursor->next;
      struct NodeObj *situ = L->cursor->next;
      situ->prev = temp;
      freeNode(&L->cursor);
      L->numItems--;
     }
    }
    L->cursor = ((void *)0);
    L->cursorIndex = -1;
}


newEntry

decompiled_code:
double *__fastcall newEntry(int a1, double a2)
{
double *result; // rax

result = (double *)malloc(0x10uLL);
if ( !result )
_assert_fail("E!=NULL", "Matrix.c", 0x1Bu, "newEntry");
*(_DWORD *)result = a1;
result[1] = a2;
return result;
}

canonical_decompiled_code:
double *__fastcall func0(int a1, double a2)
{
double *result; // rax

result = (double *)malloc(0x10uLL);
if ( !result )
_assert_fail("E!=NULL", "Matrix.c", 0x1Bu, "newEntry");
*(_DWORD *)result = a1;
result[1] = a2;
return result;
}

original_code:
Entry newEntry(int c, double d) {
   Entry E = malloc(sizeof(EntryObj));
   ((E!=((void *)0)) ? (void) (0) : __assert_fail ("E!=NULL", "Matrix.c", 27, __extension__ __PRETTY_FUNCTION__));
   E->column = c;
   E->value = d;
   return(E);
}

canonical_original_code:
struct EntryObj *newEntry(int c, double d) {
   struct EntryObj *E = malloc(sizeof(EntryObj));
   ((E!=((void *)0)) ? (void) (0) : __assert_fail ("E!=NULL", "Matrix.c", 27, __extension__ __PRETTY_FUNCTION__));
   E->column = c;
   E->value = d;
   return(E);
}

variable_types: c int

variable_types: d double

variable_types: struct EntryObj { int column; double value; } *


freeEntry

decompiled_code:
void __fastcall freeEntry(void **a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
void *v2; // rdi

if ( a1 )
{
v2 = *a1;
if ( v2 )
{
free(v2);
*a1 = 0LL;
}
}
}

original_code:
void freeEntry(Entry* pE){
   if( pE!=((void *)0) && *pE!=((void *)0) ){
      free(*pE);
      *pE = ((void *)0);
   }
}

canonical_original_code:
void freeEntry(struct EntryObj **pE){
   if( pE!=((void *)0) && *pE!=((void *)0) ){
      free(*pE);
      *pE = ((void *)0);
   }
}

variable_types: struct EntryObj { int column; double value; } **


repo: jcranmer/libquantum

original_code:
int quda_quantum_hadamard_gate(int target, quantum_reg* qreg) {
  int states = qreg->num_states;
 int diff = 2*states - qreg->size;
 if(diff > 0) {
  if(quda_quantum_reg_enlarge(qreg,diff) == -1) return -1;
 }
 uint64_t mask = 1 << target;
 int i;
 for (i = 0; i < qreg->num_states; i++) {
  qreg->states[qreg->num_states+i].state = qreg->states[i].state ^ mask;
  qreg->states[i].amplitude = quda_complex_rmul(qreg->states[i].amplitude,
    0.707106781f);
  qreg->states[qreg->num_states+i].amplitude = qreg->states[i].amplitude;
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
  }
 }
 qreg->num_states = 2*states;
 quda_quantum_reg_coalesce(qreg);
 return 0;
}

canonical_original_code:
int quda_quantum_hadamard_gate(int target, struct quantum_reg *qreg) {
  int states = qreg->num_states;
 int diff = 2*states - qreg->size;
 if(diff > 0) {
  if(quda_quantum_reg_enlarge(qreg,diff) == -1) return -1;
 }
 unsigned long mask = 1 << target;
 int i;
 for (i = 0; i < qreg->num_states; i++) {
  qreg->states[qreg->num_states+i].state = qreg->states[i].state ^ mask;
  qreg->states[i].amplitude = quda_complex_rmul(qreg->states[i].amplitude,
    0.707106781f);
  qreg->states[qreg->num_states+i].amplitude = qreg->states[i].amplitude;
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
  }
 }
 qreg->num_states = 2*states;
 quda_quantum_reg_coalesce(qreg);
 return 0;
}

variable_types: target int

variable_types: struct quantum_reg { int qubits; int size; int scratch; int num_states; struct quantum_state_t { unsigned long state; struct complex_t { float real; float imag; } amplitude; } *states; } *

variable_types: states int

variable_types: diff int

variable_types:
mask
unsigned long

variable_types: i int

user_defined_types: struct quantum_reg { int qubits; int size; int scratch; int num_states; struct quantum_state_t *states; }

user_defined_types: struct quantum_state_t { unsigned long state; struct complex_t amplitude; }


original_code:
void quda_quantum_pauli_y_gate(int target, quantum_reg* qreg) {
 int i;
 uint64_t mask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  qreg->states[i].state = qreg->states[i].state ^ mask;
  qreg->states[i].amplitude = quda_complex_mul_i(qreg->states[i].amplitude);
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
  }
 }
}

canonical_original_code:
void quda_quantum_pauli_y_gate(int target, struct quantum_reg *qreg) {
 int i;
 unsigned long mask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  qreg->states[i].state = qreg->states[i].state ^ mask;
  qreg->states[i].amplitude = quda_complex_mul_i(qreg->states[i].amplitude);
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
  }
 }
}

user_defined_types: struct complex_t { float real; float imag; }


original_code:
void quda_quantum_pauli_z_gate(int target, quantum_reg* qreg) {
 int i;
 uint64_t mask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
  }
 }
}

canonical_original_code:
void quda_quantum_pauli_z_gate(int target, struct quantum_reg *qreg) {
 int i;
 unsigned long mask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
  }
 }
}


original_code:
void quda_quantum_phase_gate(int target, quantum_reg* qreg) {
 int i;
 uint64_t mask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_mul_i(qreg->states[i].amplitude);
  }
 }
}

canonical_original_code:
void quda_quantum_phase_gate(int target, struct quantum_reg *qreg) {
 int i;
 unsigned long mask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_mul_i(qreg->states[i].amplitude);
  }
 }
}


decompiled_code:
__int64 __fastcall quda_quantum_pi_over_8_gate(char a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rbx
double v5; // xmm0_8

result = *(unsigned int *)(a2 + 12);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
while ( 1 )
{
v4 = *(_QWORD *)(a2 + 16) + 16 * v3;
result = *(_QWORD *)v4 & (1 << a1);
if ( result )
break;
if ( *(_DWORD *)(a2 + 12) <= (int)++v3 )
return result;
}
++v3;
v5 = quda_complex_mul(*(double *)(v4 + 8), 0.0003207296242245382);
result = 0x3F3504F33F3504F3LL;
*(double *)(v4 + 8) = v5;
}
while ( *(_DWORD *)(a2 + 12) > (int)v3 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rbp
__int64 v4; // rbx
double v5; // xmm0_8

result = *(unsigned int *)(a2 + 12);
if ( (int)result > 0 )
{
v3 = 0LL;
do
{
while ( 1 )
{
v4 = *(_QWORD *)(a2 + 16) + 16 * v3;
result = *(_QWORD *)v4 & (1 << a1);
if ( result )
break;
if ( *(_DWORD *)(a2 + 12) <= (int)++v3 )
return result;
}
++v3;
v5 = quda_complex_mul(*(double *)(v4 + 8), 0.0003207296242245382);
result = 0x3F3504F33F3504F3LL;
*(double *)(v4 + 8) = v5;
}
while ( *(_DWORD *)(a2 + 12) > (int)v3 );
}
return result;
}

original_code:
void quda_quantum_pi_over_8_gate(int target, quantum_reg* qreg) {
 complex_t c = { .real = 0.707106781f, .imag = 0.707106781f };
 int i;
 uint64_t mask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_mul(qreg->states[i].amplitude,c);
  }
 }
}

canonical_original_code:
void quda_quantum_pi_over_8_gate(int target, struct quantum_reg *qreg) {
 struct complex_t c = { .real = 0.707106781f, .imag = 0.707106781f };
 int i;
 unsigned long mask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_mul(qreg->states[i].amplitude,c);
  }
 }
}

variable_types: struct complex_t { float real; float imag; }


decompiled_code:
void __fastcall quda_quantum_rotate_k_gate(char a1, __int64 a2, char a3)
{
__m128i v3; // xmm2
__m128i v4; // xmm0
unsigned __int64 v5; // rdx
double v6; // xmm1_8
__int64 v7; // rbp
__int64 v8; // rbx
double cosx; // [rsp+8h] [rbp-38h] BYREF
double sinx[6]; // [rsp+10h] [rbp-30h] BYREF

sincos((float)(3.1415927 / (float)(1 << (a3 - 1))), sinx, &cosx);
v3 = 0LL;
v4 = 0LL;
*(float *)v3.m128i_i32 = sinx[0];
*(float *)v4.m128i_i32 = cosx;
v5 = ((unsigned __int64)(unsigned int)_mm_cvtsi128_si32(v3) << 32) | (unsigned int)_mm_cvtsi128_si32(v4);
if ( *(int *)(a2 + 12) > 0 )
{
v6 = *(double *)&v5;
v7 = 0LL;
do
{
while ( 1 )
{
v8 = *(_QWORD *)(a2 + 16) + 16 * v7;
if ( (*(_QWORD *)v8 & (1 << a1)) != 0LL )
break;
if ( *(_DWORD *)(a2 + 12) <= (int)++v7 )
return;
}
++v7;
*(double *)(v8 + 8) = quda_complex_mul(*(double *)(v8 + 8), v6);
}
while ( *(_DWORD *)(a2 + 12) > (int)v7 );
}
}

original_code:
void quda_quantum_rotate_k_gate(int target, quantum_reg* qreg, int k) {
 float temp = 3.141592654f / (1 << (k-1));
 complex_t c = { .real = cos(temp), .imag = sin(temp) };
 uint64_t mask = 1 << target;
 int i;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_mul(qreg->states[i].amplitude,c);
  }
 }
}

canonical_original_code:
void quda_quantum_rotate_k_gate(int target, struct quantum_reg *qreg, int k) {
 float temp = 3.141592654f / (1 << (k-1));
 struct complex_t c = { .real = cos(temp), .imag = sin(temp) };
 unsigned long mask = 1 << target;
 int i;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & mask) {
   qreg->states[i].amplitude = quda_complex_mul(qreg->states[i].amplitude,c);
  }
 }
}

variable_types: k int

variable_types: temp float


original_code:
void quda_quantum_controlled_y_gate(int control,int target, quantum_reg* qreg) {
 int i;
 uint64_t cmask = 1 << control;
 uint64_t tmask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & cmask) {
   qreg->states[i].state = qreg->states[i].state ^ tmask;
   qreg->states[i].amplitude = quda_complex_mul_i(qreg->states[i].amplitude);
   if(qreg->states[i].state & tmask) {
    qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
   }
  }
 }
}

canonical_original_code:
void quda_quantum_controlled_y_gate(int control, int target, struct quantum_reg *qreg) {
 int i;
 unsigned long cmask = 1 << control;
 unsigned long tmask = 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if(qreg->states[i].state & cmask) {
   qreg->states[i].state = qreg->states[i].state ^ tmask;
   qreg->states[i].amplitude = quda_complex_mul_i(qreg->states[i].amplitude);
   if(qreg->states[i].state & tmask) {
    qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
   }
  }
 }
}

variable_types: control int

variable_types:
cmask
unsigned long

variable_types:
tmask
unsigned long


original_code:
void quda_quantum_controlled_z_gate(int control, int target, quantum_reg* qreg) {
 int i;
 uint64_t mask = 1 << control;
 mask |= 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if((qreg->states[i].state & mask) == mask) {
   qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
  }
 }
}

canonical_original_code:
void quda_quantum_controlled_z_gate(int control, int target, struct quantum_reg *qreg) {
 int i;
 unsigned long mask = 1 << control;
 mask |= 1 << target;
 for (i = 0; i < qreg->num_states; i++) {
  if((qreg->states[i].state & mask) == mask) {
   qreg->states[i].amplitude = quda_complex_neg(qreg->states[i].amplitude);
  }
 }
}


original_code:
void quda_quantum_controlled_phase_gate(int control, int target, quantum_reg* qreg) {
 uint64_t mask = 1 << control;
 mask |= 1 << target;
 int i;
 for (i = 0; i < qreg->num_states; i++) {
  if((qreg->states[i].state & mask) == mask) {
   qreg->states[i].amplitude = quda_complex_mul_i(qreg->states[i].amplitude);
  }
 }
}

canonical_original_code:
void quda_quantum_controlled_phase_gate(int control, int target, struct quantum_reg *qreg) {
 unsigned long mask = 1 << control;
 mask |= 1 << target;
 int i;
 for (i = 0; i < qreg->num_states; i++) {
  if((qreg->states[i].state & mask) == mask) {
   qreg->states[i].amplitude = quda_complex_mul_i(qreg->states[i].amplitude);
  }
 }
}


original_code:
void quda_quantum_controlled_rotate_k_gate(int control, int target, quantum_reg* qreg, int k) {
 float temp = 3.141592654f / (1 << (k-1));
 complex_t c = { .real = cos(temp), .imag = sin(temp) };
 uint64_t mask = 1 << control;
 mask |= 1 << target;
 int i;
 for (i = 0; i < qreg->num_states; i++) {
  if((qreg->states[i].state & mask) == mask) {
   qreg->states[i].amplitude = quda_complex_mul(qreg->states[i].amplitude,c);
  }
 }
}

canonical_original_code:
void quda_quantum_controlled_rotate_k_gate(int control, int target, struct quantum_reg *qreg, int k) {
 float temp = 3.141592654f / (1 << (k-1));
 struct complex_t c = { .real = cos(temp), .imag = sin(temp) };
 unsigned long mask = 1 << control;
 mask |= 1 << target;
 int i;
 for (i = 0; i < qreg->num_states; i++) {
  if((qreg->states[i].state & mask) == mask) {
   qreg->states[i].amplitude = quda_complex_mul(qreg->states[i].amplitude,c);
  }
 }
}


original_code:
int quda_check_normalization(quantum_reg* qreg) {
 int i;
 float p = 0.0;
 for(i=0;i<qreg->num_states;i++) {
  p += quda_complex_abs_square(qreg->states[i].amplitude);
 }
 if(qreg->num_states > 0 && (p < 1.0 - 1e-7 || p > 1.0)) {
  return -1;
 } else {
  printf("NORM OK, P = %f\n",p);
 }
 return 0;
}

canonical_original_code:
int quda_check_normalization(struct quantum_reg *qreg) {
 int i;
 float p = 0.0;
 for(i=0;i<qreg->num_states;i++) {
  p += quda_complex_abs_square(qreg->states[i].amplitude);
 }
 if(qreg->num_states > 0 && (p < 1.0 - 1e-7 || p > 1.0)) {
  return -1;
 } else {
  printf("NORM OK, P = %f\n",p);
 }
 return 0;
}

variable_types: p float