lstPush

repo: zmushko/librnotify

decompiled_code:
__int64 __fastcall lstPush(_QWORD **a1, const char *a2)
{
_QWORD *v2; // rbp
__int64 v3; // rbx
__int64 v4; // r12
size_t v5; // rax
char *v6; // rax
_QWORD *v7; // rax
_QWORD *v9; // rax

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

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD **a1, const char *a2)
{
_QWORD *v2; // rbp
__int64 v3; // rbx
__int64 v4; // r12
size_t v5; // rax
char *v6; // rax
_QWORD *v7; // rax
_QWORD *v9; // rax

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

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
void **v3; // rbx

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

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

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
{
v3 = (void **)((char *)ptr + 8);
do
{
free(v2);
v2 = *v3++;
}
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:
__int64 lstString(char *format, ...)
{
int v1; // eax
char *v2; // rax
__int64 v3; // r12
__int64 result; // rax
gcc_va_list va; // [rsp+0h] [rbp-F8h] BYREF
__m128i arg; // [rsp+18h] [rbp-E0h] BYREF
void *v7; // [rsp+28h] [rbp-D0h]

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

canonical_decompiled_code:
__int64 func2(char *format, ...)
{
int v1; // eax
char *v2; // rax
__int64 v3; // r12
__int64 result; // rax
gcc_va_list va; // [rsp+0h] [rbp-F8h] BYREF
__m128i arg; // [rsp+18h] [rbp-E0h] BYREF
void *v7; // [rsp+28h] [rbp-D0h]

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

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 *