decompiled_code:
double __fastcall normalize_row(_QWORD *a1, unsigned int a2, char a3, char a4, double a5)
{
char v5; // r14
__int64 v7; // rbp
_QWORD *v8; // rbx
__int64 v9; // r12
double v11; // xmm0_8
__int64 v12; // r12
__int64 v13; // rdx
__int64 v14; // rsi
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // [rsp+0h] [rbp-38h]

v5 = a4;
v7 = (int)a2;
v8 = a1;
if ( a3 )
{
v9 = 0LL;
v17 = logsum(a1, a2, 1LL);
if ( a1[1] )
{
do
{
v11 = gsl_matrix_get(a1, (int)a2, v9);
if ( a4 )
gsl_matrix_set(a1, (int)a2, v9, v11 - v17);
else
gsl_matrix_set(a1, (int)a2, v9, v11 - v17 + a5);
++v9;
}
while ( a1[1] != v9 );
}
}
else
{
v12 = 0LL;
v17 = logsum(a1, a2, 0LL);
if ( *a1 )
{
v13 = (int)a2;
v14 = 0LL;
if ( !a4 )
goto LABEL_15;
LABEL_12:
v15 = gsl_matrix_get(a1, v14, v13);
gsl_matrix_set(v8, v12, v7, v15 - v17);
while ( *v8 != ++v12 )
{
v13 = v7;
v14 = v12;
a1 = v8;
if ( a4 )
goto LABEL_12;
LABEL_15:
v16 = gsl_matrix_get(a1, v14, v13);
gsl_matrix_set(v8, v12, v7, v16 - v17 + a5);
}
}
}
if ( !v5 )
v17 = exp(a5) * v17;
return v17;
}

canonical_decompiled_code:
double __fastcall func0(_QWORD *a1, unsigned int a2, char a3, char a4, double a5)
{
char v5; // r14
__int64 v7; // rbp
_QWORD *v8; // rbx
__int64 v9; // r12
double v11; // xmm0_8
__int64 v12; // r12
__int64 v13; // rdx
__int64 v14; // rsi
double v15; // xmm0_8
double v16; // xmm0_8
double v17; // [rsp+0h] [rbp-38h]

v5 = a4;
v7 = (int)a2;
v8 = a1;
if ( a3 )
{
v9 = 0LL;
v17 = logsum(a1, a2, 1LL);
if ( a1[1] )
{
do
{
v11 = gsl_matrix_get(a1, (int)a2, v9);
if ( a4 )
gsl_matrix_set(a1, (int)a2, v9, v11 - v17);
else
gsl_matrix_set(a1, (int)a2, v9, v11 - v17 + a5);
++v9;
}
while ( a1[1] != v9 );
}
}
else
{
v12 = 0LL;
v17 = logsum(a1, a2, 0LL);
if ( *a1 )
{
v13 = (int)a2;
v14 = 0LL;
if ( !a4 )
goto LABEL_15;
LABEL_12:
v15 = gsl_matrix_get(a1, v14, v13);
gsl_matrix_set(v8, v12, v7, v15 - v17);
while ( *v8 != ++v12 )
{
v13 = v7;
v14 = v12;
a1 = v8;
if ( a4 )
goto LABEL_12;
LABEL_15:
v16 = gsl_matrix_get(a1, v14, v13);
gsl_matrix_set(v8, v12, v7, v16 - v17 + a5);
}
}
}
if ( !v5 )
v17 = exp(a5) * v17;
return v17;
}

original_code:
double normalize_row(gsl_matrix * q, int row, _Bool isrow,
       _Bool noweight, double weight){
  double loglike;
  if (isrow)
    loglike = logsum(q,row,1);
  else
    loglike = logsum(q,row,0);
  int dd;
  if (isrow)
    for (dd = 0; dd != q->size2; ++dd) {
      if ( noweight )
 gsl_matrix_set(q,row,dd,gsl_matrix_get(q,row,dd)-loglike);
      else
 gsl_matrix_set(q,row,dd,gsl_matrix_get(q,row,dd)-loglike+weight);
    }
  else
    for (dd = 0; dd != q->size1; ++dd) {
      if ( noweight )
 gsl_matrix_set(q,dd,row,gsl_matrix_get(q,dd,row)-loglike);
      else
 gsl_matrix_set(q,dd,row,gsl_matrix_get(q,dd,row)-loglike+weight);
    }
  if ( ! noweight ) loglike*= exp(weight);
  return loglike;
}

canonical_original_code:
double normalize_row(struct gsl_matrix *q, int row, _Bool isrow, _Bool noweight, double weight){
  double loglike;
  if (isrow)
    loglike = logsum(q,row,1);
  else
    loglike = logsum(q,row,0);
  int dd;
  if (isrow)
    for (dd = 0; dd != q->size2; ++dd) {
      if ( noweight )
 gsl_matrix_set(q,row,dd,gsl_matrix_get(q,row,dd)-loglike);
      else
 gsl_matrix_set(q,row,dd,gsl_matrix_get(q,row,dd)-loglike+weight);
    }
  else
    for (dd = 0; dd != q->size1; ++dd) {
      if ( noweight )
 gsl_matrix_set(q,dd,row,gsl_matrix_get(q,dd,row)-loglike);
      else
 gsl_matrix_set(q,dd,row,gsl_matrix_get(q,dd,row)-loglike+weight);
    }
  if ( ! noweight ) loglike*= exp(weight);
  return loglike;
}

variable_types: weight double

variable_types: loglike double

return_type: double

user_defined_types: struct gsl_block_struct { unsigned long size; double *data; }


repo: jobovy/extreme-deconvolution

decompiled_code:
void __fastcall bovy_randvec(__int64 a1, int a2, double a3)
{
double v4; // xmm0_8
double v5; // xmm0_8
__int64 v6; // rbx
__int64 i; // r13
double v8; // xmm0_8
__int64 v9; // rsi
double v10; // [rsp+0h] [rbp-38h]

v4 = (double)a2;
if ( (double)a2 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
v10 = a3 / v5;
if ( a2 )
{
v6 = (unsigned int)a2;
for ( i = 0LL; i != v6; ++i )
{
v8 = gsl_rng_uniform(randgen);
v9 = i;
gsl_vector_set(a1, v9, (v8 + v8 - 1.0) * v10);
}
}
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2, double a3)
{
double v4; // xmm0_8
double v5; // xmm0_8
__int64 v6; // rbx
__int64 i; // r13
double v8; // xmm0_8
__int64 v9; // rsi
double v10; // [rsp+0h] [rbp-38h]

v4 = (double)a2;
if ( (double)a2 < 0.0 )
v5 = sqrt(v4);
else
v5 = sqrt(v4);
v10 = a3 / v5;
if ( a2 )
{
v6 = (unsigned int)a2;
for ( i = 0LL; i != v6; ++i )
{
v8 = gsl_rng_uniform(randgen);
v9 = i;
gsl_vector_set(a1, v9, (v8 + v8 - 1.0) * v10);
}
}
}

original_code:
void bovy_randvec(gsl_vector * eps, int d, double length){
  length /= sqrt((double)d);
  int dd;
  for (dd = 0; dd != d; ++dd)
    gsl_vector_set(eps,dd,(2.*gsl_rng_uniform(randgen)-1.)*length);
  return;
}

canonical_original_code:
void bovy_randvec(struct gsl_vector *eps, int d, double length){
  length /= sqrt((double)d);
  int dd;
  for (dd = 0; dd != d; ++dd)
    gsl_vector_set(eps,dd,(2.*gsl_rng_uniform(randgen)-1.)*length);
  return;
}

variable_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: d int

variable_types: length double

variable_types: dd int

return_type: void

user_defined_types: struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct *block; int owner; }


splitnmergegauss

decompiled_code:
__int64 __fastcall splitnmergegauss(double *a1, unsigned int a2, __int64 a3, unsigned int a4, unsigned int a5, int a6)
{
__int64 *v9; // rax
__int64 v10; // r15
__int64 v11; // r14
double *v12; // r15
int v13; // er8
__int64 v14; // rbx
__int64 v15; // r13
double v16; // xmm0_8
double v17; // xmm0_8
double v18; // xmm0_8
double v19; // xmm0_8
double v20; // xmm6_8
__int64 v21; // rsi
double *v22; // r15
double v23; // xmm0_8
double v24; // xmm0_8
double v25; // xmm0_8
__int64 v26; // rbx
int v27; // er14
unsigned int v28; // er13
double *v29; // rbp
unsigned int v30; // er15
__int64 v31; // r12
int v32; // ecx
__int64 v33; // rdi
__int64 v34; // rdi
__int64 v35; // rdi
double v37; // xmm0_8
__int64 v38; // [rsp+8h] [rbp-C0h]
__int64 v39; // [rsp+10h] [rbp-B8h]
__int64 v40; // [rsp+18h] [rbp-B0h]
__int64 v41; // [rsp+20h] [rbp-A8h]
__int64 v42; // [rsp+28h] [rbp-A0h]
__int64 v43; // [rsp+30h] [rbp-98h]
__int64 v44; // [rsp+38h] [rbp-90h]
__int64 v45; // [rsp+38h] [rbp-90h]
double *v46; // [rsp+40h] [rbp-88h]
double v47; // [rsp+40h] [rbp-88h]
double v48; // [rsp+40h] [rbp-88h]
double x; // [rsp+50h] [rbp-78h]
double xa; // [rsp+50h] [rbp-78h]
double xb; // [rsp+50h] [rbp-78h]
__int64 v53; // [rsp+58h] [rbp-70h]
double v54; // [rsp+68h] [rbp-60h]
int v56; // [rsp+70h] [rbp-58h]
int v57; // [rsp+74h] [rbp-54h]
int v58; // [rsp+74h] [rbp-54h]
int v59; // [rsp+74h] [rbp-54h]
double v60; // [rsp+78h] [rbp-50h]
double v61; // [rsp+80h] [rbp-48h]
double v62; // [rsp+88h] [rbp-40h]

v9 = (__int64 *)*((_QWORD *)a1 + 2);
v46 = a1;
v10 = (int)*v9;
v44 = *v9;
v42 = gsl_vector_alloc(v10);
v41 = gsl_matrix_alloc(v10, v10);
v11 = gsl_vector_alloc(v10);
v38 = gsl_matrix_alloc(v10, v10);
v39 = gsl_vector_alloc(v10);
v40 = gsl_matrix_alloc(v10, v10);
v53 = gsl_matrix_alloc(v10, v10);
gsl_matrix_set_identity(v53);
v43 = gsl_vector_alloc(v10);
if ( a2 )
{
v12 = a1;
v13 = a6;
v14 = 0LL;
v15 = a2;
while ( 1 )
{
while ( a4 != (_DWORD)v14 )
{
if ( a5 == (_DWORD)v14 )
goto LABEL_8;
LABEL_4:
if ( v13 != (_DWORD)v14 )
goto LABEL_5;
LABEL_9:
v20 = *v12;
v21 = *((_QWORD *)v12 + 1);
v59 = v13;
++v14;
v12 += 3;
v62 = v20;
gsl_vector_memcpy(v39, v21);
gsl_matrix_memcpy(v40, *((_QWORD *)v12 - 1));
v13 = v59;
if ( v14 == v15 )
{
LABEL_10:
a6 = v13;
v46 = &a1[3 * v14];
goto LABEL_11;
}
}
v57 = v13;
v60 = *v12;
gsl_vector_memcpy(v42, *((_QWORD *)v12 + 1));
gsl_matrix_memcpy(v41, *((_QWORD *)v12 + 2));
v16 = logsum(a3, a4, 0LL);
v17 = exp(v16);
v13 = v57;
v54 = v17;
if ( a5 != (_DWORD)v14 )
goto LABEL_4;
LABEL_8:
v58 = v13;
v61 = *v12;
gsl_vector_memcpy(v11, *((_QWORD *)v12 + 1));
gsl_matrix_memcpy(v38, *((_QWORD *)v12 + 2));
v18 = logsum(a3, a5, 0LL);
v19 = exp(v18);
v13 = v58;
x = v19;
if ( v58 == (_DWORD)v14 )
goto LABEL_9;
LABEL_5:
++v14;
v12 += 3;
if ( v14 == v15 )
goto LABEL_10;
}
}
LABEL_11:
v22 = &v46[-3 * (int)a2];
if ( x == 0.0 && v54 == 0.0 )
{
gsl_vector_add(v42, v11);
gsl_vector_scale(v42, 0.5);
gsl_matrix_add(v41, v38);
gsl_matrix_scale(v41, 0.5);
v23 = *(double *)&LC1;
}
else
{
gsl_vector_scale(v42, v54 / (x + v54));
v48 = x / (x + v54);
gsl_vector_scale(v11, v48);
gsl_vector_add(v42, v11);
gsl_matrix_scale(v41, v54 / (x + v54));
gsl_matrix_scale(v38, v48);
gsl_matrix_add(v41, v38);
v23 = *(double *)&LC1;
}
v47 = v23 * v62;
v24 = bovy_det(v40);
xa = pow(v24, 1.0 / (double)(int)v44);
gsl_matrix_scale(v53, xa);
gsl_matrix_memcpy(v38, v53);
gsl_matrix_memcpy(v40, v53);
gsl_vector_memcpy(v11, v39);
if ( xa < 0.0 )
{
v37 = sqrt(xa);
bovy_randvec(v43, (unsigned int)v44, v37);
gsl_vector_add(v11, v43);
v25 = sqrt(xa);
}
else
{
xb = sqrt(xa);
bovy_randvec(v43, (unsigned int)v44, xb);
gsl_vector_add(v11, v43);
v25 = xb;
}
bovy_randvec(v43, (unsigned int)v44, v25);
gsl_vector_add(v39, v43);
if ( a2 )
{
v45 = v11;
v26 = 0LL;
v27 = a6;
v28 = a4;
v29 = v22;
v30 = a5;
v31 = a2;
do
{
while ( 1 )
{
v32 = v26;
if ( (_DWORD)v26 == v28 )
break;
if ( (_DWORD)v26 == v30 )
goto LABEL_23;
LABEL_19:
if ( v32 != v27 )
goto LABEL_20;
LABEL_24:
v35 = *((_QWORD *)v29 + 1);
++v26;
v29 += 3;
*(v29 - 3) = v47;
gsl_vector_memcpy(v35, v39);
gsl_matrix_memcpy(*((_QWORD *)v29 - 1), v40);
if ( v31 == v26 )
goto LABEL_25;
}
v33 = *((_QWORD *)v29 + 1);
*v29 = v60 + v61;
gsl_vector_memcpy(v33, v42);
gsl_matrix_memcpy(*((_QWORD *)v29 + 2), v41);
v32 = v26;
if ( (_DWORD)v26 != v30 )
goto LABEL_19;
LABEL_23:
v34 = *((_QWORD *)v29 + 1);
v56 = v32;
*v29 = v47;
gsl_vector_memcpy(v34, v45);
gsl_matrix_memcpy(*((_QWORD *)v29 + 2), v38);
if ( v56 == v27 )
goto LABEL_24;
LABEL_20:
++v26;
v29 += 3;
}
while ( v31 != v26 );
}
LABEL_25:
gsl_matrix_free(v53);
return gsl_vector_free(v43);
}

canonical_decompiled_code:
__int64 __fastcall func0(double *a1, unsigned int a2, __int64 a3, unsigned int a4, unsigned int a5, int a6)
{
__int64 *v9; // rax
__int64 v10; // r15
__int64 v11; // r14
double *v12; // r15
int v13; // er8
__int64 v14; // rbx
__int64 v15; // r13
double v16; // xmm0_8
double v17; // xmm0_8
double v18; // xmm0_8
double v19; // xmm0_8
double v20; // xmm6_8
__int64 v21; // rsi
double *v22; // r15
double v23; // xmm0_8
double v24; // xmm0_8
double v25; // xmm0_8
__int64 v26; // rbx
int v27; // er14
unsigned int v28; // er13
double *v29; // rbp
unsigned int v30; // er15
__int64 v31; // r12
int v32; // ecx
__int64 v33; // rdi
__int64 v34; // rdi
__int64 v35; // rdi
double v37; // xmm0_8
__int64 v38; // [rsp+8h] [rbp-C0h]
__int64 v39; // [rsp+10h] [rbp-B8h]
__int64 v40; // [rsp+18h] [rbp-B0h]
__int64 v41; // [rsp+20h] [rbp-A8h]
__int64 v42; // [rsp+28h] [rbp-A0h]
__int64 v43; // [rsp+30h] [rbp-98h]
__int64 v44; // [rsp+38h] [rbp-90h]
__int64 v45; // [rsp+38h] [rbp-90h]
double *v46; // [rsp+40h] [rbp-88h]
double v47; // [rsp+40h] [rbp-88h]
double v48; // [rsp+40h] [rbp-88h]
double x; // [rsp+50h] [rbp-78h]
double xa; // [rsp+50h] [rbp-78h]
double xb; // [rsp+50h] [rbp-78h]
__int64 v53; // [rsp+58h] [rbp-70h]
double v54; // [rsp+68h] [rbp-60h]
int v56; // [rsp+70h] [rbp-58h]
int v57; // [rsp+74h] [rbp-54h]
int v58; // [rsp+74h] [rbp-54h]
int v59; // [rsp+74h] [rbp-54h]
double v60; // [rsp+78h] [rbp-50h]
double v61; // [rsp+80h] [rbp-48h]
double v62; // [rsp+88h] [rbp-40h]

v9 = (__int64 *)*((_QWORD *)a1 + 2);
v46 = a1;
v10 = (int)*v9;
v44 = *v9;
v42 = gsl_vector_alloc(v10);
v41 = gsl_matrix_alloc(v10, v10);
v11 = gsl_vector_alloc(v10);
v38 = gsl_matrix_alloc(v10, v10);
v39 = gsl_vector_alloc(v10);
v40 = gsl_matrix_alloc(v10, v10);
v53 = gsl_matrix_alloc(v10, v10);
gsl_matrix_set_identity(v53);
v43 = gsl_vector_alloc(v10);
if ( a2 )
{
v12 = a1;
v13 = a6;
v14 = 0LL;
v15 = a2;
while ( 1 )
{
while ( a4 != (_DWORD)v14 )
{
if ( a5 == (_DWORD)v14 )
goto LABEL_8;
LABEL_4:
if ( v13 != (_DWORD)v14 )
goto LABEL_5;
LABEL_9:
v20 = *v12;
v21 = *((_QWORD *)v12 + 1);
v59 = v13;
++v14;
v12 += 3;
v62 = v20;
gsl_vector_memcpy(v39, v21);
gsl_matrix_memcpy(v40, *((_QWORD *)v12 - 1));
v13 = v59;
if ( v14 == v15 )
{
LABEL_10:
a6 = v13;
v46 = &a1[3 * v14];
goto LABEL_11;
}
}
v57 = v13;
v60 = *v12;
gsl_vector_memcpy(v42, *((_QWORD *)v12 + 1));
gsl_matrix_memcpy(v41, *((_QWORD *)v12 + 2));
v16 = logsum(a3, a4, 0LL);
v17 = exp(v16);
v13 = v57;
v54 = v17;
if ( a5 != (_DWORD)v14 )
goto LABEL_4;
LABEL_8:
v58 = v13;
v61 = *v12;
gsl_vector_memcpy(v11, *((_QWORD *)v12 + 1));
gsl_matrix_memcpy(v38, *((_QWORD *)v12 + 2));
v18 = logsum(a3, a5, 0LL);
v19 = exp(v18);
v13 = v58;
x = v19;
if ( v58 == (_DWORD)v14 )
goto LABEL_9;
LABEL_5:
++v14;
v12 += 3;
if ( v14 == v15 )
goto LABEL_10;
}
}
LABEL_11:
v22 = &v46[-3 * (int)a2];
if ( x == 0.0 && v54 == 0.0 )
{
gsl_vector_add(v42, v11);
gsl_vector_scale(v42, 0.5);
gsl_matrix_add(v41, v38);
gsl_matrix_scale(v41, 0.5);
v23 = *(double *)&LC1;
}
else
{
gsl_vector_scale(v42, v54 / (x + v54));
v48 = x / (x + v54);
gsl_vector_scale(v11, v48);
gsl_vector_add(v42, v11);
gsl_matrix_scale(v41, v54 / (x + v54));
gsl_matrix_scale(v38, v48);
gsl_matrix_add(v41, v38);
v23 = *(double *)&LC1;
}
v47 = v23 * v62;
v24 = bovy_det(v40);
xa = pow(v24, 1.0 / (double)(int)v44);
gsl_matrix_scale(v53, xa);
gsl_matrix_memcpy(v38, v53);
gsl_matrix_memcpy(v40, v53);
gsl_vector_memcpy(v11, v39);
if ( xa < 0.0 )
{
v37 = sqrt(xa);
bovy_randvec(v43, (unsigned int)v44, v37);
gsl_vector_add(v11, v43);
v25 = sqrt(xa);
}
else
{
xb = sqrt(xa);
bovy_randvec(v43, (unsigned int)v44, xb);
gsl_vector_add(v11, v43);
v25 = xb;
}
bovy_randvec(v43, (unsigned int)v44, v25);
gsl_vector_add(v39, v43);
if ( a2 )
{
v45 = v11;
v26 = 0LL;
v27 = a6;
v28 = a4;
v29 = v22;
v30 = a5;
v31 = a2;
do
{
while ( 1 )
{
v32 = v26;
if ( (_DWORD)v26 == v28 )
break;
if ( (_DWORD)v26 == v30 )
goto LABEL_23;
LABEL_19:
if ( v32 != v27 )
goto LABEL_20;
LABEL_24:
v35 = *((_QWORD *)v29 + 1);
++v26;
v29 += 3;
*(v29 - 3) = v47;
gsl_vector_memcpy(v35, v39);
gsl_matrix_memcpy(*((_QWORD *)v29 - 1), v40);
if ( v31 == v26 )
goto LABEL_25;
}
v33 = *((_QWORD *)v29 + 1);
*v29 = v60 + v61;
gsl_vector_memcpy(v33, v42);
gsl_matrix_memcpy(*((_QWORD *)v29 + 2), v41);
v32 = v26;
if ( (_DWORD)v26 != v30 )
goto LABEL_19;
LABEL_23:
v34 = *((_QWORD *)v29 + 1);
v56 = v32;
*v29 = v47;
gsl_vector_memcpy(v34, v45);
gsl_matrix_memcpy(*((_QWORD *)v29 + 2), v38);
if ( v56 == v27 )
goto LABEL_24;
LABEL_20:
++v26;
v29 += 3;
}
while ( v31 != v26 );
}
LABEL_25:
gsl_matrix_free(v53);
return gsl_vector_free(v43);
}

original_code:
void splitnmergegauss(struct gaussian * gaussians,int K,
        gsl_matrix * qij, int j, int k, int l){
  int d = (gaussians->VV)->size1;
  struct gaussian gaussianj, gaussiank, gaussianl;
  gaussianj.mm = gsl_vector_alloc(d);
  gaussianj.VV = gsl_matrix_alloc(d,d);
  gaussiank.mm = gsl_vector_alloc(d);
  gaussiank.VV = gsl_matrix_alloc(d,d);
  gaussianl.mm = gsl_vector_alloc(d);
  gaussianl.VV = gsl_matrix_alloc(d,d);
  gsl_matrix * unitm = gsl_matrix_alloc(d,d);
  gsl_matrix_set_identity(unitm);
  gsl_vector * eps = gsl_vector_alloc(d);
  double qjj,qjk,detVVjl;
  int kk;
  for (kk = 0; kk != K; ++kk){
    if (kk == j){
      gaussianj.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussianj.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussianj.VV,gaussians->VV);
      qjj = exp(logsum(qij,j,0));
    }
    if (kk == k){
      gaussiank.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussiank.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussiank.VV,gaussians->VV);
      qjk = exp(logsum(qij,k,0));
    }
    if (kk == l){
      gaussianl.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussianl.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussianl.VV,gaussians->VV);
    }
    ++gaussians;
  }
  gaussians -= K;
  gaussianj.alpha += gaussiank.alpha;
  if (qjk == 0. && qjj == 0){
    gsl_vector_add(gaussianj.mm,gaussiank.mm);
    gsl_vector_scale(gaussianj.mm,0.5);
    gsl_matrix_add(gaussianj.VV,gaussiank.VV);
    gsl_matrix_scale(gaussianj.VV,0.5);
  }
  else{
    gsl_vector_scale(gaussianj.mm,qjj/(qjj+qjk));
    gsl_vector_scale(gaussiank.mm,qjk/(qjj+qjk));
    gsl_vector_add(gaussianj.mm,gaussiank.mm);
    gsl_matrix_scale(gaussianj.VV,qjj/(qjj+qjk));
    gsl_matrix_scale(gaussiank.VV,qjk/(qjj+qjk));
    gsl_matrix_add(gaussianj.VV,gaussiank.VV);
  }
  gaussianl.alpha /= 2.;
  gaussiank.alpha = gaussianl.alpha;
  detVVjl = bovy_det(gaussianl.VV);
  detVVjl= pow(detVVjl,1./d);
  gsl_matrix_scale(unitm,detVVjl);
  gsl_matrix_memcpy(gaussiank.VV,unitm);
  gsl_matrix_memcpy(gaussianl.VV,unitm);
  gsl_vector_memcpy(gaussiank.mm,gaussianl.mm);
  bovy_randvec(eps,d,sqrt(detVVjl));
  gsl_vector_add(gaussiank.mm,eps);
  bovy_randvec(eps,d,sqrt(detVVjl));
  gsl_vector_add(gaussianl.mm,eps);
  for (kk = 0; kk != K; ++kk){
    if (kk == j){
      gaussians->alpha = gaussianj.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussianj.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussianj.VV);
    }
    if (kk == k){
      gaussians->alpha = gaussiank.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussiank.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussiank.VV);
    }
    if (kk == l){
      gaussians->alpha = gaussianl.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussianl.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussianl.VV);
    }
    ++gaussians;
  }
  gaussians -= K;
  gsl_matrix_free(unitm);
  gsl_vector_free(eps);
  return ;
}

canonical_original_code:
void splitnmergegauss(struct gaussian *gaussians, int K, struct gsl_matrix *qij, int j, int k, int l){
  int d = (gaussians->VV)->size1;
  struct gaussian gaussianj; struct gaussian gaussiank; struct gaussian gaussianl;
  gaussianj.mm = gsl_vector_alloc(d);
  gaussianj.VV = gsl_matrix_alloc(d,d);
  gaussiank.mm = gsl_vector_alloc(d);
  gaussiank.VV = gsl_matrix_alloc(d,d);
  gaussianl.mm = gsl_vector_alloc(d);
  gaussianl.VV = gsl_matrix_alloc(d,d);
  struct gsl_matrix *unitm = gsl_matrix_alloc(d,d);
  gsl_matrix_set_identity(unitm);
  struct gsl_vector *eps = gsl_vector_alloc(d);
  double qjj; double qjk; double detVVjl;
  int kk;
  for (kk = 0; kk != K; ++kk){
    if (kk == j){
      gaussianj.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussianj.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussianj.VV,gaussians->VV);
      qjj = exp(logsum(qij,j,0));
    }
    if (kk == k){
      gaussiank.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussiank.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussiank.VV,gaussians->VV);
      qjk = exp(logsum(qij,k,0));
    }
    if (kk == l){
      gaussianl.alpha = gaussians->alpha;
      gsl_vector_memcpy(gaussianl.mm,gaussians->mm);
      gsl_matrix_memcpy(gaussianl.VV,gaussians->VV);
    }
    ++gaussians;
  }
  gaussians -= K;
  gaussianj.alpha += gaussiank.alpha;
  if (qjk == 0. && qjj == 0){
    gsl_vector_add(gaussianj.mm,gaussiank.mm);
    gsl_vector_scale(gaussianj.mm,0.5);
    gsl_matrix_add(gaussianj.VV,gaussiank.VV);
    gsl_matrix_scale(gaussianj.VV,0.5);
  }
  else{
    gsl_vector_scale(gaussianj.mm,qjj/(qjj+qjk));
    gsl_vector_scale(gaussiank.mm,qjk/(qjj+qjk));
    gsl_vector_add(gaussianj.mm,gaussiank.mm);
    gsl_matrix_scale(gaussianj.VV,qjj/(qjj+qjk));
    gsl_matrix_scale(gaussiank.VV,qjk/(qjj+qjk));
    gsl_matrix_add(gaussianj.VV,gaussiank.VV);
  }
  gaussianl.alpha /= 2.;
  gaussiank.alpha = gaussianl.alpha;
  detVVjl = bovy_det(gaussianl.VV);
  detVVjl= pow(detVVjl,1./d);
  gsl_matrix_scale(unitm,detVVjl);
  gsl_matrix_memcpy(gaussiank.VV,unitm);
  gsl_matrix_memcpy(gaussianl.VV,unitm);
  gsl_vector_memcpy(gaussiank.mm,gaussianl.mm);
  bovy_randvec(eps,d,sqrt(detVVjl));
  gsl_vector_add(gaussiank.mm,eps);
  bovy_randvec(eps,d,sqrt(detVVjl));
  gsl_vector_add(gaussianl.mm,eps);
  for (kk = 0; kk != K; ++kk){
    if (kk == j){
      gaussians->alpha = gaussianj.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussianj.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussianj.VV);
    }
    if (kk == k){
      gaussians->alpha = gaussiank.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussiank.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussiank.VV);
    }
    if (kk == l){
      gaussians->alpha = gaussianl.alpha;
      gsl_vector_memcpy(gaussians->mm,gaussianl.mm);
      gsl_matrix_memcpy(gaussians->VV,gaussianl.VV);
    }
    ++gaussians;
  }
  gaussians -= K;
  gsl_matrix_free(unitm);
  gsl_vector_free(eps);
  return ;
}

variable_types: struct gaussian { double alpha; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *mm; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *VV; } *

variable_types: K int

variable_types:
qij
struct gsl_matrix *

variable_types: j int

variable_types: k int

variable_types: l int

variable_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *

variable_types: qjj double

variable_types: qjk double

variable_types: detVVjl double

variable_types: kk int

user_defined_types: struct gaussian { double alpha; struct gsl_vector *mm; struct gsl_matrix *VV; }


decompiled_code:
double __fastcall bovy_det(_QWORD *a1)
{
__int64 v1; // r12
double v3; // [rsp+8h] [rbp-30h]
unsigned int v4[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = gsl_permutation_alloc(*a1);
gsl_linalg_LU_decomp(a1, v1, v4);
v3 = gsl_linalg_LU_det(a1, v4[0]);
gsl_permutation_free(v1);
return v3;
}

canonical_decompiled_code:
double __fastcall func0(_QWORD *a1)
{
__int64 v1; // r12
double v3; // [rsp+8h] [rbp-30h]
unsigned int v4[7]; // [rsp+1Ch] [rbp-1Ch] BYREF

v1 = gsl_permutation_alloc(*a1);
gsl_linalg_LU_decomp(a1, v1, v4);
v3 = gsl_linalg_LU_det(a1, v4[0]);
gsl_permutation_free(v1);
return v3;
}

original_code:
double bovy_det(gsl_matrix * A){
  gsl_permutation * p = gsl_permutation_alloc (A->size1);
  int signum;
  double det;
  gsl_linalg_LU_decomp(A,p,&signum);
  det= gsl_linalg_LU_det(A,signum);
  gsl_permutation_free(p);
  return det;
}

canonical_original_code:
double bovy_det(struct gsl_matrix *A){
  struct gsl_permutation_struct *p = gsl_permutation_alloc (A->size1);
  int signum;
  double det;
  gsl_linalg_LU_decomp(A,p,&signum);
  det= gsl_linalg_LU_det(A,signum);
  gsl_permutation_free(p);
  return det;
}

variable_types: struct gsl_permutation_struct { unsigned long size; unsigned long *data; } *

variable_types: signum int

variable_types: det double

user_defined_types: struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; }


logsum

original_code:
double logsum(gsl_matrix * q, int row, _Bool isrow){
  double logxmin = log(((double)2.22507385850720138309023271733240406e-308L));
  double logxmax = log(((double)1.79769313486231570814527423731704357e+308L));
  int l = (isrow) ? q->size2 : q->size1;
  double max, min;
  minmax(q,row,isrow,&min,&max);
  min *= -1.;
  min += logxmin;
  max *= -1.;
  max += logxmax - log(l);
  (min > max) ? (max=max) : (max=min);
  double loglike=0.0;
  int dd;
  if (isrow)
    for (dd = 0; dd != q->size2; ++dd)
 loglike += exp(gsl_matrix_get(q,row,dd)+max);
  else
    for (dd = 0; dd != q->size1; ++dd)
 loglike += exp(gsl_matrix_get(q,dd,row)+max);
  return log(loglike)-max;
}

canonical_original_code:
double logsum(struct gsl_matrix *q, int row, _Bool isrow){
  double logxmin = log(((double)2.22507385850720138309023271733240406e-308L));
  double logxmax = log(((double)1.79769313486231570814527423731704357e+308L));
  int l = (isrow) ? q->size2 : q->size1;
  double max; double min;
  minmax(q,row,isrow,&min,&max);
  min *= -1.;
  min += logxmin;
  max *= -1.;
  max += logxmax - log(l);
  (min > max) ? (max=max) : (max=min);
  double loglike = 0.0;
  int dd;
  if (isrow)
    for (dd = 0; dd != q->size2; ++dd)
 loglike += exp(gsl_matrix_get(q,row,dd)+max);
  else
    for (dd = 0; dd != q->size1; ++dd)
 loglike += exp(gsl_matrix_get(q,dd,row)+max);
  return log(loglike)-max;
}

variable_types: row int

variable_types: logxmin double

variable_types: logxmax double

variable_types: max double

variable_types: min double

variable_types: loglike double


repo: joefarebrother/scheme

decompiled_code:
char *__fastcall int_to_string(unsigned int a1)
{
char s[20]; // [rsp+4h] [rbp-14h] BYREF

snprintf(s, 0xCuLL, "%d", a1);
return strdup(s);
}

canonical_decompiled_code:
char *__fastcall func3(unsigned int a1)
{
char s[20]; // [rsp+4h] [rbp-14h] BYREF

snprintf(s, 0xCuLL, "%d", a1);
return strdup(s);
}

original_code:
char *int_to_string(int num)
{
 char buf[12];
 snprintf(buf, 12, "%d", num);
 return strdup(buf);
}

variable_types: num int

variable_types:
buf
char [12]

return_type: char *


decompiled_code:
char *__fastcall str_append(void *src, void *a2)
{
size_t v2; // rbx
size_t v3; // r12
char *v4; // rax
char *v5; // rbp
char *v6; // r12

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc(v2 + v3 + 1);
if ( !v4 )
return 0LL;
v5 = v4;
memcpy(v4, src, v2);
memcpy(&v5[v2], a2, v3 + 1);
v6 = strdup(v5);
free(v5);
return v6;
}

canonical_decompiled_code:
char *__fastcall func4(void *src, void *a2)
{
size_t v2; // rbx
size_t v3; // r12
char *v4; // rax
char *v5; // rbp
char *v6; // r12

v2 = strlen((const char *)src);
v3 = strlen((const char *)a2);
v4 = (char *)malloc(v2 + v3 + 1);
if ( !v4 )
return 0LL;
v5 = v4;
memcpy(v4, src, v2);
memcpy(&v5[v2], a2, v3 + 1);
v6 = strdup(v5);
free(v5);
return v6;
}

original_code:
char *str_append(char* first, char *second){
 char *buf = malloc(strlen(first) + strlen(second) + 1);
 char *ret;
 if(buf == ((void *)0))
  return ((void *)0);
 strcpy(buf, first);
 strcat(buf, second);
 ret = strdup(buf);
 free(buf);
 return ret;
}

canonical_original_code:
char *str_append(char *first, char *second){
 char *buf = malloc(strlen(first) + strlen(second) + 1);
 char *ret;
 if(buf == ((void *)0))
  return ((void *)0);
 strcpy(buf, first);
 strcat(buf, second);
 ret = strdup(buf);
 free(buf);
 return ret;
}

variable_types:
first
char *

variable_types:
second
char *

variable_types:
buf
char *

variable_types:
ret
char *


repo: joeledwards/asl-station-processor

original_code:
static char *scale_value (int64_t v, string *result)
{
  string s ;
  float r ;
  if (v != -1)

      if (v > 9999999)

          {
            r = v / 1000000.0 ;
            sprintf(s, "%5.2fM", r) ;
          }
      else if (v > 99999)

          {
            r = v / 1000.0 ;
            sprintf(s, "%4.1fK", r) ;
          }
        else
          sprintf(s, "%d", v) ;
    else
      s[0] = 0 ;
  strcpy(result, s) ;
  return result ;
}

canonical_original_code:
static char *scale_value(long v, char (*result)[256])
{
  char s[256];
  float r;
  if (v != -1)

      if (v > 9999999)

          {
            r = v / 1000000.0 ;
            sprintf(s, "%5.2fM", r) ;
          }
      else if (v > 99999)

          {
            r = v / 1000.0 ;
            sprintf(s, "%4.1fK", r) ;
          }
        else
          sprintf(s, "%d", v) ;
    else
      s[0] = 0 ;
  strcpy(result, s) ;
  return result ;
}

variable_types: v long

variable_types:
result
char (*)[256]

variable_types:
s
char [256]

variable_types: r float


original_code:
static char *format_time (int64_t sec, string *result)
{
  int64_t days, hours, minutes ;
  string s, s1 ;
  if (sec >= 0)

      (*result)[0] = 0 ;
    else
      {
        strcpy(result, "-") ;
        sec = abs(sec) ;
      }
  days = sec / 86400 ;
  sec = sec - days * 86400 ;
  hours = sec / 3600 ;
  sec = sec - hours * 3600 ;
  minutes = sec / 60 ;
  sec = sec - minutes * 60 ;
  s[0] = 0 ;
  if (days > 0)

      sprintf(s, "%dd", days) ;
  if ((s[0]) || (hours > 0))

      {
        condtwo (hours, (s[0]), s1, "h") ;
        strcat(s, s1) ;
      }
  if ((s[0]) || (minutes > 0))

      {
        condtwo (minutes, (s[0]), s1, "m") ;
        strcat(s, s1) ;
      }
  condtwo (sec, (s[0]), s1, "s") ;
  strcat(s, s1) ;
  strcat(result, s) ;
  return result ;
}

canonical_original_code:
static char *format_time(long sec, char (*result)[256])
{
  long days; long hours; long minutes;
  char s[256]; char s1[256];
  if (sec >= 0)

      (*result)[0] = 0 ;
    else
      {
        strcpy(result, "-") ;
        sec = abs(sec) ;
      }
  days = sec / 86400 ;
  sec = sec - days * 86400 ;
  hours = sec / 3600 ;
  sec = sec - hours * 3600 ;
  minutes = sec / 60 ;
  sec = sec - minutes * 60 ;
  s[0] = 0 ;
  if (days > 0)

      sprintf(s, "%dd", days) ;
  if ((s[0]) || (hours > 0))

      {
        condtwo (hours, (s[0]), s1, "h") ;
        strcat(s, s1) ;
      }
  if ((s[0]) || (minutes > 0))

      {
        condtwo (minutes, (s[0]), s1, "m") ;
        strcat(s, s1) ;
      }
  condtwo (sec, (s[0]), s1, "s") ;
  strcat(s, s1) ;
  strcat(result, s) ;
  return result ;
}

variable_types: sec long

variable_types: days long

variable_types: hours long

variable_types: minutes long


decompiled_code:
int show_opstat()
{
const char *v0; // rax
double v1; // xmm1_8
__int64 v2; // rdi
float v3; // xmm0_4
const char *v4; // rax
__int64 v5; // rdi
const char *v6; // rax
__int64 v7; // r12
const char *v8; // rax
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
unsigned __int64 v11; // r13
unsigned int i; // ebp
unsigned int v13; // ebx
__int64 v14; // rdi
char *v15; // rax
unsigned __int64 v16; // rdi
char *v17; // rax
int result; // eax
char *v19; // rax
float v20; // xmm0_4
const char *v21; // rax
const char *v22; // rax
char *v23; // rax
const char *v24; // rax
float v25; // xmm0_4
float v26; // xmm0_4
float v27; // xmm0_4
float v28; // xmm0_4
float v29; // xmm0_4
char *v30; // rax
int v31; // eax
__int64 v32; // r12
char *v33; // rax
char v34; // cl
__int64 v35; // rbx
__int64 v36; // rdx
int v37; // eax
char *v38; // rax
int v39; // eax
char v40[4]; // [rsp+1Ch] [rbp-25Ch] BYREF
char s[16]; // [rsp+20h] [rbp-258h] BYREF
char src[16]; // [rsp+30h] [rbp-248h] BYREF
__m128i dest[16]; // [rsp+40h] [rbp-238h] BYREF
char v44[312]; // [rsp+140h] [rbp-138h] BYREF

lib_get_state(context, v40, &opstat);
putchar(10);
printf("Station Name: %s\n", (const char *)&opstat);
printf("Data Port: %d\n", (unsigned int)*((unsigned __int16 *)&opstat + 5) + 1);
printf("Tag ID: %d\n", *((unsigned int *)&opstat + 3));
v0 = (const char *)showsn((unsigned int)((_DWORD)&opstat + 16), v44);
printf("Serial Number: %s\n", v0);
v1 = now();
v2 = *((unsigned int *)&opstat + 6);
v3 = ((double)*((int *)&opstat + 7) + v1 - (double)(int)v2) / 86400.0;
v4 = (const char *)jul_string(v2, dest);
printf("Time of Last Reboot: %s/%4.2fd\n", v4, v3);
v5 = *((unsigned int *)&opstat + 109);
if ( (_DWORD)v5 )
{
v6 = (const char *)jul_string(v5, dest);
printf("Last Data Received: %s\n", v6);
}
else
{
puts("No Data Recieved");
}
v7 = *((unsigned __int16 *)&opstat + 222);
v8 = (const char *)showdot(*((unsigned int *)&opstat + 110), v44);
printf("Current Address: %s:%d\n", v8, v7);
v9 = *((_WORD *)&opstat + 124);
if ( v9 <= 1u )
{
s[0] = 0;
LABEL_6:
v10 = *((_WORD *)&opstat + 125);
if ( v10 > 1u )
goto LABEL_7;
goto LABEL_37;
}
if ( v9 <= 0x3Bu )
{
sprintf(s, " %dmin=", v9);
goto LABEL_6;
}
v10 = *((_WORD *)&opstat + 125);
strcpy(s, " Hour=");
if ( v10 > 1u )
{
LABEL_7:
if ( v10 <= 0x17u )
sprintf(src, " %dhr=", v10);
else
strcpy(src, " Day=");
goto LABEL_9;
}
LABEL_37:
src[0] = 0;
LABEL_9:
v11 = (unsigned int)((_DWORD)&opstat + 32);
for ( i = 0; i != 18; ++i )
{
v13 = 0;
lib_acc_types(i, dest);
do
{
if ( v13 == 1 )
{
strcat((char *)dest, s);
if ( *((_WORD *)&opstat + 124) > 1u )
{
if ( s[0] )
{
v14 = *((int *)&opstat + 3 * i + 9);
if ( (_DWORD)v14 != -1 )
goto LABEL_16;
}
}
}
else if ( v13 != 2 )
{
if ( *(_DWORD *)v11 != -1 )
strcat((char *)dest, " minute=");
v14 = *((int *)&opstat + 3 * i + v13 + 8);
if ( (_DWORD)v14 == -1 )
goto LABEL_20;
LABEL_16:
if ( i == 10 )
goto LABEL_45;
goto LABEL_17;
}
strcat((char *)dest, src);
if ( *((_WORD *)&opstat + 125) <= 1u )
break;
if ( !src[0] )
break;
v14 = *((int *)&opstat + 3 * i + 10);
if ( (_DWORD)v14 == -1 )
break;
v13 = 2;
if ( i == 10 )
{
LABEL_45:
v28 = (double)(int)v14 * 0.1;
sprintf(v44, "%3.1f%", v28);
LABEL_47:
strcat((char *)dest, v44);
goto LABEL_20;
}
LABEL_17:
if ( i == 11 )
{
v29 = (double)(int)v14 * 0.01;
sprintf(v44, "%4.2f", v29);
goto LABEL_47;
}
if ( i == 7 )
goto LABEL_45;
v15 = scale_value(v14, v44);
strcat((char *)dest, v15);
LABEL_20:
++v13;
}
while ( v13 != 3 );
if ( dest[0].m128i_i8[0] )
puts((const char *)dest);
v11 += 12LL;
}
v16 = *((int *)&opstat + 66);
if ( (v16 & 0x80000000) != 0LL )
{
v30 = format_time(-(int)v16, v44);
printf("Time Disonnected: %s\n", v30);
if ( current_state == 10 )
goto LABEL_49;
LABEL_26:
result = *((_DWORD *)&opstat + 65);
if ( result != -66666666 )
{
LABEL_27:
v19 = format_time(result, v44);
result = printf("Status Latency: %s\n", v19);
goto LABEL_28;
}
}
else
{
v17 = format_time(v16, v44);
printf("Time Connected: %s\n", v17);
if ( current_state != 10 )
goto LABEL_26;
LABEL_49:
v31 = *((_DWORD *)&opstat + 64);
if ( v31 != -66666666 )
{
v38 = format_time(v31, v44);
printf("Data Latency: %s\n", v38);
}
v32 = 0LL;
v33 = scale_value(*((unsigned int *)&opstat + 67), v44);
printf("Total Data Gaps: %s\n", v33);
dest[0].m128i_i8[0] = 0;
do
{
while ( 1 )
{
v34 = v32++;
if ( (*((_QWORD *)&opstat + 42) & (1 << v34)) != 0LL )
break;
if ( v32 == 6 )
goto LABEL_55;
}
sprintf(v44, "%d", v32);
strcat((char *)dest, v44);
}
while ( v32 != 6 );
LABEL_55:
if ( dest[0].m128i_i8[0] )
printf("Digitzer Cal. Error on %s\n", (const char *)dest);
result = *((_DWORD *)&opstat + 65);
if ( result != -66666666 )
goto LABEL_27;
LABEL_28:
if ( current_state == 10 )
{
v20 = *((float *)&opstat + 88);
if ( v20 > 5.0 )
{
printf("Input Supply Voltage: %4.2f\n", v20);
v39 = lib_round((float)(1000.0 * *((float *)&opstat + 89)));
printf("Supply Current: %dma\n", v39);
result = printf("Temperature: %d\n", *((_QWORD *)&opstat + 43));
}
}
}
if ( *((_DWORD *)&opstat + 90) != -1 )
{
v21 = (const char *)lib_gps_state(*((unsigned int *)&opstat + 91), v44);
printf("GPS State: %s\n", v21);
v22 = (const char *)lib_gps_fix(*((unsigned int *)&opstat + 92), v44);
printf("GPS Fix: %s\n", v22);
v23 = format_time(*((int *)&opstat + 90), v44);
printf("GPS Age: %s\n", v23);
v24 = (const char *)lib_pll_state(*((unsigned int *)&opstat + 93), v44);
printf("PLL State: %s\n", v24);
v25 = *((double *)&opstat + 47);
printf("Latitude: %8.6f\n", v25);
v26 = *((double *)&opstat + 48);
printf("Longitude: %8.6f\n", v26);
v27 = *((double *)&opstat + 49);
result = printf("Elevation: %3.1f\n", v27);
}
if ( current_state == 10 )
{
v35 = 0LL;
dest[0] = _mm_load_si128((const __m128i *)&LC46);
do
{
v36 = *((_QWORD *)&opstat + v35++ + 36);
sprintf(v44, " %d", v36);
strcat((char *)dest, v44);
}
while ( v35 != 6 );
puts((const char *)dest);
v37 = lib_round(*((float *)&opstat + 68));
printf("Packet Buffer: %d%%\n", v37);
printf("Clock Quality: %d%%\n", *((unsigned __int16 *)&opstat + 138));
result = printf("Clock Drift: %dusec\n", *((int *)&opstat + 70));
}
return result;
}

canonical_decompiled_code:
int func3()
{
const char *v0; // rax
double v1; // xmm1_8
__int64 v2; // rdi
float v3; // xmm0_4
const char *v4; // rax
__int64 v5; // rdi
const char *v6; // rax
__int64 v7; // r12
const char *v8; // rax
unsigned __int16 v9; // ax
unsigned __int16 v10; // ax
unsigned __int64 v11; // r13
unsigned int i; // ebp
unsigned int v13; // ebx
__int64 v14; // rdi
char *v15; // rax
unsigned __int64 v16; // rdi
char *v17; // rax
int result; // eax
char *v19; // rax
float v20; // xmm0_4
const char *v21; // rax
const char *v22; // rax
char *v23; // rax
const char *v24; // rax
float v25; // xmm0_4
float v26; // xmm0_4
float v27; // xmm0_4
float v28; // xmm0_4
float v29; // xmm0_4
char *v30; // rax
int v31; // eax
__int64 v32; // r12
char *v33; // rax
char v34; // cl
__int64 v35; // rbx
__int64 v36; // rdx
int v37; // eax
char *v38; // rax
int v39; // eax
char v40[4]; // [rsp+1Ch] [rbp-25Ch] BYREF
char s[16]; // [rsp+20h] [rbp-258h] BYREF
char src[16]; // [rsp+30h] [rbp-248h] BYREF
__m128i dest[16]; // [rsp+40h] [rbp-238h] BYREF
char v44[312]; // [rsp+140h] [rbp-138h] BYREF

lib_get_state(context, v40, &opstat);
putchar(10);
printf("Station Name: %s\n", (const char *)&opstat);
printf("Data Port: %d\n", (unsigned int)*((unsigned __int16 *)&opstat + 5) + 1);
printf("Tag ID: %d\n", *((unsigned int *)&opstat + 3));
v0 = (const char *)showsn((unsigned int)((_DWORD)&opstat + 16), v44);
printf("Serial Number: %s\n", v0);
v1 = now();
v2 = *((unsigned int *)&opstat + 6);
v3 = ((double)*((int *)&opstat + 7) + v1 - (double)(int)v2) / 86400.0;
v4 = (const char *)jul_string(v2, dest);
printf("Time of Last Reboot: %s/%4.2fd\n", v4, v3);
v5 = *((unsigned int *)&opstat + 109);
if ( (_DWORD)v5 )
{
v6 = (const char *)jul_string(v5, dest);
printf("Last Data Received: %s\n", v6);
}
else
{
puts("No Data Recieved");
}
v7 = *((unsigned __int16 *)&opstat + 222);
v8 = (const char *)showdot(*((unsigned int *)&opstat + 110), v44);
printf("Current Address: %s:%d\n", v8, v7);
v9 = *((_WORD *)&opstat + 124);
if ( v9 <= 1u )
{
s[0] = 0;
LABEL_6:
v10 = *((_WORD *)&opstat + 125);
if ( v10 > 1u )
goto LABEL_7;
goto LABEL_37;
}
if ( v9 <= 0x3Bu )
{
sprintf(s, " %dmin=", v9);
goto LABEL_6;
}
v10 = *((_WORD *)&opstat + 125);
strcpy(s, " Hour=");
if ( v10 > 1u )
{
LABEL_7:
if ( v10 <= 0x17u )
sprintf(src, " %dhr=", v10);
else
strcpy(src, " Day=");
goto LABEL_9;
}
LABEL_37:
src[0] = 0;
LABEL_9:
v11 = (unsigned int)((_DWORD)&opstat + 32);
for ( i = 0; i != 18; ++i )
{
v13 = 0;
lib_acc_types(i, dest);
do
{
if ( v13 == 1 )
{
strcat((char *)dest, s);
if ( *((_WORD *)&opstat + 124) > 1u )
{
if ( s[0] )
{
v14 = *((int *)&opstat + 3 * i + 9);
if ( (_DWORD)v14 != -1 )
goto LABEL_16;
}
}
}
else if ( v13 != 2 )
{
if ( *(_DWORD *)v11 != -1 )
strcat((char *)dest, " minute=");
v14 = *((int *)&opstat + 3 * i + v13 + 8);
if ( (_DWORD)v14 == -1 )
goto LABEL_20;
LABEL_16:
if ( i == 10 )
goto LABEL_45;
goto LABEL_17;
}
strcat((char *)dest, src);
if ( *((_WORD *)&opstat + 125) <= 1u )
break;
if ( !src[0] )
break;
v14 = *((int *)&opstat + 3 * i + 10);
if ( (_DWORD)v14 == -1 )
break;
v13 = 2;
if ( i == 10 )
{
LABEL_45:
v28 = (double)(int)v14 * 0.1;
sprintf(v44, "%3.1f%", v28);
LABEL_47:
strcat((char *)dest, v44);
goto LABEL_20;
}
LABEL_17:
if ( i == 11 )
{
v29 = (double)(int)v14 * 0.01;
sprintf(v44, "%4.2f", v29);
goto LABEL_47;
}
if ( i == 7 )
goto LABEL_45;
v15 = func0(v14, v44);
strcat((char *)dest, v15);
LABEL_20:
++v13;
}
while ( v13 != 3 );
if ( dest[0].m128i_i8[0] )
puts((const char *)dest);
v11 += 12LL;
}
v16 = *((int *)&opstat + 66);
if ( (v16 & 0x80000000) != 0LL )
{
v30 = func2(-(int)v16, v44);
printf("Time Disonnected: %s\n", v30);
if ( current_state == 10 )
goto LABEL_49;
LABEL_26:
result = *((_DWORD *)&opstat + 65);
if ( result != -66666666 )
{
LABEL_27:
v19 = func2(result, v44);
result = printf("Status Latency: %s\n", v19);
goto LABEL_28;
}
}
else
{
v17 = func2(v16, v44);
printf("Time Connected: %s\n", v17);
if ( current_state != 10 )
goto LABEL_26;
LABEL_49:
v31 = *((_DWORD *)&opstat + 64);
if ( v31 != -66666666 )
{
v38 = func2(v31, v44);
printf("Data Latency: %s\n", v38);
}
v32 = 0LL;
v33 = func0(*((unsigned int *)&opstat + 67), v44);
printf("Total Data Gaps: %s\n", v33);
dest[0].m128i_i8[0] = 0;
do
{
while ( 1 )
{
v34 = v32++;
if ( (*((_QWORD *)&opstat + 42) & (1 << v34)) != 0LL )
break;
if ( v32 == 6 )
goto LABEL_55;
}
sprintf(v44, "%d", v32);
strcat((char *)dest, v44);
}
while ( v32 != 6 );
LABEL_55:
if ( dest[0].m128i_i8[0] )
printf("Digitzer Cal. Error on %s\n", (const char *)dest);
result = *((_DWORD *)&opstat + 65);
if ( result != -66666666 )
goto LABEL_27;
LABEL_28:
if ( current_state == 10 )
{
v20 = *((float *)&opstat + 88);
if ( v20 > 5.0 )
{
printf("Input Supply Voltage: %4.2f\n", v20);
v39 = lib_round((float)(1000.0 * *((float *)&opstat + 89)));
printf("Supply Current: %dma\n", v39);
result = printf("Temperature: %d\n", *((_QWORD *)&opstat + 43));
}
}
}
if ( *((_DWORD *)&opstat + 90) != -1 )
{
v21 = (const char *)lib_gps_state(*((unsigned int *)&opstat + 91), v44);
printf("GPS State: %s\n", v21);
v22 = (const char *)lib_gps_fix(*((unsigned int *)&opstat + 92), v44);
printf("GPS Fix: %s\n", v22);
v23 = func2(*((int *)&opstat + 90), v44);
printf("GPS Age: %s\n", v23);
v24 = (const char *)lib_pll_state(*((unsigned int *)&opstat + 93), v44);
printf("PLL State: %s\n", v24);
v25 = *((double *)&opstat + 47);
printf("Latitude: %8.6f\n", v25);
v26 = *((double *)&opstat + 48);
printf("Longitude: %8.6f\n", v26);
v27 = *((double *)&opstat + 49);
result = printf("Elevation: %3.1f\n", v27);
}
if ( current_state == 10 )
{
v35 = 0LL;
dest[0] = _mm_load_si128((const __m128i *)&LC46);
do
{
v36 = *((_QWORD *)&opstat + v35++ + 36);
sprintf(v44, " %d", v36);
strcat((char *)dest, v44);
}
while ( v35 != 6 );
puts((const char *)dest);
v37 = lib_round(*((float *)&opstat + 68));
printf("Packet Buffer: %d%%\n", v37);
printf("Clock Quality: %d%%\n", *((unsigned __int16 *)&opstat + 138));
result = printf("Clock Drift: %dusec\n", *((int *)&opstat + 70));
}
return result;
}

original_code:
void show_opstat (void)
{
  enum tliberr err ;
  enum tacctype acctype ;
  enum taccdur accdur ;
  string s, s1 ;
  double toff ;
  float r ;
  int64_t pwc, i, v ;
  string15 shour, sday ;
  lib_get_state (context, &(err), &(opstat)) ;
  printf ("\n") ;
  printf ("Station Name: %s\n", opstat.station_name) ;
  printf ("Data Port: %d\n", opstat.station_port + 1) ;
  printf ("Tag ID: %d\n", opstat.station_tag) ;
  printf ("Serial Number: %s\n", showsn(opstat.station_serial, &(s1))) ;
  toff = now () + opstat.timezone_offset - opstat.station_reboot ;
  r = toff / 86400.0 ;
  printf ("Time of Last Reboot: %s/%4.2fd\n", jul_string (opstat.station_reboot, &(s)), r) ;
  if (opstat.last_data_time)

      printf("Last Data Received: %s\n", jul_string (opstat.last_data_time, &(s))) ;
    else
      printf ("No Data Recieved\n") ;
  printf ("Current Address: %s:%d\n", showdot(opstat.current_ip, &(s1)), (int64_t)opstat.current_port) ;
  if (opstat.minutes_of_stats < 2)

      shour[0] = 0 ;
  else if (opstat.minutes_of_stats >= 60)

      strcpy(shour, " Hour=") ;
    else
      sprintf(shour, " %dmin=", opstat.minutes_of_stats) ;
  if (opstat.hours_of_stats < 2)

      sday[0] = 0 ;
  else if (opstat.hours_of_stats >= 24)

      strcpy(sday, " Day=") ;
    else
      sprintf(sday, " %dhr=", opstat.hours_of_stats) ;
  for (acctype = AC_GAPS ; acctype <= AC_IOERR ; acctype++)
    {
      lib_acc_types (acctype, &(s)) ;
      for (accdur = AD_MINUTE ; accdur <= AD_DAY ; accdur++)
        {
          switch (accdur) {
            case AD_MINUTE :
              if (opstat.accstats[acctype][accdur] != -1)

                  strcat(s, " minute=") ;
              break ;
            case AD_HOUR :
              strcat(s, shour) ;
              break ;
            case AD_DAY :
              strcat(s, sday) ;
              break ;
          }
          if ((accdur == AD_HOUR) && ((opstat.minutes_of_stats < 2) || (shour[0] == 0)) ||
             (accdur == AD_DAY) && ((opstat.hours_of_stats < 2) || (sday[0] == 0)) ||
             (opstat.accstats[acctype][accdur] == -1))

              ;
            else
              switch (acctype) {
                case AC_DUTY :
                case AC_COMEFF :
                  r = opstat.accstats[acctype][accdur] * 0.1 ;
                  sprintf(s1, "%3.1f%", r) ;
                  strcat(s, s1) ;
                  break ;
                case AC_THROUGH :
                  r = opstat.accstats[acctype][accdur] * 0.01 ;
                  sprintf(s1, "%4.2f", r) ;
                  strcat(s, s1) ;
                  break ;
                default :
                  strcat(s, scale_value(opstat.accstats[acctype][accdur], &(s1))) ;
                  break ;
              }
        }
      if (s[0])

          printf ("%s\n", s) ;
    }
  if (opstat.runtime >= 0)

      printf("Time Connected: %s\n", format_time(abs(opstat.runtime), &(s1))) ;
    else
      printf("Time Disonnected: %s\n", format_time(abs(opstat.runtime), &(s1))) ;
  if (current_state == LIBSTATE_RUN)

      {
        if (opstat.data_latency != -66666666)

            printf ("Data Latency: %s\n", format_time(opstat.data_latency, &(s1))) ;
        printf ("Total Data Gaps: %s\n", scale_value(opstat.totalgaps, &(s1))) ;
        s[0] = 0 ;
        for (i = 0 ; i <= 6 - 1 ; i++)
          if (opstat.calibration_errors & (1 << i))

              {
                sprintf(s1, "%d", i + 1) ;
                strcat(s, s1) ;
              }
        if (s[0])

            printf ("Digitzer Cal. Error on %s\n", s) ;
      }
   if (opstat.status_latency != -66666666)

      printf ("Status Latency: %s\n", format_time(opstat.status_latency, &(s1))) ;
  if ((current_state == LIBSTATE_RUN) && (opstat.pwr_volt > 5))

      {
        r = opstat.pwr_volt ;
        printf ("Input Supply Voltage: %4.2f\n", r) ;
        pwc = lib_round(opstat.pwr_cur * 1000) ;
        printf ("Supply Current: %dma\n", pwc) ;
        printf ("Temperature: %d\n", opstat.sys_temp) ;
      }
  if (opstat.gps_age != -1)

      {
        printf ("GPS State: %s\n", lib_gps_state (opstat.gps_stat, &(s1))) ;
        printf ("GPS Fix: %s\n", lib_gps_fix (opstat.gps_fix, &(s1))) ;
        printf ("GPS Age: %s\n", format_time(opstat.gps_age, &(s1))) ;
        printf ("PLL State: %s\n", lib_pll_state(opstat.pll_stat, &(s1))) ;
        r = opstat.gps_lat ;
        printf ("Latitude: %8.6f\n", r) ;
        r = opstat.gps_long ;
        printf ("Longitude: %8.6f\n", r) ;
        r = opstat.gps_elev ;
        printf ("Elevation: %3.1f\n", r) ;
      }
  if (current_state == LIBSTATE_RUN)

      {
        strcpy(s, "Mass Positions:") ;
        for (i = 0 ; i <= 5 ; i++)
          {
            sprintf(s1, " %d", opstat.mass_pos[i]) ;
            strcat(s, s1) ;
          }
        printf ("%s\n", s) ;
        v = lib_round(opstat.pkt_full) ;
        printf ("Packet Buffer: %d%%\n", v) ;
        printf ("Clock Quality: %d%%\n", opstat.clock_qual) ;
        v = opstat.clock_drift ;
        printf ("Clock Drift: %dusec\n", v) ;
      }
}

canonical_original_code:
void show_opstat()
{
  enum tliberr err;
  enum tacctype acctype;
  enum taccdur accdur;
  char s[256]; char s1[256];
  double toff;
  float r;
  long pwc; long i; long v;
  char shour[16]; char sday[16];
  lib_get_state (context, &(err), &(opstat)) ;
  printf ("\n") ;
  printf ("Station Name: %s\n", opstat.station_name) ;
  printf ("Data Port: %d\n", opstat.station_port + 1) ;
  printf ("Tag ID: %d\n", opstat.station_tag) ;
  printf ("Serial Number: %s\n", showsn(opstat.station_serial, &(s1))) ;
  toff = now () + opstat.timezone_offset - opstat.station_reboot ;
  r = toff / 86400.0 ;
  printf ("Time of Last Reboot: %s/%4.2fd\n", jul_string (opstat.station_reboot, &(s)), r) ;
  if (opstat.last_data_time)

      printf("Last Data Received: %s\n", jul_string (opstat.last_data_time, &(s))) ;
    else
      printf ("No Data Recieved\n") ;
  printf ("Current Address: %s:%d\n", showdot(opstat.current_ip, &(s1)), (long)opstat.current_port) ;
  if (opstat.minutes_of_stats < 2)

      shour[0] = 0 ;
  else if (opstat.minutes_of_stats >= 60)

      strcpy(shour, " Hour=") ;
    else
      sprintf(shour, " %dmin=", opstat.minutes_of_stats) ;
  if (opstat.hours_of_stats < 2)

      sday[0] = 0 ;
  else if (opstat.hours_of_stats >= 24)

      strcpy(sday, " Day=") ;
    else
      sprintf(sday, " %dhr=", opstat.hours_of_stats) ;
  for (acctype = AC_GAPS ; acctype <= AC_IOERR ; acctype++)
    {
      lib_acc_types (acctype, &(s)) ;
      for (accdur = AD_MINUTE ; accdur <= AD_DAY ; accdur++)
        {
          switch (accdur) {
            case AD_MINUTE :
              if (opstat.accstats[acctype][accdur] != -1)

                  strcat(s, " minute=") ;
              break ;
            case AD_HOUR :
              strcat(s, shour) ;
              break ;
            case AD_DAY :
              strcat(s, sday) ;
              break ;
          }
          if ((accdur == AD_HOUR) && ((opstat.minutes_of_stats < 2) || (shour[0] == 0)) ||
             (accdur == AD_DAY) && ((opstat.hours_of_stats < 2) || (sday[0] == 0)) ||
             (opstat.accstats[acctype][accdur] == -1))

              ;
            else
              switch (acctype) {
                case AC_DUTY :
                case AC_COMEFF :
                  r = opstat.accstats[acctype][accdur] * 0.1 ;
                  sprintf(s1, "%3.1f%", r) ;
                  strcat(s, s1) ;
                  break ;
                case AC_THROUGH :
                  r = opstat.accstats[acctype][accdur] * 0.01 ;
                  sprintf(s1, "%4.2f", r) ;
                  strcat(s, s1) ;
                  break ;
                default :
                  strcat(s, scale_value(opstat.accstats[acctype][accdur], &(s1))) ;
                  break ;
              }
        }
      if (s[0])

          printf ("%s\n", s) ;
    }
  if (opstat.runtime >= 0)

      printf("Time Connected: %s\n", format_time(abs(opstat.runtime), &(s1))) ;
    else
      printf("Time Disonnected: %s\n", format_time(abs(opstat.runtime), &(s1))) ;
  if (current_state == LIBSTATE_RUN)

      {
        if (opstat.data_latency != -66666666)

            printf ("Data Latency: %s\n", format_time(opstat.data_latency, &(s1))) ;
        printf ("Total Data Gaps: %s\n", scale_value(opstat.totalgaps, &(s1))) ;
        s[0] = 0 ;
        for (i = 0 ; i <= 6 - 1 ; i++)
          if (opstat.calibration_errors & (1 << i))

              {
                sprintf(s1, "%d", i + 1) ;
                strcat(s, s1) ;
              }
        if (s[0])

            printf ("Digitzer Cal. Error on %s\n", s) ;
      }
   if (opstat.status_latency != -66666666)

      printf ("Status Latency: %s\n", format_time(opstat.status_latency, &(s1))) ;
  if ((current_state == LIBSTATE_RUN) && (opstat.pwr_volt > 5))

      {
        r = opstat.pwr_volt ;
        printf ("Input Supply Voltage: %4.2f\n", r) ;
        pwc = lib_round(opstat.pwr_cur * 1000) ;
        printf ("Supply Current: %dma\n", pwc) ;
        printf ("Temperature: %d\n", opstat.sys_temp) ;
      }
  if (opstat.gps_age != -1)

      {
        printf ("GPS State: %s\n", lib_gps_state (opstat.gps_stat, &(s1))) ;
        printf ("GPS Fix: %s\n", lib_gps_fix (opstat.gps_fix, &(s1))) ;
        printf ("GPS Age: %s\n", format_time(opstat.gps_age, &(s1))) ;
        printf ("PLL State: %s\n", lib_pll_state(opstat.pll_stat, &(s1))) ;
        r = opstat.gps_lat ;
        printf ("Latitude: %8.6f\n", r) ;
        r = opstat.gps_long ;
        printf ("Longitude: %8.6f\n", r) ;
        r = opstat.gps_elev ;
        printf ("Elevation: %3.1f\n", r) ;
      }
  if (current_state == LIBSTATE_RUN)

      {
        strcpy(s, "Mass Positions:") ;
        for (i = 0 ; i <= 5 ; i++)
          {
            sprintf(s1, " %d", opstat.mass_pos[i]) ;
            strcat(s, s1) ;
          }
        printf ("%s\n", s) ;
        v = lib_round(opstat.pkt_full) ;
        printf ("Packet Buffer: %d%%\n", v) ;
        printf ("Clock Quality: %d%%\n", opstat.clock_qual) ;
        v = opstat.clock_drift ;
        printf ("Clock Drift: %dusec\n", v) ;
      }
}

variable_types: enum tliberr { LIBERR_NOERR=0, LIBERR_PERM=1, LIBERR_TMSERV=2, LIBERR_NOTR=3, LIBERR_INVREG=4, LIBERR_PAR=5, LIBERR_SNV=6, LIBERR_CTRL=7, LIBERR_SPEC=8, LIBERR_MEM=9, LIBERR_CIP=10, LIBERR_DNA=11, LIBERR_DB9=12, LIBERR_MEMEW=13, LIBERR_THREADERR=14, LIBERR_BADDIR=15, LIBERR_REGTO=16, LIBERR_STATTO=17, LIBERR_DATATO=18, LIBERR_NOSTAT=19, LIBERR_INVSTAT=20, LIBERR_CFGWAIT=21, LIBERR_INVCFG=22, LIBERR_TOKENS_CHANGE=23, LIBERR_INVAL_TOKENS=24, LIBERR_BUFSHUT=25, LIBERR_CONNSHUT=26, LIBERR_CLOSED=27, LIBERR_NETFAIL=28, LIBERR_TUNBUSY=29, LIBERR_INVCTX=30 }

variable_types: enum tacctype { AC_GAPS=0, AC_BOOTS=1, AC_READ=2, AC_WRITE=3, AC_COMATP=4, AC_COMSUC=5, AC_PACKETS=6, AC_COMEFF=7, AC_POCS=8, AC_NEWIP=9, AC_DUTY=10, AC_THROUGH=11, AC_MISSING=12, AC_FILL=13, AC_CMDTO=14, AC_SEQERR=15, AC_CHECK=16, AC_IOERR=17 }

variable_types: enum taccdur { AD_MINUTE=0, AD_HOUR=1, AD_DAY=2 }

variable_types: toff double

variable_types: pwc long

variable_types: i long

variable_types:
shour
char [16]

variable_types:
sday
char [16]


decompiled_code:
int show_modules()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 v2; // rdx
const char *v3; // rsi
__int64 v4; // rbx
int result; // eax
__int64 v6; // rbp
__int64 v7; // rdx
const char *v8; // rsi

v0 = get_modules();
puts("Seneca Modules and Versions:");
v1 = v0 + 744;
do
{
if ( !*(_BYTE *)v0 )
break;
v2 = *(_QWORD *)(v0 + 16);
v3 = (const char *)v0;
v0 += 24LL;
printf("%13s %d\n", v3, v2);
}
while ( v0 != v1 );
v4 = lib_get_modules();
result = puts("Lib330 Modules and Versions:");
v6 = v4 + 744;
do
{
if ( !*(_BYTE *)v4 )
break;
v7 = *(_QWORD *)(v4 + 16);
v8 = (const char *)v4;
v4 += 24LL;
result = printf("%13s %d\n", v8, v7);
}
while ( v4 != v6 );
return result;
}

canonical_decompiled_code:
int func4()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 v2; // rdx
const char *v3; // rsi
__int64 v4; // rbx
int result; // eax
__int64 v6; // rbp
__int64 v7; // rdx
const char *v8; // rsi

v0 = get_modules();
puts("Seneca Modules and Versions:");
v1 = v0 + 744;
do
{
if ( !*(_BYTE *)v0 )
break;
v2 = *(_QWORD *)(v0 + 16);
v3 = (const char *)v0;
v0 += 24LL;
printf("%13s %d\n", v3, v2);
}
while ( v0 != v1 );
v4 = lib_get_modules();
result = puts("Lib330 Modules and Versions:");
v6 = v4 + 744;
do
{
if ( !*(_BYTE *)v4 )
break;
v7 = *(_QWORD *)(v4 + 16);
v8 = (const char *)v4;
v4 += 24LL;
result = printf("%13s %d\n", v8, v7);
}
while ( v4 != v6 );
return result;
}

original_code:
void show_modules (void)
{
  int64_t i ;
  pmodules pm ;
  tmodule *pone ;
  pm = get_modules () ;
  printf ("Seneca Modules and Versions:\n") ;
  for (i = 0 ; i <= (31 - 1) ; i++)
    {
      pone = &((*pm)[i]) ;
      if ((*pm)[i].name[0])

          printf ("%13s %d\n", &(pone->name), pone->ver) ;
        else
          break ;
    }
  pm = lib_get_modules () ;
  printf ("Lib330 Modules and Versions:\n") ;
  for (i = 0 ; i <= (31 - 1) ; i++)
    {
      pone = &((*pm)[i]) ;
      if ((*pm)[i].name[0])

          printf ("%13s %d\n", &(pone->name), pone->ver) ;
        else
          break ;
    }
}

canonical_original_code:
void show_modules()
{
  long i;
  struct tmodule (*pm)[31];
  struct tmodule *pone;
  pm = get_modules () ;
  printf ("Seneca Modules and Versions:\n") ;
  for (i = 0 ; i <= (31 - 1) ; i++)
    {
      pone = &((*pm)[i]) ;
      if ((*pm)[i].name[0])

          printf ("%13s %d\n", &(pone->name), pone->ver) ;
        else
          break ;
    }
  pm = lib_get_modules () ;
  printf ("Lib330 Modules and Versions:\n") ;
  for (i = 0 ; i <= (31 - 1) ; i++)
    {
      pone = &((*pm)[i]) ;
      if ((*pm)[i].name[0])

          printf ("%13s %d\n", &(pone->name), pone->ver) ;
        else
          break ;
    }
}

variable_types: struct tmodule { char name[16]; long ver; } (*)[31]

variable_types: struct tmodule { char name[16]; long ver; } *


decompiled_code:
// attributes: thunk
__int64 __fastcall ST_Julian2(__int64 a1, __int64 a2, __int64 a3)
{
return julday2(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2, __int64 a3)
{
return func1(a1, a2, a3);
}

original_code:
long ST_Julian2(long year, long mon, long day) {
  return(_julday2(year, mon, day));
}

variable_types: year long

variable_types: mon long

variable_types: day long

return_type: long


decompiled_code:
__int64 __fastcall ST_CnvJulToSTD2(int a1)
{
__int16 v2; // [rsp+1Eh] [rbp-1Ah] BYREF
char v3[2]; // [rsp+20h] [rbp-18h] BYREF
__int16 v4; // [rsp+22h] [rbp-16h] BYREF
unsigned __int16 v5; // [rsp+24h] [rbp-14h] BYREF
__int64 v6; // [rsp+26h] [rbp-12h]

ST_CnvJulToCal2(a1, (__int64)&v2, (__int64)v3, &v4, &v5);
BYTE6(v6) = 0;
LOWORD(v6) = v2;
*(_DWORD *)((char *)&v6 + 2) = v5;
return v6;
}

original_code:
STDTIME2 ST_CnvJulToSTD2(JULIAN injul) {
  STDTIME2 rettim = {0, 0, 0, 0, 0, 0};
  WORD outyr, outmon, outday, outjday;
  ST_CnvJulToCal2(injul, &outyr, &outmon, &outday, &outjday);
  rettim.year = outyr;
  rettim.day = outjday;
  return(rettim);
}

canonical_original_code:
struct __sjtim2 ST_CnvJulToSTD2(long injul) {
  struct __sjtim2 rettim = {0, 0, 0, 0, 0, 0};
  short outyr; short outmon; short outday; short outjday;
  ST_CnvJulToCal2(injul, &outyr, &outmon, &outday, &outjday);
  rettim.year = outyr;
  rettim.day = outjday;
  return(rettim);
}

variable_types: injul long

variable_types: struct __sjtim2 { short year; short day; char hour; char minute; char second; short tenth_msec; }

variable_types: outyr short

variable_types: outmon short

variable_types: outday short

variable_types: outjday short


decompiled_code:
__int64 __fastcall ms_gswap4a(unsigned int *a1)
{
__int64 result; // rax

result = _byteswap_ulong(*a1);
*a1 = result;
return result;
}

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

result = _byteswap_ulong(*a1);
*a1 = result;
return result;
}

canonical_original_code:
void ms_gswap4a(void *data4)
{
  unsigned int *data = data4;
  *data=(((*data>>24)&0xff) | ((*data&0xff)<<24) |
  ((*data>>8)&0xff00) | ((*data&0xff00)<<8));
}

variable_types:
data
unsigned int *


decompiled_code:
__int64 __fastcall ms_gswap8a(unsigned int *a1)
{
__int64 result; // rax
unsigned __int32 v2; // edx

result = _byteswap_ulong(*a1);
v2 = _byteswap_ulong(a1[1]);
a1[1] = result;
*a1 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
__int64 result; // rax
unsigned __int32 v2; // edx

result = _byteswap_ulong(*a1);
v2 = _byteswap_ulong(a1[1]);
a1[1] = result;
*a1 = v2;
return result;
}


decompiled_code:
__int64 __fastcall prioqueue_init(__int64 a1, int a2, __int64 a3, __int64 a4)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 72) = a2;
*(_QWORD *)(a1 + 80) = a3;
*(_DWORD *)(a1 + 76) = 0;
*(_QWORD *)(a1 + 88) = a4;
return avltree_init(a1, queue_element_compare, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, int a2, __int64 a3, __int64 a4)
{
if ( !a1 )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 72) = a2;
*(_QWORD *)(a1 + 80) = a3;
*(_DWORD *)(a1 + 76) = 0;
*(_QWORD *)(a1 + 88) = a4;
return avltree_init(a1, queue_element_compare, 0LL);
}

original_code:
int prioqueue_init(queue_t *queue, int capacity,
                   prioqueue_duplicate duplicate,
                   prioqueue_deallocate deallocate)
{
    int result = -1;
    if (queue) {
        queue->capacity = capacity;
        queue->size = 0;
        queue->callback_duplicate = duplicate;
        queue->callback_deallocate = deallocate;
        result = avltree_init(&queue->tree, _queue_element_compare, 0);
    }
    return result;
}

canonical_original_code:
int prioqueue_init(struct QUEUE *queue, int capacity, void (*duplicate)(void *item, void **duplicate), void (*deallocate)(void *item))
{
    int result = -1;
    if (queue) {
        queue->capacity = capacity;
        queue->size = 0;
        queue->callback_duplicate = duplicate;
        queue->callback_deallocate = deallocate;
        result = avltree_init(&queue->tree, _queue_element_compare, 0);
    }
    return result;
}

variable_types: struct QUEUE { struct avltree { struct avltree_node { struct avltree_node *left; unsigned long parent; } *root; int (*cmp_fn)(struct avltree_node *, struct avltree_node *); int height; struct avltree_node *first; unsigned long reserved[4]; } tree; int capacity; int size; void (*callback_duplicate)(void *item, void **duplicate); void (*callback_deallocate)(void *item); } *

variable_types: capacity int

variable_types:
duplicate
void (*)(void *item, void **duplicate)

variable_types:
deallocate
void (*)(void *item)

variable_types: result int

return_type: int

user_defined_types: struct QUEUE { struct avltree tree; int capacity; int size; void (*callback_duplicate)(void *item, void **duplicate); void (*callback_deallocate)(void *item); }

user_defined_types: struct avltree { struct avltree_node *root; int (*cmp_fn)(struct avltree_node *, struct avltree_node *); int height; struct avltree_node *first; unsigned long reserved[4]; }


decompiled_code:
__int64 __fastcall prioqueue_full(__int64 a1)
{
int v1; // edx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *(_DWORD *)(a1 + 72);
result = 0LL;
if ( v1 >= 0 )
result = v1 <= *(_DWORD *)(a1 + 76);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // edx
__int64 result; // rax

if ( !a1 )
return 0xFFFFFFFFLL;
v1 = *(_DWORD *)(a1 + 72);
result = 0LL;
if ( v1 >= 0 )
result = v1 <= *(_DWORD *)(a1 + 76);
return result;
}

original_code:
int prioqueue_full(queue_t *queue)
{
    if (queue == ((void *)0))
        return -1;
    if ((queue->capacity > -1) && (queue->size >= queue->capacity))
        return 1;
    return 0;
}

canonical_original_code:
int prioqueue_full(struct QUEUE *queue)
{
    if (queue == ((void *)0))
        return -1;
    if ((queue->capacity > -1) && (queue->size >= queue->capacity))
        return 1;
    return 0;
}

user_defined_types: struct avltree_node { struct avltree_node *left; unsigned long parent; }


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

if ( a1 )
result = *(_DWORD *)(a1 + 76) == 0;
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(_DWORD *)(a1 + 76) == 0;
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int prioqueue_empty(queue_t *queue)
{
    if (queue == ((void *)0))
        return -1;
    return (queue->size == 0);
}

canonical_original_code:
int prioqueue_empty(struct QUEUE *queue)
{
    if (queue == ((void *)0))
        return -1;
    return (queue->size == 0);
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 76);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 76);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int prioqueue_size(queue_t *queue)
{
    if (queue == ((void *)0))
        return -1;
    return queue->size;
}

canonical_original_code:
int prioqueue_size(struct QUEUE *queue)
{
    if (queue == ((void *)0))
        return -1;
    return queue->size;
}


decompiled_code:
__int64 __fastcall prioqueue_add(__int64 a1, __int64 a2, int a3)
{
int v3; // eax
char *v5; // r14
__int64 v6; // rbp
void (__fastcall *v7)(_QWORD); // rax
void (__fastcall *v8)(__int64, char *); // rax
struct timezone tz; // [rsp+8h] [rbp-30h] BYREF

v3 = *(_DWORD *)(a1 + 72);
if ( !v3 )
return 0xFFFFFFFFLL;
v5 = 0LL;
if ( v3 <= 0 )
goto LABEL_16;
while ( *(_DWORD *)(a1 + 76) >= v3 )
{
v6 = avltree_first(a1);
avltree_remove(v6, a1);
v7 = *(void (__fastcall **)(_QWORD))(a1 + 88);
--*(_DWORD *)(a1 + 76);
v5 = (char *)(v6 - 32);
if ( v7 )
v7(*(_QWORD *)(v6 - 8));
v3 = *(_DWORD *)(a1 + 72);
*(_QWORD *)(v6 - 8) = 0LL;
if ( v3 <= 0 )
goto LABEL_10;
}
if ( !v5 )
{
LABEL_16:
v5 = (char *)malloc(0x38uLL);
if ( !v5 )
return 0xFFFFFFFFLL;
}
LABEL_10:
tz = 0LL;
gettimeofday((struct timeval *)(v5 + 8), &tz);
v8 = *(void (__fastcall **)(__int64, char *))(a1 + 80);
*(_DWORD *)v5 = a3;
*((_QWORD *)v5 + 3) = a2;
if ( v8 )
v8(a2, v5 + 24);
avltree_insert(v5 + 32, a1);
++*(_DWORD *)(a1 + 76);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, int a3)
{
int v3; // eax
char *v5; // r14
__int64 v6; // rbp
void (__fastcall *v7)(_QWORD); // rax
void (__fastcall *v8)(__int64, char *); // rax
struct timezone tz; // [rsp+8h] [rbp-30h] BYREF

v3 = *(_DWORD *)(a1 + 72);
if ( !v3 )
return 0xFFFFFFFFLL;
v5 = 0LL;
if ( v3 <= 0 )
goto LABEL_16;
while ( *(_DWORD *)(a1 + 76) >= v3 )
{
v6 = avltree_first(a1);
avltree_remove(v6, a1);
v7 = *(void (__fastcall **)(_QWORD))(a1 + 88);
--*(_DWORD *)(a1 + 76);
v5 = (char *)(v6 - 32);
if ( v7 )
v7(*(_QWORD *)(v6 - 8));
v3 = *(_DWORD *)(a1 + 72);
*(_QWORD *)(v6 - 8) = 0LL;
if ( v3 <= 0 )
goto LABEL_10;
}
if ( !v5 )
{
LABEL_16:
v5 = (char *)malloc(0x38uLL);
if ( !v5 )
return 0xFFFFFFFFLL;
}
LABEL_10:
tz = 0LL;
gettimeofday((struct timeval *)(v5 + 8), &tz);
v8 = *(void (__fastcall **)(__int64, char *))(a1 + 80);
*(_DWORD *)v5 = a3;
*((_QWORD *)v5 + 3) = a2;
if ( v8 )
v8(a2, v5 + 24);
avltree_insert(v5 + 32, a1);
++*(_DWORD *)(a1 + 76);
return 0LL;
}

original_code:
int prioqueue_add(queue_t *queue, void *data, int priority)
{
    struct avltree_node *node = ((void *)0);
    queue_element_t *element = ((void *)0);
    struct timezone tz_info;
    if (queue->capacity == 0) {
        return -1;
    }
    while (queue->capacity > 0 && queue->size >= queue->capacity) {
        node = avltree_first(&queue->tree);
        avltree_remove(node, &queue->tree);
        queue->size--;
        element = (queue_element_t *)({ const struct avltree_node *__mptr = (node); (queue_element_t *)( (char *)__mptr - __builtin_offsetof (queue_element_t, node) );});
        if (queue->callback_deallocate != ((void *)0)) {
            queue->callback_deallocate(element->data);
        }
        element->data = ((void *)0);
        node = ((void *)0);
    }
    if ( (element == ((void *)0)) &&
         (element = (queue_element_t *)malloc(sizeof(queue_element_t))) == ((void *)0))
    {
        return -1;
    }
    else {
        tz_info.tz_minuteswest = 0;
        tz_info.tz_dsttime = 0;
        gettimeofday(&element->time_received, &tz_info);
        element->priority = priority;
        element->data = data;
        if (queue->callback_duplicate != ((void *)0)) {
            queue->callback_duplicate(data, &element->data);
        }
        avltree_insert(&element->node, &queue->tree);
        queue->size++;
    }
    return 0;
}

canonical_original_code:
int prioqueue_add(struct QUEUE *queue, void *data, int priority)
{
    struct avltree_node *node = ((void *)0);
    struct QUEUE_ELEMENT *element = ((void *)0);
    struct timezone tz_info;
    if (queue->capacity == 0) {
        return -1;
    }
    while (queue->capacity > 0 && queue->size >= queue->capacity) {
        node = avltree_first(&queue->tree);
        avltree_remove(node, &queue->tree);
        queue->size--;
        element = (struct QUEUE_ELEMENT *)({ struct avltree_node *__mptr = (node); (struct QUEUE_ELEMENT *)( (char *)__mptr - __builtin_offsetof (queue_element_t, node) );});
        if (queue->callback_deallocate != ((void *)0)) {
            queue->callback_deallocate(element->data);
        }
        element->data = ((void *)0);
        node = ((void *)0);
    }
    if ( (element == ((void *)0)) &&
         (element = (struct QUEUE_ELEMENT *)malloc(sizeof(queue_element_t))) == ((void *)0))
    {
        return -1;
    }
    else {
        tz_info.tz_minuteswest = 0;
        tz_info.tz_dsttime = 0;
        gettimeofday(&element->time_received, &tz_info);
        element->priority = priority;
        element->data = data;
        if (queue->callback_duplicate != ((void *)0)) {
            queue->callback_duplicate(data, &element->data);
        }
        avltree_insert(&element->node, &queue->tree);
        queue->size++;
    }
    return 0;
}

variable_types:
data
void *

variable_types: priority int

variable_types: struct avltree_node { struct avltree_node *left; unsigned long parent; } *

variable_types: struct QUEUE_ELEMENT { int priority; struct timeval { long tv_sec; long tv_usec; } time_received; void *data; struct avltree_node { struct avltree_node *left; unsigned long parent; } node; } *

variable_types: struct timezone { int tz_minuteswest; int tz_dsttime; }

user_defined_types: struct QUEUE_ELEMENT { int priority; struct timeval time_received; void *data; struct avltree_node node; }


decompiled_code:
__int64 __fastcall prioqueue_clone(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
__int64 v5; // rbp

if ( !a1 || !a2 )
return (unsigned int)-1;
v2 = *(_DWORD *)(a2 + 72);
*(_DWORD *)(a1 + 76) = 0;
*(_DWORD *)(a1 + 72) = v2;
*(_QWORD *)(a1 + 80) = *(_QWORD *)(a2 + 80);
*(_QWORD *)(a1 + 88) = *(_QWORD *)(a2 + 88);
v3 = avltree_init(a1, queue_element_compare, 0LL);
if ( v3 )
return v3;
v5 = avltree_first(a2);
if ( !v5 )
return v3;
do
{
prioqueue_add(a1, *(_QWORD *)(v5 - 8), *(_DWORD *)(v5 - 32));
v5 = avltree_next(v5);
}
while ( v5 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // er12
__int64 v5; // rbp

if ( !a1 || !a2 )
return (unsigned int)-1;
v2 = *(_DWORD *)(a2 + 72);
*(_DWORD *)(a1 + 76) = 0;
*(_DWORD *)(a1 + 72) = v2;
*(_QWORD *)(a1 + 80) = *(_QWORD *)(a2 + 80);
*(_QWORD *)(a1 + 88) = *(_QWORD *)(a2 + 88);
v3 = avltree_init(a1, queue_element_compare, 0LL);
if ( v3 )
return v3;
v5 = avltree_first(a2);
if ( !v5 )
return v3;
do
{
func5(a1, *(_QWORD *)(v5 - 8), *(_DWORD *)(v5 - 32));
v5 = avltree_next(v5);
}
while ( v5 );
return v3;
}

original_code:
int prioqueue_clone(queue_t *target, queue_t *source)
{
    int result = -1;
    struct avltree_node *node;
    queue_element_t *element = ((void *)0);
    if (target && source) {
        target->capacity = source->capacity;
        target->size = 0;
        target->callback_duplicate = source->callback_duplicate;
        target->callback_deallocate = source->callback_deallocate;
        if (!(result = avltree_init(&target->tree, _queue_element_compare, 0))) {
            node = avltree_first(&source->tree);
            while (node != ((void *)0)) {
                element = (queue_element_t *)({ const struct avltree_node *__mptr = (node); (queue_element_t *)( (char *)__mptr - __builtin_offsetof (queue_element_t, node) );});
                prioqueue_add(target, element->data, element->priority);
                node = avltree_next(node);
            }
            result = 0;
        }
    }
    return result;
}

canonical_original_code:
int prioqueue_clone(struct QUEUE *target, struct QUEUE *source)
{
    int result = -1;
    struct avltree_node *node;
    struct QUEUE_ELEMENT *element = ((void *)0);
    if (target && source) {
        target->capacity = source->capacity;
        target->size = 0;
        target->callback_duplicate = source->callback_duplicate;
        target->callback_deallocate = source->callback_deallocate;
        if (!(result = avltree_init(&target->tree, _queue_element_compare, 0))) {
            node = avltree_first(&source->tree);
            while (node != ((void *)0)) {
                element = (struct QUEUE_ELEMENT *)({ struct avltree_node *__mptr = (node); (struct QUEUE_ELEMENT *)( (char *)__mptr - __builtin_offsetof (queue_element_t, node) );});
                prioqueue_add(target, element->data, element->priority);
                node = avltree_next(node);
            }
            result = 0;
        }
    }
    return result;
}

variable_types:
source
struct QUEUE *

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
__int64 __fastcall prioqueue_peek_high(__int64 a1)
{
return fetch_queue_item(a1, 1, 0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return func7(a1, 1, 0);
}

original_code:
void *prioqueue_peek_high(queue_t *queue)
{
    return _fetch_queue_item(queue, 1 , 0 );
}

canonical_original_code:
void *prioqueue_peek_high(struct QUEUE *queue)
{
    return _fetch_queue_item(queue, 1 , 0 );
}

return_type: void *


decompiled_code:
__int64 __fastcall prioqueue_pop_high(__int64 a1)
{
return fetch_queue_item(a1, 1, 1);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return func7(a1, 1, 1);
}

original_code:
void *prioqueue_pop_high(queue_t *queue)
{
    return _fetch_queue_item(queue, 1 , 1 );
}

canonical_original_code:
void *prioqueue_pop_high(struct QUEUE *queue)
{
    return _fetch_queue_item(queue, 1 , 1 );
}


decompiled_code:
__int64 __fastcall prioqueue_peek_low(__int64 a1)
{
return fetch_queue_item(a1, 0, 0);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
return func7(a1, 0, 0);
}

original_code:
void *prioqueue_peek_low(queue_t *queue)
{
    return _fetch_queue_item(queue, 0 , 0 );
}

canonical_original_code:
void *prioqueue_peek_low(struct QUEUE *queue)
{
    return _fetch_queue_item(queue, 0 , 0 );
}


decompiled_code:
__int64 __fastcall prioqueue_pop_low(__int64 a1)
{
return fetch_queue_item(a1, 0, 1);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
return func7(a1, 0, 1);
}

original_code:
void *prioqueue_pop_low(queue_t *queue)
{
    return _fetch_queue_item(queue, 0 , 1 );
}

canonical_original_code:
void *prioqueue_pop_low(struct QUEUE *queue)
{
    return _fetch_queue_item(queue, 0 , 1 );
}


hash

original_code:
static unsigned long hash(const char *str)
{
    unsigned long hash = 5381;
    int c;
    while ((c = *str++)) {
        hash = ((hash << 5) + hash) + c;
    }
    return hash;
}

canonical_original_code:
static unsigned long hash(char *str)
{
    unsigned long hash = 5381;
    int c;
    while ((c = *str++)) {
        hash = ((hash << 5) + hash) + c;
    }
    return hash;
}

variable_types:
str
char *

variable_types:
hash
unsigned long

variable_types: c int

return_type: unsigned long


original_code:
static int remove_pair(Map *map, Bucket *bucket, const char *key)
{
    unsigned int i, n, moves, found;
    Pair *pair;
    Pair *new_pairs;
    n = bucket->count;
    if (n == 0) {
        return 0;
    }
    pair = bucket->pairs;
    i = 0;
    moves = 0;
    found = 0;
    while (i < n) {
        if ((pair->key == ((void *)0))) {
            if (map->free_func != 0) {
                map->free_func(pair->value);
            }
            memmove(pair, pair+sizeof(Pair), (n - i - 1) * sizeof(Pair));
            moves++;
        } else if (strcmp(pair->key, key) == 0) {
            if (map->free_func != 0) {
                map->free_func(pair->value);
            }
            free(pair->key);
            memmove(pair, pair+sizeof(Pair), (n - i - 1) * sizeof(Pair));
            moves++;
            found = 1;
        }
        pair++;
        i++;
    }
    bucket->count -= moves;
    new_pairs = realloc(bucket->pairs, (bucket->count - moves) * sizeof(Pair));
    if (new_pairs != ((void *)0)) {
        bucket->pairs = new_pairs;
    }
    return found;
}

canonical_original_code:
static int remove_pair(struct Map *map, struct Bucket *bucket, char *key)
{
    unsigned int i; unsigned int n; unsigned int moves; unsigned int found;
    struct Pair *pair;
    struct Pair *new_pairs;
    n = bucket->count;
    if (n == 0) {
        return 0;
    }
    pair = bucket->pairs;
    i = 0;
    moves = 0;
    found = 0;
    while (i < n) {
        if ((pair->key == ((void *)0))) {
            if (map->free_func != 0) {
                map->free_func(pair->value);
            }
            memmove(pair, pair+sizeof(Pair), (n - i - 1) * sizeof(Pair));
            moves++;
        } else if (strcmp(pair->key, key) == 0) {
            if (map->free_func != 0) {
                map->free_func(pair->value);
            }
            free(pair->key);
            memmove(pair, pair+sizeof(Pair), (n - i - 1) * sizeof(Pair));
            moves++;
            found = 1;
        }
        pair++;
        i++;
    }
    bucket->count -= moves;
    new_pairs = realloc(bucket->pairs, (bucket->count - moves) * sizeof(Pair));
    if (new_pairs != ((void *)0)) {
        bucket->pairs = new_pairs;
    }
    return found;
}

variable_types: struct Map { unsigned int count; void (*free_func)(void *value); void *(*dup_func)(void *value); struct Bucket { unsigned int count; struct Pair { char *key; void *value; } *pairs; } *buckets; } *

variable_types:
bucket
struct Bucket *

variable_types:
key
char *

variable_types:
i
unsigned int

variable_types:
n
unsigned int

variable_types:
moves
unsigned int

variable_types:
found
unsigned int

user_defined_types: struct Map { unsigned int count; void (*free_func)(void *value); void *(*dup_func)(void *value); struct Bucket *buckets; }

user_defined_types: struct Bucket { unsigned int count; struct Pair *pairs; }


decompiled_code:
void __fastcall map_delete(void *ptr)
{
__int64 v1; // rax
_QWORD *v2; // r13
_QWORD *v3; // r14
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rbx
void (__fastcall *v7)(_QWORD); // rax

if ( ptr )
{
v1 = *(unsigned int *)ptr;
v2 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( (_DWORD)v1 )
{
v3 = &v2[2 * v1];
do
{
v4 = *(unsigned int *)v2;
v5 = v2[1];
if ( (_DWORD)v4 )
{
v6 = v5 + 16 * v4;
do
{
free(*(void **)v5);
v7 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
if ( v7 )
v7(*(_QWORD *)(v5 + 8));
v5 += 16LL;
}
while ( v5 != v6 );
v5 = v2[1];
}
v2 += 2;
free((void *)v5);
}
while ( v2 != v3 );
v2 = (_QWORD *)*((_QWORD *)ptr + 3);
}
free(v2);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
__int64 v1; // rax
_QWORD *v2; // r13
_QWORD *v3; // r14
__int64 v4; // rbx
__int64 v5; // rbp
__int64 v6; // rbx
void (__fastcall *v7)(_QWORD); // rax

if ( ptr )
{
v1 = *(unsigned int *)ptr;
v2 = (_QWORD *)*((_QWORD *)ptr + 3);
if ( (_DWORD)v1 )
{
v3 = &v2[2 * v1];
do
{
v4 = *(unsigned int *)v2;
v5 = v2[1];
if ( (_DWORD)v4 )
{
v6 = v5 + 16 * v4;
do
{
free(*(void **)v5);
v7 = (void (__fastcall *)(_QWORD))*((_QWORD *)ptr + 1);
if ( v7 )
v7(*(_QWORD *)(v5 + 8));
v5 += 16LL;
}
while ( v5 != v6 );
v5 = v2[1];
}
v2 += 2;
free((void *)v5);
}
while ( v2 != v3 );
v2 = (_QWORD *)*((_QWORD *)ptr + 3);
}
free(v2);
free(ptr);
}
}

original_code:
void map_delete(Map *map)
{
    unsigned int i, j, n, m;
    Bucket *bucket;
    Pair *pair;
    if (map == ((void *)0)) {
        return;
    }
    n = map->count;
    bucket = map->buckets;
    i = 0;
    while (i < n) {
        m = bucket->count;
        pair = bucket->pairs;
        j = 0;
        while(j < m) {
            free(pair->key);
            if (map->free_func != 0) {
                map->free_func(pair->value);
            }
            pair++;
            j++;
        }
        free(bucket->pairs);
        bucket++;
        i++;
    }
    free(map->buckets);
    free(map);
}

canonical_original_code:
void map_delete(struct Map *map)
{
    unsigned int i; unsigned int j; unsigned int n; unsigned int m;
    struct Bucket *bucket;
    struct Pair *pair;
    if (map == ((void *)0)) {
        return;
    }
    n = map->count;
    bucket = map->buckets;
    i = 0;
    while (i < n) {
        m = bucket->count;
        pair = bucket->pairs;
        j = 0;
        while(j < m) {
            free(pair->key);
            if (map->free_func != 0) {
                map->free_func(pair->value);
            }
            pair++;
            j++;
        }
        free(bucket->pairs);
        bucket++;
        i++;
    }
    free(map->buckets);
    free(map);
}

variable_types:
j
unsigned int

variable_types:
m
unsigned int

variable_types: struct Bucket { unsigned int count; struct Pair { char *key; void *value; } *pairs; } *


decompiled_code:
const char **__fastcall map_get(__int64 a1, char *a2)
{
unsigned __int64 v2; // rax
unsigned int *v3; // r9
const char **result; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = hash(a2);
result = get_pair_constprop_0((unsigned int *)(*((_QWORD *)v3 + 3) + 16 * (v2 % *v3)), a2);
if ( result )
result = (const char **)result[1];
return result;
}

canonical_decompiled_code:
const char **__fastcall func4(__int64 a1, char *a2)
{
unsigned __int64 v2; // rax
unsigned int *v3; // r9
const char **result; // rax

if ( !a1 || !a2 )
return 0LL;
v2 = func0(a2);
result = func2((unsigned int *)(*((_QWORD *)v3 + 3) + 16 * (v2 % *v3)), a2);
if ( result )
result = (const char **)result[1];
return result;
}

original_code:
void *map_get(const Map *map, const char *key)
{
    unsigned int index;
    Bucket *bucket;
    Pair *pair;
    if (map == ((void *)0)) {
        return ((void *)0);
    }
    if (key == ((void *)0)) {
        return ((void *)0);
    }
    index = hash(key) % map->count;
    bucket = &(map->buckets[index]);
    pair = get_pair(map, bucket, key);
    if (pair == ((void *)0)) {
        return ((void *)0);
    }
    return pair->value;
}

canonical_original_code:
void *map_get(struct Map *map, char *key)
{
    unsigned int index;
    struct Bucket *bucket;
    struct Pair *pair;
    if (map == ((void *)0)) {
        return ((void *)0);
    }
    if (key == ((void *)0)) {
        return ((void *)0);
    }
    index = hash(key) % map->count;
    bucket = &(map->buckets[index]);
    pair = get_pair(map, bucket, key);
    if (pair == ((void *)0)) {
        return ((void *)0);
    }
    return pair->value;
}

variable_types:
index
unsigned int

variable_types: struct Pair { char *key; void *value; } *


decompiled_code:
_BOOL8 __fastcall map_contains(__int64 a1, char *a2)
{
return map_get(a1, a2) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, char *a2)
{
return func4(a1, a2) != 0LL;
}

original_code:
int map_contains(const Map *map, const char *key)
{
    return (map_get(map, key) != ((void *)0));
}

canonical_original_code:
int map_contains(struct Map *map, char *key)
{
    return (map_get(map, key) != ((void *)0));
}


decompiled_code:
__int64 __fastcall map_remove(__int64 a1, char *a2)
{
unsigned __int64 v2; // rax
unsigned int *v3; // r9
const char *v4; // r10

if ( !a1 || !a2 )
return 0LL;
v2 = hash(a2);
return remove_pair((__int64)v3, *((_QWORD *)v3 + 3) + 16 * (v2 % *v3), v4);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, char *a2)
{
unsigned __int64 v2; // rax
unsigned int *v3; // r9
const char *v4; // r10

if ( !a1 || !a2 )
return 0LL;
v2 = func0(a2);
return func1((__int64)v3, *((_QWORD *)v3 + 3) + 16 * (v2 % *v3), v4);
}

original_code:
int map_remove(Map *map, const char *key)
{
    unsigned int index;
    Bucket *bucket;
    if (map == ((void *)0)) {
        return 0;
    }
    if (key == ((void *)0)) {
        return 0;
    }
    index = hash(key) % map->count;
    bucket = &(map->buckets[index]);
    return remove_pair(map, bucket, key);
}

canonical_original_code:
int map_remove(struct Map *map, char *key)
{
    unsigned int index;
    struct Bucket *bucket;
    if (map == ((void *)0)) {
        return 0;
    }
    if (key == ((void *)0)) {
        return 0;
    }
    index = hash(key) % map->count;
    bucket = &(map->buckets[index]);
    return remove_pair(map, bucket, key);
}


original_code:
int map_put(Map *map, const char *key, void *value)
{
    unsigned int key_len, index;
    Bucket *bucket;
    Pair *tmp_pairs, *pair;
    char *new_key;
    void *new_value;
    void *old_value;
    if (map == ((void *)0)) {
        return 0;
    }
    if (key == ((void *)0)) {
        return 0;
    }
    key_len = strlen(key);
    index = hash(key) % map->count;
    bucket = &(map->buckets[index]);
    if ((pair = get_pair(map, bucket, key)) != ((void *)0)) {
        old_value = pair->value;
        if (map->dup_func != ((void *)0)) {
            if (value != ((void *)0)) {
                new_value = map->dup_func(value);
                if (new_value == ((void *)0)) {
                    return 0;
                }
            } else {
                new_value = ((void *)0);
            }
            pair->value = new_value;
        } else {
            pair->value = value;
        }
        if (map->free_func != ((void *)0)) {
            map->free_func(old_value);
        }
        return 1;
    }
    new_key = malloc((key_len + 1) * sizeof(char));
    if (new_key == ((void *)0)) {
        return 0;
    }
    if (map->dup_func != ((void *)0)) {
        new_value = map->dup_func(value);
        if (new_value == ((void *)0)) {
            free(new_key);
            return 0;
        }
    } else {
        new_value = value;
    }
    if (bucket->count == 0) {
        bucket->pairs = malloc(sizeof(Pair));
        if (bucket->pairs == ((void *)0)) {
            free(new_key);
            if (map->free_func != ((void *)0)) {
                map->free_func(new_value);
            }
            return 0;
        }
        bucket->count = 1;
    }
    else {
        tmp_pairs = realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair));
        if (tmp_pairs == ((void *)0)) {
            free(new_key);
            if (map->free_func != ((void *)0)) {
                map->free_func(new_value);
            }
            return 0;
        }
        bucket->pairs = tmp_pairs;
        bucket->count++;
    }
    pair = &(bucket->pairs[bucket->count - 1]);
    pair->key = new_key;
    pair->value = new_value;
    strcpy(pair->key, key);
    return 1;
}

canonical_original_code:
int map_put(struct Map *map, char *key, void *value)
{
    unsigned int key_len; unsigned int index;
    struct Bucket *bucket;
    struct Pair *tmp_pairs; struct Pair *pair;
    char *new_key;
    void *new_value;
    void *old_value;
    if (map == ((void *)0)) {
        return 0;
    }
    if (key == ((void *)0)) {
        return 0;
    }
    key_len = strlen(key);
    index = hash(key) % map->count;
    bucket = &(map->buckets[index]);
    if ((pair = get_pair(map, bucket, key)) != ((void *)0)) {
        old_value = pair->value;
        if (map->dup_func != ((void *)0)) {
            if (value != ((void *)0)) {
                new_value = map->dup_func(value);
                if (new_value == ((void *)0)) {
                    return 0;
                }
            } else {
                new_value = ((void *)0);
            }
            pair->value = new_value;
        } else {
            pair->value = value;
        }
        if (map->free_func != ((void *)0)) {
            map->free_func(old_value);
        }
        return 1;
    }
    new_key = malloc((key_len + 1) * sizeof(char));
    if (new_key == ((void *)0)) {
        return 0;
    }
    if (map->dup_func != ((void *)0)) {
        new_value = map->dup_func(value);
        if (new_value == ((void *)0)) {
            free(new_key);
            return 0;
        }
    } else {
        new_value = value;
    }
    if (bucket->count == 0) {
        bucket->pairs = malloc(sizeof(Pair));
        if (bucket->pairs == ((void *)0)) {
            free(new_key);
            if (map->free_func != ((void *)0)) {
                map->free_func(new_value);
            }
            return 0;
        }
        bucket->count = 1;
    }
    else {
        tmp_pairs = realloc(bucket->pairs, (bucket->count + 1) * sizeof(Pair));
        if (tmp_pairs == ((void *)0)) {
            free(new_key);
            if (map->free_func != ((void *)0)) {
                map->free_func(new_value);
            }
            return 0;
        }
        bucket->pairs = tmp_pairs;
        bucket->count++;
    }
    pair = &(bucket->pairs[bucket->count - 1]);
    pair->key = new_key;
    pair->value = new_value;
    strcpy(pair->key, key);
    return 1;
}

variable_types:
value
void *


decompiled_code:
__int64 __fastcall map_get_count(unsigned int *a1)
{
__int64 v1; // rdx
_DWORD *v2; // rax
_DWORD *v3; // rcx
unsigned int v4; // edx

if ( !a1 )
return 0LL;
v1 = *a1;
v2 = (_DWORD *)*((_QWORD *)a1 + 3);
if ( !(_DWORD)v1 )
return 0LL;
v3 = &v2[4 * v1];
v4 = 0;
do
{
v4 += *v2;
v2 += 4;
}
while ( v3 != v2 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1)
{
__int64 v1; // rdx
_DWORD *v2; // rax
_DWORD *v3; // rcx
unsigned int v4; // edx

if ( !a1 )
return 0LL;
v1 = *a1;
v2 = (_DWORD *)*((_QWORD *)a1 + 3);
if ( !(_DWORD)v1 )
return 0LL;
v3 = &v2[4 * v1];
v4 = 0;
do
{
v4 += *v2;
v2 += 4;
}
while ( v3 != v2 );
return v4;
}

original_code:
int map_get_count(const Map *map)
{
    unsigned int i, j, n, m;
    unsigned int count;
    Bucket *bucket;
    Pair *pair;
    if (map == ((void *)0)) {
        return 0;
    }
    bucket = map->buckets;
    n = map->count;
    i = 0;
    count = 0;
    while (i < n) {
        pair = bucket->pairs;
        m = bucket->count;
        j = 0;
        while (j < m) {
            count++;
            pair++;
            j++;
        }
        bucket++;
        i++;
    }
    return count;
}

canonical_original_code:
int map_get_count(struct Map *map)
{
    unsigned int i; unsigned int j; unsigned int n; unsigned int m;
    unsigned int count;
    struct Bucket *bucket;
    struct Pair *pair;
    if (map == ((void *)0)) {
        return 0;
    }
    bucket = map->buckets;
    n = map->count;
    i = 0;
    count = 0;
    while (i < n) {
        pair = bucket->pairs;
        m = bucket->count;
        j = 0;
        while (j < m) {
            count++;
            pair++;
            j++;
        }
        bucket++;
        i++;
    }
    return count;
}

variable_types:
count
unsigned int


original_code:
int map_enum(const Map *map, map_enum_func enum_func, const void *obj)
{
    unsigned int i, j, n, m;
    Bucket *bucket;
    Pair *pair;
    if (map == ((void *)0)) {
        return 0;
    }
    if (enum_func == ((void *)0)) {
        return 0;
    }
    bucket = map->buckets;
    n = map->count;
    i = 0;
    while (i < n) {
        pair = bucket->pairs;
        m = bucket->count;
        j = 0;
        while (j < m) {
            enum_func(pair->key, pair->value, obj);
            pair++;
            j++;
        }
        bucket++;
        i++;
    }
    return 1;
}

canonical_original_code:
int map_enum(struct Map *map, void (*enum_func)(char *key, void *value, void *obj), void *obj)
{
    unsigned int i; unsigned int j; unsigned int n; unsigned int m;
    struct Bucket *bucket;
    struct Pair *pair;
    if (map == ((void *)0)) {
        return 0;
    }
    if (enum_func == ((void *)0)) {
        return 0;
    }
    bucket = map->buckets;
    n = map->count;
    i = 0;
    while (i < n) {
        pair = bucket->pairs;
        m = bucket->count;
        j = 0;
        while (j < m) {
            enum_func(pair->key, pair->value, obj);
            pair++;
            j++;
        }
        bucket++;
        i++;
    }
    return 1;
}

variable_types: void (*)(char *key, void *value, void *obj)

variable_types:
obj
void *


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

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

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

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

original_code:
buffer_t* buffer_init()
{
    buffer_t* buf = ((void *)0);
    buf = (buffer_t*)malloc(sizeof(buffer_t));
    if (buf) {
        buf->content = ((void *)0);
        buf->capacity = 0;
        buf->length = 0;
        buf->offset = 0;
    }
    return buf;
}

canonical_original_code:
struct _buffer *buffer_init()
{
    struct _buffer *buf = ((void *)0);
    buf = (struct _buffer *)malloc(sizeof(buffer_t));
    if (buf) {
        buf->content = ((void *)0);
        buf->capacity = 0;
        buf->length = 0;
        buf->offset = 0;
    }
    return buf;
}

variable_types: struct _buffer { unsigned char *content; unsigned long length; unsigned long capacity; unsigned long offset; } *


original_code:
void buffer_reset(buffer_t* buf)
{
    if (buf) {
        if (buf->content) {
            free(buf->content);
            buf->content = ((void *)0);
        }
        buf->capacity = 0;
        buf->length = 0;
        buf->offset = 0;
    }
}

canonical_original_code:
void buffer_reset(struct _buffer *buf)
{
    if (buf) {
        if (buf->content) {
            free(buf->content);
            buf->content = ((void *)0);
        }
        buf->capacity = 0;
        buf->length = 0;
        buf->offset = 0;
    }
}

user_defined_types: struct _buffer { unsigned char *content; unsigned long length; unsigned long capacity; unsigned long offset; }


decompiled_code:
__int64 __fastcall buffer_destroy(void *ptr)
{
if ( ptr )
{
buffer_reset((__int64)ptr);
free(ptr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *ptr)
{
if ( ptr )
{
func1((__int64)ptr);
free(ptr);
}
return 0LL;
}

original_code:
buffer_t* buffer_destroy(buffer_t* buf)
{
    if (buf) {
        buffer_reset(buf);
        free(buf);
        buf = ((void *)0);
    }
    return buf;
}

canonical_original_code:
struct _buffer *buffer_destroy(struct _buffer *buf)
{
    if (buf) {
        buffer_reset(buf);
        free(buf);
        buf = ((void *)0);
    }
    return buf;
}

variable_types:
buf
struct _buffer *

return_type: struct _buffer { unsigned char *content; unsigned long length; unsigned long capacity; unsigned long offset; } *


decompiled_code:
_BOOL8 __fastcall buffer_good(_QWORD *a1)
{
unsigned __int64 v1; // rdx
_BOOL8 result; // rax

if ( !a1 )
return 0LL;
v1 = a1[1];
result = 0LL;
if ( v1 <= a1[2] )
result = v1 >= a1[3];
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(_QWORD *a1)
{
unsigned __int64 v1; // rdx
_BOOL8 result; // rax

if ( !a1 )
return 0LL;
v1 = a1[1];
result = 0LL;
if ( v1 <= a1[2] )
result = v1 >= a1[3];
return result;
}

original_code:
int buffer_good(const buffer_t* buf)
{
    if (!buf) return 0;
    if (buf->length > buf->capacity) return 0;
    if (buf->offset > buf->length) return 0;
    return 1;
}

canonical_original_code:
int buffer_good(struct _buffer *buf)
{
    if (!buf) return 0;
    if (buf->length > buf->capacity) return 0;
    if (buf->offset > buf->length) return 0;
    return 1;
}


decompiled_code:
unsigned __int64 __fastcall buffer_seek(_QWORD *a1, unsigned __int64 a2)
{
_BOOL4 v2; // er8
unsigned __int64 result; // rax

v2 = buffer_good(a1);
result = 0LL;
if ( v2 && a1[1] >= a2 )
{
a1[3] = a2;
result = a2;
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(_QWORD *a1, unsigned __int64 a2)
{
_BOOL4 v2; // er8
unsigned __int64 result; // rax

v2 = func3(a1);
result = 0LL;
if ( v2 && a1[1] >= a2 )
{
a1[3] = a2;
result = a2;
}
return result;
}

original_code:
size_t buffer_seek(buffer_t* buf, size_t offset)
{
    size_t new_offset = 0;
    if (buffer_good(buf)) {
        if (offset <= buf->length) {
            new_offset = buf->offset = offset;
        }
    }
    return new_offset;
}

canonical_original_code:
unsigned long buffer_seek(struct _buffer *buf, unsigned long offset)
{
    unsigned long new_offset = 0;
    if (buffer_good(buf)) {
        if (offset <= buf->length) {
            new_offset = buf->offset = offset;
        }
    }
    return new_offset;
}

variable_types:
offset
unsigned long


decompiled_code:
unsigned __int64 __fastcall buffer_seek_start(_QWORD *a1)
{
return buffer_seek(a1, 0LL);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func5(_QWORD *a1)
{
return func4(a1, 0LL);
}

original_code:
size_t buffer_seek_start(buffer_t* buf)
{
    return buffer_seek(buf, 0);
}

canonical_original_code:
unsigned long buffer_seek_start(struct _buffer *buf)
{
    return buffer_seek(buf, 0);
}


decompiled_code:
__int64 __fastcall buffer_seek_end(_QWORD *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = buffer_good(a1);
result = 0LL;
if ( v1 )
{
result = a1[1];
a1[3] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
_BOOL4 v1; // er8
__int64 result; // rax

v1 = func3(a1);
result = 0LL;
if ( v1 )
{
result = a1[1];
a1[3] = result;
}
return result;
}

original_code:
size_t buffer_seek_end(buffer_t* buf)
{
    size_t new_offset = 0;
    if (buffer_good(buf)) {
        new_offset = buf->offset = buf->length;
    }
    return new_offset;
}

canonical_original_code:
unsigned long buffer_seek_end(struct _buffer *buf)
{
    unsigned long new_offset = 0;
    if (buffer_good(buf)) {
        new_offset = buf->offset = buf->length;
    }
    return new_offset;
}


decompiled_code:
__int64 __fastcall buffer_erase(void **a1, unsigned __int64 a2)
{
char *v4; // rdi
char *v5; // rdx
char *v6; // rax
size_t v7; // rbx
char *v8; // rax

if ( buffer_good(a1) )
{
if ( a2 )
{
v4 = (char *)*a1;
if ( v4 )
{
v5 = (char *)a1[1];
v6 = (char *)a1[3];
if ( v5 - v6 >= a2 )
{
v7 = (size_t)&v5[-a2];
memmove(&v4[(_QWORD)v6], &v6[a2 + (_QWORD)v4], v5 - &v6[a2]);
v8 = (char *)realloc(*a1, v7);
if ( v8 )
{
*a1 = v8;
a1[2] = (void *)v7;
a1[1] = (void *)v7;
buffer_seek_end(a1);
}
}
}
}
}
return 0LL;
}

original_code:
size_t buffer_erase(buffer_t* buf, size_t length)
{
    size_t bytes_erased = 0;
    uint8_t* tmp_buf = ((void *)0);
    uint8_t* src = ((void *)0);
    uint8_t* dst = ((void *)0);
    size_t copy_length = 0;
    size_t new_length = 0;
    if ( buffer_good(buf) && length && buf->content &&
         ((buf->length - buf->offset) >= length) ) {
        dst = buf->content + buf->offset;
        src = buf->content + buf->offset + length;
        copy_length = buf->length - (buf->offset + length);
        new_length = buf->length - length;
        memmove(dst, src, copy_length);
        tmp_buf = (uint8_t*)realloc(buf->content, new_length);
        if (tmp_buf) {
            buf->content = tmp_buf;
            buf->capacity = new_length;
            buf->length = new_length;
            buffer_seek_end(buf);
        }
    }
    return bytes_erased;
}

canonical_original_code:
unsigned long buffer_erase(struct _buffer *buf, unsigned long length)
{
    unsigned long bytes_erased = 0;
    unsigned char *tmp_buf = ((void *)0);
    unsigned char *src = ((void *)0);
    unsigned char *dst = ((void *)0);
    unsigned long copy_length = 0;
    unsigned long new_length = 0;
    if ( buffer_good(buf) && length && buf->content &&
         ((buf->length - buf->offset) >= length) ) {
        dst = buf->content + buf->offset;
        src = buf->content + buf->offset + length;
        copy_length = buf->length - (buf->offset + length);
        new_length = buf->length - length;
        memmove(dst, src, copy_length);
        tmp_buf = (unsigned char *)realloc(buf->content, new_length);
        if (tmp_buf) {
            buf->content = tmp_buf;
            buf->capacity = new_length;
            buf->length = new_length;
            buffer_seek_end(buf);
        }
    }
    return bytes_erased;
}

variable_types:
length
unsigned long

variable_types:
src
unsigned char *

variable_types:
dst
unsigned char *