original_code:
double apply_prior(int prior_type,double r,double prior_arg[])
{
 if(prior_type==0)
  return flat_prior(r,prior_arg[0],prior_arg[1]);
 else if(prior_type==1)
  return log_prior(r,prior_arg[0],prior_arg[1]);
 return 0;
}

canonical_original_code:
double apply_prior(int prior_type, double r, double prior_arg[])
{
 if(prior_type==0)
  return flat_prior(r,prior_arg[0],prior_arg[1]);
 else if(prior_type==1)
  return log_prior(r,prior_arg[0],prior_arg[1]);
 return 0;
}


original_code:
void quick_sort(double *arr, unsigned long *brr, unsigned long n)
{
 unsigned long i;
 unsigned long ir=n;
 unsigned long j;
 unsigned long k;
 unsigned long l=0;
 unsigned long M=7;
 unsigned long *istack;
 unsigned long jstack=0;
 unsigned long NSTACK=50;
 double a,dble_temp;
 unsigned long ul_temp,b;
 istack=(unsigned long*)malloc(NSTACK*sizeof(unsigned long));
 for (;;)
 {
  if (ir-l < M)
  {
   for (j=l+1;j<=ir;j++)
   {
    a=arr[j];
    b=brr[j];
    for (i=j-1;i>=1;i--)
    {
     if (arr[i] <= a)
     {
      break;
     }
     arr[i+1]=arr[i];
     brr[i+1]=brr[i];
    }
    arr[i+1]=a;
    brr[i+1]=b;
   }
   if (!jstack)
   {
    break;
   }
   ir=istack[jstack];
   l=istack[jstack-1];
   jstack -= 2;
  }
  else
  {
   k=(l+ir) >> 1;
   dble_temp=arr[k];
   arr[k]=arr[l+1];
   arr[l+1]=dble_temp;
   ul_temp=brr[k];
   brr[k]=brr[l+1];
   brr[l+1]=ul_temp;
   if (arr[l] > arr[ir])
   {
    dble_temp=arr[l];
    arr[l]=arr[ir];
    arr[ir]=dble_temp;
    ul_temp=brr[l];
    brr[l]=brr[ir];
    brr[ir]=ul_temp;
   }
   if (arr[l+1] > arr[ir])
   {
    dble_temp=arr[l+1];
    arr[l+1]=arr[ir];
    arr[ir]=dble_temp;
    ul_temp=brr[l+1];
    brr[l+1]=brr[ir];
    brr[ir]=ul_temp;
   }
   if (arr[l] > arr[l+1])
   {
    dble_temp=arr[l];
    arr[l]=arr[l+1];
    arr[l+1]=dble_temp;
    ul_temp=brr[l];
    brr[l]=brr[l+1];
    brr[l+1]=ul_temp;
   }
   i=l+1;
   j=ir;
   a=arr[l+1];
   b=brr[l+1];
   for (;;)
   {
    do
    {
     i++;
    }
    while(arr[i] < a);
    do
    {
     j--;
    }
    while (arr[j] > a);
    if (j < i)
    {
     break;
    }
    dble_temp=arr[i];
    arr[i]=arr[j];
    arr[j]=dble_temp;
    ul_temp=brr[i];
    brr[i]=brr[j];
    brr[j]=ul_temp;
   }
   arr[l+1]=arr[j];
   arr[j]=a;
   brr[l+1]=brr[j];
   brr[j]=b;
   jstack += 2;
   if(jstack > NSTACK)
   {
    printf("NSTACK too small in quick_sort()\n");
    free(istack);
    exit(0);
   }
   if (ir-i+1 >= j-l)
   {
    istack[jstack]=ir;
    istack[jstack-1]=i;
    ir=j-1;
   }
   else
   {
    istack[jstack]=j-1;
    istack[jstack-1]=l;
    l=i;
   }
  }
 }
 free(istack);
}

canonical_original_code:
void quick_sort(double *arr, unsigned long *brr, unsigned long n)
{
 unsigned long i;
 unsigned long ir = n;
 unsigned long j;
 unsigned long k;
 unsigned long l = 0;
 unsigned long M = 7;
 unsigned long *istack;
 unsigned long jstack = 0;
 unsigned long NSTACK = 50;
 double a; double dble_temp;
 unsigned long ul_temp; unsigned long b;
 istack=(unsigned long *)malloc(NSTACK*sizeof(unsigned long));
 for (;;)
 {
  if (ir-l < M)
  {
   for (j=l+1;j<=ir;j++)
   {
    a=arr[j];
    b=brr[j];
    for (i=j-1;i>=1;i--)
    {
     if (arr[i] <= a)
     {
      break;
     }
     arr[i+1]=arr[i];
     brr[i+1]=brr[i];
    }
    arr[i+1]=a;
    brr[i+1]=b;
   }
   if (!jstack)
   {
    break;
   }
   ir=istack[jstack];
   l=istack[jstack-1];
   jstack -= 2;
  }
  else
  {
   k=(l+ir) >> 1;
   dble_temp=arr[k];
   arr[k]=arr[l+1];
   arr[l+1]=dble_temp;
   ul_temp=brr[k];
   brr[k]=brr[l+1];
   brr[l+1]=ul_temp;
   if (arr[l] > arr[ir])
   {
    dble_temp=arr[l];
    arr[l]=arr[ir];
    arr[ir]=dble_temp;
    ul_temp=brr[l];
    brr[l]=brr[ir];
    brr[ir]=ul_temp;
   }
   if (arr[l+1] > arr[ir])
   {
    dble_temp=arr[l+1];
    arr[l+1]=arr[ir];
    arr[ir]=dble_temp;
    ul_temp=brr[l+1];
    brr[l+1]=brr[ir];
    brr[ir]=ul_temp;
   }
   if (arr[l] > arr[l+1])
   {
    dble_temp=arr[l];
    arr[l]=arr[l+1];
    arr[l+1]=dble_temp;
    ul_temp=brr[l];
    brr[l]=brr[l+1];
    brr[l+1]=ul_temp;
   }
   i=l+1;
   j=ir;
   a=arr[l+1];
   b=brr[l+1];
   for (;;)
   {
    do
    {
     i++;
    }
    while(arr[i] < a);
    do
    {
     j--;
    }
    while (arr[j] > a);
    if (j < i)
    {
     break;
    }
    dble_temp=arr[i];
    arr[i]=arr[j];
    arr[j]=dble_temp;
    ul_temp=brr[i];
    brr[i]=brr[j];
    brr[j]=ul_temp;
   }
   arr[l+1]=arr[j];
   arr[j]=a;
   brr[l+1]=brr[j];
   brr[j]=b;
   jstack += 2;
   if(jstack > NSTACK)
   {
    printf("NSTACK too small in quick_sort()\n");
    free(istack);
    exit(0);
   }
   if (ir-i+1 >= j-l)
   {
    istack[jstack]=ir;
    istack[jstack-1]=i;
    ir=j-1;
   }
   else
   {
    istack[jstack]=j-1;
    istack[jstack-1]=l;
    l=i;
   }
  }
 }
 free(istack);
}

variable_types:
arr
double *

variable_types:
brr
unsigned long *

variable_types:
n
unsigned long

variable_types:
i
unsigned long

variable_types:
ir
unsigned long

variable_types:
j
unsigned long

variable_types:
k
unsigned long

variable_types:
l
unsigned long

variable_types:
M
unsigned long

variable_types:
istack
unsigned long *

variable_types:
jstack
unsigned long

variable_types:
NSTACK
unsigned long

variable_types: a double

variable_types:
b
unsigned long

return_type: void


decompiled_code:
void __fastcall sort_live_points(__int64 a1, unsigned int a2, unsigned int a3)
{
_QWORD *v4; // r14
char *v5; // rax
char *v6; // r15
char *v7; // rbx
char *v8; // r13
char *v9; // rbp
__int64 v10; // r12
__int64 v11; // rbp
_QWORD *v12; // rdi
__int64 i; // rax
_QWORD *v14; // rbx
_QWORD *ptr; // [rsp+0h] [rbp-58h]

ptr = malloc(8LL * a2);
v4 = malloc(8LL * a2);
v5 = (char *)malloc(40LL * a2);
v6 = v5;
if ( a2 )
{
v7 = v5;
v8 = &v5[40 * a2];
v9 = v5;
do
{
init_live_point(v9, a3);
v9 += 40;
}
while ( v9 != v8 );
v10 = a1;
v11 = a1;
do
{
copy_live_point(v7, v10);
v7 += 40;
v10 += 40LL;
}
while ( v7 != v8 );
v12 = (_QWORD *)(a1 + 16);
for ( i = 0LL; i != a2; ++i )
{
ptr[i] = *v12;
v4[i] = i;
v12 += 5;
}
quick_sort((__int64)ptr, (__int64)v4, a2);
v14 = v4;
do
{
copy_live_point(v11, &v6[40 * *v14++]);
v11 += 40LL;
}
while ( v14 != &v4[a2] );
}
else
{
quick_sort((__int64)ptr, (__int64)v4, 0LL);
}
free(ptr);
free(v4);
free(v6);
}

original_code:
void sort_live_points(live_point* lvs,unsigned num_live,unsigned num_dim)
{
 double* llvals;
 unsigned long* inds;
 unsigned i;
 live_point* temp_lvs;
 llvals=(double*)malloc(num_live*sizeof(double));
 inds=(unsigned long*)malloc(num_live*sizeof(unsigned long));
 temp_lvs=(live_point*)malloc(num_live*sizeof(live_point));
 for(i=0;i<num_live;++i)
 {
  init_live_point(&temp_lvs[i],num_dim);
 }
 for(i=0;i<num_live;++i)
 {
  copy_live_point(&temp_lvs[i],&lvs[i]);
 }
 for(i=0;i<num_live;++i)
 {
  llvals[i]=lvs[i].log_lik;
  inds[i]=(unsigned long)i;
 }
 quick_sort(llvals,inds,num_live);
 for(i=0;i<num_live;++i)
 {
  copy_live_point(&lvs[i],&temp_lvs[inds[i]]);
 }
 free(llvals);
 free(inds);
 free(temp_lvs);
}

canonical_original_code:
void sort_live_points(struct live_point *lvs, unsigned int num_live, unsigned int num_dim)
{
 double *llvals;
 unsigned long *inds;
 unsigned int i;
 struct live_point *temp_lvs;
 llvals=(double *)malloc(num_live*sizeof(double));
 inds=(unsigned long *)malloc(num_live*sizeof(unsigned long));
 temp_lvs=(struct live_point *)malloc(num_live*sizeof(live_point));
 for(i=0;i<num_live;++i)
 {
  init_live_point(&temp_lvs[i],num_dim);
 }
 for(i=0;i<num_live;++i)
 {
  copy_live_point(&temp_lvs[i],&lvs[i]);
 }
 for(i=0;i<num_live;++i)
 {
  llvals[i]=lvs[i].log_lik;
  inds[i]=(unsigned long)i;
 }
 quick_sort(llvals,inds,num_live);
 for(i=0;i<num_live;++i)
 {
  copy_live_point(&lvs[i],&temp_lvs[inds[i]]);
 }
 free(llvals);
 free(inds);
 free(temp_lvs);
}

variable_types: struct live_point { double *u; double *x; double log_lik; double log_weight; unsigned int num_dim; } *

variable_types:
llvals
double *

variable_types:
inds
unsigned long *

variable_types:
i
unsigned int


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

*(_QWORD *)(a1 + 8) = malloc(8LL * a2);
*(_QWORD *)a1 = malloc(8LL * a2);
result = LC0;
*(_QWORD *)(a1 + 16) = LC0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 32) = a2;
return result;
}

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

*(_QWORD *)(a1 + 8) = malloc(8LL * a2);
*(_QWORD *)a1 = malloc(8LL * a2);
result = LC0;
*(_QWORD *)(a1 + 16) = LC0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 32) = a2;
return result;
}

original_code:
void init_live_point(live_point* lp, unsigned num_dim)
{
 lp->x=(double*)malloc(num_dim*sizeof(double));
 lp->u=(double*)malloc(num_dim*sizeof(double));
 lp->log_lik=-1e90;
 lp->log_weight=0;
 lp->num_dim=num_dim;
}

canonical_original_code:
void init_live_point(struct live_point *lp, unsigned int num_dim)
{
 lp->x=(double *)malloc(num_dim*sizeof(double));
 lp->u=(double *)malloc(num_dim*sizeof(double));
 lp->log_lik=-1e90;
 lp->log_weight=0;
 lp->num_dim=num_dim;
}

user_defined_types: struct live_point { double *u; double *x; double log_lik; double log_weight; unsigned int num_dim; }


decompiled_code:
__int64 __fastcall free_live_point(__int64 a1)
{
void *v2; // rdi
__int64 result; // rax

v2 = *(void **)(a1 + 8);
if ( v2 )
free(v2);
if ( *(_QWORD *)a1 )
free(*(void **)a1);
result = LC0;
*(_QWORD *)(a1 + 16) = LC0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 32) = 0;
return result;
}

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

v2 = *(void **)(a1 + 8);
if ( v2 )
free(v2);
if ( *(_QWORD *)a1 )
free(*(void **)a1);
result = LC0;
*(_QWORD *)(a1 + 16) = LC0;
*(_QWORD *)(a1 + 24) = 0LL;
*(_DWORD *)(a1 + 32) = 0;
return result;
}

original_code:
void free_live_point(live_point* lp)
{
 if(lp->x != ((void *)0))
  free(lp->x);
 if(lp->u != ((void *)0))
  free(lp->u);
 lp->log_lik=-1e90;
 lp->log_weight=0;
 lp->num_dim=0;
}

canonical_original_code:
void free_live_point(struct live_point *lp)
{
 if(lp->x != ((void *)0))
  free(lp->x);
 if(lp->u != ((void *)0))
  free(lp->u);
 lp->log_lik=-1e90;
 lp->log_weight=0;
 lp->num_dim=0;
}


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

result = *(unsigned int *)(a1 + 32);
if ( (_DWORD)result != *(_DWORD *)(a2 + 32) )
_assert_fail("destination->num_dim==source->num_dim", "live_point.c", 0x1Fu, "copy_live_point");
v3 = 0;
if ( (_DWORD)result )
{
do
{
result = v3;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v3) = *(_QWORD *)(*(_QWORD *)a2 + 8LL * v3);
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v3) = *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL * v3);
++v3;
}
while ( *(_DWORD *)(a1 + 32) > v3 );
}
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a2 + 16);
*(_QWORD *)(a1 + 24) = *(_QWORD *)(a2 + 24);
return result;
}

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

result = *(unsigned int *)(a1 + 32);
if ( (_DWORD)result != *(_DWORD *)(a2 + 32) )
_assert_fail("destination->num_dim==source->num_dim", "live_point.c", 0x1Fu, "copy_live_point");
v3 = 0;
if ( (_DWORD)result )
{
do
{
result = v3;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v3) = *(_QWORD *)(*(_QWORD *)a2 + 8LL * v3);
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * v3) = *(_QWORD *)(*(_QWORD *)(a2 + 8) + 8LL * v3);
++v3;
}
while ( *(_DWORD *)(a1 + 32) > v3 );
}
*(_QWORD *)(a1 + 16) = *(_QWORD *)(a2 + 16);
*(_QWORD *)(a1 + 24) = *(_QWORD *)(a2 + 24);
return result;
}

original_code:
void copy_live_point(live_point* destination,live_point* source)
{
 unsigned i;
 ((destination->num_dim==source->num_dim) ? (void) (0) : __assert_fail ("destination->num_dim==source->num_dim", "live_point.c", 31, __extension__ __PRETTY_FUNCTION__));
 for(i=0;i<destination->num_dim;++i)
 {
  destination->u[i]=source->u[i];
  destination->x[i]=source->x[i];
 }
 destination->log_lik=source->log_lik;
 destination->log_weight=source->log_weight;
}

canonical_original_code:
void copy_live_point(struct live_point *destination, struct live_point *source)
{
 unsigned int i;
 ((destination->num_dim==source->num_dim) ? (void) (0) : __assert_fail ("destination->num_dim==source->num_dim", "live_point.c", 31, __extension__ __PRETTY_FUNCTION__));
 for(i=0;i<destination->num_dim;++i)
 {
  destination->u[i]=source->u[i];
  destination->x[i]=source->x[i];
 }
 destination->log_lik=source->log_lik;
 destination->log_weight=source->log_weight;
}

variable_types:
source
struct live_point *


decompiled_code:
double __fastcall log_add(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8
double v4; // xmm0_8

if ( a1 <= a2 )
{
v4 = exp(a1 - a2);
result = log(v4 + 1.0) + a2;
}
else
{
v2 = exp(a2 - a1);
result = log(v2 + 1.0) + a1;
}
return result;
}

canonical_decompiled_code:
double __fastcall func0(double a1, double a2)
{
double v2; // xmm0_8
double result; // xmm0_8
double v4; // xmm0_8

if ( a1 <= a2 )
{
v4 = exp(a1 - a2);
result = log(v4 + 1.0) + a2;
}
else
{
v2 = exp(a2 - a1);
result = log(v2 + 1.0) + a1;
}
return result;
}

original_code:
double log_add(double x,double y)
{
 return (x>y ? x+log(1.+exp(y-x)) : y+log(1.+exp(x-y)) );
}

canonical_original_code:
double log_add(double x, double y)
{
 return (x>y ? x+log(1.+exp(y-x)) : y+log(1.+exp(x-y)) );
}

variable_types: x double

variable_types: y double

return_type: double


original_code:
void print_post_stats(live_point* psamps,unsigned long num_post_samps,double logz,unsigned num_dim)
{
 double* mom1=(double*)malloc(num_dim*sizeof(double));
 double* mom2=(double*)malloc(num_dim*sizeof(double));
 double* weight=(double*)malloc(num_post_samps*sizeof(double));
 unsigned i,j;
 for(i=0;i<num_dim;++i)
 {
  mom1[i]=0.;
  mom2[i]=0.;
 }
 for(i=0;i<num_post_samps;++i)
 {
  weight[i]=exp(psamps[i].log_weight-logz);
  for(j=0;j<num_dim;++j)
  {
   mom1[j]+=weight[i]*psamps[i].x[j];
   mom2[j]+=weight[i]*psamps[i].x[j]*psamps[i].x[j];
  }
 }
 printf("\n\nPosterior Statistics\n");
 printf("Dimension           Mean                            Standard Deviation\n");
 printf("--------------------------------------------------------------------------\n");
 for(i=0;i<num_dim;++i)
 {
  printf("%4d                %12.10e                %12.10e\n",i,mom1[i],sqrt(mom2[i]-mom1[i]*mom1[i]));
 }
 free(mom1);
 free(mom2);
 free(weight);
}

canonical_original_code:
void print_post_stats(struct live_point *psamps, unsigned long num_post_samps, double logz, unsigned int num_dim)
{
 double *mom1 = (double*)malloc(num_dim*sizeof(double));
 double *mom2 = (double*)malloc(num_dim*sizeof(double));
 double *weight = (double*)malloc(num_post_samps*sizeof(double));
 unsigned int i; unsigned int j;
 for(i=0;i<num_dim;++i)
 {
  mom1[i]=0.;
  mom2[i]=0.;
 }
 for(i=0;i<num_post_samps;++i)
 {
  weight[i]=exp(psamps[i].log_weight-logz);
  for(j=0;j<num_dim;++j)
  {
   mom1[j]+=weight[i]*psamps[i].x[j];
   mom2[j]+=weight[i]*psamps[i].x[j]*psamps[i].x[j];
  }
 }
 printf("\n\nPosterior Statistics\n");
 printf("Dimension           Mean                            Standard Deviation\n");
 printf("--------------------------------------------------------------------------\n");
 for(i=0;i<num_dim;++i)
 {
  printf("%4d                %12.10e                %12.10e\n",i,mom1[i],sqrt(mom2[i]-mom1[i]*mom1[i]));
 }
 free(mom1);
 free(mom2);
 free(weight);
}

variable_types: logz double

variable_types:
weight
double *

variable_types:
j
unsigned int


original_code:
void print_max_like_estimate(live_point* lvpnts,unsigned num_live,unsigned num_dim)
{
 unsigned best=0;
 unsigned i;
 for(i=0;i<num_live;++i)
 {
  if(lvpnts[i].log_lik>lvpnts[best].log_lik)
  {
   best=i;
  }
 }
 printf("\nMax Like parameters\n");
 printf("Dimension           Value\n");
 printf("--------------------------------------------------------------------------\n");
 for(i=0;i<num_dim;++i)
 {
  printf("%4d                %12.10e\n",i,lvpnts[best].x[i]);
 }
}

canonical_original_code:
void print_max_like_estimate(struct live_point *lvpnts, unsigned int num_live, unsigned int num_dim)
{
 unsigned int best = 0;
 unsigned int i;
 for(i=0;i<num_live;++i)
 {
  if(lvpnts[i].log_lik>lvpnts[best].log_lik)
  {
   best=i;
  }
 }
 printf("\nMax Like parameters\n");
 printf("Dimension           Value\n");
 printf("--------------------------------------------------------------------------\n");
 for(i=0;i<num_dim;++i)
 {
  printf("%4d                %12.10e\n",i,lvpnts[best].x[i]);
 }
}

variable_types:
best
unsigned int


decompiled_code:
void __fastcall explore_prior_space(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4, void (__fastcall *a5)(_QWORD, _QWORD, _QWORD, double *), double a6)
{
double *v7; // r12
__int64 v8; // rbx
double *v9; // rbp
double v10; // xmm0_8
double v14[8]; // [rsp+28h] [rbp-40h] BYREF

v7 = (double *)malloc(0x28uLL);
init_live_point(v7, a2);
do
{
if ( a2 )
{
v8 = 0LL;
do
{
v9 = (double *)(*((_QWORD *)v7 + 1) + v8);
*v9 = genrand_uniform(a4);
v8 += 8LL;
}
while ( v8 != 8LL * (a2 - 1) + 8 );
}
a5(*((_QWORD *)v7 + 1), a2, a3, v14);
v10 = v14[0];
v7[2] = v14[0];
}
while ( v10 <= a6 );
copy_live_point(a1, v7);
free(v7);
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, unsigned int a2, unsigned int a3, __int64 a4, void (__fastcall *a5)(_QWORD, _QWORD, _QWORD, double *), double a6)
{
double *v7; // r12
__int64 v8; // rbx
double *v9; // rbp
double v10; // xmm0_8
double v14[8]; // [rsp+28h] [rbp-40h] BYREF

v7 = (double *)malloc(0x28uLL);
init_live_point(v7, a2);
do
{
if ( a2 )
{
v8 = 0LL;
do
{
v9 = (double *)(*((_QWORD *)v7 + 1) + v8);
*v9 = genrand_uniform(a4);
v8 += 8LL;
}
while ( v8 != 8LL * (a2 - 1) + 8 );
}
a5(*((_QWORD *)v7 + 1), a2, a3, v14);
v10 = v14[0];
v7[2] = v14[0];
}
while ( v10 <= a6 );
copy_live_point(a1, v7);
free(v7);
}

original_code:
void explore_prior_space(live_point* livpnt,double llstar,unsigned num_dim,
unsigned num_par,ellipsis_mt19937_rng* rng,
void (*log_likelihood)(double *cube, unsigned ndim, unsigned npar, double *lnew))
{
 unsigned i;
 double llik;
 live_point* trial_lvpnt=(live_point*)malloc(sizeof(live_point));
 init_live_point(trial_lvpnt,num_dim);
 for(;;)
 {
  for(i=0;i<num_dim;++i)
  {
   trial_lvpnt->x[i]=genrand_uniform(rng);
  }
  log_likelihood(trial_lvpnt->x,num_dim,num_par,&llik);
  trial_lvpnt->log_lik=llik;
  if(trial_lvpnt->log_lik > llstar)
  {
   copy_live_point(livpnt,trial_lvpnt);
   break;
  }
 }
 free(trial_lvpnt);
}

canonical_original_code:
void explore_prior_space(struct live_point *livpnt, double llstar, unsigned int num_dim, unsigned int num_par, struct ellipsis_mt19937_rng *rng, void (*log_likelihood)(double *cube, unsigned int ndim, unsigned int npar, double *lnew))
{
 unsigned int i;
 double llik;
 struct live_point *trial_lvpnt = (live_point*)malloc(sizeof(live_point));
 init_live_point(trial_lvpnt,num_dim);
 for(;;)
 {
  for(i=0;i<num_dim;++i)
  {
   trial_lvpnt->x[i]=genrand_uniform(rng);
  }
  log_likelihood(trial_lvpnt->x,num_dim,num_par,&llik);
  trial_lvpnt->log_lik=llik;
  if(trial_lvpnt->log_lik > llstar)
  {
   copy_live_point(livpnt,trial_lvpnt);
   break;
  }
 }
 free(trial_lvpnt);
}

variable_types: llstar double

variable_types: struct ellipsis_mt19937_rng { unsigned long mt[624]; int mti; } *

variable_types: void (*)(double *cube, unsigned int ndim, unsigned int npar, double *lnew)

variable_types: llik double


original_code:
void explore_prior_space_with_mcmc(live_point* livpnt,double llstar,unsigned num_dim,
 unsigned num_par,ellipsis_mt19937_rng* rng,
 void (*log_likelihood)(double *cube, unsigned ndim, unsigned npar, double *lnew))
{
 unsigned num_samples=20;
 double step=0.1;
 unsigned accept=0;
 unsigned reject=0;
 unsigned i;
 double llik;
 unsigned samps=0;
 double* uvals;
 double* uvals_new;
 double* xvals;
 double* xvals_new;
 double llik_new;
 uvals=(double*)malloc(num_dim*sizeof(double));
 uvals_new=(double*)malloc(num_dim*sizeof(double));
 xvals=(double*)malloc(num_dim*sizeof(double));
 xvals_new=(double*)malloc(num_dim*sizeof(double));
 for(i=0;i<num_dim;++i)
 {
  uvals[i]=livpnt->u[i];
  xvals[i]=livpnt->x[i];
  llik_new=livpnt->log_lik;
 }
 for(;;)
 {
  for(i=0;i<num_dim;++i)
  {
   uvals_new[i]=uvals[i]+step*(2.*genrand_uniform(rng)-1.);
   uvals_new[i]-=floor(uvals_new[i]);
   xvals_new[i]=uvals_new[i];
  }
  log_likelihood(xvals_new,num_dim,num_par,&llik);
  if(llik > llstar)
  {
   for(i=0;i<num_dim;++i)
   {
    uvals[i]=uvals_new[i];
    xvals[i]=xvals_new[i];
   }
   llik_new=llik;
   ++accept;
  }
  else
  {
   ++reject;
  }
  if(accept>reject)
  {
   step*=exp(1./(double)accept);
  }
  if(accept<reject)
  {
   step/=exp(1./(double)reject);
  }
  if(accept>0 && samps>=num_samples)
  {
   for(i=0;i<num_dim;++i)
   {
    livpnt->u[i]=uvals[i];
    livpnt->x[i]=xvals[i];
   }
   livpnt->log_lik=llik_new;
   break;
  }
  ++samps;
 }
 free(uvals);
 free(uvals_new);
 free(xvals);
 free(xvals_new);
}

canonical_original_code:
void explore_prior_space_with_mcmc(struct live_point *livpnt, double llstar, unsigned int num_dim, unsigned int num_par, struct ellipsis_mt19937_rng *rng, void (*log_likelihood)(double *cube, unsigned int ndim, unsigned int npar, double *lnew))
{
 unsigned int num_samples = 20;
 double step = 0.1;
 unsigned int accept = 0;
 unsigned int reject = 0;
 unsigned int i;
 double llik;
 unsigned int samps = 0;
 double *uvals;
 double *uvals_new;
 double *xvals;
 double *xvals_new;
 double llik_new;
 uvals=(double *)malloc(num_dim*sizeof(double));
 uvals_new=(double *)malloc(num_dim*sizeof(double));
 xvals=(double *)malloc(num_dim*sizeof(double));
 xvals_new=(double *)malloc(num_dim*sizeof(double));
 for(i=0;i<num_dim;++i)
 {
  uvals[i]=livpnt->u[i];
  xvals[i]=livpnt->x[i];
  llik_new=livpnt->log_lik;
 }
 for(;;)
 {
  for(i=0;i<num_dim;++i)
  {
   uvals_new[i]=uvals[i]+step*(2.*genrand_uniform(rng)-1.);
   uvals_new[i]-=floor(uvals_new[i]);
   xvals_new[i]=uvals_new[i];
  }
  log_likelihood(xvals_new,num_dim,num_par,&llik);
  if(llik > llstar)
  {
   for(i=0;i<num_dim;++i)
   {
    uvals[i]=uvals_new[i];
    xvals[i]=xvals_new[i];
   }
   llik_new=llik;
   ++accept;
  }
  else
  {
   ++reject;
  }
  if(accept>reject)
  {
   step*=exp(1./(double)accept);
  }
  if(accept<reject)
  {
   step/=exp(1./(double)reject);
  }
  if(accept>0 && samps>=num_samples)
  {
   for(i=0;i<num_dim;++i)
   {
    livpnt->u[i]=uvals[i];
    livpnt->x[i]=xvals[i];
   }
   livpnt->log_lik=llik_new;
   break;
  }
  ++samps;
 }
 free(uvals);
 free(uvals_new);
 free(xvals);
 free(xvals_new);
}

variable_types: step double

variable_types:
accept
unsigned int

variable_types:
reject
unsigned int

variable_types:
samps
unsigned int

variable_types:
uvals
double *

variable_types:
xvals
double *

user_defined_types: struct ellipsis_mt19937_rng { unsigned long mt[624]; int mti; }


decompiled_code:
void __fastcall explore_prior_space_with_mcmc_var_tuned(__int64 *a1, __int64 a2, int a3, unsigned int a4, unsigned int a5, __int64 a6, double a7, void (__fastcall *a8)(double *, _QWORD, _QWORD, __int64 *))
{
size_t v9; // rbx
double *v10; // rcx
unsigned int v11; // edx
unsigned int v12; // eax
_QWORD *v13; // r14
__int64 v14; // rbx
double v15; // xmm0_8
double v16; // xmm1_8
_QWORD *v17; // rax
double v18; // xmm1_8
double v19; // xmm1_8
__int64 v20; // rax
double v21; // xmm0_8
double v22; // xmm0_8
__int64 v23; // rbx
double v24; // xmm0_8
__int64 v25; // xmm1_8
__int64 v26; // rax
_QWORD *v27; // r12
double *v28; // r15
_QWORD *v29; // rbp
double *v30; // r13
__int64 v31; // rcx
__int64 v32; // rdx
__int64 v33; // rax
double v34; // [rsp+8h] [rbp-B0h]
double v35; // [rsp+8h] [rbp-B0h]
double v36; // [rsp+10h] [rbp-A8h]
double *v37; // [rsp+18h] [rbp-A0h]
size_t size; // [rsp+28h] [rbp-90h]
unsigned int sizea; // [rsp+28h] [rbp-90h]
unsigned int v41; // [rsp+30h] [rbp-88h]
double *v43; // [rsp+40h] [rbp-78h]
unsigned int i; // [rsp+50h] [rbp-68h]
__int64 v47; // [rsp+58h] [rbp-60h]
__int64 v48[8]; // [rsp+78h] [rbp-40h] BYREF

v9 = 8LL * a4;
size = v9;
v43 = (double *)malloc(v9);
v37 = (double *)malloc(v9);
if ( a3 )
{
v10 = (double *)(a2 + 16);
v11 = 0;
v12 = 0;
do
{
if ( *v10 > *(double *)(a2 + 40LL * v11 + 16) )
v11 = v12;
++v12;
v10 += 5;
}
while ( a3 != v12 );
}
else
{
v11 = 0;
}
if ( a4 )
{
v13 = (_QWORD *)(a2 + 40LL * v11);
v14 = 0LL;
do
{
v17 = (_QWORD *)a2;
v16 = 0.0;
v34 = 0.0;
if ( a3 )
{
do
{
v15 = *(double *)(*v17 + v14 * 8);
v34 = v34 + v15;
v16 = v16 + v15 * v15;
v17 += 5;
}
while ( v17 != (_QWORD *)(a2 + 40LL * (unsigned int)(a3 - 1) + 40) );
}
v18 = (v16 - v34 * v34 / (double)a3) / (double)a3;
if ( v18 < 0.0 )
v19 = sqrt(v18);
else
v19 = sqrt(v18);
v43[v14] = v19;
v37[v14] = (v34 / (double)a3 + *(double *)(*v13 + v14 * 8)) * 0.5;
++v14;
}
while ( v14 != a4 );
v27 = malloc(size);
v28 = (double *)malloc(size);
v29 = malloc(size);
v30 = (double *)malloc(size);
v31 = *a1;
v32 = a1[1];
v47 = a1[2];
v33 = 0LL;
do
{
v27[v33] = *(_QWORD *)(v31 + 8 * v33);
v29[v33] = *(_QWORD *)(v32 + 8 * v33);
++v33;
}
while ( v33 != a4 );
}
else
{
v27 = malloc(v9);
v28 = (double *)malloc(v9);
v29 = malloc(v9);
v30 = (double *)malloc(v9);
}
v41 = 0;
sizea = 0;
for ( i = 0; ; ++i )
{
if ( a4 )
{
v23 = 0LL;
do
{
v35 = (*(double *)&v27[v23] + v37[v23]) * 0.5;
v36 = v43[v23];
v24 = genrand_uniform(a6) * v36 + v35;
v28[v23] = v24;
v30[v23++] = v24;
}
while ( a4 != v23 );
a8(v30, a4, a5, v48);
v25 = v48[0];
if ( *(double *)v48 <= a7 )
{
LABEL_28:
++v41;
goto LABEL_29;
}
v20 = 0LL;
do
{
v27[v20] = *(_QWORD *)&v28[v20];
v29[v20] = *(_QWORD *)&v30[v20];
++v20;
}
while ( a4 != v20 );
}
else
{
a8(v30, 0LL, a5, v48);
v25 = v48[0];
if ( *(double *)v48 <= a7 )
goto LABEL_28;
}
++sizea;
v47 = v25;
LABEL_29:
if ( sizea > v41 )
{
v21 = 1.0 / (double)(int)sizea;
if ( v21 >= 709.0 )
exp(v21);
}
if ( sizea < v41 )
{
v22 = 1.0 / (double)(int)v41;
if ( v22 >= 709.0 )
exp(v22);
}
if ( sizea && i > 0x13 )
break;
}
if ( a4 )
{
v26 = 0LL;
do
{
*(_QWORD *)(*a1 + v26 * 8) = v27[v26];
*(_QWORD *)(a1[1] + v26 * 8) = v29[v26];
++v26;
}
while ( v26 != a4 );
}
a1[2] = v47;
free(v27);
free(v28);
free(v29);
free(v30);
free(v43);
free(v37);
}

original_code:
void explore_prior_space_with_mcmc_var_tuned(live_point* livpnt,double llstar,
 live_point* phys_live_points,unsigned num_phys_live,unsigned num_dim,unsigned num_par, ellipsis_mt19937_rng* rng,
 void (*log_likelihood)(double *cube, unsigned ndim, unsigned npar, double *lnew))
{
 unsigned num_samples=20;
 unsigned i,j;
 double llik;
 unsigned samps=0;
 unsigned accept=0;
 unsigned reject=0;
 double step=2.;
 double* sigma;
 double* mean;
 double sum;
 double sum2;
 double enlarge_fact=2.;
 double* uvals;
 double* uvals_new;
 double* xvals;
 double* xvals_new;
 double llik_new;
 unsigned best=0;
 sigma=(double*)malloc(num_dim*sizeof(double));
 mean=(double*)malloc(num_dim*sizeof(double));
 for(i=0;i<num_phys_live;++i)
 {
  if(phys_live_points[i].log_lik>phys_live_points[best].log_lik)
  {
   best=i;
  }
 }
 for(i=0;i<num_dim;++i)
 {
  sum=0;
  sum2=0;
  for(j=0;j<num_phys_live;++j)
  {
   sum+=phys_live_points[j].u[i];
   sum2+=phys_live_points[j].u[i]*phys_live_points[j].u[i];
  }
  sigma[i]=sqrt( (sum2-sum*sum/(double)num_phys_live)/(double)num_phys_live );
  mean[i]=(phys_live_points[best].u[i]+sum/(double)num_phys_live)*0.5;
 }
 uvals=(double*)malloc(num_dim*sizeof(double));
 uvals_new=(double*)malloc(num_dim*sizeof(double));
 xvals=(double*)malloc(num_dim*sizeof(double));
 xvals_new=(double*)malloc(num_dim*sizeof(double));
 for(i=0;i<num_dim;++i)
 {
  uvals[i]=livpnt->u[i];
  xvals[i]=livpnt->x[i];
  llik_new=livpnt->log_lik;
 }
 for(;;)
 {
  for(i=0;i<num_dim;++i)
  {
   uvals_new[i]=(uvals[i]+mean[i])*0.5+sigma[i]*genrand_uniform(rng);
   xvals_new[i]=uvals_new[i];
  }
  log_likelihood(xvals_new,num_dim,num_par,&llik);
  if(llik > llstar)
  {
   for(i=0;i<num_dim;++i)
   {
    uvals[i]=uvals_new[i];
    xvals[i]=xvals_new[i];
   }
   llik_new=llik;
   ++accept;
  }
  else
  {
   ++reject;
  }
  if(accept>reject)
  {
   step*=exp(1./(double)accept);
  }
  if(accept<reject)
  {
   step/=exp(1./(double)reject);
  }
  if(accept>0 && samps>=num_samples)
  {
   for(i=0;i<num_dim;++i)
   {
    livpnt->u[i]=uvals[i];
    livpnt->x[i]=xvals[i];
   }
   livpnt->log_lik=llik_new;
   break;
  }
  ++samps;
 }
 free(uvals);
 free(uvals_new);
 free(xvals);
 free(xvals_new);
 free(sigma);
 free(mean);
}

canonical_original_code:
void explore_prior_space_with_mcmc_var_tuned(struct live_point *livpnt, double llstar, struct live_point *phys_live_points, unsigned int num_phys_live, unsigned int num_dim, unsigned int num_par, struct ellipsis_mt19937_rng *rng, void (*log_likelihood)(double *cube, unsigned int ndim, unsigned int npar, double *lnew))
{
 unsigned int num_samples = 20;
 unsigned int i; unsigned int j;
 double llik;
 unsigned int samps = 0;
 unsigned int accept = 0;
 unsigned int reject = 0;
 double step = 2.;
 double *sigma;
 double *mean;
 double sum;
 double sum2;
 double enlarge_fact = 2.;
 double *uvals;
 double *uvals_new;
 double *xvals;
 double *xvals_new;
 double llik_new;
 unsigned int best = 0;
 sigma=(double *)malloc(num_dim*sizeof(double));
 mean=(double *)malloc(num_dim*sizeof(double));
 for(i=0;i<num_phys_live;++i)
 {
  if(phys_live_points[i].log_lik>phys_live_points[best].log_lik)
  {
   best=i;
  }
 }
 for(i=0;i<num_dim;++i)
 {
  sum=0;
  sum2=0;
  for(j=0;j<num_phys_live;++j)
  {
   sum+=phys_live_points[j].u[i];
   sum2+=phys_live_points[j].u[i]*phys_live_points[j].u[i];
  }
  sigma[i]=sqrt( (sum2-sum*sum/(double)num_phys_live)/(double)num_phys_live );
  mean[i]=(phys_live_points[best].u[i]+sum/(double)num_phys_live)*0.5;
 }
 uvals=(double *)malloc(num_dim*sizeof(double));
 uvals_new=(double *)malloc(num_dim*sizeof(double));
 xvals=(double *)malloc(num_dim*sizeof(double));
 xvals_new=(double *)malloc(num_dim*sizeof(double));
 for(i=0;i<num_dim;++i)
 {
  uvals[i]=livpnt->u[i];
  xvals[i]=livpnt->x[i];
  llik_new=livpnt->log_lik;
 }
 for(;;)
 {
  for(i=0;i<num_dim;++i)
  {
   uvals_new[i]=(uvals[i]+mean[i])*0.5+sigma[i]*genrand_uniform(rng);
   xvals_new[i]=uvals_new[i];
  }
  log_likelihood(xvals_new,num_dim,num_par,&llik);
  if(llik > llstar)
  {
   for(i=0;i<num_dim;++i)
   {
    uvals[i]=uvals_new[i];
    xvals[i]=xvals_new[i];
   }
   llik_new=llik;
   ++accept;
  }
  else
  {
   ++reject;
  }
  if(accept>reject)
  {
   step*=exp(1./(double)accept);
  }
  if(accept<reject)
  {
   step/=exp(1./(double)reject);
  }
  if(accept>0 && samps>=num_samples)
  {
   for(i=0;i<num_dim;++i)
   {
    livpnt->u[i]=uvals[i];
    livpnt->x[i]=xvals[i];
   }
   livpnt->log_lik=llik_new;
   break;
  }
  ++samps;
 }
 free(uvals);
 free(uvals_new);
 free(xvals);
 free(xvals_new);
 free(sigma);
 free(mean);
}

variable_types: struct live_point { double *u; double *x; double log_lik; double log_weight; unsigned int num_dim; } *

variable_types:
i
unsigned int

variable_types:
sigma
double *

variable_types:
mean
double *

variable_types: sum double


main

canonical_name: main

repo: tbullard/npuzzle

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
return 0;
}

original_code:
int main(void) {
    return 0;
}

canonical_original_code:
int main() {
    return 0;
}

return_type: int


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

if ( a1 )
result = ***a1;
else
result = 0LL;
return result;
}

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

if ( a1 )
result = ***a1;
else
result = 0LL;
return result;
}

original_code:
void* heap_peek(heap* p_queue) {
    void* data;
    data = ((void *)0);
    if(p_queue) {
        data = p_queue->heap_memory[0]->data;
    }
    return data;
}

canonical_original_code:
void *heap_peek(struct priority_queue *p_queue) {
    void *data;
    data = ((void *)0);
    if(p_queue) {
        data = p_queue->heap_memory[0]->data;
    }
    return data;
}

variable_types: struct priority_queue { struct heap_node { void *data; int index; } **heap_memory; unsigned long size; unsigned long capacity; int (*heap_func)(void *, void *); int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); } *

variable_types:
data
void *

return_type: void *

user_defined_types: struct priority_queue { struct heap_node **heap_memory; unsigned long size; unsigned long capacity; int (*heap_func)(void *, void *); int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); }


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

result = 1LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8) == 0LL;
return result;
}

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

result = 1LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8) == 0LL;
return result;
}

original_code:
int heap_is_empty(heap* p_queue) {
    int empty;
    empty = 1;
    if(p_queue) {
        if(p_queue->size) {
            empty = 0;
        }
    }
    return empty;
}

canonical_original_code:
int heap_is_empty(struct priority_queue *p_queue) {
    int empty;
    empty = 1;
    if(p_queue) {
        if(p_queue->size) {
            empty = 0;
        }
    }
    return empty;
}

variable_types: empty int

user_defined_types: struct heap_node { void *data; int index; }


original_code:
int heap_remove(heap* p_queue) {
    int removed, heapd, i;
    node* cur_node, *tmp_node, *l_child, *r_child;
    removed = 0;
    if(p_queue) {
        if(!heap_is_empty(p_queue)) {
            removed = 1;
            heapd = i = 0;
            tmp_node = p_queue->heap_memory[0];
            cur_node = p_queue->heap_memory[p_queue->size - 1];
            p_queue->heap_memory[0] = cur_node;
            cur_node->index = 0;
            p_queue->heap_memory[p_queue->size - 1] = ((void *)0);
            p_queue->free_func(tmp_node->data);
            free(tmp_node);
            --p_queue->size;
            if(!heap_is_empty(p_queue)) {
                while(!heapd) {
                    l_child = r_child = ((void *)0);
                    if((i << 1) + 1 < p_queue->size) {
                        l_child = p_queue->heap_memory[(i << 1) + 1];
                    } else {
                        heapd = 1;
                    }
                    if((i + 1) << 1 < p_queue->size) {
                        r_child = p_queue->heap_memory[(i + 1) << 1];
                    }
                    if(l_child && r_child) {
                        if(p_queue->heap_func(r_child->data, l_child->data)) {
                            if(p_queue->heap_func(cur_node->data,
                                                  l_child->data)) {
                                p_queue->heap_memory[i] = l_child;
                                p_queue->heap_memory[(i << 1) + 1] = cur_node;
                                l_child->index = i;
                                cur_node->index = (i << 1) + 1;
                                i = (i << 1) + 1;
                            } else {
                                heapd = 1;
                            }
                        } else if(p_queue->heap_func(cur_node->data,
                                                     r_child->data)) {
                            p_queue->heap_memory[i] = r_child;
                            p_queue->heap_memory[(i + 1) << 1] = cur_node;
                            r_child->index = i;
                            cur_node->index = (i + 1) << 1;
                            i = (i + 1) << 1;
                        } else {
                            heapd = 1;
                        }
                    } else if(l_child){
                        if(p_queue->heap_func(cur_node->data, l_child->data)) {
                            p_queue->heap_memory[i] = l_child;
                            p_queue->heap_memory[(i << 1) + 1] = cur_node;
                            l_child->index = i;
                            cur_node->index = (i << 1) + 1;
                            i = (i + 1) << 1;
                        } else {
                            heapd = 1;
                        }
                    }
                }
            }
        }
    }
    return removed;
}

canonical_original_code:
int heap_remove(struct priority_queue *p_queue) {
    int removed; int heapd; int i;
    struct heap_node *cur_node; struct heap_node *tmp_node; struct heap_node *l_child; struct heap_node *r_child;
    removed = 0;
    if(p_queue) {
        if(!heap_is_empty(p_queue)) {
            removed = 1;
            heapd = i = 0;
            tmp_node = p_queue->heap_memory[0];
            cur_node = p_queue->heap_memory[p_queue->size - 1];
            p_queue->heap_memory[0] = cur_node;
            cur_node->index = 0;
            p_queue->heap_memory[p_queue->size - 1] = ((void *)0);
            p_queue->free_func(tmp_node->data);
            free(tmp_node);
            --p_queue->size;
            if(!heap_is_empty(p_queue)) {
                while(!heapd) {
                    l_child = r_child = ((void *)0);
                    if((i << 1) + 1 < p_queue->size) {
                        l_child = p_queue->heap_memory[(i << 1) + 1];
                    } else {
                        heapd = 1;
                    }
                    if((i + 1) << 1 < p_queue->size) {
                        r_child = p_queue->heap_memory[(i + 1) << 1];
                    }
                    if(l_child && r_child) {
                        if(p_queue->heap_func(r_child->data, l_child->data)) {
                            if(p_queue->heap_func(cur_node->data,
                                                  l_child->data)) {
                                p_queue->heap_memory[i] = l_child;
                                p_queue->heap_memory[(i << 1) + 1] = cur_node;
                                l_child->index = i;
                                cur_node->index = (i << 1) + 1;
                                i = (i << 1) + 1;
                            } else {
                                heapd = 1;
                            }
                        } else if(p_queue->heap_func(cur_node->data,
                                                     r_child->data)) {
                            p_queue->heap_memory[i] = r_child;
                            p_queue->heap_memory[(i + 1) << 1] = cur_node;
                            r_child->index = i;
                            cur_node->index = (i + 1) << 1;
                            i = (i + 1) << 1;
                        } else {
                            heapd = 1;
                        }
                    } else if(l_child){
                        if(p_queue->heap_func(cur_node->data, l_child->data)) {
                            p_queue->heap_memory[i] = l_child;
                            p_queue->heap_memory[(i << 1) + 1] = cur_node;
                            l_child->index = i;
                            cur_node->index = (i << 1) + 1;
                            i = (i + 1) << 1;
                        } else {
                            heapd = 1;
                        }
                    }
                }
            }
        }
    }
    return removed;
}

variable_types: removed int

variable_types: heapd int

variable_types: i int

variable_types: struct heap_node { void *data; int index; } *


decompiled_code:
__int64 __fastcall heap_up_mod_data(__int64 a1, _QWORD *a2, __int64 a3)
{
__int64 result; // rax
_BOOL4 v5; // edx
int v6; // ebx
int v7; // er14
__int64 v8; // r13

if ( !a1 )
return 0LL;
result = 0LL;
if ( a2 )
{
v5 = heap_is_empty(a1);
result = 0LL;
if ( !v5 )
{
(*(void (__fastcall **)(_QWORD))(a1 + 48))(*a2);
*a2 = a3;
v6 = *((_DWORD *)a2 + 2);
*((_DWORD *)a2 + 2) = 0;
if ( v6 )
{
do
{
v7 = v6;
v6 = (v6 - 1) >> 1;
v8 = *(_QWORD *)(*(_QWORD *)a1 + 8LL * v6);
if ( !(*(unsigned int (__fastcall **)(_QWORD, _QWORD))(a1 + 24))(*(_QWORD *)v8, *a2) )
{
*((_DWORD *)a2 + 2) = v7;
return 1LL;
}
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v6) = a2;
*(_QWORD *)(*(_QWORD *)a1 + 8LL * v7) = v8;
*(_DWORD *)(v8 + 8) = v7;
}
while ( v6 );
result = 1LL;
}
else
{
result = 1LL;
}
}
}
return result;
}

original_code:
int heap_up_mod_data(heap* p_queue, void* change_node, void* data) {
    int moded, heapd, i;
    node* cur_node, *tmp_node;
    moded = heapd = 0;
    if(p_queue && change_node) {
        if(!heap_is_empty(p_queue)) {
            moded = 1;
            cur_node = (node*)change_node;
            p_queue->free_func(cur_node->data);
            cur_node->data = data;
            i = cur_node->index;
            cur_node->index = 0;
            while(!heapd && i) {
                tmp_node = p_queue->heap_memory[(i - 1) >> 1];
                if(p_queue->heap_func(tmp_node->data, cur_node->data)) {
                    p_queue->heap_memory[(i - 1) >> 1] = cur_node;
                    p_queue->heap_memory[i] = tmp_node;
                    tmp_node->index = i;
                    i = (i - 1) >> 1;
                } else {
                    cur_node->index = i;
                    heapd = 1;
                }
            }
        }
    }
    return moded;
}

canonical_original_code:
int heap_up_mod_data(struct priority_queue *p_queue, void *change_node, void *data) {
    int moded; int heapd; int i;
    struct heap_node *cur_node; struct heap_node *tmp_node;
    moded = heapd = 0;
    if(p_queue && change_node) {
        if(!heap_is_empty(p_queue)) {
            moded = 1;
            cur_node = (struct heap_node *)change_node;
            p_queue->free_func(cur_node->data);
            cur_node->data = data;
            i = cur_node->index;
            cur_node->index = 0;
            while(!heapd && i) {
                tmp_node = p_queue->heap_memory[(i - 1) >> 1];
                if(p_queue->heap_func(tmp_node->data, cur_node->data)) {
                    p_queue->heap_memory[(i - 1) >> 1] = cur_node;
                    p_queue->heap_memory[i] = tmp_node;
                    tmp_node->index = i;
                    i = (i - 1) >> 1;
                } else {
                    cur_node->index = i;
                    heapd = 1;
                }
            }
        }
    }
    return moded;
}

variable_types: moded int


decompiled_code:
_BOOL8 __fastcall heap_contains(__int64 a1, __int64 a2)
{
_BOOL4 v2; // er12
__int64 v3; // rbp

v2 = 0;
if ( a1 )
{
v2 = heap_is_empty(a1);
if ( v2 )
{
v2 = 0;
}
else if ( *(_QWORD *)(a1 + 8) )
{
v3 = 0LL;
while ( (*(unsigned int (__fastcall **)(_QWORD, __int64))(a1 + 32))(**(_QWORD **)(*(_QWORD *)a1 + 8 * v3), a2) )
{
if ( *(_QWORD *)(a1 + 8) <= (unsigned __int64)++v3 )
return v2;
}
v2 = 1;
}
}
return v2;
}

original_code:
int heap_contains(heap* p_queue, const void* data) {
    int contains, i;
    node* cur_node;
    contains = 0;
    if(p_queue) {
        if(!heap_is_empty(p_queue)) {
            for(i = 0; i < p_queue->size && !contains; i++) {
                cur_node = p_queue->heap_memory[i];
                if(!p_queue->comp_func(cur_node->data, data)) {
                    contains = 1;
                }
            }
        }
    }
    return contains;
}

canonical_original_code:
int heap_contains(struct priority_queue *p_queue, void *data) {
    int contains; int i;
    struct heap_node *cur_node;
    contains = 0;
    if(p_queue) {
        if(!heap_is_empty(p_queue)) {
            for(i = 0; i < p_queue->size && !contains; i++) {
                cur_node = p_queue->heap_memory[i];
                if(!p_queue->comp_func(cur_node->data, data)) {
                    contains = 1;
                }
            }
        }
    }
    return contains;
}

variable_types: contains int


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

result = 0LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
size_t heap_size(heap* p_queue) {
    size_t size;
    if(p_queue) {
        size = p_queue->size;
    }
    return size;
}

canonical_original_code:
unsigned long heap_size(struct priority_queue *p_queue) {
    unsigned long size;
    if(p_queue) {
        size = p_queue->size;
    }
    return size;
}

variable_types:
size
unsigned long

return_type: unsigned long


original_code:
void heap_empty(heap* p_queue) {
    int i;
    node* cur_node;
    if(p_queue) {
        if(!heap_is_empty(p_queue)) {
            for(i = 0; i < p_queue->size; i++) {
                cur_node = p_queue->heap_memory[i];
                p_queue->heap_memory[i] = ((void *)0);
                p_queue->free_func(cur_node->data);
                free(cur_node);
            }
        }
    }
    return;
}

canonical_original_code:
void heap_empty(struct priority_queue *p_queue) {
    int i;
    struct heap_node *cur_node;
    if(p_queue) {
        if(!heap_is_empty(p_queue)) {
            for(i = 0; i < p_queue->size; i++) {
                cur_node = p_queue->heap_memory[i];
                p_queue->heap_memory[i] = ((void *)0);
                p_queue->free_func(cur_node->data);
                free(cur_node);
            }
        }
    }
    return;
}


decompiled_code:
void __fastcall heap_kill(void *ptr)
{
if ( ptr )
{
heap_empty((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
if ( ptr )
{
func6((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void heap_kill(heap* p_queue) {
    if(p_queue) {
        heap_empty(p_queue);
        free(p_queue->heap_memory);
        free(p_queue);
    }
    return;
}

canonical_original_code:
void heap_kill(struct priority_queue *p_queue) {
    if(p_queue) {
        heap_empty(p_queue);
        free(p_queue->heap_memory);
        free(p_queue);
    }
    return;
}


decompiled_code:
void __fastcall heap_dissolve(void *ptr)
{
unsigned __int64 v2; // rbx
void **v3; // rax
void *v4; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
{
v3 = (void **)(*(_QWORD *)ptr + 8 * v2);
v4 = *v3;
*v3 = 0LL;
free(v4);
++v2;
}
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
unsigned __int64 v2; // rbx
void **v3; // rax
void *v4; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 1) )
{
v2 = 0LL;
do
{
v3 = (void **)(*(_QWORD *)ptr + 8 * v2);
v4 = *v3;
*v3 = 0LL;
free(v4);
++v2;
}
while ( *((_QWORD *)ptr + 1) > v2 );
}
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void heap_dissolve(heap* p_queue) {
    int i;
    node* cur_node;
    if(p_queue) {
        for(i = 0; i < p_queue->size; i++) {
            cur_node = p_queue->heap_memory[i];
            p_queue->heap_memory[i] = ((void *)0);
            free(cur_node);
        }
        free(p_queue->heap_memory);
        free(p_queue);
    }
    return;
}

canonical_original_code:
void heap_dissolve(struct priority_queue *p_queue) {
    int i;
    struct heap_node *cur_node;
    if(p_queue) {
        for(i = 0; i < p_queue->size; i++) {
            cur_node = p_queue->heap_memory[i];
            p_queue->heap_memory[i] = ((void *)0);
            free(cur_node);
        }
        free(p_queue->heap_memory);
        free(p_queue);
    }
    return;
}


decompiled_code:
void __fastcall heap_traverse(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
unsigned __int64 v2; // rbx

if ( a1 && !heap_is_empty((__int64)a1) && a1[1] )
{
v2 = 0LL;
do
a2(**(_QWORD **)(*a1 + 8 * v2++));
while ( a1[1] > v2 );
}
}

canonical_decompiled_code:
void __fastcall func9(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
unsigned __int64 v2; // rbx

if ( a1 && !func1((__int64)a1) && a1[1] )
{
v2 = 0LL;
do
a2(**(_QWORD **)(*a1 + 8 * v2++));
while ( a1[1] > v2 );
}
}

original_code:
void heap_traverse(heap* p_queue, generic_op do_func) {
    int i;
    node* cur_node;
    if(p_queue) {
        if(!heap_is_empty(p_queue)) {
            for(i = 0; i < p_queue->size; i++) {
                cur_node = p_queue->heap_memory[i];
                do_func(cur_node->data);
            }
        }
    }
    return;
}

canonical_original_code:
void heap_traverse(struct priority_queue *p_queue, void (*do_func)(void *)) {
    int i;
    struct heap_node *cur_node;
    if(p_queue) {
        if(!heap_is_empty(p_queue)) {
            for(i = 0; i < p_queue->size; i++) {
                cur_node = p_queue->heap_memory[i];
                do_func(cur_node->data);
            }
        }
    }
    return;
}


decompiled_code:
void __fastcall list_push_front(__int64 a1, __int64 a2)
{
_QWORD *v2; // rax

if ( a1 )
{
v2 = list_node_create(a2);
if ( *(_QWORD *)a1 )
**(_QWORD **)a1 = v2;
else
*(_QWORD *)(a1 + 8) = v2;
v2[1] = *(_QWORD *)a1;
*(_QWORD *)a1 = v2;
++*(_QWORD *)(a1 + 16);
}
}

original_code:
void list_push_front(list* llist, void* data) {
    node* new_node;
    if(llist) {
        new_node = list_node_create(data);
        if(llist->head) {
            llist->head->prev = new_node;
        } else {
            llist->tail = new_node;
        }
        new_node->next = llist->head;
        llist->head = new_node;
        llist->size++;
    }
    return;
}

canonical_original_code:
void list_push_front(struct linked_list *llist, void *data) {
    struct list_node *new_node;
    if(llist) {
        new_node = list_node_create(data);
        if(llist->head) {
            llist->head->prev = new_node;
        } else {
            llist->tail = new_node;
        }
        new_node->next = llist->head;
        llist->head = new_node;
        llist->size++;
    }
    return;
}

variable_types: struct linked_list { struct list_node { struct list_node *prev; struct list_node *next; void *data; } *head; struct list_node *tail; unsigned long size; int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); } *

user_defined_types: struct linked_list { struct list_node *head; struct list_node *tail; unsigned long size; int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); }


original_code:
void list_push_back(list* llist, void* data) {
    node* new_node;
    if(llist) {
        new_node = list_node_create(data);
        if(llist->tail) {
            llist->tail->next = new_node;
        } else {
            llist->head = new_node;
        }
        new_node->prev = llist->tail;
        llist->tail = new_node;
        llist->size++;
    }
    return;
}

canonical_original_code:
void list_push_back(struct linked_list *llist, void *data) {
    struct list_node *new_node;
    if(llist) {
        new_node = list_node_create(data);
        if(llist->tail) {
            llist->tail->next = new_node;
        } else {
            llist->head = new_node;
        }
        new_node->prev = llist->tail;
        llist->tail = new_node;
        llist->size++;
    }
    return;
}

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


decompiled_code:
__int64 __fastcall list_insert_at(_QWORD *a1, int a2, __int64 a3)
{
__int64 result; // rax
unsigned __int64 v4; // rcx
_QWORD *v5; // rcx
_QWORD *v6; // rdx
int i; // eax

if ( a2 < 0 )
return 0LL;
result = 0LL;
if ( a1 )
{
v4 = a1[2];
result = 0LL;
if ( a2 <= v4 )
{
if ( a2 )
{
if ( a2 == v4 )
{
list_push_back(a1, a3);
result = 1LL;
}
else
{
v5 = list_node_create(a3);
v6 = (_QWORD *)*a1;
for ( i = 0; i != a2; ++i )
v6 = (_QWORD *)v6[1];
*(_QWORD *)(*v6 + 8LL) = v5;
*v5 = *v6;
v5[1] = v6;
*v6 = v5;
++a1[2];
result = 1LL;
}
}
else
{
list_push_front((__int64)a1, a3);
result = 1LL;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, int a2, __int64 a3)
{
__int64 result; // rax
unsigned __int64 v4; // rcx
_QWORD *v5; // rcx
_QWORD *v6; // rdx
int i; // eax

if ( a2 < 0 )
return 0LL;
result = 0LL;
if ( a1 )
{
v4 = a1[2];
result = 0LL;
if ( a2 <= v4 )
{
if ( a2 )
{
if ( a2 == v4 )
{
func1(a1, a3);
result = 1LL;
}
else
{
v5 = list_node_create(a3);
v6 = (_QWORD *)*a1;
for ( i = 0; i != a2; ++i )
v6 = (_QWORD *)v6[1];
*(_QWORD *)(*v6 + 8LL) = v5;
*v5 = *v6;
v5[1] = v6;
*v6 = v5;
++a1[2];
result = 1LL;
}
}
else
{
func0((__int64)a1, a3);
result = 1LL;
}
}
}
return result;
}

original_code:
int list_insert_at(list* llist, int index, void* data) {
    int insert, cur_Index;
    node* cur_node;
    node* new_node;
    insert = 0;
    if(llist) {
        insert = (index > -1 && index <= llist->size) ? 1 : 0;
        if(insert) {
            if(index) {
                if(index != llist->size) {
                    new_node = list_node_create(data);
                    cur_Index = 0;
                    cur_node = llist->head;
                    while(cur_Index != index) {
                        cur_node = cur_node->next;
                        cur_Index++;
                    }
                    cur_node->prev->next = new_node;
                    new_node->prev = cur_node->prev;
                    new_node->next = cur_node;
                    cur_node->prev = new_node;
                    llist->size++;
                } else {
                    list_push_back(llist, data);
                }
            } else {
                list_push_front(llist, data);
            }
        }
    }
    return insert;
}

canonical_original_code:
int list_insert_at(struct linked_list *llist, int index, void *data) {
    int insert; int cur_Index;
    struct list_node *cur_node;
    struct list_node *new_node;
    insert = 0;
    if(llist) {
        insert = (index > -1 && index <= llist->size) ? 1 : 0;
        if(insert) {
            if(index) {
                if(index != llist->size) {
                    new_node = list_node_create(data);
                    cur_Index = 0;
                    cur_node = llist->head;
                    while(cur_Index != index) {
                        cur_node = cur_node->next;
                        cur_Index++;
                    }
                    cur_node->prev->next = new_node;
                    new_node->prev = cur_node->prev;
                    new_node->next = cur_node;
                    cur_node->prev = new_node;
                    llist->size++;
                } else {
                    list_push_back(llist, data);
                }
            } else {
                list_push_front(llist, data);
            }
        }
    }
    return insert;
}

variable_types: index int

variable_types: insert int

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


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

result = 1LL;
if ( a1 )
result = *(_QWORD *)(a1 + 16) == 0LL;
return result;
}

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

result = 1LL;
if ( a1 )
result = *(_QWORD *)(a1 + 16) == 0LL;
return result;
}

original_code:
int list_is_empty(list* llist) {
    int empty;
    empty = 1;
    if(llist) {
        if(llist->size) {
            empty = 0;
        }
    }
    return empty;
}

canonical_original_code:
int list_is_empty(struct linked_list *llist) {
    int empty;
    empty = 1;
    if(llist) {
        if(llist->size) {
            empty = 0;
        }
    }
    return empty;
}


decompiled_code:
__int64 __fastcall list_remove_front(__int64 a1)
{
__int64 result; // rax
_BOOL4 v2; // edx
__int64 v3; // rax

result = 0LL;
if ( a1 )
{
v2 = list_is_empty(a1);
result = 0LL;
if ( !v2 )
{
--*(_QWORD *)(a1 + 16);
(*(void (__fastcall **)(_QWORD))(a1 + 40))(*(_QWORD *)(*(_QWORD *)a1 + 16LL));
if ( *(_QWORD *)(a1 + 16) )
{
v3 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
*(_QWORD *)a1 = v3;
*(_QWORD *)(*(_QWORD *)v3 + 8LL) = 0LL;
free(**(void ***)a1);
**(_QWORD **)a1 = 0LL;
}
else
{
*(_QWORD *)(a1 + 8) = 0LL;
free(*(void **)a1);
*(_QWORD *)a1 = 0LL;
}
result = 1LL;
}
}
return result;
}

original_code:
int list_remove_front(list* llist) {
    int removeal;
    removeal = 0;
    if(llist) {
        removeal = !list_is_empty(llist) ? 1 : 0;
        if(removeal) {
            --llist->size;
            llist->free_func(llist->head->data);
            if(llist->size) {
                llist->head = llist->head->next;
                llist->head->prev->next = ((void *)0);
                free(llist->head->prev);
                llist->head->prev = ((void *)0);
            } else {
                llist->tail = ((void *)0);
                free(llist->head);
                llist->head = ((void *)0);
            }
        }
    }
    return removeal;
}

canonical_original_code:
int list_remove_front(struct linked_list *llist) {
    int removeal;
    removeal = 0;
    if(llist) {
        removeal = !list_is_empty(llist) ? 1 : 0;
        if(removeal) {
            --llist->size;
            llist->free_func(llist->head->data);
            if(llist->size) {
                llist->head = llist->head->next;
                llist->head->prev->next = ((void *)0);
                free(llist->head->prev);
                llist->head->prev = ((void *)0);
            } else {
                llist->tail = ((void *)0);
                free(llist->head);
                llist->head = ((void *)0);
            }
        }
    }
    return removeal;
}

variable_types: removeal int


original_code:
int list_remove_back(list* llist) {
    int removeal;
    removeal = 0;
    if(llist) {
        removeal = !list_is_empty(llist) ? 1 : 0;
        if(removeal) {
            --llist->size;
            llist->free_func(llist->tail->data);
            if(llist->size) {
                llist->tail = llist->tail->prev;
                llist->tail->next->prev = ((void *)0);
                free(llist->tail->next);
                llist->tail->next = ((void *)0);
            } else {
                llist->tail = ((void *)0);
                free(llist->head);
                llist->head = ((void *)0);
            }
        }
    }
    return removeal;
}

canonical_original_code:
int list_remove_back(struct linked_list *llist) {
    int removeal;
    removeal = 0;
    if(llist) {
        removeal = !list_is_empty(llist) ? 1 : 0;
        if(removeal) {
            --llist->size;
            llist->free_func(llist->tail->data);
            if(llist->size) {
                llist->tail = llist->tail->prev;
                llist->tail->next->prev = ((void *)0);
                free(llist->tail->next);
                llist->tail->next = ((void *)0);
            } else {
                llist->tail = ((void *)0);
                free(llist->head);
                llist->head = ((void *)0);
            }
        }
    }
    return removeal;
}


decompiled_code:
__int64 __fastcall list_pop(_QWORD *a1)
{
__int64 result; // rax
_BOOL4 v3; // edx
void *v4; // rdi
_QWORD *v5; // rax

result = 0LL;
if ( a1 )
{
v3 = list_is_empty((__int64)a1);
result = 0LL;
if ( !v3 )
{
--a1[2];
v4 = (void *)*a1;
v5 = *(_QWORD **)(*a1 + 8LL);
*a1 = v5;
if ( v5 )
*v5 = 0LL;
else
a1[1] = 0LL;
free(v4);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
__int64 result; // rax
_BOOL4 v3; // edx
void *v4; // rdi
_QWORD *v5; // rax

result = 0LL;
if ( a1 )
{
v3 = func3((__int64)a1);
result = 0LL;
if ( !v3 )
{
--a1[2];
v4 = (void *)*a1;
v5 = *(_QWORD **)(*a1 + 8LL);
*a1 = v5;
if ( v5 )
*v5 = 0LL;
else
a1[1] = 0LL;
free(v4);
result = 1LL;
}
}
return result;
}

original_code:
int list_pop(list* llist) {
    int popped;
    node* cur_node;
    popped = 0;
    if(llist) {
        if(!list_is_empty(llist)) {
            popped = 1;
            --llist->size;
            cur_node = llist->head;
            llist->head = llist->head->next;
            if(llist->head) {
                llist->head->prev = ((void *)0);
            } else {
                llist->tail = ((void *)0);
            }
            cur_node->next = ((void *)0);
            free(cur_node);
        }
    }
    return popped;
}

canonical_original_code:
int list_pop(struct linked_list *llist) {
    int popped;
    struct list_node *cur_node;
    popped = 0;
    if(llist) {
        if(!list_is_empty(llist)) {
            popped = 1;
            --llist->size;
            cur_node = llist->head;
            llist->head = llist->head->next;
            if(llist->head) {
                llist->head->prev = ((void *)0);
            } else {
                llist->tail = ((void *)0);
            }
            cur_node->next = ((void *)0);
            free(cur_node);
        }
    }
    return popped;
}

variable_types: popped int


decompiled_code:
__int64 __fastcall list_deque(_QWORD *a1)
{
__int64 result; // rax
_BOOL4 v3; // edx
__int64 *v4; // rdi
__int64 v5; // rax

result = 0LL;
if ( a1 )
{
v3 = list_is_empty((__int64)a1);
result = 0LL;
if ( !v3 )
{
--a1[2];
v4 = (__int64 *)a1[1];
v5 = *v4;
a1[1] = *v4;
if ( v5 )
*(_QWORD *)(v5 + 8) = 0LL;
else
*a1 = 0LL;
free(v4);
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
__int64 result; // rax
_BOOL4 v3; // edx
__int64 *v4; // rdi
__int64 v5; // rax

result = 0LL;
if ( a1 )
{
v3 = func3((__int64)a1);
result = 0LL;
if ( !v3 )
{
--a1[2];
v4 = (__int64 *)a1[1];
v5 = *v4;
a1[1] = *v4;
if ( v5 )
*(_QWORD *)(v5 + 8) = 0LL;
else
*a1 = 0LL;
free(v4);
result = 1LL;
}
}
return result;
}

original_code:
int list_deque(list* llist) {
    int dequed;
    node* cur_node;
    dequed = 0;
    if(llist) {
        if(!list_is_empty(llist)) {
            dequed = 1;
            --llist->size;
            cur_node = llist->tail;
            llist->tail = llist->tail->prev;
            if(llist->tail) {
                llist->tail->next = ((void *)0);
            } else {
                llist->head = ((void *)0);
            }
            cur_node->prev = ((void *)0);
            free(cur_node);
        }
    }
    return dequed;
}

canonical_original_code:
int list_deque(struct linked_list *llist) {
    int dequed;
    struct list_node *cur_node;
    dequed = 0;
    if(llist) {
        if(!list_is_empty(llist)) {
            dequed = 1;
            --llist->size;
            cur_node = llist->tail;
            llist->tail = llist->tail->prev;
            if(llist->tail) {
                llist->tail->next = ((void *)0);
            } else {
                llist->head = ((void *)0);
            }
            cur_node->prev = ((void *)0);
            free(cur_node);
        }
    }
    return dequed;
}

variable_types: dequed int


decompiled_code:
__int64 __fastcall list_remove_at_index(__int64 a1, int a2)
{
__int64 result; // rax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // rdx
__int64 *v5; // r12
__int64 v6; // rax

if ( a2 < 0 )
return 0LL;
result = 0LL;
if ( a1 )
{
result = list_is_empty(a1);
if ( (_DWORD)result )
{
result = 0LL;
}
else
{
v3 = *(_QWORD *)(a1 + 16);
if ( a2 < v3 )
{
if ( a2 )
{
v4 = v3 - 1;
if ( a2 == v4 )
{
list_remove_back(a1);
result = 1LL;
}
else
{
v5 = *(__int64 **)a1;
do
{
v5 = (__int64 *)v5[1];
LODWORD(result) = result + 1;
}
while ( a2 != (_DWORD)result );
*(_QWORD *)(a1 + 16) = v4;
(*(void (__fastcall **)(__int64))(a1 + 40))(v5[2]);
v6 = *v5;
*(_QWORD *)v5[1] = *v5;
*(_QWORD *)(v6 + 8) = v5[1];
free(v5);
result = 1LL;
}
}
else
{
list_remove_front(a1);
result = 1LL;
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
__int64 result; // rax
unsigned __int64 v3; // rdx
unsigned __int64 v4; // rdx
__int64 *v5; // r12
__int64 v6; // rax

if ( a2 < 0 )
return 0LL;
result = 0LL;
if ( a1 )
{
result = func3(a1);
if ( (_DWORD)result )
{
result = 0LL;
}
else
{
v3 = *(_QWORD *)(a1 + 16);
if ( a2 < v3 )
{
if ( a2 )
{
v4 = v3 - 1;
if ( a2 == v4 )
{
func5(a1);
result = 1LL;
}
else
{
v5 = *(__int64 **)a1;
do
{
v5 = (__int64 *)v5[1];
LODWORD(result) = result + 1;
}
while ( a2 != (_DWORD)result );
*(_QWORD *)(a1 + 16) = v4;
(*(void (__fastcall **)(__int64))(a1 + 40))(v5[2]);
v6 = *v5;
*(_QWORD *)v5[1] = *v5;
*(_QWORD *)(v6 + 8) = v5[1];
free(v5);
result = 1LL;
}
}
else
{
func4(a1);
result = 1LL;
}
}
}
}
return result;
}

original_code:
int list_remove_at_index(list* llist, int index) {
    int removeal, found, cur_Index;
    node* cur_node;
    cur_node = ((void *)0);
    removeal = 0;
    if(llist) {
        found = cur_Index = 0;
        removeal = (index > -1 && !list_is_empty(llist) &&
                    index < llist->size) ? 1 : 0;
        if(removeal) {
            if(!index) {
                list_remove_front(llist);
            } else if(index == (llist->size - 1)) {
                list_remove_back(llist);
            } else {
                cur_node = llist->head;
                while(!found) {
                    if(cur_Index == index) {
                        found = 1;
                        --llist->size;
                        llist->free_func(cur_node->data);
                        cur_node->next->prev = cur_node->prev;
                        cur_node->prev->next = cur_node->next;
                        cur_node->next = ((void *)0);
                        cur_node->prev = ((void *)0);
                        free(cur_node);
                    } else {
                        cur_node = cur_node->next;
                        cur_Index++;
                    }
                }
            }
        }
    }
    return removeal;
}

canonical_original_code:
int list_remove_at_index(struct linked_list *llist, int index) {
    int removeal; int found; int cur_Index;
    struct list_node *cur_node;
    cur_node = ((void *)0);
    removeal = 0;
    if(llist) {
        found = cur_Index = 0;
        removeal = (index > -1 && !list_is_empty(llist) &&
                    index < llist->size) ? 1 : 0;
        if(removeal) {
            if(!index) {
                list_remove_front(llist);
            } else if(index == (llist->size - 1)) {
                list_remove_back(llist);
            } else {
                cur_node = llist->head;
                while(!found) {
                    if(cur_Index == index) {
                        found = 1;
                        --llist->size;
                        llist->free_func(cur_node->data);
                        cur_node->next->prev = cur_node->prev;
                        cur_node->prev->next = cur_node->next;
                        cur_node->next = ((void *)0);
                        cur_node->prev = ((void *)0);
                        free(cur_node);
                    } else {
                        cur_node = cur_node->next;
                        cur_Index++;
                    }
                }
            }
        }
    }
    return removeal;
}

variable_types: found int


original_code:
int list_remove_if(list* llist, generic_pred pred_func) {
    int count;
    node* past_node;
    node* cur_node;
    cur_node = ((void *)0);
    past_node = ((void *)0);
    count = 0;
    if(llist) {
        if(!list_is_empty(llist)) {
            past_node = llist->head;
            cur_node = llist->head->next;
            while(past_node && pred_func(past_node->data)) {
                past_node = past_node->next;
                if(past_node) {
                    cur_node = past_node->next;
                }
                list_remove_front(llist);
                count++;
            }
            while(cur_node) {
                if(pred_func(cur_node->data)) {
                    if(cur_node != llist->tail) {
                        --llist->size;
                        llist->free_func(cur_node->data);
                        cur_node = cur_node->next;
                        cur_node->prev = cur_node->prev->prev;
                        past_node = past_node->next;
                        past_node->prev->next = past_node->next;
                        past_node->prev = ((void *)0);
                        past_node->next = ((void *)0);
                        free(past_node);
                        past_node = cur_node->prev;
                    } else {
                        list_remove_back(llist);
                        past_node = ((void *)0);
                        cur_node = ((void *)0);
                    }
                    count++;
                } else {
                    past_node = past_node->next;
                    cur_node = past_node->next;
                }
            }
        }
    }
    return count;
}

canonical_original_code:
int list_remove_if(struct linked_list *llist, int (*pred_func)(void *)) {
    int count;
    struct list_node *past_node;
    struct list_node *cur_node;
    cur_node = ((void *)0);
    past_node = ((void *)0);
    count = 0;
    if(llist) {
        if(!list_is_empty(llist)) {
            past_node = llist->head;
            cur_node = llist->head->next;
            while(past_node && pred_func(past_node->data)) {
                past_node = past_node->next;
                if(past_node) {
                    cur_node = past_node->next;
                }
                list_remove_front(llist);
                count++;
            }
            while(cur_node) {
                if(pred_func(cur_node->data)) {
                    if(cur_node != llist->tail) {
                        --llist->size;
                        llist->free_func(cur_node->data);
                        cur_node = cur_node->next;
                        cur_node->prev = cur_node->prev->prev;
                        past_node = past_node->next;
                        past_node->prev->next = past_node->next;
                        past_node->prev = ((void *)0);
                        past_node->next = ((void *)0);
                        free(past_node);
                        past_node = cur_node->prev;
                    } else {
                        list_remove_back(llist);
                        past_node = ((void *)0);
                        cur_node = ((void *)0);
                    }
                    count++;
                } else {
                    past_node = past_node->next;
                    cur_node = past_node->next;
                }
            }
        }
    }
    return count;
}

variable_types: count int


original_code:
void* list_get_at(list* llist, int index) {
    int cur_Index, found, in_range;
    node* cur_node;
    cur_node = ((void *)0);
    if(llist) {
        cur_node = llist->head;
        cur_Index = found = 0;
        in_range = (index > -1 && !list_is_empty(llist) &&
                    index < llist->size) ? 1 : 0;
        if(in_range) {
            while(!found) {
                if(cur_Index == index) {
                    found = 1;
                } else {
                    cur_node = cur_node->next;
                    cur_Index++;
                }
            }
        }
    }
    return cur_node ? cur_node->data : ((void *)0);
}

canonical_original_code:
void *list_get_at(struct linked_list *llist, int index) {
    int cur_Index; int found; int in_range;
    struct list_node *cur_node;
    cur_node = ((void *)0);
    if(llist) {
        cur_node = llist->head;
        cur_Index = found = 0;
        in_range = (index > -1 && !list_is_empty(llist) &&
                    index < llist->size) ? 1 : 0;
        if(in_range) {
            while(!found) {
                if(cur_Index == index) {
                    found = 1;
                } else {
                    cur_node = cur_node->next;
                    cur_Index++;
                }
            }
        }
    }
    return cur_node ? cur_node->data : ((void *)0);
}


decompiled_code:
__int64 __fastcall list_front(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = list_is_empty(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = func3(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(*(_QWORD *)a1 + 16LL);
return result;
}

original_code:
void* list_front(list* llist) {
    void* data;
    data = ((void *)0);
    if(llist) {
        data = !list_is_empty(llist) ? llist->head->data : ((void *)0);
    }
    return data;
}

canonical_original_code:
void *list_front(struct linked_list *llist) {
    void *data;
    data = ((void *)0);
    if(llist) {
        data = !list_is_empty(llist) ? llist->head->data : ((void *)0);
    }
    return data;
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall list_back(__int64 a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

if ( !a1 )
return 0LL;
v1 = list_is_empty(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL);
return result;
}

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

if ( !a1 )
return 0LL;
v1 = func3(a1);
result = 0LL;
if ( !v1 )
result = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 16LL);
return result;
}

original_code:
void* list_back(list* llist) {
    void* data;
    data = ((void *)0);
    if(llist) {
        data = !list_is_empty(llist) ? llist->tail->data : ((void *)0);
    }
    return data;
}

canonical_original_code:
void *list_back(struct linked_list *llist) {
    void *data;
    data = ((void *)0);
    if(llist) {
        data = !list_is_empty(llist) ? llist->tail->data : ((void *)0);
    }
    return data;
}


original_code:
int list_contains(list* llist, const void* data) {
    int found;
    node* cur_node;
    found = 0;
    if(llist) {
        cur_node = llist->head;
        if(!list_is_empty(llist)) {
            while(!found && cur_node) {
                if(!llist->comp_func(cur_node->data, data)) {
                    found = 1;
                } else {
                    cur_node = cur_node->next;
                }
            }
        }
    }
    return found;
}

canonical_original_code:
int list_contains(struct linked_list *llist, void *data) {
    int found;
    struct list_node *cur_node;
    found = 0;
    if(llist) {
        cur_node = llist->head;
        if(!list_is_empty(llist)) {
            while(!found && cur_node) {
                if(!llist->comp_func(cur_node->data, data)) {
                    found = 1;
                } else {
                    cur_node = cur_node->next;
                }
            }
        }
    }
    return found;
}


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

LODWORD(result) = 0;
if ( a1 )
LODWORD(result) = *(_DWORD *)(a1 + 16);
return (int)result;
}

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

LODWORD(result) = 0;
if ( a1 )
LODWORD(result) = *(_DWORD *)(a1 + 16);
return (int)result;
}

original_code:
size_t list_size(list* llist) {
    int size;
    size = 0;
    if(llist) {
        size = llist->size;
    }
    return size;
}

canonical_original_code:
unsigned long list_size(struct linked_list *llist) {
    int size;
    size = 0;
    if(llist) {
        size = llist->size;
    }
    return size;
}

variable_types: size int


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

if ( a1 && *(_QWORD *)(a1 + 16) )
{
do
result = list_remove_front(a1);
while ( *(_QWORD *)(a1 + 16) );
}
return result;
}

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

if ( a1 && *(_QWORD *)(a1 + 16) )
{
do
result = func4(a1);
while ( *(_QWORD *)(a1 + 16) );
}
return result;
}

original_code:
void list_empty(list* llist) {
    if(llist) {
        while(llist->size) {
            list_remove_front(llist);
        }
    }
    return;
}

canonical_original_code:
void list_empty(struct linked_list *llist) {
    if(llist) {
        while(llist->size) {
            list_remove_front(llist);
        }
    }
    return;
}


decompiled_code:
void __fastcall list_kill(void *ptr)
{
if ( ptr )
{
list_empty((__int64)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func16(void *ptr)
{
if ( ptr )
{
func15((__int64)ptr);
free(ptr);
}
}

original_code:
void list_kill(list* llist) {
    if(llist) {
        list_empty(llist);
        free(llist);
    }
    return;
}

canonical_original_code:
void list_kill(struct linked_list *llist) {
    if(llist) {
        list_empty(llist);
        free(llist);
    }
    return;
}


decompiled_code:
void __fastcall list_dissolve(void *ptr)
{
if ( ptr )
{
while ( !list_is_empty((__int64)ptr) )
list_pop(ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func17(void *ptr)
{
if ( ptr )
{
while ( !func3((__int64)ptr) )
func6(ptr);
free(ptr);
}
}

original_code:
void list_dissolve(list* llist) {
    if(llist) {
        while(!list_is_empty(llist)) {
            list_pop(llist);
        }
        free(llist);
    }
    return;
}

canonical_original_code:
void list_dissolve(struct linked_list *llist) {
    if(llist) {
        while(!list_is_empty(llist)) {
            list_pop(llist);
        }
        free(llist);
    }
    return;
}


decompiled_code:
__int64 __fastcall list_traverse(__int64 *a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 i; // rbx
__int64 result; // rax

if ( a1 )
{
for ( i = *a1; i; i = *(_QWORD *)(i + 8) )
result = a2(*(_QWORD *)(i + 16));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(__int64 *a1, __int64 (__fastcall *a2)(_QWORD))
{
__int64 i; // rbx
__int64 result; // rax

if ( a1 )
{
for ( i = *a1; i; i = *(_QWORD *)(i + 8) )
result = a2(*(_QWORD *)(i + 16));
}
return result;
}

original_code:
void list_traverse(list* llist, generic_op do_func) {
    node* cur_node;
    if(llist) {
        cur_node = llist->head;
        while(cur_node) {
            do_func(cur_node->data);
            cur_node = cur_node->next;
        }
    }
    return;
}

canonical_original_code:
void list_traverse(struct linked_list *llist, void (*do_func)(void *)) {
    struct list_node *cur_node;
    if(llist) {
        cur_node = llist->head;
        while(cur_node) {
            do_func(cur_node->data);
            cur_node = cur_node->next;
        }
    }
    return;
}


original_code:
int hash_table_insert(hash_table* hash, void* data, int soft_insert) {
    int inserted, i, j, new_Capacity, empty;
    unsigned int hash_key;
    bucket* new_Bucket;
    bucket* cur_Bucket;
    bucket* dest_Bucket;
    hash_table* new_Hash;
    inserted = empty = 0;
    if(hash) {
        inserted = 1;
        if(hash->cur_load_factor >= hash->load_factor_limit) {
            new_Capacity = (2 * hash->capacity) + 1;
            new_Hash = hash_table_create(new_Capacity,
                                         hash->load_factor_limit,
                                         hash->hash_alg,
                                         hash->comp_func,
                                         hash->copy_func,
                                         hash->free_func);
            new_Hash->size = hash->size;
            for(i = 0; i < hash->capacity; i++) {
                cur_Bucket = hash->bucket_list[i];
                if(cur_Bucket) {
                    if(!cur_Bucket->removed) {
                        j = 0;
                        cur_Bucket->hash_key = new_Hash->hash_alg(cur_Bucket->data) % new_Capacity;
                        dest_Bucket = new_Hash->bucket_list[cur_Bucket->hash_key];
                        while(dest_Bucket) {
                            j++;
                            if(j + cur_Bucket->hash_key == new_Capacity) {
                                j = -cur_Bucket->hash_key;
                            }
                            dest_Bucket = new_Hash->bucket_list[cur_Bucket->hash_key + j];
                        }
                        new_Hash->bucket_list[cur_Bucket->hash_key + j] = cur_Bucket;
                    } else {
                        if(!soft_insert) {
                            hash->free_func(cur_Bucket->data);
                        }
                        free(cur_Bucket);
                    }
                }
            }
            free(hash->bucket_list);
            *hash = *new_Hash;
            free(new_Hash);
        }
        hash_key = hash->hash_alg(data) % hash->capacity;
        new_Bucket = hash_table_bucket_create(data, hash_key);
        dest_Bucket = hash->bucket_list[new_Bucket->hash_key];
        j = 0;
        while(dest_Bucket && !empty) {
            if(dest_Bucket->removed) {
                empty = 1;
                if(!soft_insert) {
                    hash->free_func(dest_Bucket->data);
                }
                free(dest_Bucket);
            } else if(!hash->comp_func(dest_Bucket->data, data)) {
                empty = 1;
                inserted = 0;
                free(new_Bucket);
            } else {
                j++;
                if(j + new_Bucket->hash_key == hash->capacity) {
                    j = -new_Bucket->hash_key;
                }
                dest_Bucket = hash->bucket_list[new_Bucket->hash_key + j];
            }
        }
        if(inserted) {
            hash->bucket_list[new_Bucket->hash_key + j] = new_Bucket;
            hash->size++;
            hash->cur_load_factor = (float)hash->size / hash->capacity;
        }
    }
    return inserted;
}

canonical_original_code:
int hash_table_insert(struct linear_hash_table *hash, void *data, int soft_insert) {
    int inserted; int i; int j; int new_Capacity; int empty;
    unsigned int hash_key;
    struct hash_table_bucket *new_Bucket;
    struct hash_table_bucket *cur_Bucket;
    struct hash_table_bucket *dest_Bucket;
    struct linear_hash_table *new_Hash;
    inserted = empty = 0;
    if(hash) {
        inserted = 1;
        if(hash->cur_load_factor >= hash->load_factor_limit) {
            new_Capacity = (2 * hash->capacity) + 1;
            new_Hash = hash_table_create(new_Capacity,
                                         hash->load_factor_limit,
                                         hash->hash_alg,
                                         hash->comp_func,
                                         hash->copy_func,
                                         hash->free_func);
            new_Hash->size = hash->size;
            for(i = 0; i < hash->capacity; i++) {
                cur_Bucket = hash->bucket_list[i];
                if(cur_Bucket) {
                    if(!cur_Bucket->removed) {
                        j = 0;
                        cur_Bucket->hash_key = new_Hash->hash_alg(cur_Bucket->data) % new_Capacity;
                        dest_Bucket = new_Hash->bucket_list[cur_Bucket->hash_key];
                        while(dest_Bucket) {
                            j++;
                            if(j + cur_Bucket->hash_key == new_Capacity) {
                                j = -cur_Bucket->hash_key;
                            }
                            dest_Bucket = new_Hash->bucket_list[cur_Bucket->hash_key + j];
                        }
                        new_Hash->bucket_list[cur_Bucket->hash_key + j] = cur_Bucket;
                    } else {
                        if(!soft_insert) {
                            hash->free_func(cur_Bucket->data);
                        }
                        free(cur_Bucket);
                    }
                }
            }
            free(hash->bucket_list);
            *hash = *new_Hash;
            free(new_Hash);
        }
        hash_key = hash->hash_alg(data) % hash->capacity;
        new_Bucket = hash_table_bucket_create(data, hash_key);
        dest_Bucket = hash->bucket_list[new_Bucket->hash_key];
        j = 0;
        while(dest_Bucket && !empty) {
            if(dest_Bucket->removed) {
                empty = 1;
                if(!soft_insert) {
                    hash->free_func(dest_Bucket->data);
                }
                free(dest_Bucket);
            } else if(!hash->comp_func(dest_Bucket->data, data)) {
                empty = 1;
                inserted = 0;
                free(new_Bucket);
            } else {
                j++;
                if(j + new_Bucket->hash_key == hash->capacity) {
                    j = -new_Bucket->hash_key;
                }
                dest_Bucket = hash->bucket_list[new_Bucket->hash_key + j];
            }
        }
        if(inserted) {
            hash->bucket_list[new_Bucket->hash_key + j] = new_Bucket;
            hash->size++;
            hash->cur_load_factor = (float)hash->size / hash->capacity;
        }
    }
    return inserted;
}

variable_types: struct linear_hash_table { struct hash_table_bucket { void *data; unsigned int hash_key; char removed; } **bucket_list; unsigned long size; unsigned long capacity; float cur_load_factor; float load_factor_limit; unsigned int (*hash_alg)(void *); int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); } *

variable_types: inserted int

variable_types: j int

variable_types: empty int

user_defined_types: struct linear_hash_table { struct hash_table_bucket **bucket_list; unsigned long size; unsigned long capacity; float cur_load_factor; float load_factor_limit; unsigned int (*hash_alg)(void *); int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); }


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

result = 1LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8) == 0LL;
return result;
}

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

result = 1LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8) == 0LL;
return result;
}

original_code:
int hash_table_is_empty(hash_table* hash) {
    int empty;
    empty = 1;
    if(hash) {
        if(hash->size) {
            empty = 0;
        }
    }
    return empty;
}

canonical_original_code:
int hash_table_is_empty(struct linear_hash_table *hash) {
    int empty;
    empty = 1;
    if(hash) {
        if(hash->size) {
            empty = 0;
        }
    }
    return empty;
}

user_defined_types: struct hash_table_bucket { void *data; unsigned int hash_key; char removed; }


original_code:
int hash_table_remove(hash_table* hash, void* data) {
    int removed, i, j;
    unsigned int hash_key;
    bucket* cur_Bucket;
    removed = 0;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            i = 0;
            j = 0;
            hash_key = hash->hash_alg(data) % hash->capacity;
            cur_Bucket = hash->bucket_list[hash_key];
            while(cur_Bucket && j < hash->capacity && !removed) {
                i++;
                j++;
                if(!hash->comp_func(cur_Bucket->data, data)) {
                    if(!cur_Bucket->removed) {
                        --hash->size;
                        removed = 1;
                        cur_Bucket->removed = 1;
                    } else {
                        j = hash->capacity;
                    }
                }
                if(i + hash_key == hash->capacity) {
                    i = -hash_key;
                }
                cur_Bucket = hash->bucket_list[hash_key + i];
            }
        }
    }
    return removed;
}

canonical_original_code:
int hash_table_remove(struct linear_hash_table *hash, void *data) {
    int removed; int i; int j;
    unsigned int hash_key;
    struct hash_table_bucket *cur_Bucket;
    removed = 0;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            i = 0;
            j = 0;
            hash_key = hash->hash_alg(data) % hash->capacity;
            cur_Bucket = hash->bucket_list[hash_key];
            while(cur_Bucket && j < hash->capacity && !removed) {
                i++;
                j++;
                if(!hash->comp_func(cur_Bucket->data, data)) {
                    if(!cur_Bucket->removed) {
                        --hash->size;
                        removed = 1;
                        cur_Bucket->removed = 1;
                    } else {
                        j = hash->capacity;
                    }
                }
                if(i + hash_key == hash->capacity) {
                    i = -hash_key;
                }
                cur_Bucket = hash->bucket_list[hash_key + i];
            }
        }
    }
    return removed;
}

variable_types: removed int

variable_types: i int

variable_types: struct hash_table_bucket { void *data; unsigned int hash_key; char removed; } *


original_code:
int hash_table_contains(hash_table* hash, const void* data) {
    int i, j, contains;
    unsigned int hash_key;
    bucket* cur_Bucket;
    contains = 0;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            i = 0;
            j = 0;
            hash_key = hash->hash_alg(data) % hash->capacity;
            cur_Bucket = hash->bucket_list[hash_key];
            while(cur_Bucket && !contains && j < hash->capacity) {
                i++;
                j++;
                if(!hash->comp_func(cur_Bucket->data, data)) {
                    if(!cur_Bucket->removed) {
                        contains = 1;
                    } else {
                        j = hash->capacity;
                    }
                }
                if(i + hash_key == hash->capacity) {
                    i = -hash_key;
                }
                cur_Bucket = hash->bucket_list[hash_key + i];
            }
        }
    }
    return contains;
}

canonical_original_code:
int hash_table_contains(struct linear_hash_table *hash, void *data) {
    int i; int j; int contains;
    unsigned int hash_key;
    struct hash_table_bucket *cur_Bucket;
    contains = 0;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            i = 0;
            j = 0;
            hash_key = hash->hash_alg(data) % hash->capacity;
            cur_Bucket = hash->bucket_list[hash_key];
            while(cur_Bucket && !contains && j < hash->capacity) {
                i++;
                j++;
                if(!hash->comp_func(cur_Bucket->data, data)) {
                    if(!cur_Bucket->removed) {
                        contains = 1;
                    } else {
                        j = hash->capacity;
                    }
                }
                if(i + hash_key == hash->capacity) {
                    i = -hash_key;
                }
                cur_Bucket = hash->bucket_list[hash_key + i];
            }
        }
    }
    return contains;
}

variable_types: contains int


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

result = 0LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
size_t hash_table_size(hash_table* hash) {
    size_t size;
    size = 0;
    if(hash) {
        size = hash->size;
    }
    return size;
}

canonical_original_code:
unsigned long hash_table_size(struct linear_hash_table *hash) {
    unsigned long size;
    size = 0;
    if(hash) {
        size = hash->size;
    }
    return size;
}

variable_types:
size
unsigned long


original_code:
void hash_table_empty(hash_table* hash) {
    int i;
    bucket* cur_Bucket;
    if(hash) {
        hash->size = 0;
        for(i = 0; i < hash->capacity; i++) {
            cur_Bucket = hash->bucket_list[i];
            if(cur_Bucket) {
                hash->bucket_list[i] = ((void *)0);
                hash->free_func(cur_Bucket->data);
                free(cur_Bucket);
            }
        }
    }
    return;
}

canonical_original_code:
void hash_table_empty(struct linear_hash_table *hash) {
    int i;
    struct hash_table_bucket *cur_Bucket;
    if(hash) {
        hash->size = 0;
        for(i = 0; i < hash->capacity; i++) {
            cur_Bucket = hash->bucket_list[i];
            if(cur_Bucket) {
                hash->bucket_list[i] = ((void *)0);
                hash->free_func(cur_Bucket->data);
                free(cur_Bucket);
            }
        }
    }
    return;
}


decompiled_code:
void __fastcall hash_table_kill(void *ptr)
{
if ( ptr )
{
hash_table_empty((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( ptr )
{
func5((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void hash_table_kill(hash_table* hash) {
    if(hash) {
        hash_table_empty(hash);
        free(hash->bucket_list);
        free(hash);
    }
    return;
}

canonical_original_code:
void hash_table_kill(struct linear_hash_table *hash) {
    if(hash) {
        hash_table_empty(hash);
        free(hash->bucket_list);
        free(hash);
    }
    return;
}


decompiled_code:
void __fastcall hash_table_dissolve(void *ptr)
{
unsigned __int64 v2; // rbx
void **v3; // rax
void *v4; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
v2 = 0LL;
do
{
v3 = (void **)(*(_QWORD *)ptr + 8 * v2);
v4 = *v3;
if ( *v3 )
{
*v3 = 0LL;
free(v4);
}
++v2;
}
while ( *((_QWORD *)ptr + 2) > v2 );
}
free(*(void **)ptr);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
unsigned __int64 v2; // rbx
void **v3; // rax
void *v4; // rdi

if ( ptr )
{
if ( *((_QWORD *)ptr + 2) )
{
v2 = 0LL;
do
{
v3 = (void **)(*(_QWORD *)ptr + 8 * v2);
v4 = *v3;
if ( *v3 )
{
*v3 = 0LL;
free(v4);
}
++v2;
}
while ( *((_QWORD *)ptr + 2) > v2 );
}
free(*(void **)ptr);
free(ptr);
}
}

original_code:
void hash_table_dissolve(hash_table* hash) {
    int i;
    bucket* cur_Bucket;
    if(hash) {
        for(i = 0; i < hash->capacity; i++) {
            cur_Bucket = hash->bucket_list[i];
            if(cur_Bucket) {
                hash->bucket_list[i] = ((void *)0);
                free(cur_Bucket);
            }
        }
        free(hash->bucket_list);
        free(hash);
    }
    return;
}

canonical_original_code:
void hash_table_dissolve(struct linear_hash_table *hash) {
    int i;
    struct hash_table_bucket *cur_Bucket;
    if(hash) {
        for(i = 0; i < hash->capacity; i++) {
            cur_Bucket = hash->bucket_list[i];
            if(cur_Bucket) {
                hash->bucket_list[i] = ((void *)0);
                free(cur_Bucket);
            }
        }
        free(hash->bucket_list);
        free(hash);
    }
    return;
}


decompiled_code:
void __fastcall hash_table_traverse(_QWORD *a1, void (__fastcall *a2)(_QWORD))
{
unsigned __int64 v2; // rbx
__int64 v3; // rax

if ( a1 && !hash_table_is_empty((__int64)a1) && a1[2] )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(*a1 + 8 * v2);
if ( v3 )
{
if ( !*(_BYTE *)(v3 + 12) )
a2(*(_QWORD *)v3);
}
++v2;
}
while ( a1[2] > v2 );
}
}

original_code:
void hash_table_traverse(hash_table* hash, generic_op do_func) {
    int i;
    bucket* cur_Bucket;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            for(i = 0; i < hash->capacity; i++) {
                cur_Bucket = hash->bucket_list[i];
                if(cur_Bucket) {
                    if(!cur_Bucket->removed) {
                        do_func(cur_Bucket->data);
                    }
                }
            }
        }
    }
    return;
}

canonical_original_code:
void hash_table_traverse(struct linear_hash_table *hash, void (*do_func)(void *)) {
    int i;
    struct hash_table_bucket *cur_Bucket;
    if(hash) {
        if(!hash_table_is_empty(hash)) {
            for(i = 0; i < hash->capacity; i++) {
                cur_Bucket = hash->bucket_list[i];
                if(cur_Bucket) {
                    if(!cur_Bucket->removed) {
                        do_func(cur_Bucket->data);
                    }
                }
            }
        }
    }
    return;
}


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

if ( a2 < 0 || !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 24) >= a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

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

if ( a2 < 0 || !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 24) >= a2 )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL * a2);
return result;
}

original_code:
void* array_list_get(array_list* array, int index) {
    void* data;
    data = ((void *)0);
    if(array) {
        if (index >= 0 && index <= array->index) {
            data = array->memory[index];
        }
    }
    return data;
}

canonical_original_code:
void *array_list_get(struct dynamic_array *array, int index) {
    void *data;
    data = ((void *)0);
    if(array) {
        if (index >= 0 && index <= array->index) {
            data = array->memory[index];
        }
    }
    return data;
}

variable_types: struct dynamic_array { void **memory; unsigned long allocated; unsigned long used; int index; int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); } *

variable_types: index int


original_code:
int array_list_push(array_list* array, void* data) {
    int pushed;
    size_t toallocate;
    size_t size;
    size = sizeof(void*);
    pushed = 0;
    if(array) {
        pushed = 1;
        if ((array->allocated - array->used) < size) {
            toallocate = (array->allocated == 0) ? size :
                         (array->allocated * 2);
            array->memory = realloc(array->memory, toallocate);
            array->allocated = toallocate;
        }
        array->memory[++array->index] = data;
        array->used += size;
    }
    return pushed;
}

canonical_original_code:
int array_list_push(struct dynamic_array *array, void *data) {
    int pushed;
    unsigned long toallocate;
    unsigned long size;
    size = sizeof(void *);
    pushed = 0;
    if(array) {
        pushed = 1;
        if ((array->allocated - array->used) < size) {
            toallocate = (array->allocated == 0) ? size :
                         (array->allocated * 2);
            array->memory = realloc(array->memory, toallocate);
            array->allocated = toallocate;
        }
        array->memory[++array->index] = data;
        array->used += size;
    }
    return pushed;
}

variable_types: pushed int

variable_types:
toallocate
unsigned long

user_defined_types: struct dynamic_array { void **memory; unsigned long allocated; unsigned long used; int index; int (*comp_func)(void *, void *); void *(*copy_func)(void *); void (*free_func)(void *); }


decompiled_code:
__int64 __fastcall array_list_insert(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

if ( a2 < 0 || !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 24) >= a2 )
{
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, __int64 a3)
{
__int64 result; // rax

if ( a2 < 0 || !a1 )
return 0LL;
result = 0LL;
if ( *(_DWORD *)(a1 + 24) >= a2 )
{
*(_QWORD *)(*(_QWORD *)a1 + 8LL * a2) = a3;
result = 1LL;
}
return result;
}

original_code:
int array_list_insert(array_list* array, int index, void* data) {
    int inserted;
    inserted = 0;
    if(array) {
        if (index >= 0 && index <= array->index) {
            inserted = 1;
            array->memory[index] = data;
        }
    }
    return inserted;
}

canonical_original_code:
int array_list_insert(struct dynamic_array *array, int index, void *data) {
    int inserted;
    inserted = 0;
    if(array) {
        if (index >= 0 && index <= array->index) {
            inserted = 1;
            array->memory[index] = data;
        }
    }
    return inserted;
}