lsfit

repo: yangmw/fedorov

original_code:
void lsfit(vec* c, mat* S, const vec* x, const vec* y, const vec* dy, const int nfunc, double f(int, double)){
  int n = x->size;
  int m = nfunc;
  mat* A = mat_new(n,m);
  mat* R = mat_new(m,m);
  vec* b = vec_new(n);
  vec* q = vec_new(m);
  double xi, dyi, Aik;
  vec_memcpy(b,y);
  vec_div(b,dy);
  for(int i=0; i<n; i++){
      for(int k=0; k<m; k++){
      xi = vec_get(x,i);
      dyi = vec_get(dy,i);
      Aik = f(k, xi)/dyi;
      mat_set(A, i, k, Aik);
      }
  }
  qrdec(A, R);
  qrback(c, A, R, b);
  qrinverse(R);
  mat_mul_BT(S,R,R);
  mat_free(A);
  mat_free(R);
  vec_free(b);
  vec_free(q);
}

canonical_original_code:
void lsfit(struct vec *c, struct mat *S, struct vec *x, struct vec *y, struct vec *dy, int nfunc, double f(int, double)){
  int n = x->size;
  int m = nfunc;
  struct mat *A = mat_new(n,m);
  struct mat *R = mat_new(m,m);
  struct vec *b = vec_new(n);
  struct vec *q = vec_new(m);
  double xi; double dyi; double Aik;
  vec_memcpy(b,y);
  vec_div(b,dy);
  for(int i = 0; i<n; i++){
      for(int k = 0; k<m; k++){
      xi = vec_get(x,i);
      dyi = vec_get(dy,i);
      Aik = f(k, xi)/dyi;
      mat_set(A, i, k, Aik);
      }
  }
  qrdec(A, R);
  qrback(c, A, R, b);
  qrinverse(R);
  mat_mul_BT(S,R,R);
  mat_free(A);
  mat_free(R);
  vec_free(b);
  vec_free(q);
}

variable_types: struct vec { unsigned long size; unsigned long stride; double *val; _Bool owner; } *

variable_types: struct mat { unsigned long row; unsigned long col; double *val; _Bool owner; } *

variable_types:
x
struct vec *

variable_types:
y
struct vec *

variable_types:
dy
struct vec *

variable_types: nfunc int

variable_types:
f
double (int, double)

variable_types: n int

variable_types: m int

variable_types: xi double

variable_types: dyi double

variable_types: Aik double

variable_types: k int


lstPush

repo: zmushko/librnotify

decompiled_code:
__int64 __fastcall lstPush(void **a1, const char *a2)
{
_QWORD *v3; // rax
__int64 v4; // rbx
size_t v5; // rax
__int64 v6; // r13
void **v7; // r14
char *v8; // rdi
char *v9; // rax
__int64 result; // rax
_QWORD *v11; // rax

if ( !a1 || !a2 )
{
*_errno_location() = 22;
return -1LL;
}
v3 = *a1;
if ( *a1 )
{
v4 = 0LL;
if ( *v3 )
{
do
++v4;
while ( v3[v4] );
}
}
else
{
v11 = malloc(8uLL);
*a1 = v11;
if ( !v11 )
return -1LL;
*v11 = 0LL;
v4 = 0LL;
}
v5 = strlen(a2);
v6 = 8 * v4;
v7 = (void **)((char *)*a1 + 8 * v4);
*v7 = malloc(v5 + 1);
v8 = (char *)*((_QWORD *)*a1 + v4);
if ( !v8 )
return -1LL;
strcpy(v8, a2);
v9 = (char *)realloc(*a1, v6 + 16);
if ( v9 )
{
*a1 = v9;
*(_QWORD *)&v9[v6 + 8] = 0LL;
result = v4;
}
else
{
free(*((void **)*a1 + v4));
*((_QWORD *)*a1 + v4) = 0LL;
result = -1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(void **a1, const char *a2)
{
_QWORD *v3; // rax
__int64 v4; // rbx
size_t v5; // rax
__int64 v6; // r13
void **v7; // r14
char *v8; // rdi
char *v9; // rax
__int64 result; // rax
_QWORD *v11; // rax

if ( !a1 || !a2 )
{
*_errno_location() = 22;
return -1LL;
}
v3 = *a1;
if ( *a1 )
{
v4 = 0LL;
if ( *v3 )
{
do
++v4;
while ( v3[v4] );
}
}
else
{
v11 = malloc(8uLL);
*a1 = v11;
if ( !v11 )
return -1LL;
*v11 = 0LL;
v4 = 0LL;
}
v5 = strlen(a2);
v6 = 8 * v4;
v7 = (void **)((char *)*a1 + 8 * v4);
*v7 = malloc(v5 + 1);
v8 = (char *)*((_QWORD *)*a1 + v4);
if ( !v8 )
return -1LL;
strcpy(v8, a2);
v9 = (char *)realloc(*a1, v6 + 16);
if ( v9 )
{
*a1 = v9;
*(_QWORD *)&v9[v6 + 8] = 0LL;
result = v4;
}
else
{
free(*((void **)*a1 + v4));
*((_QWORD *)*a1 + v4) = 0LL;
result = -1LL;
}
return result;
}

original_code:
ssize_t lstPush(char*** lst, const char* str)
{
 if (lst == ((void *)0)
  || str == ((void *)0))
 {
         (*__errno_location ()) = 22;
  return -1;
 }
 size_t len_ptr = sizeof(void*);
        size_t i = 0;
 if (*lst == ((void *)0))
 {
  *lst = (char**)malloc(len_ptr);
  if (*lst == ((void *)0))
  {
   return -1;
  }
  (*lst)[0] = ((void *)0);
 }
 else
 {
  while ((*lst)[i])
  {
   i++;
  }
 }
 (*lst)[i] = (char*)malloc(strlen(str) + 1);
 if ((*lst)[i] == ((void *)0))
 {
  return -1;
 }
 strcpy((*lst)[i], str);
 char** t = (char**)realloc(*lst, len_ptr*(i + 2));
 if (t == ((void *)0))
 {
  free((*lst)[i]);
  (*lst)[i] = ((void *)0);
  return -1;
 }
 *lst = t;
 (*lst)[i + 1] = ((void *)0);
 return i;
}

canonical_original_code:
long lstPush(char ***lst, char *str)
{
 if (lst == ((void *)0)
  || str == ((void *)0))
 {
         (*__errno_location ()) = 22;
  return -1;
 }
 unsigned long len_ptr = sizeof(void*);
        unsigned long i = 0;
 if (*lst == ((void *)0))
 {
  *lst = (char **)malloc(len_ptr);
  if (*lst == ((void *)0))
  {
   return -1;
  }
  (*lst)[0] = ((void *)0);
 }
 else
 {
  while ((*lst)[i])
  {
   i++;
  }
 }
 (*lst)[i] = (char *)malloc(strlen(str) + 1);
 if ((*lst)[i] == ((void *)0))
 {
  return -1;
 }
 strcpy((*lst)[i], str);
 char **t = (char**)realloc(*lst, len_ptr*(i + 2));
 if (t == ((void *)0))
 {
  free((*lst)[i]);
  (*lst)[i] = ((void *)0);
  return -1;
 }
 *lst = t;
 (*lst)[i + 1] = ((void *)0);
 return i;
}

variable_types:
lst
char ***

variable_types:
str
char *

variable_types:
i
unsigned long

variable_types:
t
char **

return_type: long


lstFree

decompiled_code:
void __fastcall lstFree(void *ptr)
{
void *v2; // rdi
char *v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (char *)ptr + 8;
do
{
free(v2);
v3 += 8;
v2 = (void *)*((_QWORD *)v3 - 1);
}
while ( v2 );
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
char *v3; // rbx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (char *)ptr + 8;
do
{
free(v2);
v3 += 8;
v2 = (void *)*((_QWORD *)v3 - 1);
}
while ( v2 );
}
free(ptr);
}
}

original_code:
void lstFree(char** lst)
{
 if (lst == ((void *)0))
 {
  return;
 }
        size_t i = 0;
        while (lst[i])
 {
            free(lst[i]);
     i++;
 }
 free(lst);
}

canonical_original_code:
void lstFree(char **lst)
{
 if (lst == ((void *)0))
 {
  return;
 }
        unsigned long i = 0;
        while (lst[i])
 {
            free(lst[i]);
     i++;
 }
 free(lst);
}

variable_types:
lst
char **

return_type: void


lstString

decompiled_code:
char *lstString(char *format, ...)
{
int v1; // eax
char *v2; // rax
char *v3; // rbp
__m128i v5; // [rsp+0h] [rbp-F8h] BYREF
void *v6; // [rsp+10h] [rbp-E8h]
gcc_va_list arg; // [rsp+18h] [rbp-E0h] BYREF

if ( format )
{
va_start(arg, format);
v5 = _mm_loadu_si128((const __m128i *)arg);
v6 = arg[0].reg_save_area;
v1 = vsnprintf(0LL, 0LL, format, &v5);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
vsprintf(v2, format, arg);
else
*_errno_location() = 12;
}
else
{
*_errno_location() = 22;
v3 = 0LL;
}
return v3;
}

canonical_decompiled_code:
char *func2(char *format, ...)
{
int v1; // eax
char *v2; // rax
char *v3; // rbp
__m128i v5; // [rsp+0h] [rbp-F8h] BYREF
void *v6; // [rsp+10h] [rbp-E8h]
gcc_va_list arg; // [rsp+18h] [rbp-E0h] BYREF

if ( format )
{
va_start(arg, format);
v5 = _mm_loadu_si128((const __m128i *)arg);
v6 = arg[0].reg_save_area;
v1 = vsnprintf(0LL, 0LL, format, &v5);
v2 = (char *)malloc(v1 + 1);
v3 = v2;
if ( v2 )
vsprintf(v2, format, arg);
else
*_errno_location() = 12;
}
else
{
*_errno_location() = 22;
v3 = 0LL;
}
return v3;
}

original_code:
char* lstString(const char* format, ...)
{
 if(format == ((void *)0))
 {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 va_list ap, apt;
 __builtin_va_start(ap,format);
 __builtin_va_copy(apt,ap);
 char* rval = (char*)malloc(vsnprintf(((void *)0), 0, format, apt) + 1);
 if(rval == ((void *)0))
 {
  __builtin_va_end(ap);
  __builtin_va_end(apt);
  (*__errno_location ()) = 12;
  return ((void *)0);
 }
 vsprintf(rval, format, ap);
 __builtin_va_end(ap);
 __builtin_va_end(apt);
 return rval;
}

canonical_original_code:
char *lstString(char *format, ...)
{
 if(format == ((void *)0))
 {
  (*__errno_location ()) = 22;
  return ((void *)0);
 }
 __builtin_va_list ap; __builtin_va_list apt;
 __builtin_va_start(ap,format);
 __builtin_va_copy(apt,ap);
 char *rval = (char*)malloc(vsnprintf(((void *)0), 0, format, apt) + 1);
 if(rval == ((void *)0))
 {
  __builtin_va_end(ap);
  __builtin_va_end(apt);
  (*__errno_location ()) = 12;
  return ((void *)0);
 }
 vsprintf(rval, format, ap);
 __builtin_va_end(ap);
 __builtin_va_end(apt);
 return rval;
}

variable_types:
format
char *

variable_types:
rval
char *

return_type: char *