decompiled_code:
int __fastcall vector_arr_out(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 v4[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = gsl_vector_view_array(v4, a1, a2);
return vector_out(v4, v2);
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 v4[7]; // [rsp+0h] [rbp-38h] BYREF

v2 = gsl_vector_view_array(v4, a1, a2);
return func0(v4, v2);
}

original_code:
void vector_arr_out(double* v,int n){
 gsl_vector_view vv=gsl_vector_view_array(v,n);
 vector_out(&vv.vector);
}

canonical_original_code:
void vector_arr_out(double *v, int n){
 struct _gsl_vector_view vv = gsl_vector_view_array(v,n);
 vector_out(&vv.vector);
}

variable_types:
v
double *

variable_types: n int

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

user_defined_types: struct _gsl_vector_view { struct gsl_vector vector; }


repo: antoniofabio/idmclib

decompiled_code:
__int64 __fastcall matrix_arr_out(__int64 a1, int a2, int a3)
{
double v3; // xmm0_8
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

v3 = gsl_matrix_view_array(v5, a1, a2, a3);
return matrix_out(v5, v3);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, int a3)
{
double v3; // xmm0_8
__int64 v5[7]; // [rsp+0h] [rbp-38h] BYREF

v3 = gsl_matrix_view_array(v5, a1, a2, a3);
return func1(v5, v3);
}

original_code:
void matrix_arr_out(double* v,int m,int n){
 gsl_matrix_view mv=gsl_matrix_view_array(v,m,n);
 matrix_out(&mv.matrix);
}

canonical_original_code:
void matrix_arr_out(double *v, int m, int n){
 struct _gsl_matrix_view mv = gsl_matrix_view_array(v,m,n);
 matrix_out(&mv.matrix);
}

variable_types: m int

variable_types: struct _gsl_matrix_view { 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; } matrix; }

return_type: void

user_defined_types: struct _gsl_matrix_view { struct gsl_matrix matrix; }

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


decompiled_code:
__int64 __fastcall clone_matrix(_QWORD *a1)
{
__int64 v1; // r12

v1 = gsl_matrix_alloc(*a1, a1[1]);
gsl_matrix_memcpy(v1, a1);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1)
{
__int64 v1; // r12

v1 = gsl_matrix_alloc(*a1, a1[1]);
gsl_matrix_memcpy(v1, a1);
return v1;
}

original_code:
gsl_matrix* clone_matrix(gsl_matrix* m){
 gsl_matrix* m1=gsl_matrix_alloc((*m).size1,(*m).size2);
 gsl_matrix_memcpy(m1,m);
 return m1;
}

canonical_original_code:
struct gsl_matrix *clone_matrix(struct gsl_matrix *m){
 struct gsl_matrix *m1 = gsl_matrix_alloc((*m).size1,(*m).size2);
 gsl_matrix_memcpy(m1,m);
 return m1;
}

variable_types:
m
struct gsl_matrix *

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


decompiled_code:
void *__fastcall clone_array(void *src, int a2)
{
void *v2; // rax

v2 = malloc(8 * a2);
return memcpy(v2, src, 8 * a2);
}

canonical_decompiled_code:
void *__fastcall func5(void *src, int a2)
{
void *v2; // rax

v2 = malloc(8 * a2);
return memcpy(v2, src, 8 * a2);
}

original_code:
double* clone_array(double* a, int d){
 int dd=d*sizeof(double);
 double* b=(double*) malloc(dd);
 memcpy(b,a,dd);
 return b;
}

canonical_original_code:
double *clone_array(double *a, int d){
 int dd = d*sizeof(double);
 double *b = (double*) malloc(dd);
 memcpy(b,a,dd);
 return b;
}

variable_types:
a
double *

variable_types: d int

variable_types: dd int

variable_types:
b
double *

return_type: double *


mvproduct

decompiled_code:
__int64 __fastcall mvproduct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
__int64 v5; // r13
__int64 v6; // r12
_BYTE v9[48]; // [rsp+0h] [rbp-B8h] BYREF
char v10[48]; // [rsp+30h] [rbp-88h] BYREF
char v11[88]; // [rsp+60h] [rbp-58h] BYREF

v5 = a5;
v6 = a4;
gsl_vector_view_array(v9, a2, a5);
gsl_matrix_view_array(v11, a1, v6, v5);
gsl_vector_view_array(v10, a3, v6);
return gsl_blas_dgemv(111LL, v11, v9, v10, 1.0, 0.0);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, int a4, int a5)
{
__int64 v5; // r13
__int64 v6; // r12
_BYTE v9[48]; // [rsp+0h] [rbp-B8h] BYREF
char v10[48]; // [rsp+30h] [rbp-88h] BYREF
char v11[88]; // [rsp+60h] [rbp-58h] BYREF

v5 = a5;
v6 = a4;
gsl_vector_view_array(v9, a2, a5);
gsl_matrix_view_array(v11, a1, v6, v5);
gsl_vector_view_array(v10, a3, v6);
return gsl_blas_dgemv(111LL, v11, v9, v10, 1.0, 0.0);
}

original_code:
inline void mvproduct(double* a, double* b, double* result,int m,int n){
 gsl_vector_view vv=gsl_vector_view_array(b,n);
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 gsl_vector_view rv=gsl_vector_view_array(result,m);
 gsl_blas_dgemv(CblasNoTrans,1.0,&(av.matrix),&(vv.vector),0.0,&(rv.vector));
}

canonical_original_code:
inline void mvproduct(double *a, double *b, double *result, int m, int n){
 struct _gsl_vector_view vv = gsl_vector_view_array(b,n);
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 struct _gsl_vector_view rv = gsl_vector_view_array(result,m);
 gsl_blas_dgemv(CblasNoTrans,1.0,&(av.matrix),&(vv.vector),0.0,&(rv.vector));
}

variable_types:
result
double *

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

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


sum

decompiled_code:
__int64 __fastcall sum(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
double v4; // xmm0_8
_BYTE v6[48]; // [rsp+0h] [rbp-78h] BYREF
char v7[72]; // [rsp+30h] [rbp-48h] BYREF

v3 = a3;
gsl_vector_view_array(v6, a1, a3);
v4 = gsl_vector_view_array(v7, a2, v3);
return gsl_vector_add(v6, v7, v4);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // r12
double v4; // xmm0_8
_BYTE v6[48]; // [rsp+0h] [rbp-78h] BYREF
char v7[72]; // [rsp+30h] [rbp-48h] BYREF

v3 = a3;
gsl_vector_view_array(v6, a1, a3);
v4 = gsl_vector_view_array(v7, a2, v3);
return gsl_vector_add(v6, v7, v4);
}

original_code:
inline void sum(double* a, double* b, int d){
 gsl_vector_view av=gsl_vector_view_array(a,d);
 gsl_vector_view bv=gsl_vector_view_array(b,d);
 gsl_vector_add(&av.vector,&bv.vector);
}

canonical_original_code:
inline void sum(double *a, double *b, int d){
 struct _gsl_vector_view av = gsl_vector_view_array(a,d);
 struct _gsl_vector_view bv = gsl_vector_view_array(b,d);
 gsl_vector_add(&av.vector,&bv.vector);
}


mmproduct

decompiled_code:
__int64 __fastcall mmproduct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v6; // r14
__int64 v7; // r13
__int64 v8; // r12
_BYTE v11[48]; // [rsp+0h] [rbp-B8h] BYREF
char v12[48]; // [rsp+30h] [rbp-88h] BYREF
char v13[88]; // [rsp+60h] [rbp-58h] BYREF

v6 = a5;
v7 = a6;
v8 = a4;
gsl_matrix_view_array(v11, a2, a5, a6);
gsl_matrix_view_array(v12, a1, v8, v6);
gsl_matrix_view_array(v13, a3, v8, v7);
return gsl_blas_dgemm(111LL, 111LL, v12, v11, v13, 1.0, 0.0);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v6; // r14
__int64 v7; // r13
__int64 v8; // r12
_BYTE v11[48]; // [rsp+0h] [rbp-B8h] BYREF
char v12[48]; // [rsp+30h] [rbp-88h] BYREF
char v13[88]; // [rsp+60h] [rbp-58h] BYREF

v6 = a5;
v7 = a6;
v8 = a4;
gsl_matrix_view_array(v11, a2, a5, a6);
gsl_matrix_view_array(v12, a1, v8, v6);
gsl_matrix_view_array(v13, a3, v8, v7);
return gsl_blas_dgemm(111LL, 111LL, v12, v11, v13, 1.0, 0.0);
}

original_code:
inline void mmproduct(const double* a, const double* b, double* result,int m,int n,int p){
 gsl_matrix_view bv=gsl_matrix_view_array((double*) b,n,p);
 gsl_matrix_view av=gsl_matrix_view_array((double*) a,m,n);
 gsl_matrix_view rv=gsl_matrix_view_array(result,m,p);
 gsl_blas_dgemm(CblasNoTrans,CblasNoTrans,1.0,&(av.matrix),&(bv.matrix),0.0,&(rv.matrix));
}

canonical_original_code:
inline void mmproduct(double *a, double *b, double *result, int m, int n, int p){
 struct _gsl_matrix_view bv = gsl_matrix_view_array((double*) b,n,p);
 struct _gsl_matrix_view av = gsl_matrix_view_array((double*) a,m,n);
 struct _gsl_matrix_view rv = gsl_matrix_view_array(result,m,p);
 gsl_blas_dgemm(CblasNoTrans,CblasNoTrans,1.0,&(av.matrix),&(bv.matrix),0.0,&(rv.matrix));
}

variable_types: p int


mcproduct

decompiled_code:
__int64 __fastcall mcproduct(__int64 a1, int a2, int a3, double a4)
{
char v6[56]; // [rsp+10h] [rbp-38h] BYREF

gsl_matrix_view_array(v6, a1, a2, a3);
return gsl_matrix_scale(v6, a4);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2, int a3, double a4)
{
char v6[56]; // [rsp+10h] [rbp-38h] BYREF

gsl_matrix_view_array(v6, a1, a2, a3);
return gsl_matrix_scale(v6, a4);
}

original_code:
inline void mcproduct(double* a,double c,int m,int n){
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 gsl_matrix_scale(&av.matrix,c);
}

canonical_original_code:
inline void mcproduct(double *a, double c, int m, int n){
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 gsl_matrix_scale(&av.matrix,c);
}

variable_types: c double


vcproduct

decompiled_code:
__int64 __fastcall vcproduct(__int64 a1, int a2, double a3)
{
char v5[56]; // [rsp+10h] [rbp-38h] BYREF

gsl_vector_view_array(v5, a1, a2);
return gsl_vector_scale(v5, a3);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2, double a3)
{
char v5[56]; // [rsp+10h] [rbp-38h] BYREF

gsl_vector_view_array(v5, a1, a2);
return gsl_vector_scale(v5, a3);
}

original_code:
inline void vcproduct(double* v, double c,int n){
 gsl_vector_view vv=gsl_vector_view_array(v,n);
 gsl_vector_scale(&vv.vector,c);
}

canonical_original_code:
inline void vcproduct(double *v, double c, int n){
 struct _gsl_vector_view vv = gsl_vector_view_array(v,n);
 gsl_vector_scale(&vv.vector,c);
}


transpose

decompiled_code:
__int64 __fastcall transpose(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v4; // r13
__int64 v5; // r12
double v6; // xmm0_8
_BYTE v8[48]; // [rsp+0h] [rbp-78h] BYREF
char v9[72]; // [rsp+30h] [rbp-48h] BYREF

v4 = a3;
v5 = a4;
gsl_matrix_view_array(v8, a1, a3, a4);
v6 = gsl_matrix_view_array(v9, a2, v5, v4);
return gsl_matrix_transpose_memcpy(v9, v8, v6);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v4; // r13
__int64 v5; // r12
double v6; // xmm0_8
_BYTE v8[48]; // [rsp+0h] [rbp-78h] BYREF
char v9[72]; // [rsp+30h] [rbp-48h] BYREF

v4 = a3;
v5 = a4;
gsl_matrix_view_array(v8, a1, a3, a4);
v6 = gsl_matrix_view_array(v9, a2, v5, v4);
return gsl_matrix_transpose_memcpy(v9, v8, v6);
}

original_code:
inline void transpose(const double* a, double* b, int m,int n){
 gsl_matrix_view av=gsl_matrix_view_array((double*) a,m,n);
 gsl_matrix_view bv=gsl_matrix_view_array(b,n,m);
 gsl_matrix_transpose_memcpy(&bv.matrix,&av.matrix);
}

canonical_original_code:
inline void transpose(double *a, double *b, int m, int n){
 struct _gsl_matrix_view av = gsl_matrix_view_array((double*) a,m,n);
 struct _gsl_matrix_view bv = gsl_matrix_view_array(b,n,m);
 gsl_matrix_transpose_memcpy(&bv.matrix,&av.matrix);
}


asym

decompiled_code:
__int64 __fastcall asym(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 v3; // rbx
_BYTE v5[48]; // [rsp+0h] [rbp-A8h] BYREF
char v6[48]; // [rsp+30h] [rbp-78h] BYREF
char v7[72]; // [rsp+60h] [rbp-48h] BYREF

v2 = gsl_matrix_view_array(v7, a1, a2, a2);
if ( a2 > 1 )
{
v3 = 1LL;
do
{
gsl_matrix_superdiagonal(v5, v7, v3, v2);
gsl_matrix_subdiagonal(v6, v7, v3++);
gsl_vector_memcpy(v5, v6);
v2 = *(double *)&LC5;
gsl_vector_scale(v5, -1.0);
}
while ( v3 != a2 );
}
gsl_matrix_superdiagonal(v6, v7, 0LL, v2);
return gsl_vector_set_zero(v6);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, int a2)
{
double v2; // xmm0_8
__int64 v3; // rbx
_BYTE v5[48]; // [rsp+0h] [rbp-A8h] BYREF
char v6[48]; // [rsp+30h] [rbp-78h] BYREF
char v7[72]; // [rsp+60h] [rbp-48h] BYREF

v2 = gsl_matrix_view_array(v7, a1, a2, a2);
if ( a2 > 1 )
{
v3 = 1LL;
do
{
gsl_matrix_superdiagonal(v5, v7, v3, v2);
gsl_matrix_subdiagonal(v6, v7, v3++);
gsl_vector_memcpy(v5, v6);
v2 = *(double *)&LC5;
gsl_vector_scale(v5, -1.0);
}
while ( v3 != a2 );
}
gsl_matrix_superdiagonal(v6, v7, 0LL, v2);
return gsl_vector_set_zero(v6);
}

original_code:
inline void asym(double* a,int n){
 int i;
 gsl_matrix_view av=gsl_matrix_view_array(a,n,n);
 for (i=1;i<n;i++){
  gsl_vector_view vsup=gsl_matrix_superdiagonal(&av.matrix,i);
  gsl_vector_view vsub=gsl_matrix_subdiagonal(&av.matrix,i);
  gsl_vector_memcpy(&vsup.vector,&vsub.vector);
  gsl_vector_scale(&vsup.vector,-1);
 }
 gsl_vector_view vsup=gsl_matrix_superdiagonal(&av.matrix,0);
 gsl_vector_set_zero(&vsup.vector);
}

canonical_original_code:
inline void asym(double *a, int n){
 int i;
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,n,n);
 for (i=1;i<n;i++){
  struct _gsl_vector_view vsup = gsl_matrix_superdiagonal(&av.matrix,i);
  struct _gsl_vector_view vsub = gsl_matrix_subdiagonal(&av.matrix,i);
  gsl_vector_memcpy(&vsup.vector,&vsub.vector);
  gsl_vector_scale(&vsup.vector,-1);
 }
 struct _gsl_vector_view vsup = gsl_matrix_superdiagonal(&av.matrix,0);
 gsl_vector_set_zero(&vsup.vector);
}

variable_types: i int


decompiled_code:
__int64 __fastcall qr_coded(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v5; // rbx
__int64 v6; // rdx
double v7; // xmm0_8
_BYTE v9[48]; // [rsp+0h] [rbp-78h] BYREF
char v10[72]; // [rsp+30h] [rbp-48h] BYREF

v5 = a4;
gsl_matrix_view_array(v10, a1, a3, a4);
v6 = a3;
if ( (int)v5 <= a3 )
v6 = v5;
v7 = gsl_vector_view_array(v9, a2, v6);
return gsl_linalg_QR_decomp(v10, v9, v7);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2, int a3, int a4)
{
__int64 v5; // rbx
__int64 v6; // rdx
double v7; // xmm0_8
_BYTE v9[48]; // [rsp+0h] [rbp-78h] BYREF
char v10[72]; // [rsp+30h] [rbp-48h] BYREF

v5 = a4;
gsl_matrix_view_array(v10, a1, a3, a4);
v6 = a3;
if ( (int)v5 <= a3 )
v6 = v5;
v7 = gsl_vector_view_array(v9, a2, v6);
return gsl_linalg_QR_decomp(v10, v9, v7);
}

original_code:
inline void qr_coded(double* a, double* tau, int m,int n){
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 int d;
 if (m<n) d=m; else d=n;
 gsl_vector_view tv=gsl_vector_view_array(tau,d);
 gsl_linalg_QR_decomp(&av.matrix,&tv.vector);
}

canonical_original_code:
inline void qr_coded(double *a, double *tau, int m, int n){
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 int d;
 if (m<n) d=m; else d=n;
 struct _gsl_vector_view tv = gsl_vector_view_array(tau,d);
 gsl_linalg_QR_decomp(&av.matrix,&tv.vector);
}

variable_types:
tau
double *


decompiled_code:
__int64 __fastcall qr_decomp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5, int a6)
{
__int64 v7; // r12
__int64 v9; // rdx
double v10; // xmm0_8
char v12[48]; // [rsp+10h] [rbp-F8h] BYREF
char v13[48]; // [rsp+40h] [rbp-C8h] BYREF
char v14[48]; // [rsp+70h] [rbp-98h] BYREF
char v15[104]; // [rsp+A0h] [rbp-68h] BYREF

v7 = a5;
gsl_matrix_view_array(v13, a3, a5, a5);
gsl_matrix_view_array(v14, a4, v7, a6);
gsl_matrix_view_array(v15, a1, v7, a6);
v9 = a6;
if ( (int)v7 <= a6 )
v9 = v7;
v10 = gsl_vector_view_array(v12, a2, v9);
return gsl_linalg_QR_unpack(v15, v12, v13, v14, v10);
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int a5, int a6)
{
__int64 v7; // r12
__int64 v9; // rdx
double v10; // xmm0_8
char v12[48]; // [rsp+10h] [rbp-F8h] BYREF
char v13[48]; // [rsp+40h] [rbp-C8h] BYREF
char v14[48]; // [rsp+70h] [rbp-98h] BYREF
char v15[104]; // [rsp+A0h] [rbp-68h] BYREF

v7 = a5;
gsl_matrix_view_array(v13, a3, a5, a5);
gsl_matrix_view_array(v14, a4, v7, a6);
gsl_matrix_view_array(v15, a1, v7, a6);
v9 = a6;
if ( (int)v7 <= a6 )
v9 = v7;
v10 = gsl_vector_view_array(v12, a2, v9);
return gsl_linalg_QR_unpack(v15, v12, v13, v14, v10);
}

original_code:
inline void qr_decomp(double* a, double* tau, double* q, double* r,int m,int n){
 gsl_matrix_view qv=gsl_matrix_view_array(q,m,m);
 gsl_matrix_view rv=gsl_matrix_view_array(r,m,n);
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 int d;
 if (m<n) d=m; else d=n;
 gsl_vector_view tv=gsl_vector_view_array(tau,d);
 gsl_linalg_QR_unpack(&av.matrix,&tv.vector,&qv.matrix,&rv.matrix);
}

canonical_original_code:
inline void qr_decomp(double *a, double *tau, double *q, double *r, int m, int n){
 struct _gsl_matrix_view qv = gsl_matrix_view_array(q,m,m);
 struct _gsl_matrix_view rv = gsl_matrix_view_array(r,m,n);
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 int d;
 if (m<n) d=m; else d=n;
 struct _gsl_vector_view tv = gsl_vector_view_array(tau,d);
 gsl_linalg_QR_unpack(&av.matrix,&tv.vector,&qv.matrix,&rv.matrix);
}

variable_types:
q
double *

variable_types:
r
double *


decompiled_code:
void __fastcall qr_qmproduct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v8; // rbp
__int64 v9; // rbx
__int64 v10; // rdx
double v11; // xmm0_8
__int64 i; // rbx
__int64 v13; // rdx
__int64 v14; // [rsp+8h] [rbp-100h]
char v15[48]; // [rsp+10h] [rbp-F8h] BYREF
char v16[48]; // [rsp+40h] [rbp-C8h] BYREF
char v17[48]; // [rsp+70h] [rbp-98h] BYREF
char v18[104]; // [rsp+A0h] [rbp-68h] BYREF

v8 = a6;
v9 = a5;
v14 = a4;
gsl_matrix_view_array(v17, a1, a4, a5);
gsl_matrix_view_array(v18, a3, v14, v8);
v10 = a4;
if ( (int)v9 <= a4 )
v10 = v9;
v11 = gsl_vector_view_array(v15, a2, v10);
if ( (int)v8 > 0 )
{
for ( i = 0LL; i != v8; ++i )
{
v13 = i;
gsl_matrix_column(v16, v18, v13, v11);
gsl_linalg_QR_Qvec(v17, v15, v16);
}
}
}

canonical_decompiled_code:
void __fastcall func15(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v8; // rbp
__int64 v9; // rbx
__int64 v10; // rdx
double v11; // xmm0_8
__int64 i; // rbx
__int64 v13; // rdx
__int64 v14; // [rsp+8h] [rbp-100h]
char v15[48]; // [rsp+10h] [rbp-F8h] BYREF
char v16[48]; // [rsp+40h] [rbp-C8h] BYREF
char v17[48]; // [rsp+70h] [rbp-98h] BYREF
char v18[104]; // [rsp+A0h] [rbp-68h] BYREF

v8 = a6;
v9 = a5;
v14 = a4;
gsl_matrix_view_array(v17, a1, a4, a5);
gsl_matrix_view_array(v18, a3, v14, v8);
v10 = a4;
if ( (int)v9 <= a4 )
v10 = v9;
v11 = gsl_vector_view_array(v15, a2, v10);
if ( (int)v8 > 0 )
{
for ( i = 0LL; i != v8; ++i )
{
v13 = i;
gsl_matrix_column(v16, v18, v13, v11);
gsl_linalg_QR_Qvec(v17, v15, v16);
}
}
}

original_code:
inline void qr_qmproduct(double* a, double* tau,
double* s, int m,int n,int p){
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 gsl_matrix_view sv=gsl_matrix_view_array(s,m,p);
 int d;
 if (m<n) d=m; else d=n;
 gsl_vector_view tv=gsl_vector_view_array(tau,d);
 int i;
 for (i=0;i<p;i++){
  gsl_vector_view scv=gsl_matrix_column(&sv.matrix,i);
  gsl_linalg_QR_Qvec(&av.matrix,&tv.vector,&scv.vector);
 }
}

canonical_original_code:
inline void qr_qmproduct(double *a, double *tau, double *s, int m, int n, int p){
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 struct _gsl_matrix_view sv = gsl_matrix_view_array(s,m,p);
 int d;
 if (m<n) d=m; else d=n;
 struct _gsl_vector_view tv = gsl_vector_view_array(tau,d);
 int i;
 for (i=0;i<p;i++){
  struct _gsl_vector_view scv = gsl_matrix_column(&sv.matrix,i);
  gsl_linalg_QR_Qvec(&av.matrix,&tv.vector,&scv.vector);
 }
}

variable_types:
s
double *

variable_types: n int


decompiled_code:
void __fastcall qr_qtmproduct(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v8; // rbp
__int64 v9; // rbx
__int64 v10; // rdx
double v11; // xmm0_8
__int64 i; // rbx
__int64 v13; // rdx
__int64 v14; // [rsp+8h] [rbp-100h]
char v15[48]; // [rsp+10h] [rbp-F8h] BYREF
char v16[48]; // [rsp+40h] [rbp-C8h] BYREF
char v17[48]; // [rsp+70h] [rbp-98h] BYREF
char v18[104]; // [rsp+A0h] [rbp-68h] BYREF

v8 = a6;
v9 = a5;
v14 = a4;
gsl_matrix_view_array(v17, a1, a4, a5);
gsl_matrix_view_array(v18, a3, v14, v8);
v10 = a4;
if ( (int)v9 <= a4 )
v10 = v9;
v11 = gsl_vector_view_array(v15, a2, v10);
if ( (int)v8 > 0 )
{
for ( i = 0LL; i != v8; ++i )
{
v13 = i;
gsl_matrix_column(v16, v18, v13, v11);
gsl_linalg_QR_QTvec(v17, v15, v16);
}
}
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1, __int64 a2, __int64 a3, int a4, int a5, int a6)
{
__int64 v8; // rbp
__int64 v9; // rbx
__int64 v10; // rdx
double v11; // xmm0_8
__int64 i; // rbx
__int64 v13; // rdx
__int64 v14; // [rsp+8h] [rbp-100h]
char v15[48]; // [rsp+10h] [rbp-F8h] BYREF
char v16[48]; // [rsp+40h] [rbp-C8h] BYREF
char v17[48]; // [rsp+70h] [rbp-98h] BYREF
char v18[104]; // [rsp+A0h] [rbp-68h] BYREF

v8 = a6;
v9 = a5;
v14 = a4;
gsl_matrix_view_array(v17, a1, a4, a5);
gsl_matrix_view_array(v18, a3, v14, v8);
v10 = a4;
if ( (int)v9 <= a4 )
v10 = v9;
v11 = gsl_vector_view_array(v15, a2, v10);
if ( (int)v8 > 0 )
{
for ( i = 0LL; i != v8; ++i )
{
v13 = i;
gsl_matrix_column(v16, v18, v13, v11);
gsl_linalg_QR_QTvec(v17, v15, v16);
}
}
}

original_code:
inline void qr_qtmproduct(double* a, double* tau,
double* s, int m,int n,int p){
 gsl_matrix_view av=gsl_matrix_view_array(a,m,n);
 gsl_matrix_view sv=gsl_matrix_view_array(s,m,p);
 int d;
 if (m<n) d=m; else d=n;
 gsl_vector_view tv=gsl_vector_view_array(tau,d);
 int i;
 for (i=0;i<p;i++){
  gsl_vector_view scv=gsl_matrix_column(&sv.matrix,i);
  gsl_linalg_QR_QTvec(&av.matrix,&tv.vector,&scv.vector);
 }
}

canonical_original_code:
inline void qr_qtmproduct(double *a, double *tau, double *s, int m, int n, int p){
 struct _gsl_matrix_view av = gsl_matrix_view_array(a,m,n);
 struct _gsl_matrix_view sv = gsl_matrix_view_array(s,m,p);
 int d;
 if (m<n) d=m; else d=n;
 struct _gsl_vector_view tv = gsl_vector_view_array(tau,d);
 int i;
 for (i=0;i<p;i++){
  struct _gsl_vector_view scv = gsl_matrix_column(&sv.matrix,i);
  gsl_linalg_QR_QTvec(&av.matrix,&tv.vector,&scv.vector);
 }
}

variable_types: m int

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


decompiled_code:
__int64 __fastcall idmc_cycles_eigval(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
__m128i v6; // xmm4
__m128i v7; // xmm5
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // r14
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm0_8
double v16; // [rsp+8h] [rbp-100h]
__m128i v17; // [rsp+10h] [rbp-F8h] BYREF
__m128i v18; // [rsp+20h] [rbp-E8h] BYREF
__m128i v19; // [rsp+30h] [rbp-D8h] BYREF
char v20[48]; // [rsp+40h] [rbp-C8h] BYREF
char v21[48]; // [rsp+70h] [rbp-98h] BYREF
__int128 v22[6]; // [rsp+A0h] [rbp-68h] BYREF

v4 = gsl_vector_complex_alloc(a2);
if ( !v4 )
return 1LL;
v5 = v4;
gsl_matrix_view_array(&v17, a1, a2, a2);
v6 = _mm_loadu_si128(&v18);
v7 = _mm_loadu_si128(&v19);
v22[0] = (__int128)_mm_loadu_si128(&v17);
v22[1] = (__int128)v6;
v22[2] = (__int128)v7;
v8 = gsl_eigen_nonsymm_alloc(a2);
v9 = v8;
if ( !v8 )
return 1LL;
v10 = 0LL;
gsl_eigen_nonsymm_params(0LL, 1LL, v8);
gsl_eigen_nonsymm(v22, v5, v9);
gsl_vector_complex_real(v20, v5);
gsl_vector_complex_imag(v21, v5);
if ( a2 > 0 )
{
do
{
v11 = gsl_vector_get(v20, v10);
v16 = v11 * v11;
v12 = gsl_vector_get(v21, v10);
v13 = v12 * v12 + v16;
if ( v13 < 0.0 )
v14 = sqrt(v13);
else
v14 = sqrt(v13);
*(double *)(a3 + 8 * v10++) = v14;
}
while ( v10 != a2 );
}
gsl_eigen_nonsymm_free(v9);
gsl_vector_complex_free(v5);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2, __int64 a3)
{
__int64 v4; // rax
__int64 v5; // r12
__m128i v6; // xmm4
__m128i v7; // xmm5
__int64 v8; // rax
__int64 v9; // r13
__int64 v10; // r14
double v11; // xmm0_8
double v12; // xmm0_8
double v13; // xmm0_8
double v14; // xmm0_8
double v16; // [rsp+8h] [rbp-100h]
__m128i v17; // [rsp+10h] [rbp-F8h] BYREF
__m128i v18; // [rsp+20h] [rbp-E8h] BYREF
__m128i v19; // [rsp+30h] [rbp-D8h] BYREF
char v20[48]; // [rsp+40h] [rbp-C8h] BYREF
char v21[48]; // [rsp+70h] [rbp-98h] BYREF
__int128 v22[6]; // [rsp+A0h] [rbp-68h] BYREF

v4 = gsl_vector_complex_alloc(a2);
if ( !v4 )
return 1LL;
v5 = v4;
gsl_matrix_view_array(&v17, a1, a2, a2);
v6 = _mm_loadu_si128(&v18);
v7 = _mm_loadu_si128(&v19);
v22[0] = (__int128)_mm_loadu_si128(&v17);
v22[1] = (__int128)v6;
v22[2] = (__int128)v7;
v8 = gsl_eigen_nonsymm_alloc(a2);
v9 = v8;
if ( !v8 )
return 1LL;
v10 = 0LL;
gsl_eigen_nonsymm_params(0LL, 1LL, v8);
gsl_eigen_nonsymm(v22, v5, v9);
gsl_vector_complex_real(v20, v5);
gsl_vector_complex_imag(v21, v5);
if ( a2 > 0 )
{
do
{
v11 = gsl_vector_get(v20, v10);
v16 = v11 * v11;
v12 = gsl_vector_get(v21, v10);
v13 = v12 * v12 + v16;
if ( v13 < 0.0 )
v14 = sqrt(v13);
else
v14 = sqrt(v13);
*(double *)(a3 + 8 * v10++) = v14;
}
while ( v10 != a2 );
}
gsl_eigen_nonsymm_free(v9);
gsl_vector_complex_free(v5);
return 0LL;
}

original_code:
int idmc_cycles_eigval(double *mat, int dim, double *ans) {
  gsl_eigen_nonsymm_workspace *ws;
  gsl_matrix_view A;
  gsl_vector_complex *eval;
  int res;
  eval = gsl_vector_complex_alloc(dim);
  if(eval==((void *)0))
    return 1;
  A = gsl_matrix_view_array(mat, dim, dim);
  ws = gsl_eigen_nonsymm_alloc(dim);
  if(ws==((void *)0))
    return 1;
  gsl_eigen_nonsymm_params( 0, 1, ws);
  res = gsl_eigen_nonsymm (&A.matrix, eval, ws);
  gsl_vector_view vr = gsl_vector_complex_real (eval);
  gsl_vector_view vi = gsl_vector_complex_imag (eval);
  for(int i=0; i<dim; i++)
    ans[i] = sqrt( pow(gsl_vector_get(&vr.vector, i),2) + pow(gsl_vector_get(&vi.vector, i),2) );
  gsl_eigen_nonsymm_free(ws);
  gsl_vector_complex_free(eval);
  return 0;
}

canonical_original_code:
int idmc_cycles_eigval(double *mat, int dim, double *ans) {
  struct gsl_eigen_nonsymm_workspace *ws;
  struct _gsl_matrix_view A;
  struct gsl_vector_complex *eval;
  int res;
  eval = gsl_vector_complex_alloc(dim);
  if(eval==((void *)0))
    return 1;
  A = gsl_matrix_view_array(mat, dim, dim);
  ws = gsl_eigen_nonsymm_alloc(dim);
  if(ws==((void *)0))
    return 1;
  gsl_eigen_nonsymm_params( 0, 1, ws);
  res = gsl_eigen_nonsymm (&A.matrix, eval, ws);
  struct _gsl_vector_view vr = gsl_vector_complex_real (eval);
  struct _gsl_vector_view vi = gsl_vector_complex_imag (eval);
  for(int i = 0; i<dim; i++)
    ans[i] = sqrt( pow(gsl_vector_get(&vr.vector, i),2) + pow(gsl_vector_get(&vi.vector, i),2) );
  gsl_eigen_nonsymm_free(ws);
  gsl_vector_complex_free(eval);
  return 0;
}

variable_types:
mat
double *

variable_types: dim int

variable_types:
ans
double *

variable_types: struct gsl_eigen_nonsymm_workspace { unsigned long size; struct gsl_vector { unsigned long size; unsigned long stride; double *data; struct gsl_block_struct { unsigned long size; double *data; } *block; int owner; } *diag; struct gsl_vector *tau; struct gsl_matrix { unsigned long size1; unsigned long size2; unsigned long tda; double *data; struct gsl_block_struct *block; int owner; } *Z; int do_balance; unsigned long n_evals; struct gsl_eigen_francis_workspace { unsigned long size; unsigned long max_iterations; unsigned long n_iter; unsigned long n_evals; int compute_t; struct gsl_matrix *H; struct gsl_matrix *Z; } *francis_workspace_p; } *

variable_types: struct _gsl_matrix_view { 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; } matrix; }

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

variable_types: res int

return_type: int

user_defined_types: struct gsl_eigen_nonsymm_workspace { unsigned long size; struct gsl_vector *diag; struct gsl_vector *tau; struct gsl_matrix *Z; int do_balance; unsigned long n_evals; struct gsl_eigen_francis_workspace *francis_workspace_p; }

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


repo: antonis-m/Parallel-Processing-Systems

decompiled_code:
int __fastcall do_error(int a1, const char *a2, void *a3)
{
size_t v4; // rax
int v5; // edi
size_t v6; // rax
FILE *v7; // rdi
char *v9; // r12
size_t v10; // rax
char s[2]; // [rsp+0h] [rbp-1018h] BYREF

s[0] = 0;
if ( program_name )
snprintf(s, 0x1000uLL, "%s: ", (const char *)program_name);
v4 = strlen(s);
vsnprintf(&s[v4], 0x1000uLL, a2, a3);
if ( a1 )
{
v5 = *_errno_location();
if ( v5 )
{
v9 = strerror(v5);
v10 = strlen(s);
snprintf(&s[v10], 0x1000uLL, ": %s", v9);
}
}
v6 = strlen(s);
v7 = stdout;
*(_WORD *)&s[v6] = 10;
fflush(v7);
fputs(s, stderr);
return fflush(0LL);
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2, void *a3)
{
size_t v4; // rax
int v5; // edi
size_t v6; // rax
FILE *v7; // rdi
char *v9; // r12
size_t v10; // rax
char s[2]; // [rsp+0h] [rbp-1018h] BYREF

s[0] = 0;
if ( program_name )
snprintf(s, 0x1000uLL, "%s: ", (const char *)program_name);
v4 = strlen(s);
vsnprintf(&s[v4], 0x1000uLL, a2, a3);
if ( a1 )
{
v5 = *_errno_location();
if ( v5 )
{
v9 = strerror(v5);
v10 = strlen(s);
snprintf(&s[v10], 0x1000uLL, ": %s", v9);
}
}
v6 = strlen(s);
v7 = stdout;
*(_WORD *)&s[v6] = 10;
fflush(v7);
fputs(s, stderr);
return fflush(0LL);
}

original_code:
static void
do_error(int use_errno, const char *fmt, va_list arg)
{
    char errmsg[4096];
    *errmsg = '\0';
    if (program_name)
        snprintf(errmsg, 4096, "%s: ", program_name);
    vsnprintf(errmsg + strlen(errmsg), 4096, fmt, arg);
    if (use_errno && (*__errno_location ()))
        snprintf(errmsg + strlen(errmsg), 4096,
                 ": %s", strerror((*__errno_location ())));
    strncat(errmsg, "\n", 4096);
    fflush(stdout);
    fputs(errmsg, stderr);
    fflush(((void *)0));
    return;
}

canonical_original_code:
static void do_error(int use_errno, char *fmt, __builtin_va_list arg)
{
    char errmsg[4096];
    *errmsg = '\0';
    if (program_name)
        snprintf(errmsg, 4096, "%s: ", program_name);
    vsnprintf(errmsg + strlen(errmsg), 4096, fmt, arg);
    if (use_errno && (*__errno_location ()))
        snprintf(errmsg + strlen(errmsg), 4096,
                 ": %s", strerror((*__errno_location ())));
    strncat(errmsg, "\n", 4096);
    fflush(stdout);
    fputs(errmsg, stderr);
    fflush(((void *)0));
    return;
}

variable_types:
fmt
char *

variable_types:
errmsg
char [4096]


warning

decompiled_code:
int warning(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return do_error(a1, a2, va);
}

canonical_decompiled_code:
int func1(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
return func0(a1, a2, va);
}

original_code:
void
warning(int use_errno, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    return;
}

canonical_original_code:
void warning(int use_errno, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    return;
}


error

decompiled_code:
void __noreturn error(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
do_error(a1, a2, va);
exit(1);
}

canonical_decompiled_code:
void __noreturn func2(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func0(a1, a2, va);
exit(1);
}

original_code:
void
error(int use_errno, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    exit(1);
}

canonical_original_code:
void error(int use_errno, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    exit(1);
}


decompiled_code:
void __fastcall set_program_name(const char *a1)
{
if ( !program_name )
{
program_name = (__int64)strdup(a1);
if ( !program_name )
error(1, "strdup failed");
}
}

canonical_decompiled_code:
void __fastcall func3(const char *a1)
{
if ( !program_name )
{
program_name = (__int64)strdup(a1);
if ( !program_name )
func2(1, "strdup failed");
}
}

original_code:
void
set_program_name(char *path)
{
    if (!program_name)
        program_name = strdup(path);
    if (!program_name)
        error(1, "strdup failed");
}

variable_types:
path
char *


fatal

decompiled_code:
void __noreturn fatal(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
do_error(a1, a2, va);
abort();
}

canonical_decompiled_code:
void __noreturn func4(int a1, const char *a2, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
func0(a1, a2, va);
abort();
}

original_code:
void
fatal(int use_errno, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    abort();
    exit(1);
}

canonical_original_code:
void fatal(int use_errno, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    do_error(use_errno, fmt, ap);
    __builtin_va_end(ap);
    abort();
    exit(1);
}


decompiled_code:
int __fastcall timer_start(struct timeval *a1)
{
int result; // eax

result = gettimeofday(a1 + 1, 0LL);
if ( result < 0 )
{
perror("gettimeofday failed");
exit(1);
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(struct timeval *a1)
{
int result; // eax

result = gettimeofday(a1 + 1, 0LL);
if ( result < 0 )
{
perror("gettimeofday failed");
exit(1);
}
return result;
}

original_code:
void timer_start(xtimer_t *timer)
{
    if (gettimeofday(&timer->timestamp, ((void *)0)) < 0) {
        perror("gettimeofday failed");
        exit(1);
    }
}

canonical_original_code:
void timer_start(struct xtimer *timer)
{
    if (gettimeofday(&timer->timestamp, ((void *)0)) < 0) {
        perror("gettimeofday failed");
        exit(1);
    }
}

variable_types: struct xtimer { struct timeval { long tv_sec; long tv_usec; } elapsed_time; struct timeval timestamp; } *

user_defined_types: struct xtimer { struct timeval elapsed_time; struct timeval timestamp; }


decompiled_code:
__int64 __fastcall timer_stop(_QWORD *a1)
{
__time_t v1; // rdx
__suseconds_t v2; // rax
__time_t v3; // rdx
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v5, 0LL) < 0 )
{
perror("gettimeofday failed");
exit(1);
}
v1 = v5.tv_sec - a1[2];
v2 = v5.tv_usec - a1[3];
if ( v2 < 0 )
{
--v1;
v2 += 1000000LL;
}
v3 = *a1 + v1;
result = a1[1] + v2;
*a1 = v3;
a1[1] = result;
if ( result > 999999 )
{
result -= 1000000LL;
*a1 = v3 + 1;
a1[1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
__time_t v1; // rdx
__suseconds_t v2; // rax
__time_t v3; // rdx
__int64 result; // rax
struct timeval v5; // [rsp+0h] [rbp-18h] BYREF

if ( gettimeofday(&v5, 0LL) < 0 )
{
perror("gettimeofday failed");
exit(1);
}
v1 = v5.tv_sec - a1[2];
v2 = v5.tv_usec - a1[3];
if ( v2 < 0 )
{
--v1;
v2 += 1000000LL;
}
v3 = *a1 + v1;
result = a1[1] + v2;
*a1 = v3;
a1[1] = result;
if ( result > 999999 )
{
result -= 1000000LL;
*a1 = v3 + 1;
a1[1] = result;
}
return result;
}

original_code:
void timer_stop(xtimer_t *timer)
{
    struct timeval t_stop;
    struct timeval t_interval;
    if (gettimeofday(&t_stop, ((void *)0)) < 0) {
        perror("gettimeofday failed");
        exit(1);
    }
    do { (&t_interval)->tv_sec = (&t_stop)->tv_sec - (&timer->timestamp)->tv_sec; (&t_interval)->tv_usec = (&t_stop)->tv_usec - (&timer->timestamp)->tv_usec; if ((&t_interval)->tv_usec < 0) { --(&t_interval)->tv_sec; (&t_interval)->tv_usec += 1000000; } } while (0);
    do { (&timer->elapsed_time)->tv_sec = (&timer->elapsed_time)->tv_sec + (&t_interval)->tv_sec; (&timer->elapsed_time)->tv_usec = (&timer->elapsed_time)->tv_usec + (&t_interval)->tv_usec; if ((&timer->elapsed_time)->tv_usec >= 1000000) { ++(&timer->elapsed_time)->tv_sec; (&timer->elapsed_time)->tv_usec -= 1000000; } } while (0);
}

canonical_original_code:
void timer_stop(struct xtimer *timer)
{
    struct timeval t_stop;
    struct timeval t_interval;
    if (gettimeofday(&t_stop, ((void *)0)) < 0) {
        perror("gettimeofday failed");
        exit(1);
    }
    do { (&t_interval)->tv_sec = (&t_stop)->tv_sec - (&timer->timestamp)->tv_sec; (&t_interval)->tv_usec = (&t_stop)->tv_usec - (&timer->timestamp)->tv_usec; if ((&t_interval)->tv_usec < 0) { --(&t_interval)->tv_sec; (&t_interval)->tv_usec += 1000000; } } while (0);
    do { (&timer->elapsed_time)->tv_sec = (&timer->elapsed_time)->tv_sec + (&t_interval)->tv_sec; (&timer->elapsed_time)->tv_usec = (&timer->elapsed_time)->tv_usec + (&t_interval)->tv_usec; if ((&timer->elapsed_time)->tv_usec >= 1000000) { ++(&timer->elapsed_time)->tv_sec; (&timer->elapsed_time)->tv_usec -= 1000000; } } while (0);
}

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


decompiled_code:
double __fastcall timer_elapsed_time(_QWORD *a1)
{
return (double)(int)a1[1] / 1000000.0 + (double)(int)*a1;
}

canonical_decompiled_code:
double __fastcall func3(_QWORD *a1)
{
return (double)(int)a1[1] / 1000000.0 + (double)(int)*a1;
}

original_code:
double timer_elapsed_time(xtimer_t *timer)
{
    return (timer->elapsed_time.tv_sec +
            timer->elapsed_time.tv_usec / (double) 1000000L);
}

canonical_original_code:
double timer_elapsed_time(struct xtimer *timer)
{
    return (timer->elapsed_time.tv_sec +
            timer->elapsed_time.tv_usec / (double) 1000000L);
}

return_type: double

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


decompiled_code:
void __fastcall free2D(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func8(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free2D(double ** a, int X, int Y) {
    int i;
    if (X>1) {
        for (i=1;i<X;i++)
            a[i]=((void *)0);
    }
    free(a[0]);
    free(a);
}

canonical_original_code:
void free2D(double **a, int X, int Y) {
    int i;
    if (X>1) {
        for (i=1;i<X;i++)
            a[i]=((void *)0);
    }
    free(a[0]);
    free(a);
}

variable_types:
a
double **

variable_types: X int

variable_types: Y int

variable_types: i int


variable_types: j int


decompiled_code:
int __fastcall print2D(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // r14
__int64 v5; // rbp
__int64 v6; // rbx
double v7; // xmm0_8
int result; // eax

if ( a2 > 0 )
{
v3 = a1;
v5 = 8LL * (unsigned int)(a3 - 1) + 8;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
v7 = *(double *)(*v3 + v6);
v6 += 8LL;
printf("%lf ", v7);
}
while ( v5 != v6 );
}
++v3;
result = putchar(10);
}
while ( v3 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

canonical_decompiled_code:
int __fastcall func10(_QWORD *a1, int a2, int a3)
{
_QWORD *v3; // r14
__int64 v5; // rbp
__int64 v6; // rbx
double v7; // xmm0_8
int result; // eax

if ( a2 > 0 )
{
v3 = a1;
v5 = 8LL * (unsigned int)(a3 - 1) + 8;
do
{
v6 = 0LL;
if ( a3 > 0 )
{
do
{
v7 = *(double *)(*v3 + v6);
v6 += 8LL;
printf("%lf ", v7);
}
while ( v5 != v6 );
}
++v3;
result = putchar(10);
}
while ( v3 != &a1[(unsigned int)(a2 - 1) + 1] );
}
return result;
}

original_code:
void print2D(double ** a, int X, int Y) {
    int i,j;
    for (i=0;i<X;i++) {
        for (j=0;j<Y;j++)
            printf("%lf ",a[i][j]);
        printf("\n");
    }
}

canonical_original_code:
void print2D(double **a, int X, int Y) {
    int i; int j;
    for (i=0;i<X;i++) {
        for (j=0;j<Y;j++)
            printf("%lf ",a[i][j]);
        printf("\n");
    }
}


decompiled_code:
void **__fastcall copy_2d(void **a1, const void **a2, __int64 a3, __int64 a4, __int64 a5)
{
memcpy(*a1, *a2, a5 * a4 * a3);
return a1;
}

canonical_decompiled_code:
void **__fastcall func0(void **a1, const void **a2, __int64 a3, __int64 a4, __int64 a5)
{
memcpy(*a1, *a2, a5 * a4 * a3);
return a1;
}

original_code:
void **copy_2d(void **dst, const void **src, size_t n, size_t m, size_t size)
{
    memcpy(dst[0], src[0], n*m*size);
    return dst;
}

canonical_original_code:
void **copy_2d(void **dst, void **src, unsigned long n, unsigned long m, unsigned long size)
{
    memcpy(dst[0], src[0], n*m*size);
    return dst;
}

variable_types:
dst
void **

variable_types:
src
void **

variable_types:
n
unsigned long

variable_types:
m
unsigned long

variable_types:
size
unsigned long

return_type: void **


decompiled_code:
void __fastcall free_2d(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
free(*(void **)ptr);
free(ptr);
}

original_code:
void free_2d(void **array)
{
    free(array[0]);
    free(array);
}

variable_types:
array
void **


repo: antonis-m/oslab

decompiled_code:
void __fastcall toupper_buf(char *a1, __int64 a2)
{
char *v2; // rsi
const __int32_t **v3; // rcx
__int64 v4; // rdx

if ( a2 )
{
v2 = &a1[a2];
v3 = __ctype_toupper_loc();
do
{
v4 = *a1++;
*(a1 - 1) = (*v3)[v4];
}
while ( v2 != a1 );
}
}

original_code:
void toupper_buf(char *buf, size_t n)
{
 size_t i;
 for (i = 0; i < n; i++)
  buf[i] = toupper(buf[i]);
}

canonical_original_code:
void toupper_buf(char *buf, unsigned long n)
{
 unsigned long i;
 for (i = 0; i < n; i++)
  buf[i] = toupper(buf[i]);
}

variable_types:
buf
char *

variable_types:
i
unsigned long


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er12
socklen_t v5; // edx
int v6; // ebp
unsigned __int16 v7; // ax
const char *v8; // rdx
ssize_t v9; // rax
size_t v10; // rbx
socklen_t addr_len; // [rsp+Ch] [rbp-ACh] BYREF
char buf[16]; // [rsp+10h] [rbp-A8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-98h] BYREF
char v14[136]; // [rsp+30h] [rbp-88h] BYREF

signal(13, (__sighandler_t)1);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
{
perror("socket");
exit(1);
}
v4 = v3;
fwrite("Created TCP socket\n", 1uLL, 0x13uLL, stderr);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(35001LL, &addr, 16LL);
*(_DWORD *)&addr.sa_data[2] = _bswap_32_constprop_0(v4);
if ( bind(v4, &addr, v5) < 0 )
{
perror("bind");
exit(1);
}
fprintf(stderr, "Bound TCP socket to port %d\n", 35001LL);
if ( listen(v4, 5) < 0 )
{
perror("listen");
exit(1);
}
while ( 1 )
{
fwrite("Waiting for an incoming connection...\n", 1uLL, 0x26uLL, stderr);
addr_len = 16;
v6 = accept(v4, &addr, &addr_len);
if ( v6 < 0 )
{
perror("accept");
exit(1);
}
if ( !inet_ntop(2, &addr.sa_data[2], buf, 0x10u) )
{
perror("could not format IP address");
exit(1);
}
v7 = _bswap_16(*(unsigned __int16 *)addr.sa_data, "Incoming connection from %s:%d\n", buf);
fprintf(stderr, "Incoming connection from %s:%d\n", v8, v7);
while ( 1 )
{
v9 = read(v6, v14, 0x64uLL);
v10 = v9;
if ( v9 <= 0 )
break;
toupper_buf(v14, v9);
if ( insist_write(v6, v14, v10) != v10 )
{
perror("write to remote peer failed");
goto LABEL_11;
}
}
if ( v9 )
perror("read from remote peer failed");
else
fwrite("Peer went away\n", 1uLL, 0xFuLL, stderr);
LABEL_11:
if ( close(v6) < 0 )
perror("close");
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
int v3; // eax
unsigned int v4; // er12
socklen_t v5; // edx
int v6; // ebp
unsigned __int16 v7; // ax
const char *v8; // rdx
ssize_t v9; // rax
size_t v10; // rbx
socklen_t addr_len; // [rsp+Ch] [rbp-ACh] BYREF
char buf[16]; // [rsp+10h] [rbp-A8h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-98h] BYREF
char v14[136]; // [rsp+30h] [rbp-88h] BYREF

signal(13, (__sighandler_t)1);
v3 = socket(2, 1, 0);
if ( v3 < 0 )
{
perror("socket");
exit(1);
}
v4 = v3;
fwrite("Created TCP socket\n", 1uLL, 0x13uLL, stderr);
*(_QWORD *)&addr.sa_data[6] = 0LL;
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func7(35001LL, &addr, 16LL);
*(_DWORD *)&addr.sa_data[2] = func8(v4);
if ( bind(v4, &addr, v5) < 0 )
{
perror("bind");
exit(1);
}
fprintf(stderr, "Bound TCP socket to port %d\n", 35001LL);
if ( listen(v4, 5) < 0 )
{
perror("listen");
exit(1);
}
while ( 1 )
{
fwrite("Waiting for an incoming connection...\n", 1uLL, 0x26uLL, stderr);
addr_len = 16;
v6 = accept(v4, &addr, &addr_len);
if ( v6 < 0 )
{
perror("accept");
exit(1);
}
if ( !inet_ntop(2, &addr.sa_data[2], buf, 0x10u) )
{
perror("could not format IP address");
exit(1);
}
v7 = func7(*(unsigned __int16 *)addr.sa_data, "Incoming connection from %s:%d\n", buf);
fprintf(stderr, "Incoming connection from %s:%d\n", v8, v7);
while ( 1 )
{
v9 = read(v6, v14, 0x64uLL);
v10 = v9;
if ( v9 <= 0 )
break;
func9(v14, v9);
if ( func10(v6, v14, v10) != v10 )
{
perror("write to remote peer failed");
goto LABEL_11;
}
}
if ( v9 )
perror("read from remote peer failed");
else
fwrite("Peer went away\n", 1uLL, 0xFuLL, stderr);
LABEL_11:
if ( close(v6) < 0 )
perror("close");
}
}

original_code:
int main(void)
{
 char buf[100];
 char addrstr[16];
 int sd, newsd;
 ssize_t n;
 socklen_t len;
 struct sockaddr_in sa;
 signal(13, ((__sighandler_t) 1));
 if ((sd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket");
  exit(1);
 }
 fprintf(stderr, "Created TCP socket\n");
 memset(&sa, 0, sizeof(sa));
 sa.sin_family = 2;
 sa.sin_port = htons(35001);
 sa.sin_addr.s_addr = htonl(((in_addr_t) 0x00000000));
 if (bind(sd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
  perror("bind");
  exit(1);
 }
 fprintf(stderr, "Bound TCP socket to port %d\n", 35001);
 if (listen(sd, 5) < 0) {
  perror("listen");
  exit(1);
 }
 for (;;) {
  fprintf(stderr, "Waiting for an incoming connection...\n");
  len = sizeof(struct sockaddr_in);
  if ((newsd = accept(sd, (struct sockaddr *)&sa, &len)) < 0) {
   perror("accept");
   exit(1);
  }
  if (!inet_ntop(2, &sa.sin_addr, addrstr, sizeof(addrstr))) {
   perror("could not format IP address");
   exit(1);
  }
  fprintf(stderr, "Incoming connection from %s:%d\n",
   addrstr, ntohs(sa.sin_port));
  for (;;) {
   n = read(newsd, buf, sizeof(buf));
   if (n <= 0) {
    if (n < 0)
     perror("read from remote peer failed");
    else
     fprintf(stderr, "Peer went away\n");
    break;
   }
   toupper_buf(buf, n);
   if (insist_write(newsd, buf, n) != n) {
    perror("write to remote peer failed");
    break;
   }
  }
  if (close(newsd) < 0)
   perror("close");
 }
 return 1;
}

canonical_original_code:
int main()
{
 char buf[100];
 char addrstr[16];
 int sd; int newsd;
 long n;
 unsigned int len;
 struct sockaddr_in sa;
 signal(13, ((void (*)(int)) 1));
 if ((sd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror("socket");
  exit(1);
 }
 fprintf(stderr, "Created TCP socket\n");
 memset(&sa, 0, sizeof(sa));
 sa.sin_family = 2;
 sa.sin_port = htons(35001);
 sa.sin_addr.s_addr = htonl(((unsigned int) 0x00000000));
 if (bind(sd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
  perror("bind");
  exit(1);
 }
 fprintf(stderr, "Bound TCP socket to port %d\n", 35001);
 if (listen(sd, 5) < 0) {
  perror("listen");
  exit(1);
 }
 for (;;) {
  fprintf(stderr, "Waiting for an incoming connection...\n");
  len = sizeof(struct sockaddr_in);
  if ((newsd = accept(sd, (struct sockaddr *)&sa, &len)) < 0) {
   perror("accept");
   exit(1);
  }
  if (!inet_ntop(2, &sa.sin_addr, addrstr, sizeof(addrstr))) {
   perror("could not format IP address");
   exit(1);
  }
  fprintf(stderr, "Incoming connection from %s:%d\n",
   addrstr, ntohs(sa.sin_port));
  for (;;) {
   n = read(newsd, buf, sizeof(buf));
   if (n <= 0) {
    if (n < 0)
     perror("read from remote peer failed");
    else
     fprintf(stderr, "Peer went away\n");
    break;
   }
   toupper_buf(buf, n);
   if (insist_write(newsd, buf, n) != n) {
    perror("write to remote peer failed");
    break;
   }
  }
  if (close(newsd) < 0)
   perror("close");
 }
 return 1;
}

variable_types:
buf
char [100]

variable_types:
addrstr
char [16]

variable_types: sd int

variable_types: newsd int

variable_types: n long

variable_types:
len
unsigned int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
ssize_t __fastcall insist_write(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t result; // rax

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
result = write(fd, buf, v5);
if ( result < 0 )
break;
buf = (char *)buf + result;
v5 -= result;
if ( !v5 )
return v3;
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func10(int fd, void *buf, size_t n)
{
size_t v3; // r13
size_t v5; // rbx
ssize_t result; // rax

v3 = n;
if ( !n )
return v3;
v5 = n;
while ( 1 )
{
result = write(fd, buf, v5);
if ( result < 0 )
break;
buf = (char *)buf + result;
v5 -= result;
if ( !v5 )
return v3;
}
return result;
}

original_code:
ssize_t insist_write(int fd, const void *buf, size_t cnt)
{
 ssize_t ret;
 size_t orig_cnt = cnt;
 while (cnt > 0) {
         ret = write(fd, buf, cnt);
         if (ret < 0)
                 return ret;
         buf += ret;
         cnt -= ret;
 }
 return orig_cnt;
}

canonical_original_code:
long insist_write(int fd, void *buf, unsigned long cnt)
{
 long ret;
 unsigned long orig_cnt = cnt;
 while (cnt > 0) {
         ret = write(fd, buf, cnt);
         if (ret < 0)
                 return ret;
         buf += ret;
         cnt -= ret;
 }
 return orig_cnt;
}

variable_types: fd int

variable_types:
buf
void *

variable_types:
cnt
unsigned long

variable_types: ret long

return_type: long


decompiled_code:
__int64 __fastcall uint16_to_batt(unsigned __int16 a1, const char *a2)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = (unsigned int)(int)(1023.0 / (double)a1 * 1.223 * 1000.0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int16 a1, const char *a2)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = (unsigned int)(int)(1023.0 / (double)a1 * 1.223 * 1000.0);
return result;
}

original_code:
long uint16_to_batt(uint16_t value)
{
 double d;
 if (value != 0)
  d = 1.223 * (1023.0 / value);
 else
  d = -0;
 return (long)(d * 1000);
}

canonical_original_code:
long uint16_to_batt(unsigned short value)
{
 double d;
 if (value != 0)
  d = 1.223 * (1023.0 / value);
 else
  d = -0;
 return (long)(d * 1000);
}

variable_types:
value
unsigned short

variable_types: d double


decompiled_code:
__int64 __fastcall uint16_to_light(unsigned __int16 a1, const char *a2)
{
return (unsigned int)(int)((double)a1 * 5000000.0 / 65535.0);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int16 a1, const char *a2)
{
return (unsigned int)(int)((double)a1 * 5000000.0 / 65535.0);
}

original_code:
long uint16_to_light(uint16_t value)
{
 return (long) (value * 5000000.0 / 65535);
}

canonical_original_code:
long uint16_to_light(unsigned short value)
{
 return (long) (value * 5000000.0 / 65535);
}


original_code:
long uint16_to_temp(uint16_t value)
{
 long l;
 double R1 = 10000.0;
 double ADC_FS = 1023.0;
 double Rth, Kelvin_Inv;
 double a = 0.001010024F;
 double b = 0.000242127F;
 double c = 0.000000146F;
 double res;
 Rth = (R1 * (ADC_FS - (double)value)) / (double)value;
 Kelvin_Inv = a + b * log(Rth) + c * pow(log(Rth), 3);
 res = (1.0 / Kelvin_Inv) - 272.15;
 l = (long)(res * 1000);
 return (l < -272150) ? -272150 : l;
}

canonical_original_code:
long uint16_to_temp(unsigned short value)
{
 long l;
 double R1 = 10000.0;
 double ADC_FS = 1023.0;
 double Rth; double Kelvin_Inv;
 double a = 0.001010024F;
 double b = 0.000242127F;
 double c = 0.000000146F;
 double res;
 Rth = (R1 * (ADC_FS - (double)value)) / (double)value;
 Kelvin_Inv = a + b * log(Rth) + c * pow(log(Rth), 3);
 res = (1.0 / Kelvin_Inv) - 272.15;
 l = (long)(res * 1000);
 return (l < -272150) ? -272150 : l;
}

variable_types: l long

variable_types: Rth double

variable_types: a double

variable_types: b double

variable_types: c double

variable_types: res double


original_code:
int main(void)
{
 unsigned int i;
 fprintf(stdout,
  "/*\n"
  " * lunix-tables.h\n"
  " *\n"
  " * Machine-generated file. DO NOT EDIT.\n"
  " * See %s instead.\n"
  " *\n"
  " * Instead of doing floating-point in kernelspace,\n"
  " * use the following lookup tables to convert 16-bit\n"
  " * raw measurements to floating point values.\n"
  " */\n"
  "\n"
  "long lookup_temperature[65536] = {\n", "mk_lookup_tables.c");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_temp(i), uint16_to_temp(i+1),
   uint16_to_temp(i+2), uint16_to_temp(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n"
  "long lookup_voltage[65536] = {\n");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_batt(i), uint16_to_batt(i+1),
   uint16_to_batt(i+2), uint16_to_batt(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n"
  "long lookup_light[65536] = {\n");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_light(i), uint16_to_light(i+1),
   uint16_to_light(i+2), uint16_to_light(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n");
 return 0;
}

canonical_original_code:
int main()
{
 unsigned int i;
 fprintf(stdout,
  "/*\n"
  " * lunix-tables.h\n"
  " *\n"
  " * Machine-generated file. DO NOT EDIT.\n"
  " * See %s instead.\n"
  " *\n"
  " * Instead of doing floating-point in kernelspace,\n"
  " * use the following lookup tables to convert 16-bit\n"
  " * raw measurements to floating point values.\n"
  " */\n"
  "\n"
  "long lookup_temperature[65536] = {\n", "mk_lookup_tables.c");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_temp(i), uint16_to_temp(i+1),
   uint16_to_temp(i+2), uint16_to_temp(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n"
  "long lookup_voltage[65536] = {\n");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_batt(i), uint16_to_batt(i+1),
   uint16_to_batt(i+2), uint16_to_batt(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n"
  "long lookup_light[65536] = {\n");
 for (i = 0; i <= 0xFFFC; i += 4) {
  fprintf(stdout, "\t%ld, %ld, %ld, %ld",
   uint16_to_light(i), uint16_to_light(i+1),
   uint16_to_light(i+2), uint16_to_light(i+3));
  fprintf(stdout, (i != 0xFFFC) ? ",\n" : "\n");
 }
 fprintf(stdout, "};\n\n");
 return 0;
}

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall fill_urandom_buff(void *buf)
{
int v1; // eax
unsigned int v2; // er12
unsigned int v3; // ebp

v1 = open("/dev/urandom", 0);
v2 = v1;
if ( v1 >= 0 )
{
v3 = read(v1, buf, 0x100uLL);
close(v2);
v2 = v3;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(void *buf)
{
int v1; // eax
unsigned int v2; // er12
unsigned int v3; // ebp

v1 = open("/dev/urandom", 0);
v2 = v1;
if ( v1 >= 0 )
{
v3 = read(v1, buf, 0x100uLL);
close(v2);
v2 = v3;
}
return v2;
}

original_code:
int fill_urandom_buff(char in[256]){
 int crypto_fd = open("/dev/urandom", 00);
 int ret = -1;
 if (crypto_fd < 0) return crypto_fd;
 ret = read(crypto_fd, (void *)in, 256);
 close(crypto_fd);
 return ret;
}

variable_types:
in
char [256]

variable_types: ret int


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // eax
int v5; // ebp
int v6; // er8
int result; // eax
char v8[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = argv[1];
if ( !v3 )
v3 = "/dev/crypto";
v4 = open(v3, 2, 0LL);
if ( v4 < 0 )
{
sprintf(v8, "open %s", v3);
perror(v8);
result = 1;
}
else
{
v5 = v4;
v6 = test_crypto(v4);
result = 1;
if ( !v6 )
{
result = close(v5);
if ( result )
{
perror("close(fd)");
result = 1;
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
int v4; // eax
int v5; // ebp
int v6; // er8
int result; // eax
char v8[136]; // [rsp+0h] [rbp-88h] BYREF

v3 = argv[1];
if ( !v3 )
v3 = "/dev/crypto";
v4 = open(v3, 2, 0LL);
if ( v4 < 0 )
{
sprintf(v8, "open %s", v3);
perror(v8);
result = 1;
}
else
{
v5 = v4;
v6 = func8(v4);
result = 1;
if ( !v6 )
{
result = close(v5);
if ( result )
{
perror("close(fd)");
result = 1;
}
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
        int fd = -1;
  char *filename;
  char error_str[100];
  filename = (argv[1] == ((void *)0)) ? "/dev/crypto" : argv[1];
        fd = open(filename, 02, 0);
        if (fd < 0) {
                sprintf(error_str, "open %s", filename);
                perror(error_str);
                return 1;
        }
        if (test_crypto(fd)){
                return 1;
 }
        if (close(fd)) {
                perror("close(fd)");
                return 1;
        }
        return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
filename
char *


decompiled_code:
int __fastcall test_crypto(int fd)
{
char *v1; // rbx
__int64 v2; // rsi
char *v3; // rbx
__int64 v4; // rsi
char *v5; // rbx
__int64 v6; // rsi
int result; // eax
__int128 v8; // [rsp+0h] [rbp-3B8h] BYREF
__int128 v9; // [rsp+10h] [rbp-3A8h]
__int128 v10; // [rsp+20h] [rbp-398h] BYREF
__int128 v11; // [rsp+30h] [rbp-388h] BYREF
__int128 v12; // [rsp+40h] [rbp-378h]
__int128 v13; // [rsp+50h] [rbp-368h]
char s1[256]; // [rsp+60h] [rbp-358h] BYREF
char v15[256]; // [rsp+160h] [rbp-258h] BYREF
char s2[256]; // [rsp+260h] [rbp-158h] BYREF
char v17[16]; // [rsp+360h] [rbp-58h] BYREF
char v18; // [rsp+370h] [rbp-48h] BYREF

v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
if ( (int)fill_urandom_buff(s1) < 0 )
{
puts("error @filling urandom data");
result = 1;
}
else
{
v1 = s1;
printf("\ninput data:");
do
{
v2 = (unsigned int)*v1++;
printf("%x", v2);
}
while ( v1 != v15 );
putchar(10);
LODWORD(v8) = 11;
*(_QWORD *)&v9 = &v18;
DWORD2(v8) = 24;
if ( ioctl(fd, 0xC0306366uLL, &v8) )
{
perror("ioctl(CIOCGSESSION)");
result = 1;
}
else
{
DWORD2(v11) = 256;
*((_QWORD *)&v12 + 1) = v15;
LODWORD(v11) = DWORD2(v10);
*(_QWORD *)&v12 = s1;
*((_QWORD *)&v13 + 1) = v17;
WORD2(v11) = 0;
printf("\nencrypted data:");
if ( ioctl(fd, 0xC0306368uLL, &v11) )
goto LABEL_17;
v3 = v15;
do
{
v4 = (unsigned int)*v3++;
printf("%x", v4);
}
while ( v3 != s2 );
putchar(10);
*(_QWORD *)&v12 = v15;
*((_QWORD *)&v12 + 1) = s2;
WORD2(v11) = 1;
if ( ioctl(fd, 0xC0306368uLL, &v11) )
{
LABEL_17:
perror("ioctl(CIOCCRYPT)");
result = 1;
}
else
{
v5 = s2;
printf("\ndecrypted data:");
do
{
v6 = (unsigned int)*v5++;
printf("%x", v6);
}
while ( v5 != v17 );
putchar(10);
if ( !memcmp(s1, s2, 0x100uLL) )
{
puts("\nTest passed");
result = ioctl(fd, 0x40046367uLL, (char *)&v10 + 8);
if ( result )
{
perror("ioctl(CIOCFSESSION)");
result = 1;
}
}
else
{
fwrite("\nFAIL: Decrypted data are different from the input data.\n", 1uLL, 0x39uLL, _bss_start);
result = 1;
}
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int fd)
{
char *v1; // rbx
__int64 v2; // rsi
char *v3; // rbx
__int64 v4; // rsi
char *v5; // rbx
__int64 v6; // rsi
int result; // eax
__int128 v8; // [rsp+0h] [rbp-3B8h] BYREF
__int128 v9; // [rsp+10h] [rbp-3A8h]
__int128 v10; // [rsp+20h] [rbp-398h] BYREF
__int128 v11; // [rsp+30h] [rbp-388h] BYREF
__int128 v12; // [rsp+40h] [rbp-378h]
__int128 v13; // [rsp+50h] [rbp-368h]
char s1[256]; // [rsp+60h] [rbp-358h] BYREF
char v15[256]; // [rsp+160h] [rbp-258h] BYREF
char s2[256]; // [rsp+260h] [rbp-158h] BYREF
char v17[16]; // [rsp+360h] [rbp-58h] BYREF
char v18; // [rsp+370h] [rbp-48h] BYREF

v8 = 0LL;
v9 = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
if ( (int)func7(s1) < 0 )
{
puts("error @filling urandom data");
result = 1;
}
else
{
v1 = s1;
printf("\ninput data:");
do
{
v2 = (unsigned int)*v1++;
printf("%x", v2);
}
while ( v1 != v15 );
putchar(10);
LODWORD(v8) = 11;
*(_QWORD *)&v9 = &v18;
DWORD2(v8) = 24;
if ( ioctl(fd, 0xC0306366uLL, &v8) )
{
perror("ioctl(CIOCGSESSION)");
result = 1;
}
else
{
DWORD2(v11) = 256;
*((_QWORD *)&v12 + 1) = v15;
LODWORD(v11) = DWORD2(v10);
*(_QWORD *)&v12 = s1;
*((_QWORD *)&v13 + 1) = v17;
WORD2(v11) = 0;
printf("\nencrypted data:");
if ( ioctl(fd, 0xC0306368uLL, &v11) )
goto LABEL_17;
v3 = v15;
do
{
v4 = (unsigned int)*v3++;
printf("%x", v4);
}
while ( v3 != s2 );
putchar(10);
*(_QWORD *)&v12 = v15;
*((_QWORD *)&v12 + 1) = s2;
WORD2(v11) = 1;
if ( ioctl(fd, 0xC0306368uLL, &v11) )
{
LABEL_17:
perror("ioctl(CIOCCRYPT)");
result = 1;
}
else
{
v5 = s2;
printf("\ndecrypted data:");
do
{
v6 = (unsigned int)*v5++;
printf("%x", v6);
}
while ( v5 != v17 );
putchar(10);
if ( !memcmp(s1, s2, 0x100uLL) )
{
puts("\nTest passed");
result = ioctl(fd, 0x40046367uLL, (char *)&v10 + 8);
if ( result )
{
perror("ioctl(CIOCFSESSION)");
result = 1;
}
}
else
{
fwrite("\nFAIL: Decrypted data are different from the input data.\n", 1uLL, 0x39uLL, _bss_start);
result = 1;
}
}
}
}
return result;
}

original_code:
static int test_crypto(int cfd)
{
 int i = -1;
        struct session_op sess;
        struct crypt_op cryp;
        struct {
                char in[256],
                        encrypted[256],
                        decrypted[256],
                        iv[16],
                        key[24];
        } data;
        memset(&sess, 0, sizeof(sess));
        memset(&cryp, 0, sizeof(cryp));
 if (fill_urandom_buff(data.in) < 0) {
  printf("error @filling urandom data\n");
  return 1;
 }
 printf("\ninput data:");
 for (i = 0; i < 256; i++) {
  printf("%x", data.in[i]);
 }
 printf("\n");
        sess.cipher = CRYPTO_AES_CBC;
        sess.keylen = 24;
        sess.key = (__u8 *)data.key;
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((102)) << 0) | ((((sizeof(struct session_op)))) << ((0 +8)+8))), &sess)) {
                perror("ioctl(CIOCGSESSION)");
                return 1;
        }
        cryp.ses = sess.ses;
        cryp.len = sizeof(data.in);
        cryp.src = (__u8 *)data.in;
        cryp.dst = (__u8 *)data.encrypted;
        cryp.iv = (__u8 *)data.iv;
        cryp.op = 0;
 printf("\nencrypted data:");
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((104)) << 0) | ((((sizeof(struct crypt_op)))) << ((0 +8)+8))), &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 1;
        }
 for (i = 0; i < 256; i++) {
  printf("%x", data.encrypted[i]);
 }
 printf("\n");
        cryp.src = (__u8 *)data.encrypted;
        cryp.dst = (__u8 *)data.decrypted;
        cryp.op = 1;
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((104)) << 0) | ((((sizeof(struct crypt_op)))) << ((0 +8)+8))), &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 1;
        }
 printf("\ndecrypted data:");
 for (i = 0; i < 256; i++) {
  printf("%x", data.decrypted[i]);
 }
 printf("\n");
        if (memcmp(data.in, data.decrypted, sizeof(data.in)) != 0) {
                fprintf(stderr,
                        "\nFAIL: Decrypted data are different from the input data.\n");
                return 1;
        } else
                printf("\nTest passed\n");
        if (ioctl(cfd, (((1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((103)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))), &sess.ses)) {
                perror("ioctl(CIOCFSESSION)");
                return 1;
        }
        return 0;
}

canonical_original_code:
static int test_crypto(int cfd)
{
 int i = -1;
        struct session_op sess;
        struct crypt_op cryp;
        struct { char in[256]; } data;
        memset(&sess, 0, sizeof(sess));
        memset(&cryp, 0, sizeof(cryp));
 if (fill_urandom_buff(data.in) < 0) {
  printf("error @filling urandom data\n");
  return 1;
 }
 printf("\ninput data:");
 for (i = 0; i < 256; i++) {
  printf("%x", data.in[i]);
 }
 printf("\n");
        sess.cipher = CRYPTO_AES_CBC;
        sess.keylen = 24;
        sess.key = (unsigned char *)data.key;
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((102)) << 0) | ((((sizeof(struct session_op)))) << ((0 +8)+8))), &sess)) {
                perror("ioctl(CIOCGSESSION)");
                return 1;
        }
        cryp.ses = sess.ses;
        cryp.len = sizeof(data.in);
        cryp.src = (unsigned char *)data.in;
        cryp.dst = (unsigned char *)data.encrypted;
        cryp.iv = (unsigned char *)data.iv;
        cryp.op = 0;
 printf("\nencrypted data:");
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((104)) << 0) | ((((sizeof(struct crypt_op)))) << ((0 +8)+8))), &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 1;
        }
 for (i = 0; i < 256; i++) {
  printf("%x", data.encrypted[i]);
 }
 printf("\n");
        cryp.src = (unsigned char *)data.encrypted;
        cryp.dst = (unsigned char *)data.decrypted;
        cryp.op = 1;
        if (ioctl(cfd, (((2U|1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((104)) << 0) | ((((sizeof(struct crypt_op)))) << ((0 +8)+8))), &cryp)) {
                perror("ioctl(CIOCCRYPT)");
                return 1;
        }
 printf("\ndecrypted data:");
 for (i = 0; i < 256; i++) {
  printf("%x", data.decrypted[i]);
 }
 printf("\n");
        if (memcmp(data.in, data.decrypted, sizeof(data.in)) != 0) {
                fprintf(stderr,
                        "\nFAIL: Decrypted data are different from the input data.\n");
                return 1;
        } else
                printf("\nTest passed\n");
        if (ioctl(cfd, (((1U) << (((0 +8)+8)+14)) | ((('c')) << (0 +8)) | (((103)) << 0) | ((((sizeof(__u32)))) << ((0 +8)+8))), &sess.ses)) {
                perror("ioctl(CIOCFSESSION)");
                return 1;
        }
        return 0;
}

variable_types: cfd int

variable_types: i int

variable_types: struct session_op { unsigned int cipher; unsigned int mac; unsigned int keylen; unsigned char *key; unsigned int mackeylen; unsigned char *mackey; unsigned int ses; }

variable_types: struct crypt_op { unsigned int ses; unsigned short op; unsigned short flags; unsigned int len; unsigned char *src; unsigned char *dst; unsigned char *mac; unsigned char *iv; }

variable_types:
data
struct { char in[256]; }


repo: anttisalonen/lvm

decompiled_code:
__int64 __fastcall get_two_nums(const char *a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax
const char *v5; // rdi
__int64 result; // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = strtol(a1, endptr, 0);
v5 = endptr[0];
*a2 = v4;
result = 0LL;
if ( *v5 == 32 )
{
*a3 = strtol(v5, endptr, 0);
result = (*endptr[0] == 10) | (unsigned __int8)(*endptr[0] == 0);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1, _DWORD *a2, _DWORD *a3)
{
int v4; // eax
const char *v5; // rdi
__int64 result; // rax
char *endptr[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = strtol(a1, endptr, 0);
v5 = endptr[0];
*a2 = v4;
result = 0LL;
if ( *v5 == 32 )
{
*a3 = strtol(v5, endptr, 0);
result = (*endptr[0] == 10) | (unsigned __int8)(*endptr[0] == 0);
}
return result;
}

original_code:
long int get_two_nums(const char *buf, int *a, int *b)
{
 char *endptr;
 *a = strtol(buf, &endptr, 0);
 if(*endptr && *endptr == ' ') {
  *b = strtol(endptr, &endptr, 0);
  return !(*endptr && *endptr != '\n');
 }
 else {
  return 0;
 }
}

canonical_original_code:
long get_two_nums(char *buf, int *a, int *b)
{
 char *endptr;
 *a = strtol(buf, &endptr, 0);
 if(*endptr && *endptr == ' ') {
  *b = strtol(endptr, &endptr, 0);
  return !(*endptr && *endptr != '\n');
 }
 else {
  return 0;
 }
}

variable_types:
buf
char *

variable_types:
a
int *

variable_types:
b
int *

variable_types:
endptr
char *


getnum

decompiled_code:
__int64 __fastcall getnum(const char *a1, _DWORD *a2)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 0);
if ( !*endptr || *endptr == 10 )
{
*a2 = 1;
}
else
{
result = 0LL;
*a2 = 0;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, _DWORD *a2)
{
__int64 result; // rax
char *endptr; // [rsp+8h] [rbp-10h] BYREF

result = strtol(a1, &endptr, 0);
if ( !*endptr || *endptr == 10 )
{
*a2 = 1;
}
else
{
result = 0LL;
*a2 = 0;
}
return result;
}

original_code:
long int getnum(const char *buf, int *succ)
{
 char *endptr;
 long int val = strtol(buf, &endptr, 0);
 if(*endptr && *endptr != '\n') {
  *succ = 0;
  return 0;
 }
 else {
  *succ = 1;
  return val;
 }
}

canonical_original_code:
long getnum(char *buf, int *succ)
{
 char *endptr;
 long val = strtol(buf, &endptr, 0);
 if(*endptr && *endptr != '\n') {
  *succ = 0;
  return 0;
 }
 else {
  *succ = 1;
  return val;
 }
}

variable_types:
succ
int *

variable_types: val long


original_code:
void num_to_be(long int val, int bytes, char *buf)
{
 char v = 0;
 if(val < 0) {
  v = 0x80;
  val = -val;
 }
 v |= (val & 0x7f);
 sprintf(buf, "%c", v);
 int i;
 val >>= 7;
 for(i = 1; i < bytes; i++) {
  v = val & 0xff;
  buf[i] = v;
  val >>= 8;
 }
}

canonical_original_code:
void num_to_be(long val, int bytes, char *buf)
{
 char v = 0;
 if(val < 0) {
  v = 0x80;
  val = -val;
 }
 v |= (val & 0x7f);
 sprintf(buf, "%c", v);
 int i;
 val >>= 7;
 for(i = 1; i < bytes; i++) {
  v = val & 0xff;
  buf[i] = v;
  val >>= 8;
 }
}

variable_types: bytes int

variable_types: v char


decompiled_code:
int __fastcall int_to_be(__int64 a1, char *a2)
{
return num_to_be(a1, 4, a2);
}

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

original_code:
void int_to_be(long int val, char *buf)
{
 num_to_be(val, 4, buf);
}

canonical_original_code:
void int_to_be(long val, char *buf)
{
 num_to_be(val, 4, buf);
}


decompiled_code:
int __fastcall output_char(char a1)
{
int result; // eax
int v2; // edx

if ( interactive )
{
if ( interactive_bufferpos > 1000 )
{
result = fwrite("Buffer full\n", 1uLL, 0xCuLL, stderr);
}
else
{
result = sprintf(&interactive_buffer[interactive_bufferpos], "%c", (unsigned int)a1);
++interactive_bufferpos;
}
}
else
{
result = output_buffer_offset;
++current_addr;
v2 = output_buffer_offset + 1;
output_buffer[output_buffer_offset] = a1;
output_buffer_offset = v2;
if ( v2 > 1023 )
{
fwrite("Output buffer full\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(char a1)
{
int result; // eax
int v2; // edx

if ( interactive )
{
if ( interactive_bufferpos > 1000 )
{
result = fwrite("Buffer full\n", 1uLL, 0xCuLL, stderr);
}
else
{
result = sprintf(&interactive_buffer[interactive_bufferpos], "%c", (unsigned int)a1);
++interactive_bufferpos;
}
}
else
{
result = output_buffer_offset;
++current_addr;
v2 = output_buffer_offset + 1;
output_buffer[output_buffer_offset] = a1;
output_buffer_offset = v2;
if ( v2 > 1023 )
{
fwrite("Output buffer full\n", 1uLL, 0x13uLL, stderr);
exit(1);
}
}
return result;
}

original_code:
void output_char(char ch)
{
 if(interactive) {
  if(interactive_bufferpos > 1000) {
   fprintf(stderr, "Buffer full\n");
   return;
  }
  interactive_bufferpos += sprintf(interactive_buffer + interactive_bufferpos,
    "%c", ch);
 }
 else {
  output_buffer[output_buffer_offset++] = ch;
  current_addr++;
  if(output_buffer_offset >= 1024) {
   fprintf(stderr, "Output buffer full\n");
   exit(1);
  }
 }
}

variable_types: ch char


decompiled_code:
int __fastcall output_header(char a1)
{
return putc(a1, stdout);
}

canonical_decompiled_code:
int __fastcall func5(char a1)
{
return putc(a1, stdout);
}

original_code:
void output_header(char ch)
{
 putc(ch, stdout);
}


decompiled_code:
const unsigned __int16 *__fastcall output_until_space(char *a1, int a2)
{
const unsigned __int16 **v3; // r12
char v4; // di
const unsigned __int16 *result; // rax

v3 = _ctype_b_loc();
while ( 1 )
{
v4 = *a1;
result = *v3;
if ( ((*v3)[*a1] & 0x2000) != 0 || !v4 )
break;
if ( a2 )
output_header(v4);
else
output_char(v4);
++a1;
}
return result;
}

canonical_decompiled_code:
const unsigned __int16 *__fastcall func6(char *a1, int a2)
{
const unsigned __int16 **v3; // r12
char v4; // di
const unsigned __int16 *result; // rax

v3 = _ctype_b_loc();
while ( 1 )
{
v4 = *a1;
result = *v3;
if ( ((*v3)[*a1] & 0x2000) != 0 || !v4 )
break;
if ( a2 )
func5(v4);
else
func4(v4);
++a1;
}
return result;
}

original_code:
void output_until_space(const char *str, int header)
{
 while(!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short int) _ISspace) && *str != '\0') {
  if(!header)
   output_char(*str);
  else
   output_header(*str);
  str++;
 }
}

canonical_original_code:
void output_until_space(char *str, int header)
{
 while(!((*__ctype_b_loc ())[(int) ((*str))] & (unsigned short) _ISspace) && *str != '\0') {
  if(!header)
   output_char(*str);
  else
   output_header(*str);
  str++;
 }
}

variable_types:
str
char *

variable_types: header int


decompiled_code:
int output_version()
{
return output_header(0);
}

canonical_decompiled_code:
int func7()
{
return func5(0);
}

original_code:
void output_version(void)
{
 output_header(0x00);
}

canonical_original_code:
void output_version()
{
 output_header(0x00);
}


decompiled_code:
int output_magic()
{
output_header(108);
output_header(83);
output_header(46);
return output_header(70);
}

original_code:
void output_magic(void)
{
 output_header(0x6c);
 output_header(0x53);
 output_header(0x2e);
 output_header(0x46);
}

canonical_original_code:
void output_magic()
{
 output_header(0x6c);
 output_header(0x53);
 output_header(0x2e);
 output_header(0x46);
}


decompiled_code:
int __fastcall output_nums(char a1, int a2, int a3)
{
char v5; // [rsp+Ch] [rbp-1Ch] BYREF
char v6; // [rsp+Dh] [rbp-1Bh]

output_char(a1);
num_to_be(a2, 2, &v5);
output_char(v5);
output_char(v6);
num_to_be(a3, 2, &v5);
output_char(v5);
return output_char(v6);
}

canonical_decompiled_code:
int __fastcall func9(char a1, int a2, int a3)
{
char v5; // [rsp+Ch] [rbp-1Ch] BYREF
char v6; // [rsp+Dh] [rbp-1Bh]

func4(a1);
func2(a2, 2, &v5);
func4(v5);
func4(v6);
func2(a3, 2, &v5);
func4(v5);
return func4(v6);
}

original_code:
void output_nums(char opcode, int a, int b)
{
 char buf[4];
 int i;
 output_char(opcode);
 num_to_be(a, 2, buf);
 for(i = 0; i < 2; i++)
  output_char(buf[i]);
 num_to_be(b, 2, buf);
 for(i = 0; i < 2; i++)
  output_char(buf[i]);
}

variable_types: opcode char

variable_types: a int

variable_types: b int

variable_types:
buf
char [4]


decompiled_code:
int __fastcall output_be(__int64 a1)
{
char *v1; // rbx
char v2; // di
int result; // eax
char v4[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char v5; // [rsp+10h] [rbp-18h] BYREF

v1 = v4;
int_to_be(a1, v4);
do
{
v2 = *v1++;
result = output_char(v2);
}
while ( v1 != &v5 );
return result;
}

canonical_decompiled_code:
int __fastcall func10(__int64 a1)
{
char *v1; // rbx
char v2; // di
int result; // eax
char v4[4]; // [rsp+Ch] [rbp-1Ch] BYREF
char v5; // [rsp+10h] [rbp-18h] BYREF

v1 = v4;
func3(a1, v4);
do
{
v2 = *v1++;
result = func4(v2);
}
while ( v1 != &v5 );
return result;
}

original_code:
void output_be(long int num)
{
 char buf[4];
 int i;
 int_to_be(num, buf);
 for(i = 0; i < 4; i++) {
  output_char(buf[i]);
 }
}

canonical_original_code:
void output_be(long num)
{
 char buf[4];
 int i;
 int_to_be(num, buf);
 for(i = 0; i < 4; i++) {
  output_char(buf[i]);
 }
}

variable_types: num long

variable_types: i int


decompiled_code:
int __fastcall output_num(char a1, __int64 a2)
{
output_char(a1);
return output_be(a2);
}

canonical_decompiled_code:
int __fastcall func11(char a1, __int64 a2)
{
func4(a1);
return func10(a2);
}

original_code:
void output_num(char opcode, long int num)
{
 output_char(opcode);
 output_be(num);
}

canonical_original_code:
void output_num(char opcode, long num)
{
 output_char(opcode);
 output_be(num);
}


decompiled_code:
int __fastcall output_to_label(char a1, int a2)
{
label_offsets[a2] = output_buffer_offset;
return output_num(a1, 0LL);
}

canonical_decompiled_code:
int __fastcall func12(char a1, int a2)
{
label_offsets[a2] = output_buffer_offset;
return func11(a1, 0LL);
}

original_code:
void output_to_label(char opcode, int label_index)
{
 label_offsets[label_index] = output_buffer_offset;
 output_num(opcode, 0);
}


output

decompiled_code:
int __fastcall output(char a1)
{
return output_char(a1);
}

canonical_decompiled_code:
int __fastcall func13(char a1)
{
return func4(a1);
}

original_code:
void output(char opcode)
{
 output_char(opcode);
}


decompiled_code:
int sync_output()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 v2; // rdi
int v3; // eax
int result; // eax
__int64 i; // rbx
int v6; // edi

v0 = 0LL;
v1 = output_buffer_offset;
do
{
while ( 1 )
{
v2 = labels[v0];
if ( (_DWORD)v2 )
break;
if ( ++v0 == 26 )
goto LABEL_5;
}
v3 = label_offsets[v0++];
output_buffer_offset = v3 + 1;
result = output_be(v2);
current_addr -= 4;
}
while ( v0 != 26 );
LABEL_5:
if ( (int)v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
{
v6 = output_buffer[i];
result = fputc(v6, stdout);
}
}
output_buffer_offset = 0;
return result;
}

canonical_decompiled_code:
int func14()
{
__int64 v0; // rbx
__int64 v1; // rbp
__int64 v2; // rdi
int v3; // eax
int result; // eax
__int64 i; // rbx
int v6; // edi

v0 = 0LL;
v1 = output_buffer_offset;
do
{
while ( 1 )
{
v2 = labels[v0];
if ( (_DWORD)v2 )
break;
if ( ++v0 == 26 )
goto LABEL_5;
}
v3 = label_offsets[v0++];
output_buffer_offset = v3 + 1;
result = func10(v2);
current_addr -= 4;
}
while ( v0 != 26 );
LABEL_5:
if ( (int)v1 > 0 )
{
for ( i = 0LL; i != v1; ++i )
{
v6 = output_buffer[i];
result = fputc(v6, stdout);
}
}
output_buffer_offset = 0;
return result;
}

original_code:
void sync_output(void)
{
 int i;
 int bufsize = output_buffer_offset;
 for(i = 0; i < 26; i++) {
  if(labels[i] != 0) {
   output_buffer_offset = label_offsets[i] + 1;
   output_be(labels[i]);
   current_addr -= 4;
  }
 }
 for(i = 0; i < bufsize; i++) {
  fprintf(stdout, "%c", output_buffer[i]);
 }
 output_buffer_offset = 0;
}

canonical_original_code:
void sync_output()
{
 int i;
 int bufsize = output_buffer_offset;
 for(i = 0; i < 26; i++) {
  if(labels[i] != 0) {
   output_buffer_offset = label_offsets[i] + 1;
   output_be(labels[i]);
   current_addr -= 4;
  }
 }
 for(i = 0; i < bufsize; i++) {
  fprintf(stdout, "%c", output_buffer[i]);
 }
 output_buffer_offset = 0;
}

variable_types: bufsize int


funend

decompiled_code:
__int64 __fastcall funend(char a1, int a2)
{
if ( a2 )
{
output(a1);
sync_output();
}
else
{
fwrite("?\n", 1uLL, 2uLL, stderr);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func15(char a1, int a2)
{
if ( a2 )
{
func13(a1);
func14();
}
else
{
fwrite("?\n", 1uLL, 2uLL, stderr);
}
return 0LL;
}

original_code:
int funend(char opcode, int fundef)
{
 if(fundef) {
  fundef = 0;
  output(opcode);
  sync_output();
 }
 else {
  fprintf(stderr, "?\n");
 }
 return fundef;
}

variable_types: fundef int


decompiled_code:
__int64 reset_labels()
{
__int64 result; // rax

result = 0LL;
memset(labels, 0, 0x68uLL);
memset(label_offsets, 0, 0x68uLL);
return result;
}

canonical_decompiled_code:
__int64 func16()
{
__int64 result; // rax

result = 0LL;
memset(labels, 0, 0x68uLL);
memset(label_offsets, 0, 0x68uLL);
return result;
}

original_code:
void reset_labels(void)
{
 memset(labels, 0x00, sizeof(labels));
 memset(label_offsets, 0x00, sizeof(label_offsets));
}

canonical_original_code:
void reset_labels()
{
 memset(labels, 0x00, sizeof(labels));
 memset(label_offsets, 0x00, sizeof(label_offsets));
}


decompiled_code:
__int64 __fastcall output_offset(char *s1, char *s, char a3)
{
int v4; // ebx
int v5; // er8
__int64 result; // rax
const char *v7; // rbx
__int64 v8; // rax
int v9; // [rsp+Ch] [rbp-4Ch] BYREF
char sa[72]; // [rsp+10h] [rbp-48h] BYREF

v4 = strlen(s);
snprintf(sa, 0x13uLL, "%s ", s);
sa[19] = 0;
v5 = strncmp(s1, sa, v4 + 1);
result = 0LL;
if ( !v5 )
{
v7 = &s1[v4 + 1];
v8 = getnum(v7, &v9);
if ( v9 )
{
output_num(a3, v8);
}
else if ( (unsigned __int8)(*v7 - 97) <= 0x19u )
{
output_to_label(a3, (char)(*v7 - 97));
}
else
{
fwrite("?\n", 1uLL, 2uLL, stderr);
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(char *s1, char *s, char a3)
{
int v4; // ebx
int v5; // er8
__int64 result; // rax
const char *v7; // rbx
__int64 v8; // rax
int v9; // [rsp+Ch] [rbp-4Ch] BYREF
char sa[72]; // [rsp+10h] [rbp-48h] BYREF

v4 = strlen(s);
snprintf(sa, 0x13uLL, "%s ", s);
sa[19] = 0;
v5 = strncmp(s1, sa, v4 + 1);
result = 0LL;
if ( !v5 )
{
v7 = &s1[v4 + 1];
v8 = func1(v7, &v9);
if ( v9 )
{
func11(a3, v8);
}
else if ( (unsigned __int8)(*v7 - 97) <= 0x19u )
{
func12(a3, (char)(*v7 - 97));
}
else
{
fwrite("?\n", 1uLL, 2uLL, stderr);
}
result = 1LL;
}
return result;
}

original_code:
int output_offset(const char *buf, const char *mnemonic,
  int opcode)
{
 char mn_buf[20];
 int mlen = strlen(mnemonic);
 snprintf(mn_buf, 19, "%s ", mnemonic);
 mn_buf[19] = '\0';
 if(!strncmp(buf, mn_buf, mlen + 1)) {
  int succ;
  long int parsed_num = getnum(buf + mlen + 1, &succ);
  if(!succ) {
   if(buf[mlen + 1] >= 'a' && buf[mlen + 1] <= 'z') {
    output_to_label(opcode, buf[mlen + 1] - 'a');
   }
   else {
    fprintf(stderr, "?\n");
   }
  }
  else {
   output_num(opcode, parsed_num);
  }
  return 1;
 }
 else
  return 0;
}

canonical_original_code:
int output_offset(char *buf, char *mnemonic, int opcode)
{
 char mn_buf[20];
 int mlen = strlen(mnemonic);
 snprintf(mn_buf, 19, "%s ", mnemonic);
 mn_buf[19] = '\0';
 if(!strncmp(buf, mn_buf, mlen + 1)) {
  int succ;
  long parsed_num = getnum(buf + mlen + 1, &succ);
  if(!succ) {
   if(buf[mlen + 1] >= 'a' && buf[mlen + 1] <= 'z') {
    output_to_label(opcode, buf[mlen + 1] - 'a');
   }
   else {
    fprintf(stderr, "?\n");
   }
  }
  else {
   output_num(opcode, parsed_num);
  }
  return 1;
 }
 else
  return 0;
}

variable_types:
buf
char *

variable_types:
mnemonic
char *

variable_types: opcode int

variable_types: mlen int

variable_types: succ int


decompiled_code:
__int64 __fastcall handle_ffidef(const char *a1)
{
int v1; // eax
int v2; // er13
char *v3; // rbp
__int64 v4; // rbx
int v5; // er12
__int64 v6; // rax
char *v7; // rdx
int v8; // er14
__int64 v9; // rbx
int v10; // er13
char *endptr; // [rsp+0h] [rbp-40h] BYREF
__int128 v13[3]; // [rsp+8h] [rbp-38h]

v13[0] = 0LL;
v1 = strtol(a1, &endptr, 0);
if ( endptr != a1 )
{
v2 = v1;
v3 = (char *)(a1 + 1);
v4 = 0LL;
if ( v1 )
{
do
{
v5 = v4;
v6 = strtol(v3, &endptr, 0);
v7 = endptr;
if ( endptr == v3 )
return 0LL;
*((_BYTE *)v13 + v4) = v6;
v3 = v7 + 1;
v8 = v4 + 1;
if ( v4 == 14 )
{
v8 = 15;
v5 = 14;
output_nums(84, v2, LOBYTE(v13[0]));
goto LABEL_8;
}
++v4;
}
while ( v6 );
output_nums(84, v2, LOBYTE(v13[0]));
if ( v8 == 1 )
{
LABEL_14:
output_until_space(v3, 0);
sync_output();
reset_labels();
return 1LL;
}
LABEL_8:
v9 = 1LL;
while ( 1 )
{
output_char(*((_BYTE *)v13 + v9));
if ( v5 <= (int)v9 )
{
v10 = v9;
output_char(0);
if ( v8 > (int)v9 + 2 )
{
LABEL_11:
output_char(*((_BYTE *)v13 + v9 + 2));
if ( v8 <= v10 + 3 )
goto LABEL_18;
goto LABEL_12;
}
}
else
{
v10 = v9;
output_char(*((_BYTE *)v13 + v9 + 1));
if ( v8 > (int)v9 + 2 )
goto LABEL_11;
}
output_char(0);
if ( v8 <= v10 + 3 )
{
LABEL_18:
output_char(0);
goto LABEL_13;
}
LABEL_12:
output_char(*((_BYTE *)v13 + v9 + 3));
LABEL_13:
v9 += 4LL;
if ( v8 <= (int)v9 )
goto LABEL_14;
}
}
}
return 0LL;
}

original_code:
int handle_ffidef(const char *buf)
{
 int parsed_funnum;
 unsigned char types[16];
 int i = 0, j = 0;
 long int val;
 const char *numptr = buf;
 memset(types, 0x00, sizeof(types));
 char *endptr;
 parsed_funnum = strtol(numptr, &endptr, 0);
 if(endptr == numptr || !parsed_funnum)
  return 0;
 numptr++;
 do {
  val = strtol(numptr, &endptr, 0);
  if(endptr == numptr)
   return 0;
  types[i] = val;
  numptr = endptr + 1;
  i++;
 } while(i < sizeof(types) - 1 && (!i || val != 0));
 output_nums(0x54, parsed_funnum, types[0]);
 for(j = 1; j < i; j += 4) {
  output_char(types[j]);
  if(j + 1 < i)
   output_char(types[j + 1]);
  else
   output_char(0);
  if(j + 2 < i)
   output_char(types[j + 2]);
  else
   output_char(0);
  if(j + 3 < i)
   output_char(types[j + 3]);
  else
   output_char(0);
 }
 output_until_space(numptr, 0);
 sync_output();
 reset_labels();
 return 1;
}

canonical_original_code:
int handle_ffidef(char *buf)
{
 int parsed_funnum;
 unsigned char types[16];
 int i = 0; int j = 0;
 long val;
 char *numptr = buf;
 memset(types, 0x00, sizeof(types));
 char *endptr;
 parsed_funnum = strtol(numptr, &endptr, 0);
 if(endptr == numptr || !parsed_funnum)
  return 0;
 numptr++;
 do {
  val = strtol(numptr, &endptr, 0);
  if(endptr == numptr)
   return 0;
  types[i] = val;
  numptr = endptr + 1;
  i++;
 } while(i < sizeof(types) - 1 && (!i || val != 0));
 output_nums(0x54, parsed_funnum, types[0]);
 for(j = 1; j < i; j += 4) {
  output_char(types[j]);
  if(j + 1 < i)
   output_char(types[j + 1]);
  else
   output_char(0);
  if(j + 2 < i)
   output_char(types[j + 2]);
  else
   output_char(0);
  if(j + 3 < i)
   output_char(types[j + 3]);
  else
   output_char(0);
 }
 output_until_space(numptr, 0);
 sync_output();
 reset_labels();
 return 1;
}

variable_types:
types
unsigned char [16]

variable_types: j int

variable_types: val long

variable_types:
numptr
char *

variable_types:
endptr
char *