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

repo: jcarrano/rtfi

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

variable_types: flags int

return_type: int


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

return_type: void


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+Ch] [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+Ch] [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
__int64 v5; // [rsp+0h] [rbp-38h] BYREF
char *s; // [rsp+8h] [rbp-30h] BYREF
time_t timer; // [rsp+18h] [rbp-20h] BYREF

v5 = 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, &v5, 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
__int64 v5; // [rsp+0h] [rbp-38h] BYREF
char *s; // [rsp+8h] [rbp-30h] BYREF
time_t timer; // [rsp+18h] [rbp-20h] BYREF

v5 = 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, &v5, 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(char **a1, size_t *a2, const char *a3, const struct tm *a4)
{
size_t v7; // rax
size_t v8; // rbx
char *v9; // rdi
size_t v10; // rbx

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

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

v7 = strftime(0LL, 0xFFFFFFFFFFFFFFFFLL, a3, a4);
v8 = v7;
v9 = *a1;
if ( !v9 || *a2 < v7 + 1 )
{
free(v9);
v10 = v8 + 1;
*a1 = (char *)func7(v10);
*a2 = v10;
}
return strftime(*a1, *a2, 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)(*(double *)(a1 + 24) - 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)(*(double *)(a1 + 24) - 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)
{
double v3; // xmm0_8
size_t result; // rax
double v5; // xmm0_8
__int64 v6; // rcx

v3 = *(double *)(a2 + 32);
result = *(_QWORD *)(a2 + 16);
*(double *)(result + 32) = v3;
*(_QWORD *)(a2 + 16) = *(_QWORD *)(result + 8);
v5 = v3 - *(double *)(result + 24);
*(double *)(a2 + 32) = v5;
v6 = *(_QWORD *)(result + 16);
if ( v6 )
*(double *)(a2 + 32) = v5 - *(double *)(v6 + 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)
{
double v3; // xmm0_8
size_t result; // rax
double v5; // xmm0_8
__int64 v6; // rcx

v3 = *(double *)(a2 + 32);
result = *(_QWORD *)(a2 + 16);
*(double *)(result + 32) = v3;
*(_QWORD *)(a2 + 16) = *(_QWORD *)(result + 8);
v5 = v3 - *(double *)(result + 24);
*(double *)(a2 + 32) = v5;
v6 = *(_QWORD *)(result + 16);
if ( v6 )
*(double *)(a2 + 32) = v5 - *(double *)(v6 + 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)
{
double v3; // xmm0_8
size_t result; // rax
double v5; // xmm0_8
__int64 v6; // rcx

v3 = *(double *)(a2 + 32);
result = *(_QWORD *)(a2 + 8);
*(double *)(result + 32) = v3;
*(_QWORD *)(a2 + 8) = *(_QWORD *)(result + 16);
v5 = v3 - *(double *)(result + 24);
*(double *)(a2 + 32) = v5;
v6 = *(_QWORD *)(result + 8);
if ( v6 )
*(double *)(a2 + 32) = v5 - *(double *)(v6 + 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)
{
double v3; // xmm0_8
size_t result; // rax
double v5; // xmm0_8
__int64 v6; // rcx

v3 = *(double *)(a2 + 32);
result = *(_QWORD *)(a2 + 8);
*(double *)(result + 32) = v3;
*(_QWORD *)(a2 + 8) = *(_QWORD *)(result + 16);
v5 = v3 - *(double *)(result + 24);
*(double *)(a2 + 32) = v5;
v6 = *(_QWORD *)(result + 8);
if ( v6 )
*(double *)(a2 + 32) = v5 - *(double *)(v6 + 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))
{
double v8; // r15
__int64 v9; // rdx
size_t result; // rax
__int64 v11; // rdx

*(double *)(a3 + 32) = *(double *)(a3 + 32) + *(double *)(a2 + 24);
v8 = a5(a2);
if ( a5(a3) < v8 )
{
v11 = *(_QWORD *)(a3 + 16);
if ( v11 )
bstreap_item_insert(a1, a2, v11, a3, a5);
else
*(_QWORD *)(a3 + 16) = a2;
result = *(_QWORD *)(a3 + 16);
if ( *(_QWORD *)(result + 40) > *(_QWORD *)(a3 + 40) )
result = bstreap_rotate_left(a1, a3, a4);
}
else
{
v9 = *(_QWORD *)(a3 + 8);
if ( v9 )
bstreap_item_insert(a1, a2, v9, a3, a5);
else
*(_QWORD *)(a3 + 8) = a2;
result = *(_QWORD *)(a3 + 8);
if ( *(_QWORD *)(result + 40) > *(_QWORD *)(a3 + 40) )
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; // rbp
__int64 v8; // rdx

result = (__int64)make_bstreap_item(a2, a3, a4);
v7 = result;
v8 = *(_QWORD *)(a1 + 8);
if ( v8 )
result = bstreap_item_insert(a1, result, v8, 0LL, a5);
else
*(_QWORD *)(a1 + 8) = result;
*(double *)a1 = *(double *)a1 + *(double *)(v7 + 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; // rbp
__int64 v8; // rdx

result = (__int64)func5(a2, a3, a4);
v7 = result;
v8 = *(_QWORD *)(a1 + 8);
if ( v8 )
result = func8(a1, result, v8, 0LL, a5);
else
*(_QWORD *)(a1 + 8) = result;
*(double *)a1 = *(double *)a1 + *(double *)(v7 + 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 *)


decompiled_code:
size_t __fastcall bstreap_item_splice(__int64 a1, __int64 a2, __int64 a3)
{
size_t result; // rax
__int64 v4; // rbp
__int64 v5; // r13
__int64 v6; // rbp

while ( 1 )
{
v4 = *(_QWORD *)(a2 + 8);
if ( !v4 )
break;
v5 = *(_QWORD *)(a2 + 16);
if ( v5 && *(_QWORD *)(v4 + 40) <= *(_QWORD *)(v5 + 40) )
{
result = bstreap_rotate_left(a1, a2, a3);
a3 = v5;
}
else
{
result = bstreap_rotate_right(a1, a2, a3);
a3 = v4;
}
LABEL_4:
*(double *)(a3 + 32) = *(double *)(a3 + 32) - *(double *)(a2 + 24);
}
v6 = *(_QWORD *)(a2 + 16);
if ( v6 )
{
result = bstreap_rotate_left(a1, a2, a3);
a3 = v6;
goto LABEL_4;
}
if ( *(_QWORD *)(a1 + 8) == a2 )
{
*(_QWORD *)(a1 + 8) = 0LL;
}
else if ( *(_QWORD *)(a3 + 8) == a2 )
{
*(_QWORD *)(a3 + 8) = 0LL;
}
else if ( *(_QWORD *)(a3 + 16) == a2 )
{
*(_QWORD *)(a3 + 16) = 0LL;
}
return result;
}

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)
{
double v6; // xmm2_8
__int64 v7; // rsi
double v8; // xmm0_8
__int64 v9; // rbp

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

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)
{
double v1; // xmm1_8
double v2; // rbp
double *v3; // rax

v1 = (double)rand() / 2147483647.0;
v2 = a1[1];
if ( v2 != 0.0 )
{
v3 = (double *)bstreap_item_sample(a1, *((_QWORD *)a1 + 1), 0LL, 0.0, v1);
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, int a2)
{
int result; // eax

if ( a1 )
{
print_bstreap_item(*(_QWORD *)(a1 + 16), (unsigned int)(a2 + 1));
padding(9, a2);
printf("%llu\n", **(_QWORD **)a1);
result = print_bstreap_item(*(_QWORD *)(a1 + 8), (unsigned int)(a2 + 1));
}
else
{
padding(9, a2);
result = puts("~");
}
return result;
}

canonical_decompiled_code:
int __fastcall func14(__int64 a1, int a2)
{
int result; // eax

if ( a1 )
{
func14(*(_QWORD *)(a1 + 16), (unsigned int)(a2 + 1));
func13(9, a2);
printf("%llu\n", **(_QWORD **)a1);
result = func14(*(_QWORD *)(a1 + 8), (unsigned int)(a2 + 1));
}
else
{
func13(9, a2);
result = puts("~");
}
return result;
}

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
double v4; // xmm1_8

if ( a2 )
{
v2 = a1;
v3 = 0.0;
do
v3 = v3 + *v2++;
while ( v2 != &a1[a2] );
}
else
{
v3 = 0.0;
}
if ( a2 < 0 )
v4 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
else
v4 = (double)(int)a2;
return v3 / v4;
}

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

if ( a2 )
{
v2 = a1;
v3 = 0.0;
do
v3 = v3 + *v2++;
while ( v2 != &a1[a2] );
}
else
{
v3 = 0.0;
}
if ( a2 < 0 )
v4 = (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1)) + (double)(int)(a2 & 1 | ((unsigned __int64)a2 >> 1));
else
v4 = (double)(int)a2;
return v3 / v4;
}

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

decompiled_code:
double __fastcall stdev(double *a1, __int64 a2)
{
double v2; // xmm0_8
double *v3; // rax
double v4; // xmm1_8
unsigned __int64 v5; // rbx
double v6; // xmm0_8
double v7; // xmm1_8

v2 = mean(a1, a2);
if ( !a2 )
{
v7 = 0.0;
return sqrt(v7);
}
v3 = a1;
v4 = 0.0;
do
{
v4 = v4 + (*v3 - v2) * (*v3 - v2);
++v3;
}
while ( v3 != &a1[a2] );
v5 = a2 - 1;
if ( a2 - 1 < 0 )
v6 = (double)(int)(v5 & 1 | (v5 >> 1)) + (double)(int)(v5 & 1 | (v5 >> 1));
else
v6 = (double)(int)v5;
v7 = v4 / v6;
if ( v7 >= 0.0 )
return sqrt(v7);
return sqrt(v7);
}

canonical_decompiled_code:
double __fastcall func1(double *a1, __int64 a2)
{
double v2; // xmm0_8
double *v3; // rax
double v4; // xmm1_8
unsigned __int64 v5; // rbx
double v6; // xmm0_8
double v7; // xmm1_8

v2 = func0(a1, a2);
if ( !a2 )
{
v7 = 0.0;
return sqrt(v7);
}
v3 = a1;
v4 = 0.0;
do
{
v4 = v4 + (*v3 - v2) * (*v3 - v2);
++v3;
}
while ( v3 != &a1[a2] );
v5 = a2 - 1;
if ( a2 - 1 < 0 )
v6 = (double)(int)(v5 & 1 | (v5 >> 1)) + (double)(int)(v5 & 1 | (v5 >> 1));
else
v6 = (double)(int)v5;
v7 = v4 / v6;
if ( v7 >= 0.0 )
return sqrt(v7);
return sqrt(v7);
}

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 v3; // ebx
double v4; // xmm0_8
double v6; // [rsp+8h] [rbp-20h]

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

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

v3 = 12;
v6 = 0.0;
do
{
v4 = (double)rand() / 2147483647.0 + v6;
v6 = v4;
--v3;
}
while ( v3 );
return (v4 - 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:
double __fastcall sample_fitness_pareto_out(double a1)
{
int v1; // eax

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

canonical_decompiled_code:
double __fastcall func5(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_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)
{
double result; // xmm0_8

result = randn(a1, a1 * 0.25);
if ( result < 0.0 )
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func6(double a1)
{
double result; // xmm0_8

result = func2(a1, a1 * 0.25);
if ( result < 0.0 )
result = 0.0;
return result;
}

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:
double __fastcall sample_fitness_normal_out(double a1)
{
double result; // xmm0_8

result = randn(a1, a1 * 0.25);
if ( result < 0.0 )
result = 0.0;
return result;
}

canonical_decompiled_code:
double __fastcall func7(double a1)
{
double result; // xmm0_8

result = func2(a1, a1 * 0.25);
if ( result < 0.0 )
result = 0.0;
return result;
}

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 | ((unsigned __int64)v1 >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 8) & 1 | ((unsigned __int64)v1 >> 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 | ((unsigned __int64)v1 >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 8) & 1 | ((unsigned __int64)v1 >> 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 v2; // xmm0_8

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

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

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

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
double v2; // xmm0_8

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

canonical_decompiled_code:
double __fastcall func3(__int64 a1)
{
__int64 v1; // rax
double v2; // xmm0_8

v1 = *(_QWORD *)(a1 + 8) * *(_QWORD *)(a1 + 8);
if ( v1 < 0 )
v2 = (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1)) + (double)(int)(v1 & 1 | ((unsigned __int64)v1 >> 1));
else
v2 = (double)(int)v1;
return v2 + *(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 | ((unsigned __int64)v1 >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 16) & 1 | ((unsigned __int64)v1 >> 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 | ((unsigned __int64)v1 >> 1))
+ (double)(int)(*(_DWORD *)(a1 + 16) & 1 | ((unsigned __int64)v1 >> 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 v2; // xmm0_8

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

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:
double __fastcall get_quadratic_out_degree(__int64 a1)
{
__int64 v1; // rax
double v2; // xmm0_8

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

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;
*((_DWORD *)result + 7) = 0;
*((_DWORD *)result + 6) = -1;
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;
*((_DWORD *)result + 7) = 0;
*((_DWORD *)result + 6) = -1;
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

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(__int64 *a1)
{
__int64 v1; // rbp

if ( a1 )
{
v1 = *a1;
if ( *a1 )
{
if ( (int)length(*a1) > 0 )
clear(v1);
free((void *)*a1);
*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
{
++*(_DWORD *)(a1 + 24);
result = *(_QWORD *)(result + 8);
*(_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
{
++*(_DWORD *)(a1 + 24);
result = *(_QWORD *)(result + 8);
*(_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(__int64 a1, __int64 a2)
{
unsigned __int64 result; // rax

result = (unsigned __int64)newNode(a2);
if ( *(int *)(a1 + 28) <= 0 )
{
*(_QWORD *)a1 = result;
*(_QWORD *)(a1 + 16) = result;
}
else
{
*(_QWORD *)(*(_QWORD *)a1 + 16LL) = result;
*(_QWORD *)(result + 8) = *(_QWORD *)a1;
*(_QWORD *)a1 = result;
result = *(unsigned int *)(a1 + 24);
if ( (_DWORD)result != -1 )
{
result = (unsigned int)(result + 1);
*(_DWORD *)(a1 + 24) = result;
}
}
++*(_DWORD *)(a1 + 28);
return result;
}

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

result = (unsigned __int64)newNode(a2);
if ( *(int *)(a1 + 28) <= 0 )
{
*(_QWORD *)a1 = result;
*(_QWORD *)(a1 + 16) = result;
}
else
{
*(_QWORD *)(*(_QWORD *)a1 + 16LL) = result;
*(_QWORD *)(result + 8) = *(_QWORD *)a1;
*(_QWORD *)a1 = result;
result = *(unsigned int *)(a1 + 24);
if ( (_DWORD)result != -1 )
{
result = (unsigned int)(result + 1);
*(_DWORD *)(a1 + 24) = result;
}
}
++*(_DWORD *)(a1 + 28);
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 + 24) = result;
--*(_DWORD *)(a1 + 28);
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 + 24) = result;
--*(_DWORD *)(a1 + 28);
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);
  }
 }
}


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


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


decompiled_code:
__int64 __fastcall quda_check_normalization(__int64 a1)
{
__int64 v1; // rbx
float v2; // xmm0_4
int v3; // eax
float v5; // [rsp+Ch] [rbp-1Ch]

if ( *(int *)(a1 + 12) <= 0 )
{
v5 = 0.0;
goto LABEL_7;
}
v1 = 0LL;
v5 = 0.0;
do
{
v2 = quda_complex_abs_square(*(double *)(*(_QWORD *)(a1 + 16) + 16 * v1 + 8)) + v5;
v5 = v2;
v3 = *(_DWORD *)(a1 + 12);
++v1;
}
while ( v3 > (int)v1 );
if ( v3 <= 0 )
goto LABEL_7;
if ( v2 < 0.9999999000000001 )
return 0xFFFFFFFFLL;
if ( v2 <= 1.0 )
{
LABEL_7:
printf("NORM OK, P = %f\n", v5);
return 0LL;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // rbx
float v2; // xmm0_4
int v3; // eax
float v5; // [rsp+Ch] [rbp-1Ch]

if ( *(int *)(a1 + 12) <= 0 )
{
v5 = 0.0;
goto LABEL_7;
}
v1 = 0LL;
v5 = 0.0;
do
{
v2 = quda_complex_abs_square(*(double *)(*(_QWORD *)(a1 + 16) + 16 * v1 + 8)) + v5;
v5 = v2;
v3 = *(_DWORD *)(a1 + 12);
++v1;
}
while ( v3 > (int)v1 );
if ( v3 <= 0 )
goto LABEL_7;
if ( v2 < 0.9999999000000001 )
return 0xFFFFFFFFLL;
if ( v2 <= 1.0 )
{
LABEL_7:
printf("NORM OK, P = %f\n", v5);
return 0LL;
}
return 0xFFFFFFFFLL;
}

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


decompiled_code:
__int64 __fastcall quda_weak_check_amplitudes(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12

if ( *(int *)(a1 + 12) <= 0 )
return 0;
v1 = 0LL;
v2 = 0;
do
{
if ( quda_complex_abs_square(*(double *)(*(_QWORD *)(a1 + 16) + 16 * v1 + 8)) > 1.0 )
v2 = 1;
++v1;
}
while ( *(_DWORD *)(a1 + 12) > (int)v1 );
return v2;
}

original_code:
int quda_weak_check_amplitudes(quantum_reg* qreg) {
 int i;
 int err = 0;
 for(i=0;i<qreg->num_states;i++) {
  if(quda_complex_abs_square(qreg->states[i].amplitude) > 1.0) {
   err = 1;
  }
 }
 return err;
}

canonical_original_code:
int quda_weak_check_amplitudes(struct quantum_reg *qreg) {
 int i;
 int err = 0;
 for(i=0;i<qreg->num_states;i++) {
  if(quda_complex_abs_square(qreg->states[i].amplitude) > 1.0) {
   err = 1;
  }
 }
 return err;
}

variable_types: err int


decompiled_code:
int __fastcall quda_quantum_reg_dump(__int64 a1, const char *a2)
{
int v2; // er14
int result; // eax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // [rsp+8h] [rbp-40h]

v8 = (1 << *(_DWORD *)a1) - 1;
v2 = ((1 << *(_DWORD *)(a1 + 8)) - 1) << *(_DWORD *)a1;
result = printf("QREG_DUMP: %d states\n", *(unsigned int *)(a1 + 12));
if ( *(int *)(a1 + 12) > 0 )
{
v4 = 0LL;
do
{
if ( a2 )
{
printf("%s: ", a2);
v5 = 16 * v4;
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * v4);
printf(
"qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",
(unsigned int)v4,
v7,
v7 & v8,
(v7 & (unsigned __int64)v2) >> *(_DWORD *)a1);
printf("%s: ", a2);
}
else
{
v5 = 16 * v4;
v6 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * v4);
printf(
"qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",
(unsigned int)v4,
v6,
v6 & v8,
(v6 & (unsigned __int64)v2) >> *(_DWORD *)a1);
}
result = printf(
"qreg->states[%d].amplitude = (%f,%f)\n",
(unsigned int)v4++,
*(float *)(*(_QWORD *)(a1 + 16) + v5 + 8),
*(float *)(*(_QWORD *)(a1 + 16) + v5 + 12));
}
while ( *(_DWORD *)(a1 + 12) > (int)v4 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, const char *a2)
{
int v2; // er14
int result; // eax
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rdx
__int64 v7; // rdx
__int64 v8; // [rsp+8h] [rbp-40h]

v8 = (1 << *(_DWORD *)a1) - 1;
v2 = ((1 << *(_DWORD *)(a1 + 8)) - 1) << *(_DWORD *)a1;
result = printf("QREG_DUMP: %d states\n", *(unsigned int *)(a1 + 12));
if ( *(int *)(a1 + 12) > 0 )
{
v4 = 0LL;
do
{
if ( a2 )
{
printf("%s: ", a2);
v5 = 16 * v4;
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * v4);
printf(
"qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",
(unsigned int)v4,
v7,
v7 & v8,
(v7 & (unsigned __int64)v2) >> *(_DWORD *)a1);
printf("%s: ", a2);
}
else
{
v5 = 16 * v4;
v6 = *(_QWORD *)(*(_QWORD *)(a1 + 16) + 16 * v4);
printf(
"qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",
(unsigned int)v4,
v6,
v6 & v8,
(v6 & (unsigned __int64)v2) >> *(_DWORD *)a1);
}
result = printf(
"qreg->states[%d].amplitude = (%f,%f)\n",
(unsigned int)v4++,
*(float *)(*(_QWORD *)(a1 + 16) + v5 + 8),
*(float *)(*(_QWORD *)(a1 + 16) + v5 + 12));
}
while ( *(_DWORD *)(a1 + 12) > (int)v4 );
}
return result;
}

original_code:
void quda_quantum_reg_dump(quantum_reg* qreg, char* tag) {
 int i;
 uint64_t mask = (1 << qreg->qubits)-1;
 uint64_t smask = ((1 << qreg->scratch)-1) << qreg->qubits;
 printf("QREG_DUMP: %d states\n",qreg->num_states);
 for(i=0;i<qreg->num_states;i++) {
  if(tag) printf("%s: ",tag);
  printf("qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",i,qreg->states[i].state,
    qreg->states[i].state & mask,(qreg->states[i].state & smask) >> qreg->qubits);
  if(tag) printf("%s: ",tag);
  printf("qreg->states[%d].amplitude = (%f,%f)\n",i,qreg->states[i].amplitude.real,
    qreg->states[i].amplitude.imag);
 }
}

canonical_original_code:
void quda_quantum_reg_dump(struct quantum_reg *qreg, char *tag) {
 int i;
 unsigned long mask = (1 << qreg->qubits)-1;
 unsigned long smask = ((1 << qreg->scratch)-1) << qreg->qubits;
 printf("QREG_DUMP: %d states\n",qreg->num_states);
 for(i=0;i<qreg->num_states;i++) {
  if(tag) printf("%s: ",tag);
  printf("qreg->states[%d].state = %lu (bits,scratch)=(%lu,%lu)\n",i,qreg->states[i].state,
    qreg->states[i].state & mask,(qreg->states[i].state & smask) >> qreg->qubits);
  if(tag) printf("%s: ",tag);
  printf("qreg->states[%d].amplitude = (%f,%f)\n",i,qreg->states[i].amplitude.real,
    qreg->states[i].amplitude.imag);
 }
}

variable_types:
tag
char *

variable_types:
smask
unsigned long


decompiled_code:
__int64 __fastcall quda_quantum_hadamard_range(int a1, int a2, __int64 a3)
{
unsigned int v3; // ebx
__int64 result; // rax

v3 = a1;
if ( a1 >= a2 )
return 0LL;
while ( 1 )
{
result = quda_quantum_hadamard_gate(v3, a3);
if ( (_DWORD)result )
break;
if ( a2 == ++v3 )
return result;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, __int64 a3)
{
unsigned int v3; // ebx
__int64 result; // rax

v3 = a1;
if ( a1 >= a2 )
return 0LL;
while ( 1 )
{
result = quda_quantum_hadamard_gate(v3, a3);
if ( (_DWORD)result )
break;
if ( a2 == ++v3 )
return result;
}
return 0xFFFFFFFFLL;
}

original_code:
int quda_quantum_hadamard_range(int start,int end,quantum_reg* qreg) {
 int i,res;
 for(i=start;i<end;i++) {
  res = quda_quantum_hadamard_gate(i,qreg);
  if(res) {
   return -1;
  }
 }
 return 0;
}

canonical_original_code:
int quda_quantum_hadamard_range(int start, int end, struct quantum_reg *qreg) {
 int i; int res;
 for(i=start;i<end;i++) {
  res = quda_quantum_hadamard_gate(i,qreg);
  if(res) {
   return -1;
  }
 }
 return 0;
}

variable_types: start int

variable_types: end int

variable_types: res int


decompiled_code:
__int64 __fastcall quda_quantum_hadamard_after(int a1, int *a2)
{
return quda_quantum_hadamard_range(a1, *a2, (__int64)a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int *a2)
{
return func3(a1, *a2, (__int64)a2);
}

original_code:
int quda_quantum_hadamard_after(int start,quantum_reg* qreg) {
 return quda_quantum_hadamard_range(start,qreg->qubits,qreg);
}

canonical_original_code:
int quda_quantum_hadamard_after(int start, struct quantum_reg *qreg) {
 return quda_quantum_hadamard_range(start,qreg->qubits,qreg);
}

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


decompiled_code:
__int64 __fastcall quda_quantum_hadamard_all(int *a1)
{
return quda_quantum_hadamard_range(0, *a1, (__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(int *a1)
{
return func3(0, *a1, (__int64)a1);
}

original_code:
int quda_quantum_hadamard_all(quantum_reg* qreg) {
 return quda_quantum_hadamard_range(0,qreg->qubits,qreg);
}

canonical_original_code:
int quda_quantum_hadamard_all(struct quantum_reg *qreg) {
 return quda_quantum_hadamard_range(0,qreg->qubits,qreg);
}


decompiled_code:
int __fastcall quda_quantum_fourier_transform(int *a1)
{
int v1; // er15
unsigned int v2; // er12
int result; // eax
int i; // er14
unsigned int v5; // ebx
unsigned int v6; // ebx
int v7; // er15

v1 = *a1;
v2 = *a1 - 1;
result = printf("Number of states: %d\n", (unsigned int)a1[3]);
if ( (v2 & 0x80000000) == 0 )
{
for ( i = v2; ; --i )
{
quda_quantum_hadamard_gate(v2, a1);
result = printf("Number of states after hadamard %d: %d\n", v2--, (unsigned int)a1[3]);
if ( v2 == -1 )
break;
if ( v1 > i )
{
v5 = v1 - v2;
do
{
quda_quantum_controlled_rotate_k_gate(i - 2 + v5, v2, a1, v5);
--v5;
}
while ( v5 != 1 );
}
}
}
if ( *a1 > 1 )
{
v6 = 0;
v7 = v1 - 1;
do
{
quda_quantum_controlled_not_gate(v6, v7 - v6, a1);
quda_quantum_controlled_not_gate(v7 - v6, v6, a1);
quda_quantum_controlled_not_gate(v6, v7 - v6, a1);
++v6;
result = *a1 / 2;
}
while ( result > (int)v6 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(int *a1)
{
int v1; // er15
unsigned int v2; // er12
int result; // eax
int i; // er14
unsigned int v5; // ebx
unsigned int v6; // ebx
int v7; // er15

v1 = *a1;
v2 = *a1 - 1;
result = printf("Number of states: %d\n", (unsigned int)a1[3]);
if ( (v2 & 0x80000000) == 0 )
{
for ( i = v2; ; --i )
{
quda_quantum_hadamard_gate(v2, a1);
result = printf("Number of states after hadamard %d: %d\n", v2--, (unsigned int)a1[3]);
if ( v2 == -1 )
break;
if ( v1 > i )
{
v5 = v1 - v2;
do
{
quda_quantum_controlled_rotate_k_gate(i - 2 + v5, v2, a1, v5);
--v5;
}
while ( v5 != 1 );
}
}
}
if ( *a1 > 1 )
{
v6 = 0;
v7 = v1 - 1;
do
{
quda_quantum_controlled_not_gate(v6, v7 - v6, a1);
quda_quantum_controlled_not_gate(v7 - v6, v6, a1);
quda_quantum_controlled_not_gate(v6, v7 - v6, a1);
++v6;
result = *a1 / 2;
}
while ( result > (int)v6 );
}
return result;
}

original_code:
void quda_quantum_fourier_transform(quantum_reg* qreg) {
 int q = qreg->qubits-1;
 int i,j;
  printf("Number of states: %d\n", qreg->num_states);
 for(i=q;i>=0;i--) {
  for(j=q;j>i;j--) {
   quda_quantum_controlled_rotate_k_gate(j,i,qreg,j-i+1);
  }
  quda_quantum_hadamard_gate(i,qreg);
  printf("Number of states after hadamard %d: %d\n", i, qreg->num_states);
 }
 for(i=0;i<qreg->qubits/2;i++) {
  quda_quantum_controlled_not_gate(i,q-i,qreg);
  quda_quantum_controlled_not_gate(q-i,i,qreg);
  quda_quantum_controlled_not_gate(i,q-i,qreg);
 }
}

canonical_original_code:
void quda_quantum_fourier_transform(struct quantum_reg *qreg) {
 int q = qreg->qubits-1;
 int i; int j;
  printf("Number of states: %d\n", qreg->num_states);
 for(i=q;i>=0;i--) {
  for(j=q;j>i;j--) {
   quda_quantum_controlled_rotate_k_gate(j,i,qreg,j-i+1);
  }
  quda_quantum_hadamard_gate(i,qreg);
  printf("Number of states after hadamard %d: %d\n", i, qreg->num_states);
 }
 for(i=0;i<qreg->qubits/2;i++) {
  quda_quantum_controlled_not_gate(i,q-i,qreg);
  quda_quantum_controlled_not_gate(q-i,i,qreg);
  quda_quantum_controlled_not_gate(i,q-i,qreg);
 }
}

variable_types: q int

variable_types: j int


decompiled_code:
__int64 __fastcall quda_classical_continued_fraction_expansion(__int64 *a1, __int64 *a2)
{
unsigned __int64 v3; // r9
unsigned __int64 v4; // rax
float v5; // xmm3_4
float v6; // xmm0_4
float v7; // xmm3_4
unsigned __int64 v8; // r8
float v9; // xmm7_4
__int64 v10; // rsi
__int64 v11; // rbx
__int64 v12; // r11
__int64 i; // rbp
__int64 result; // rax
float v15; // xmm0_4
float v16; // xmm1_4
double v17; // xmm1_8
float v18; // xmm0_4
__int64 v19; // rdx
__int64 v20; // rdx
unsigned __int64 v21; // rcx
double v22; // xmm0_8

v3 = *a2;
v4 = *a1;
if ( *a1 < 0 )
v5 = (float)(int)(*(_DWORD *)a1 & 1 | (v4 >> 1)) + (float)(int)(*(_DWORD *)a1 & 1 | (v4 >> 1));
else
v5 = (float)(int)v4;
if ( (v3 & 0x8000000000000000LL) != 0LL )
v6 = (float)(int)(*(_DWORD *)a2 & 1 | (v3 >> 1)) + (float)(int)(*(_DWORD *)a2 & 1 | (v3 >> 1));
else
v6 = (float)(int)v3;
v7 = v5 / v6;
v8 = 2 * v3;
v9 = v7;
v10 = 1LL;
v11 = 0LL;
v12 = 0LL;
for ( i = 1LL; ; i = *a1 )
{
LODWORD(result) = (int)(v9 + 0.000005);
v18 = v9 - ((double)(int)result - 0.000005);
v9 = 1.0 / v18;
result = (int)result;
v19 = v11 * (int)result;
if ( v19 + v10 > v3 )
break;
result = v12 + i * (int)result;
*a1 = result;
v20 = v10 | v19;
*a2 = v20;
v21 = *a1;
v12 = i;
v10 = v11;
if ( *a1 < 0 )
{
result = *a1 & 1 | (v21 >> 1);
v15 = (float)(int)result + (float)(int)result;
}
else
{
v15 = (float)(int)v21;
}
if ( v20 < 0 )
{
result = v20 & 1 | ((unsigned __int64)v20 >> 1);
v16 = (float)(int)result + (float)(int)result;
}
else
{
v16 = (float)(int)v20;
}
v22 = COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(v15 / v16) - v7) & LC11);
if ( (v3 & 0x4000000000000000LL) != 0 )
{
result = v8 >> 1;
v17 = (double)(int)(v8 >> 1) + (double)(int)(v8 >> 1);
}
else
{
v17 = (double)(int)v8;
}
if ( v22 <= 1.0 / v17 )
break;
v11 = v20;
}
return result;
}

original_code:
void quda_classical_continued_fraction_expansion(uint64_t* num, uint64_t* denom) {
 uint64_t orig_denom = *denom;
 float f = *num/(float)orig_denom;
 float g = f;
 uint64_t num1 = 1;
 uint64_t num2 = 0;
 uint64_t denom1 = 0;
 uint64_t denom2 = 1;
 int i;
 do {
  i = (int)(g+0.000005);
  g -= i-0.000005;
  g = 1.0/g;
  if(i * denom1 + denom2 > orig_denom) {
   break;
  }
  *num = i * num1 + num2;
  *denom = i * denom1 | denom2;
  num2 = num1;
  denom2 = denom1;
  num1 = *num;
  denom1 = *denom;
 } while(fabsf((*num/(float)*denom) - f) > 1.0 / (2 * orig_denom));
}

canonical_original_code:
void quda_classical_continued_fraction_expansion(unsigned long *num, unsigned long *denom) {
 unsigned long orig_denom = *denom;
 float f = *num/(float)orig_denom;
 float g = f;
 unsigned long num1 = 1;
 unsigned long num2 = 0;
 unsigned long denom1 = 0;
 unsigned long denom2 = 1;
 int i;
 do {
  i = (int)(g+0.000005);
  g -= i-0.000005;
  g = 1.0/g;
  if(i * denom1 + denom2 > orig_denom) {
   break;
  }
  *num = i * num1 + num2;
  *denom = i * denom1 | denom2;
  num2 = num1;
  denom2 = denom1;
  num1 = *num;
  denom1 = *denom;
 } while(fabsf((*num/(float)*denom) - f) > 1.0 / (2 * orig_denom));
}

variable_types:
num
unsigned long *

variable_types:
denom
unsigned long *

variable_types: f float

variable_types: g float

variable_types: i int


decompiled_code:
__int64 __fastcall quda_gcd_div(unsigned int a1, int a2)
{
signed int v2; // eax
unsigned int v3; // ecx

v2 = a1;
if ( !a2 )
return a1;
do
{
v3 = a2;
a2 = v2 % a2;
v2 = v3;
}
while ( a2 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, int a2)
{
signed int v2; // eax
unsigned int v3; // ecx

v2 = a1;
if ( !a2 )
return a1;
do
{
v3 = a2;
a2 = v2 % a2;
v2 = v3;
}
while ( a2 );
return v3;
}

original_code:
int quda_gcd_div(int x, int y) {
 int temp;
 while(y != 0) {
  temp = y;
  y = x % y;
  x = temp;
 }
 return x;
}

variable_types: x int

variable_types: y int

variable_types: temp int