original_code:
char *
  normalize_signed(const char *s)
{
  const char *last_nonzero_digit = ((void *)0), *p;
  char *sn;
  int i = 1;
  for (p=s+1; *p; p++)
    if (*p != ((0) + '0'))
      last_nonzero_digit = p;
  if (last_nonzero_digit == ((void *)0))
    return strdup("0");
  sn = malloc(last_nonzero_digit - s + 1);
  if (sn == ((void *)0)) return ((void *)0);
  for (p = last_nonzero_digit; p>s; p--)
    sn[i++] = *p;
  sn[0] = s[0];
  sn[last_nonzero_digit - s + 1] = '\0';
  return sn;
}

canonical_original_code:
char *normalize_signed(char *s)
{
  char *last_nonzero_digit = ((void *)0); char *p;
  char *sn;
  int i = 1;
  for (p=s+1; *p; p++)
    if (*p != ((0) + '0'))
      last_nonzero_digit = p;
  if (last_nonzero_digit == ((void *)0))
    return strdup("0");
  sn = malloc(last_nonzero_digit - s + 1);
  if (sn == ((void *)0)) return ((void *)0);
  for (p = last_nonzero_digit; p>s; p--)
    sn[i++] = *p;
  sn[0] = s[0];
  sn[last_nonzero_digit - s + 1] = '\0';
  return sn;
}

variable_types:
p
char *

variable_types: i int


repo: mjdominus/intro-c-programming

decompiled_code:
__int64 __fastcall subtract_signed_string(_BYTE *a1, const char *a2)
{
char *v2; // rax

v2 = negate_signed_string(a2);
return add_signed_string(a1, v2);
}

canonical_decompiled_code:
__int64 __fastcall func11(_BYTE *a1, const char *a2)
{
char *v2; // rax

v2 = func8(a2);
return func7(a1, v2);
}

original_code:
char *
  subtract_signed_string(const char *s1, const char *s2)
{
  return add_signed_string(s1, negate_signed_string(s2));
}

canonical_original_code:
char *subtract_signed_string(char *s1, char *s2)
{
  return add_signed_string(s1, negate_signed_string(s2));
}

return_type: char *


decompiled_code:
__int64 __fastcall compare_unsigned_string(const char *a1, const char *a2)
{
int v2; // er12
int v3; // edx
__int64 result; // rax
const char *v5; // rax
const char *v6; // rdx
char v7; // cl
char v8; // dl

v2 = strlen(a1);
v3 = strlen(a2);
result = (unsigned int)(v2 - v3);
if ( v2 == v3 )
{
v5 = &a1[v2 - 1];
v6 = &a2[v3 - 1];
if ( a1 == v5 || a2 == v6 )
{
LABEL_7:
v7 = *v5;
v8 = *v6;
result = 0LL;
if ( v7 != v8 )
result = (unsigned int)(v7 - v8);
}
else
{
while ( *v5 == *v6 )
{
--v5;
--v6;
if ( a1 == v5 || a2 == v6 )
goto LABEL_7;
}
result = (unsigned int)(*v5 - *v6);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(const char *a1, const char *a2)
{
int v2; // er12
int v3; // edx
__int64 result; // rax
const char *v5; // rax
const char *v6; // rdx
char v7; // cl
char v8; // dl

v2 = strlen(a1);
v3 = strlen(a2);
result = (unsigned int)(v2 - v3);
if ( v2 == v3 )
{
v5 = &a1[v2 - 1];
v6 = &a2[v3 - 1];
if ( a1 == v5 || a2 == v6 )
{
LABEL_7:
v7 = *v5;
v8 = *v6;
result = 0LL;
if ( v7 != v8 )
result = (unsigned int)(v7 - v8);
}
else
{
while ( *v5 == *v6 )
{
--v5;
--v6;
if ( a1 == v5 || a2 == v6 )
goto LABEL_7;
}
result = (unsigned int)(*v5 - *v6);
}
}
return result;
}

return_type: int


decompiled_code:
__int64 __fastcall compare_signed_string(__int64 a1, __int64 a2)
{
int v3; // edx
int v4; // eax

if ( *(_BYTE *)a1 == 45 )
{
if ( *(_BYTE *)a2 == 45 )
return compare_unsigned_string((const char *)(a1 + 1), (const char *)(a2 + 1));
v3 = 1;
v4 = -1;
}
else
{
if ( *(_BYTE *)a2 != 45 )
return compare_unsigned_string((const char *)(a1 + 1), (const char *)(a2 + 1));
v3 = -1;
v4 = 1;
}
return (unsigned int)(v4 - v3);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, __int64 a2)
{
int v3; // edx
int v4; // eax

if ( *(_BYTE *)a1 == 45 )
{
if ( *(_BYTE *)a2 == 45 )
return func12((const char *)(a1 + 1), (const char *)(a2 + 1));
v3 = 1;
v4 = -1;
}
else
{
if ( *(_BYTE *)a2 != 45 )
return func12((const char *)(a1 + 1), (const char *)(a2 + 1));
v3 = -1;
v4 = 1;
}
return (unsigned int)(v4 - v3);
}

original_code:
int
  compare_signed_string(const char *s1, const char *s2)
{
  int m1 = (((*(s1))=='-') ? -1 : 1), m2 = (((*(s2))=='-') ? -1 : 1);
  if (m1 == m2)
    return compare_unsigned_string(s1+1, s2+1);
  else
    return m1-m2;
}

canonical_original_code:
int compare_signed_string(char *s1, char *s2)
{
  int m1 = (((*(s1))=='-') ? -1 : 1); int m2 = (((*(s2))=='-') ? -1 : 1);
  if (m1 == m2)
    return compare_unsigned_string(s1+1, s2+1);
  else
    return m1-m2;
}


decompiled_code:
void __fastcall print_signed(_BYTE *a1)
{
char *v1; // rbx

v1 = normalize_signed(a1);
puts(v1);
free(v1);
}

canonical_decompiled_code:
void __fastcall func14(_BYTE *a1)
{
char *v1; // rbx

v1 = func10(a1);
puts(v1);
free(v1);
}

original_code:
void
  print_signed(const char *s)
{
  char *sn;
  sn = normalize_signed(s);
  puts(sn);
  free(sn);
}

canonical_original_code:
void print_signed(char *s)
{
  char *sn;
  sn = normalize_signed(s);
  puts(sn);
  free(sn);
}

variable_types:
s
char *

variable_types:
sn
char *

return_type: void


strnnew

repo: mjflick/flib

decompiled_code:
char *__fastcall strnnew(char *src, size_t n)
{
void *v2; // rbx

v2 = (void *)xmalloc(n + 1);
memset(v2, 0, n + 1);
return strncpy((char *)v2, src, n);
}

canonical_decompiled_code:
char *__fastcall func1(char *src, size_t n)
{
void *v2; // rbx

v2 = (void *)xmalloc(n + 1);
memset(v2, 0, n + 1);
return strncpy((char *)v2, src, n);
}

original_code:
char *
strnnew(const char *string, size_t len)
{
  char *s = (char *) xmalloc( len + 1 );
  memset(s, 0x0, len + 1);
  strncpy(s, string, len);
  return s;
}

canonical_original_code:
char *strnnew(char *string, unsigned long len)
{
  char *s = (char *) xmalloc( len + 1 );
  memset(s, 0x0, len + 1);
  strncpy(s, string, len);
  return s;
}

variable_types:
string
char *

variable_types:
len
unsigned long


strnew

decompiled_code:
char *__fastcall strnew(char *src)
{
size_t v1; // rax

v1 = strlen(src);
return strnnew(src, v1);
}

canonical_decompiled_code:
char *__fastcall func2(char *src)
{
size_t v1; // rax

v1 = strlen(src);
return func1(src, v1);
}

original_code:
char *
strnew(const char *string)
{
  return strnnew(string, strlen(string));
}

canonical_original_code:
char *strnew(char *string)
{
  return strnnew(string, strlen(string));
}


strnset

decompiled_code:
char *__fastcall strnset(__int64 a1, const char *a2, size_t a3)
{
size_t v4; // r13
void *v5; // rbx

v4 = a3 + 1;
v5 = (void *)xrealloc(a1, a3 + 1);
memset(v5, 0, v4);
return strncpy((char *)v5, a2, a3);
}

canonical_decompiled_code:
char *__fastcall func3(__int64 a1, const char *a2, size_t a3)
{
size_t v4; // r13
void *v5; // rbx

v4 = a3 + 1;
v5 = (void *)xrealloc(a1, a3 + 1);
memset(v5, 0, v4);
return strncpy((char *)v5, a2, a3);
}

original_code:
char *
strnset(char *s, const char *string, size_t len)
{
  s = (char *) xrealloc(s, len + 1);
  memset(s, 0x0, len + 1);
  strncpy(s, string, len);
  return s;
}

canonical_original_code:
char *strnset(char *s, char *string, unsigned long len)
{
  s = (char *) xrealloc(s, len + 1);
  memset(s, 0x0, len + 1);
  strncpy(s, string, len);
  return s;
}


strset

decompiled_code:
char *__fastcall strset(__int64 a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return strnset(a1, a2, v2);
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return func3(a1, a2, v2);
}

original_code:
char *
strset(char *s, const char *string)
{
  return strnset(s, string, strlen(string));
}

canonical_original_code:
char *strset(char *s, char *string)
{
  return strnset(s, string, strlen(string));
}


streq

decompiled_code:
_BOOL8 __fastcall streq(char *s1, char *s2)
{
size_t v2; // r12
size_t v3; // rdx
_BOOL8 result; // rax

v2 = (int)strlen(s1);
v3 = strlen(s2);
result = 0LL;
if ( v2 == v3 )
result = strncmp(s1, s2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(char *s1, char *s2)
{
size_t v2; // r12
size_t v3; // rdx
_BOOL8 result; // rax

v2 = (int)strlen(s1);
v3 = strlen(s2);
result = 0LL;
if ( v2 == v3 )
result = strncmp(s1, s2, v2) == 0;
return result;
}

original_code:
int
streq (char *s, char *comp)
{
  int s_len = strlen(s);
  if (s_len == strlen(comp))
    {
      return(strncmp(s, comp, s_len) ? 0 : 1);
    }
  else
    {
      return 0;
    }
}

canonical_original_code:
int streq(char *s, char *comp)
{
  int s_len = strlen(s);
  if (s_len == strlen(comp))
    {
      return(strncmp(s, comp, s_len) ? 0 : 1);
    }
  else
    {
      return 0;
    }
}

variable_types:
comp
char *


strreplace

decompiled_code:
const char *__fastcall strreplace(const char *a1, const char *a2, const char *a3, int a4)
{
size_t v6; // rax

v6 = strlen(a3);
return strnreplace(a1, a2, a3, v6, a4);
}

canonical_decompiled_code:
const char *__fastcall func8(const char *a1, const char *a2, const char *a3, int a4)
{
size_t v6; // rax

v6 = strlen(a3);
return func7(a1, a2, a3, v6, a4);
}

original_code:
char *
strreplace (char *s, const char *regex, const char *rep_str, int flags)
{
  return(strnreplace(s, regex, rep_str, strlen(rep_str), flags));
}

canonical_original_code:
char *strreplace(char *s, char *regex, char *rep_str, int flags)
{
  return(strnreplace(s, regex, rep_str, strlen(rep_str), flags));
}

variable_types:
regex
char *

variable_types: flags int


strnappend

decompiled_code:
char *__fastcall strnappend(void *ptr, void *src, size_t n)
{
size_t v4; // rbx
char *v5; // rbp

v4 = strlen((const char *)ptr);
v5 = (char *)xmalloc(n + v4 + 1);
memset(v5, 0, n + v4 + 1);
memcpy(v5, ptr, v4);
memcpy(&v5[v4], src, n);
free(ptr);
return v5;
}

canonical_decompiled_code:
char *__fastcall func9(void *ptr, void *src, size_t n)
{
size_t v4; // rbx
char *v5; // rbp

v4 = strlen((const char *)ptr);
v5 = (char *)xmalloc(n + v4 + 1);
memset(v5, 0, n + v4 + 1);
memcpy(v5, ptr, v4);
memcpy(&v5[v4], src, n);
free(ptr);
return v5;
}

original_code:
char *
strnappend(char *s, const char *string, size_t len)
{
  size_t s_len = strlen(s);
  size_t tot_len = len + s_len;
  char *new_str = (char *) xmalloc (tot_len + 1);
  memset(new_str, 0x0, tot_len + 1);
  memcpy(new_str, s, s_len);
  memcpy(new_str + s_len, string, len);
  free(s);
  s = new_str;
  return s;
}

canonical_original_code:
char *strnappend(char *s, char *string, unsigned long len)
{
  unsigned long s_len = strlen(s);
  unsigned long tot_len = len + s_len;
  char *new_str = (char *) xmalloc (tot_len + 1);
  memset(new_str, 0x0, tot_len + 1);
  memcpy(new_str, s, s_len);
  memcpy(new_str + s_len, string, len);
  free(s);
  s = new_str;
  return s;
}


strappend

decompiled_code:
char *__fastcall strappend(void *ptr, void *src)
{
size_t v2; // rax

v2 = strlen((const char *)src);
return strnappend(ptr, src, v2);
}

canonical_decompiled_code:
char *__fastcall func10(void *ptr, void *src)
{
size_t v2; // rax

v2 = strlen((const char *)src);
return func9(ptr, src, v2);
}

original_code:
char *
strappend(char *s, const char *string)
{
  return strnappend(s, string, strlen(string));
}

canonical_original_code:
char *strappend(char *s, char *string)
{
  return strnappend(s, string, strlen(string));
}


getname

decompiled_code:
__int64 __fastcall getname(__int64 a1)
{
return a1;
}

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

original_code:
char *getname(Person *P)
{
  return P->name;
}

canonical_original_code:
char *getname(struct PersonObj *P)
{
  return P->name;
}

variable_types: struct PersonObj { char name[40]; char *(*setname)(struct PersonObj *, char *); char *(*getname)(struct PersonObj *); void (*print)(struct PersonObj *); } *


setname

decompiled_code:
char *__fastcall setname(char *a1, const char *a2)
{
if ( a2 )
strcpy(a1, a2);
return a1;
}

canonical_decompiled_code:
char *__fastcall func9(char *a1, const char *a2)
{
if ( a2 )
strcpy(a1, a2);
return a1;
}

original_code:
char *setname(Person *P, const char *name)
{
  if(name)
    strcpy(P->name, name);
  return P->name;
}

canonical_original_code:
char *setname(struct PersonObj *P, char *name)
{
  if(name)
    strcpy(P->name, name);
  return P->name;
}

variable_types:
name
char *

user_defined_types: struct PersonObj { char name[40]; char *(*setname)(struct PersonObj *, char *); char *(*getname)(struct PersonObj *); void (*print)(struct PersonObj *); }


fprint

decompiled_code:
int __fastcall fprint(const char *a1)
{
return printf("Wisdom motivation: '%s'\n", a1);
}

canonical_decompiled_code:
int __fastcall func10(const char *a1)
{
return printf("Wisdom motivation: '%s'\n", a1);
}

original_code:
void fprint (Person *P)
{
  printf("Wisdom motivation: '%s'\n", (char *) P->name);
}

canonical_original_code:
void fprint(struct PersonObj *P)
{
  printf("Wisdom motivation: '%s'\n", (char *) P->name);
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
fatal("virtual memory exhausted");
return result;
}

canonical_decompiled_code:
void *__fastcall func12(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func11("virtual memory exhausted");
return result;
}

original_code:
void *
xmalloc (size_t size)
{
  register void *value = malloc (size);
  if (value == 0)
    _fatal ("virtual memory exhausted");
  return value;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
  register void *value = malloc (size);
  if (value == 0)
    _fatal ("virtual memory exhausted");
  return value;
}

variable_types:
size
unsigned long

variable_types:
value
void *

return_type: void *


flibnewObj

decompiled_code:
void *__fastcall flibnewObj(size_t a1, void (__fastcall *a2)(void *))
{
void *v2; // rbx

v2 = xmalloc(a1);
a2(v2);
return v2;
}

canonical_decompiled_code:
void *__fastcall func13(size_t a1, void (__fastcall *a2)(void *))
{
void *v2; // rbx

v2 = func12(a1);
a2(v2);
return v2;
}

original_code:
void *
flibnewObj (size_t s, void (*init_function)(void *))
{
  register void *obj = (void *) _xmalloc (s);
  init_function(obj);
  return obj;
}

canonical_original_code:
void *flibnewObj(unsigned long s, void (*init_function)(void *))
{
  register void *obj = (void *) _xmalloc (s);
  init_function(obj);
  return obj;
}

variable_types:
s
unsigned long

variable_types:
obj
void *


flibcloneObj

decompiled_code:
void *__fastcall flibcloneObj(size_t n, void *src)
{
void *v2; // rax

v2 = xmalloc(n);
return memcpy(v2, src, n);
}

canonical_decompiled_code:
void *__fastcall func14(size_t n, void *src)
{
void *v2; // rax

v2 = func12(n);
return memcpy(v2, src, n);
}

original_code:
void *
flibcloneObj (size_t s, void *p)
{
  register void *obj = (void *) _xmalloc (s);
  memcpy(obj, p, s);
  return obj;
}

canonical_original_code:
void *flibcloneObj(unsigned long s, void *p)
{
  register void *obj = (void *) _xmalloc (s);
  memcpy(obj, p, s);
  return obj;
}

variable_types:
p
void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rbp
void (__fastcall *v7)(__int64, __int64); // r13
__int64 v8; // rax
const char *v9; // rax

v3 = flibnewObj(64LL, initPerson, envp);
(*(void (__fastcall **)(__int64, const char *))(v3 + 40))(v3, "Silly Simon");
v4 = flibcloneObj(0x40uLL, (void *)v3);
v6 = flibnewObj(64LL, initPerson, v5);
(*(void (__fastcall **)(__int64, const char *))(v6 + 40))(v6, "Ronaldo");
(*(void (__fastcall **)(__int64))(v6 + 56))(v6);
(*(void (__fastcall **)(__int64))(v3 + 56))(v3);
v7 = *(void (__fastcall **)(__int64, __int64))(v3 + 40);
v8 = (*(__int64 (__fastcall **)(__int64))(v6 + 48))(v6);
v7(v3, v8);
(*(void (__fastcall **)(__int64))(v3 + 56))(v3);
(*(void (__fastcall **)(__int64))(v4 + 56))(v4);
v9 = (const char *)(*(__int64 (__fastcall **)(__int64))(v3 + 48))(v3);
printf("At the end of the day, the winner is %s\n", v9);
printf("Runner up is %s\n", (const char *)v4);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbx
__int64 v4; // r12
__int64 v5; // rdx
__int64 v6; // rbp
void (__fastcall *v7)(__int64, __int64); // r13
__int64 v8; // rax
const char *v9; // rax

v3 = func13(64LL, initPerson, envp);
(*(void (__fastcall **)(__int64, const char *))(v3 + 40))(v3, "Silly Simon");
v4 = func14(0x40uLL, (void *)v3);
v6 = func13(64LL, initPerson, v5);
(*(void (__fastcall **)(__int64, const char *))(v6 + 40))(v6, "Ronaldo");
(*(void (__fastcall **)(__int64))(v6 + 56))(v6);
(*(void (__fastcall **)(__int64))(v3 + 56))(v3);
v7 = *(void (__fastcall **)(__int64, __int64))(v3 + 40);
v8 = (*(__int64 (__fastcall **)(__int64))(v6 + 48))(v6);
v7(v3, v8);
(*(void (__fastcall **)(__int64))(v3 + 56))(v3);
(*(void (__fastcall **)(__int64))(v4 + 56))(v4);
v9 = (const char *)(*(__int64 (__fastcall **)(__int64))(v3 + 48))(v3);
printf("At the end of the day, the winner is %s\n", v9);
printf("Runner up is %s\n", (const char *)v4);
return 0;
}

original_code:
int main(int argc, char **argv)
{
  Person *Dan = (Person *) flibnewObj(sizeof(Person), initPerson );
  Dan->setname(Dan, "Silly Simon" );
  Person *DanCopy = (Person *) flibcloneObj(sizeof(Person), Dan);
  Person *Ron = (Person *) flibnewObj(sizeof(Person), initPerson );
  Ron->setname(Ron, "Ronaldo" );
  Ron->print(Ron );
  Dan->print(Dan );
  Dan->setname(Dan,Ron->getname(Ron ) );
  Dan->print(Dan );
  DanCopy->print(DanCopy );
  printf("At the end of the day, the winner is %s\n", Dan->getname(Dan ));
  printf("Runner up is %s\n", DanCopy->name);
  return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
  struct PersonObj *Dan = (Person *) flibnewObj(sizeof(Person), initPerson );
  Dan->setname(Dan, "Silly Simon" );
  struct PersonObj *DanCopy = (Person *) flibcloneObj(sizeof(Person), Dan);
  struct PersonObj *Ron = (Person *) flibnewObj(sizeof(Person), initPerson );
  Ron->setname(Ron, "Ronaldo" );
  Ron->print(Ron );
  Dan->print(Dan );
  Dan->setname(Dan,Ron->getname(Ron ) );
  Dan->print(Dan );
  DanCopy->print(DanCopy );
  printf("At the end of the day, the winner is %s\n", Dan->getname(Dan ));
  printf("Runner up is %s\n", DanCopy->name);
  return 0;
}

variable_types: argc int

variable_types:
argv
char **


decompiled_code:
void __fastcall fstack_init(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
}

original_code:
void
fstack_init (fstack *s)
{
  s->first = ((void *)0);
  s->last = ((void *)0);
  s->size = 0;
}

canonical_original_code:
void fstack_init(struct fstack *s)
{
  s->first = ((void *)0);
  s->last = ((void *)0);
  s->size = 0;
}

variable_types: struct fstack { struct fs_item { void *data; struct fs_item *next; struct fs_item *previous; } *first; struct fs_item *last; int size; } *

user_defined_types: struct fstack { struct fs_item *first; struct fs_item *last; int size; }


original_code:
int
fstack_unshift (fstack *s, void *item)
{
  fstack_item *this_item = (fstack_item *) xmalloc (sizeof(fstack_item));
  this_item->data = item;
  s->size++;
  if (s->first == ((void *)0))
    {
      s->first = this_item;
      s->last = s->first;
      s->first->next = s->first;
      s->first->previous = s->first;
    }
  else
    {
      fstack_item *old_first = s->first;
      s->first = this_item;
      s->first->previous = s->last;
      s->first->next = old_first;
      s->first->next->previous = s->first;
      s->last->next = s->first;
    }
  return 1;
}

canonical_original_code:
int fstack_unshift(struct fstack *s, void *item)
{
  struct fs_item *this_item = (fstack_item *) xmalloc (sizeof(fstack_item));
  this_item->data = item;
  s->size++;
  if (s->first == ((void *)0))
    {
      s->first = this_item;
      s->last = s->first;
      s->first->next = s->first;
      s->first->previous = s->first;
    }
  else
    {
      struct fs_item *old_first = s->first;
      s->first = this_item;
      s->first->previous = s->last;
      s->first->next = old_first;
      s->first->next->previous = s->first;
      s->last->next = s->first;
    }
  return 1;
}

variable_types:
item
void *

variable_types: struct fs_item { void *data; struct fs_item *next; struct fs_item *previous; } *


decompiled_code:
__int64 __fastcall fstack_length(_QWORD *a1)
{
__int64 v1; // rax
int v2; // edx

if ( !a1[1] )
return 0LL;
v1 = *(_QWORD *)(*a1 + 8LL);
if ( *a1 == v1 )
{
v2 = 0;
}
else
{
v2 = 0;
do
{
++v2;
v1 = *(_QWORD *)(v1 + 8);
}
while ( *a1 != v1 );
}
return (unsigned int)(v2 + 1);
}

original_code:
int
fstack_length (fstack *s)
{
  int count;
  if (s->last == ((void *)0))
    return 0;
  fstack_item *si = s->first->next;
  for (count = 0; si != s->first; si = si->next) count++;
  return count + 1;
}

canonical_original_code:
int fstack_length(struct fstack *s)
{
  int count;
  if (s->last == ((void *)0))
    return 0;
  struct fs_item *si = s->first->next;
  for (count = 0; si != s->first; si = si->next) count++;
  return count + 1;
}

variable_types: count int

user_defined_types: struct fs_item { void *data; struct fs_item *next; struct fs_item *previous; }


decompiled_code:
__int64 __fastcall fstack_peek_item(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx
int i; // edx

result = a1[1];
if ( result )
{
v3 = *((_DWORD *)a1 + 4);
if ( v3 < a2 )
{
result = 0LL;
}
else if ( v3 / 2 >= a2 )
{
result = *a1;
if ( a2 != 1 )
{
for ( i = 1; i != a2; ++i )
result = *(_QWORD *)(result + 8);
}
}
else
{
for ( ; a2 != v3; --v3 )
result = *(_QWORD *)(result + 16);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 *a1, int a2)
{
__int64 result; // rax
int v3; // edx
int i; // edx

result = a1[1];
if ( result )
{
v3 = *((_DWORD *)a1 + 4);
if ( v3 < a2 )
{
result = 0LL;
}
else if ( v3 / 2 >= a2 )
{
result = *a1;
if ( a2 != 1 )
{
for ( i = 1; i != a2; ++i )
result = *(_QWORD *)(result + 8);
}
}
else
{
for ( ; a2 != v3; --v3 )
result = *(_QWORD *)(result + 16);
}
}
return result;
}

original_code:
fstack_item *
fstack_peek_item (fstack *s, int pos)
{
  int count;
  fstack_item *si;
  if (s->last == ((void *)0))
    return 0;
  if (pos > s->size)
    return 0;
  if (pos <= (s->size / 2))
    {
      si = s->first;
      for (count = 1; count != pos; count++)
        si = si->next;
    }
  else
    {
      si = s->last;
      for (count = s->size; count != pos; count--)
        si = si->previous;
    }
  return si;
}

canonical_original_code:
struct fs_item *fstack_peek_item(struct fstack *s, int pos)
{
  int count;
  struct fs_item *si;
  if (s->last == ((void *)0))
    return 0;
  if (pos > s->size)
    return 0;
  if (pos <= (s->size / 2))
    {
      si = s->first;
      for (count = 1; count != pos; count++)
        si = si->next;
    }
  else
    {
      si = s->last;
      for (count = s->size; count != pos; count--)
        si = si->previous;
    }
  return si;
}

variable_types: struct fstack { struct fs_item *first; struct fs_item *last; int size; } *

variable_types: pos int

return_type: struct fs_item { void *data; struct fs_item *next; struct fs_item *previous; } *


original_code:
void *
fstack_pop (fstack *s)
{
  if (s->last == ((void *)0))
    return 0;
  fstack_item *this_item = s->last;
  s->size--;
  if (s->last == s->first)
    {
      s->last = ((void *)0);
      s->first = ((void *)0);
    }
  else
    {
      s->last->previous->next = s->first;
      s->last = s->last->previous;
      s->first->previous = s->last;
    }
  void *data = this_item->data;
  free(this_item);
  return data;
}

canonical_original_code:
void *fstack_pop(struct fstack *s)
{
  if (s->last == ((void *)0))
    return 0;
  struct fs_item *this_item = s->last;
  s->size--;
  if (s->last == s->first)
    {
      s->last = ((void *)0);
      s->first = ((void *)0);
    }
  else
    {
      s->last->previous->next = s->first;
      s->last = s->last->previous;
      s->first->previous = s->last;
    }
  void *data = this_item->data;
  free(this_item);
  return data;
}

variable_types:
data
void *


original_code:
void *
fstack_shift (fstack *s)
{
  if (s->first == ((void *)0))
    return 0;
  fstack_item *this_item = s->first;
  s->size--;
  if (s->last == s->first)
    {
      s->last = ((void *)0);
      s->first = ((void *)0);
    }
  else
    {
      s->first = s->first->next;
      s->first->previous = s->last;
      s->last->next = s->first;
    }
  void *data = this_item->data;
  free(this_item);
  return data;
}

canonical_original_code:
void *fstack_shift(struct fstack *s)
{
  if (s->first == ((void *)0))
    return 0;
  struct fs_item *this_item = s->first;
  s->size--;
  if (s->last == s->first)
    {
      s->last = ((void *)0);
      s->first = ((void *)0);
    }
  else
    {
      s->first = s->first->next;
      s->first->previous = s->last;
      s->last->next = s->first;
    }
  void *data = this_item->data;
  free(this_item);
  return data;
}


original_code:
int
fstack_insert (fstack *s, int pos, void *item)
{
  fstack_item *si;
  if (pos == 1)
    return fstack_unshift(s, item);
  if (pos == (s->size + 1))
    return fstack_push(s, item);
  if ((si = fstack_peek_item(s, pos)) == 0)
    return 0;
  fstack_item *new_item = (fstack_item *) xmalloc (sizeof(fstack_item));
  new_item->data = item;
  s->size++;
  if (s->first == ((void *)0))
    {
      s->first = new_item;
      s->last = s->first;
      s->first->next = s->first;
      s->first->previous = s->first;
    }
  else
    {
      new_item->previous = si->previous;
      new_item->next = si;
      si->previous->next = new_item;
      si->previous = new_item;
    }
  return 1;
}

canonical_original_code:
int fstack_insert(struct fstack *s, int pos, void *item)
{
  struct fs_item *si;
  if (pos == 1)
    return fstack_unshift(s, item);
  if (pos == (s->size + 1))
    return fstack_push(s, item);
  if ((si = fstack_peek_item(s, pos)) == 0)
    return 0;
  struct fs_item *new_item = (fstack_item *) xmalloc (sizeof(fstack_item));
  new_item->data = item;
  s->size++;
  if (s->first == ((void *)0))
    {
      s->first = new_item;
      s->last = s->first;
      s->first->next = s->first;
      s->first->previous = s->first;
    }
  else
    {
      new_item->previous = si->previous;
      new_item->next = si;
      si->previous->next = new_item;
      si->previous = new_item;
    }
  return 1;
}


original_code:
void *
fstack_delete (fstack *s, int pos)
{
  fstack_item *si;
  if (pos == 1)
    return fstack_shift(s);
  if (pos == s->size)
    return fstack_pop(s);
  if ((si = fstack_peek_item(s, pos)) == 0)
    return 0;
  s->size--;
  if (s->last == s->first)
    {
      s->last = ((void *)0);
      s->first = ((void *)0);
    }
  else
    {
      si->previous->next = si->next;
      si->next->previous = si->previous;
    }
  void *data = si->data;
  free(si);
  return data;
}

canonical_original_code:
void *fstack_delete(struct fstack *s, int pos)
{
  struct fs_item *si;
  if (pos == 1)
    return fstack_shift(s);
  if (pos == s->size)
    return fstack_pop(s);
  if ((si = fstack_peek_item(s, pos)) == 0)
    return 0;
  s->size--;
  if (s->last == s->first)
    {
      s->last = ((void *)0);
      s->first = ((void *)0);
    }
  else
    {
      si->previous->next = si->next;
      si->next->previous = si->previous;
    }
  void *data = si->data;
  free(si);
  return data;
}


fsnnew

decompiled_code:
char *__fastcall fsnnew(char *src, size_t n)
{
void *v2; // rbp

v2 = (void *)xmalloc(n + 1);
memset(v2, 0, n + 1);
return strncpy((char *)v2, src, n);
}

canonical_decompiled_code:
char *__fastcall func1(char *src, size_t n)
{
void *v2; // rbp

v2 = (void *)xmalloc(n + 1);
memset(v2, 0, n + 1);
return strncpy((char *)v2, src, n);
}

original_code:
fstring
fsnnew(const char *string, size_t len)
{
  fstring new;
  new.len = len;
  new.str = (char *) xmalloc(len + 1);
  memset(new.str, 0x0, new.len + 1);
  strncpy(new.str, string, new.len);
  return new;
}

canonical_original_code:
struct fstring fsnnew(char *string, unsigned long len)
{
  struct fstring new;
  new.len = len;
  new.str = (char *) xmalloc(len + 1);
  memset(new.str, 0x0, new.len + 1);
  strncpy(new.str, string, new.len);
  return new;
}

variable_types:
string
char *

variable_types:
len
unsigned long

variable_types: struct fstring { char *str; unsigned long len; }


fsnew

decompiled_code:
char *__fastcall fsnew(char *src)
{
size_t v1; // rax

v1 = strlen(src);
return fsnnew(src, v1);
}

original_code:
fstring
fsnew(const char *string)
{
  return fsnnew(string, strlen(string));
}

canonical_original_code:
struct fstring fsnew(char *string)
{
  return fsnnew(string, strlen(string));
}

return_type: struct fstring { char *str; unsigned long len; }


fsnnewp

decompiled_code:
__int64 __fastcall fsnnewp(char *src, __int64 a2)
{
__int64 v2; // rbx
void *v3; // rax

v2 = xmalloc(16LL);
*(_QWORD *)(v2 + 8) = a2;
v3 = (void *)xmalloc(a2 + 1);
*(_QWORD *)v2 = v3;
memset(v3, 0, *(_QWORD *)(v2 + 8) + 1LL);
strncpy(*(char **)v2, src, *(_QWORD *)(v2 + 8));
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src, __int64 a2)
{
__int64 v2; // rbx
void *v3; // rax

v2 = xmalloc(16LL);
*(_QWORD *)(v2 + 8) = a2;
v3 = (void *)xmalloc(a2 + 1);
*(_QWORD *)v2 = v3;
memset(v3, 0, *(_QWORD *)(v2 + 8) + 1LL);
strncpy(*(char **)v2, src, *(_QWORD *)(v2 + 8));
return v2;
}

original_code:
fstring *
fsnnewp(const char *string, size_t len)
{
  fstring *new = (fstring *) xmalloc (sizeof(fstring));
  new->len = len;
  new->str = (char *) xmalloc(len + 1);
  memset(new->str, 0x0, new->len + 1);
  strncpy(new->str, string, new->len);
  return new;
}

canonical_original_code:
struct fstring *fsnnewp(char *string, unsigned long len)
{
  struct fstring *new = (fstring *) xmalloc (sizeof(fstring));
  new->len = len;
  new->str = (char *) xmalloc(len + 1);
  memset(new->str, 0x0, new->len + 1);
  strncpy(new->str, string, new->len);
  return new;
}

variable_types: struct fstring { char *str; unsigned long len; } *


fsnewp

decompiled_code:
__int64 __fastcall fsnewp(char *src)
{
__int64 v1; // rax

v1 = strlen(src);
return fsnnewp(src, v1);
}

canonical_decompiled_code:
__int64 __fastcall func4(char *src)
{
__int64 v1; // rax

v1 = strlen(src);
return func3(src, v1);
}

original_code:
fstring *
fsnewp(const char *string)
{
  return fsnnewp(string, strlen(string));
}

canonical_original_code:
struct fstring *fsnewp(char *string)
{
  return fsnnewp(string, strlen(string));
}

return_type: struct fstring { char *str; unsigned long len; } *


fsfree

decompiled_code:
void __fastcall fsfree(void **a1)
{
free(*a1);
}

canonical_decompiled_code:
void __fastcall func5(void **a1)
{
free(*a1);
}

original_code:
void
fsfree(fstring *f)
{
  free(f->str);
}

canonical_original_code:
void fsfree(struct fstring *f)
{
  free(f->str);
}

user_defined_types: struct fstring { char *str; unsigned long len; }


fsfreep

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

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

original_code:
void
fsfreep(fstring *f)
{
  free(f->str);
  free(f);
}

canonical_original_code:
void fsfreep(struct fstring *f)
{
  free(f->str);
  free(f);
}


fsnset

decompiled_code:
__int64 __fastcall fsnset(_QWORD *a1, const char *a2, size_t a3)
{
size_t v4; // r13
void *v5; // rax

v4 = a3 + 1;
v5 = (void *)xrealloc(*a1, a3 + 1);
*a1 = v5;
memset(v5, 0, v4);
strncpy((char *)*a1, a2, a3);
a1[1] = a3;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, const char *a2, size_t a3)
{
size_t v4; // r13
void *v5; // rax

v4 = a3 + 1;
v5 = (void *)xrealloc(*a1, a3 + 1);
*a1 = v5;
memset(v5, 0, v4);
strncpy((char *)*a1, a2, a3);
a1[1] = a3;
return 1LL;
}

original_code:
int
fsnset(fstring *f, const char *string, size_t len)
{
  f->str = (char *) xrealloc(f->str, len + 1);
  memset(f->str, 0x0, len + 1);
  strncpy(f->str, string, len);
  f->len = len;
  return 1;
}

canonical_original_code:
int fsnset(struct fstring *f, char *string, unsigned long len)
{
  f->str = (char *) xrealloc(f->str, len + 1);
  memset(f->str, 0x0, len + 1);
  strncpy(f->str, string, len);
  f->len = len;
  return 1;
}


fsset

decompiled_code:
__int64 __fastcall fsset(_QWORD *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return fsnset(a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return func7(a1, a2, v2);
}

original_code:
int
fsset(fstring *f, const char *string)
{
  return fsnset(f, string, strlen(string));
}

canonical_original_code:
int fsset(struct fstring *f, char *string)
{
  return fsnset(f, string, strlen(string));
}


fseq

decompiled_code:
_BOOL8 __fastcall fseq(__int64 a1, __int64 a2)
{
size_t v2; // rdx
_BOOL8 result; // rax

v2 = *(_QWORD *)(a1 + 8);
result = 0LL;
if ( v2 == *(_QWORD *)(a2 + 8) )
result = strncmp(*(const char **)a1, *(const char **)a2, v2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1, __int64 a2)
{
size_t v2; // rdx
_BOOL8 result; // rax

v2 = *(_QWORD *)(a1 + 8);
result = 0LL;
if ( v2 == *(_QWORD *)(a2 + 8) )
result = strncmp(*(const char **)a1, *(const char **)a2, v2) == 0;
return result;
}

original_code:
int
fseq (fstring *a, fstring *b)
{
  if (a->len == b->len)
    {
      return(strncmp(a->str, b->str, a->len) ? 0 : 1);
    }
  else
    {
      return 0;
    }
}

canonical_original_code:
int fseq(struct fstring *a, struct fstring *b)
{
  if (a->len == b->len)
    {
      return(strncmp(a->str, b->str, a->len) ? 0 : 1);
    }
  else
    {
      return 0;
    }
}

variable_types:
b
struct fstring *


fsneqs

decompiled_code:
_BOOL8 __fastcall fsneqs(__int64 a1, const char *a2, size_t a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_QWORD *)(a1 + 8) == a3 )
result = strncmp(*(const char **)a1, a2, a3) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1, const char *a2, size_t a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( *(_QWORD *)(a1 + 8) == a3 )
result = strncmp(*(const char **)a1, a2, a3) == 0;
return result;
}

original_code:
int
fsneqs (fstring *f, const char *str, size_t len)
{
  if (f->len == len) {
    return(strncmp(f->str, str, len) ? 0 : 1);
  }
  else {
    return 0;
  }
}

canonical_original_code:
int fsneqs(struct fstring *f, char *str, unsigned long len)
{
  if (f->len == len) {
    return(strncmp(f->str, str, len) ? 0 : 1);
  }
  else {
    return 0;
  }
}

variable_types:
str
char *


fseqs

decompiled_code:
_BOOL8 __fastcall fseqs(__int64 a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return fsneqs(a1, a2, v2);
}

canonical_decompiled_code:
_BOOL8 __fastcall func11(__int64 a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return func10(a1, a2, v2);
}

original_code:
int
fseqs (fstring *f, const char *str)
{
  return(fsneqs(f, str, strlen(str)));
}

canonical_original_code:
int fseqs(struct fstring *f, char *str)
{
  return(fsneqs(f, str, strlen(str)));
}


fsreplace

decompiled_code:
__int64 __fastcall fsreplace(__int64 a1, const char *a2, const char *a3, int a4)
{
size_t v6; // rax

v6 = strlen(a3);
return fsnreplace(a1, a2, a3, v6, a4);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, const char *a2, const char *a3, int a4)
{
size_t v6; // rax

v6 = strlen(a3);
return func0(a1, a2, a3, v6, a4);
}

original_code:
int
fsreplace (fstring *f, const char *regex, const char *rep_str, int flags)
{
  return(fsnreplace(f, regex, rep_str, strlen(rep_str), flags));
}

canonical_original_code:
int fsreplace(struct fstring *f, char *regex, char *rep_str, int flags)
{
  return(fsnreplace(f, regex, rep_str, strlen(rep_str), flags));
}

variable_types:
regex
char *

variable_types: flags int


fsnappend

decompiled_code:
__int64 __fastcall fsnappend(__int64 a1, const void *a2, size_t a3)
{
size_t v4; // r14
char *v5; // rbp

v4 = *(_QWORD *)(a1 + 8) + a3;
v5 = (char *)xmalloc(v4 + 1);
memset(v5, 0, v4 + 1);
memcpy(v5, *(const void **)a1, *(_QWORD *)(a1 + 8));
memcpy(&v5[*(_QWORD *)(a1 + 8)], a2, a3);
free(*(void **)a1);
*(_QWORD *)a1 = v5;
*(_QWORD *)(a1 + 8) = v4;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const void *a2, size_t a3)
{
size_t v4; // r14
char *v5; // rbp

v4 = *(_QWORD *)(a1 + 8) + a3;
v5 = (char *)xmalloc(v4 + 1);
memset(v5, 0, v4 + 1);
memcpy(v5, *(const void **)a1, *(_QWORD *)(a1 + 8));
memcpy(&v5[*(_QWORD *)(a1 + 8)], a2, a3);
free(*(void **)a1);
*(_QWORD *)a1 = v5;
*(_QWORD *)(a1 + 8) = v4;
return 1LL;
}

original_code:
int
fsnappend(fstring *f, const char *string, size_t len)
{
  size_t tot_len = len + f->len;
  char *new_str = (char *) xmalloc (tot_len + 1);
  memset(new_str, 0x0, tot_len + 1);
  memcpy(new_str, f->str, f->len);
  memcpy(new_str + f->len, string, len);
  free(f->str);
  f->str = new_str;
  f->len = tot_len;
  return 1;
}

canonical_original_code:
int fsnappend(struct fstring *f, char *string, unsigned long len)
{
  unsigned long tot_len = len + f->len;
  char *new_str = (char *) xmalloc (tot_len + 1);
  memset(new_str, 0x0, tot_len + 1);
  memcpy(new_str, f->str, f->len);
  memcpy(new_str + f->len, string, len);
  free(f->str);
  f->str = new_str;
  f->len = tot_len;
  return 1;
}


fsappend

decompiled_code:
__int64 __fastcall fsappend(__int64 a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return fsnappend(a1, a2, v2);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const char *a2)
{
size_t v2; // rax

v2 = strlen(a2);
return func14(a1, a2, v2);
}

original_code:
int
fsappend(fstring *f, const char *string)
{
  return fsnappend(f, string, strlen(string));
}

canonical_original_code:
int fsappend(struct fstring *f, char *string)
{
  return fsnappend(f, string, strlen(string));
}


xcalloc

decompiled_code:
void *__fastcall xcalloc(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
fatal("virtual memory exhausted");
return result;
}

canonical_decompiled_code:
void *__fastcall func1(size_t a1, size_t a2)
{
void *result; // rax

result = calloc(a1, a2);
if ( !result )
func0("virtual memory exhausted");
return result;
}

original_code:
void *
xcalloc (size_t lsize, size_t size)
{
  register void *value = calloc (lsize, size);
  if (value == 0)
    _fatal ("virtual memory exhausted");
  return value;
}

canonical_original_code:
void *xcalloc(unsigned long lsize, unsigned long size)
{
  register void *value = calloc (lsize, size);
  if (value == 0)
    _fatal ("virtual memory exhausted");
  return value;
}

variable_types:
lsize
unsigned long

variable_types:
size
unsigned long

variable_types:
value
void *


xrealloc

decompiled_code:
void *__fastcall xrealloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
fatal("virtual memory exhausted");
return result;
}

canonical_decompiled_code:
void *__fastcall func2(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
func0("virtual memory exhausted");
return result;
}

original_code:
void *
xrealloc (void *ptr, size_t size)
{
  ptr = realloc(ptr, size);
  if (ptr == 0)
    _fatal ("virtual memory exhausted");
  return ptr;
}

canonical_original_code:
void *xrealloc(void *ptr, unsigned long size)
{
  ptr = realloc(ptr, size);
  if (ptr == 0)
    _fatal ("virtual memory exhausted");
  return ptr;
}

variable_types:
ptr
void *


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
fatal("virtual memory exhausted");
return result;
}

canonical_decompiled_code:
void *__fastcall func3(size_t a1)
{
void *result; // rax

result = malloc(a1);
if ( !result )
func0("virtual memory exhausted");
return result;
}

original_code:
void *
xmalloc (size_t size)
{
  register void *value = malloc (size);
  if (value == 0)
    _fatal ("virtual memory exhausted");
  return value;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
  register void *value = malloc (size);
  if (value == 0)
    _fatal ("virtual memory exhausted");
  return value;
}


isWhiteSpace

decompiled_code:
__int64 __fastcall isWhiteSpace(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 1u);
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
return (a1 == 32) | (unsigned __int8)((unsigned __int8)(a1 - 9) <= 1u);
}

original_code:
static inline int isWhiteSpace(char c)
{
 return c == ' ' || c == '\t' || c == '\n';
}

variable_types: c char


makeList

decompiled_code:
__int64 makeList()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func9()
{
return 0LL;
}

original_code:
ll_t makeList()
{
 ll_t newList;
 newList.head = ((void *)0);
 newList.back = ((void *)0);
 return newList;
}

canonical_original_code:
struct ll_t makeList()
{
 struct ll_t newList;
 newList.head = ((void *)0);
 newList.back = ((void *)0);
 return newList;
}

variable_types: struct ll_t { struct node_t { void *data; struct node_t *next; } *head; struct node_t *back; }

user_defined_types: struct ll_t { struct node_t *head; struct node_t *back; }


pop

original_code:
void *pop(ll_t *list)
{
 ((void) sizeof ((list->head != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->head != ((void *)0)) ; else __assert_fail ("list->head != NULL", "linkedlist.c", 26, __extension__ __PRETTY_FUNCTION__); }));
 void *data = list->head->data;
 list->head = list->head->next;
 if (list->head == ((void *)0))
  list->back = ((void *)0);
 return data;
}

canonical_original_code:
void *pop(struct ll_t *list)
{
 ((void) sizeof ((list->head != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->head != ((void *)0)) ; else __assert_fail ("list->head != NULL", "linkedlist.c", 26, __extension__ __PRETTY_FUNCTION__); }));
 void *data = list->head->data;
 list->head = list->head->next;
 if (list->head == ((void *)0))
  list->back = ((void *)0);
 return data;
}

variable_types: struct ll_t { struct node_t { void *data; struct node_t *next; } *head; struct node_t *back; } *


peek

decompiled_code:
__int64 __fastcall peek(__int64 a1)
{
if ( !*(_QWORD *)a1 )
__assert_fail("list->head != NULL", "linkedlist.c", 0x27u, "peek");
return **(_QWORD **)a1;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( !*(_QWORD *)a1 )
__assert_fail("list->head != NULL", "linkedlist.c", 0x27u, "peek");
return **(_QWORD **)a1;
}

original_code:
void *peek(ll_t *list)
{
 ((void) sizeof ((list->head != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->head != ((void *)0)) ; else __assert_fail ("list->head != NULL", "linkedlist.c", 39, __extension__ __PRETTY_FUNCTION__); }));
 return list->head->data;
}

canonical_original_code:
void *peek(struct ll_t *list)
{
 ((void) sizeof ((list->head != ((void *)0)) ? 1 : 0), __extension__ ({ if (list->head != ((void *)0)) ; else __assert_fail ("list->head != NULL", "linkedlist.c", 39, __extension__ __PRETTY_FUNCTION__); }));
 return list->head->data;
}

user_defined_types: struct node_t { void *data; struct node_t *next; }


decompiled_code:
int __fastcall print_expr(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
__int64 *v9; // rax
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9

if ( (_DWORD)a7 != 3 )
return printf("%d ", HIDWORD(a7));
printf("( ");
while ( a8 )
{
v9 = (__int64 *)pop(&a8);
print_expr((unsigned int)&a8, a2, v10, v11, v12, v13, *v9, v9[1]);
}
return printf(") ");
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, int a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7, __int64 a8)
{
__int64 *v9; // rax
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9

if ( (_DWORD)a7 != 3 )
return printf("%d ", HIDWORD(a7));
printf("( ");
while ( a8 )
{
v9 = (__int64 *)pop(&a8);
func0((unsigned int)&a8, a2, v10, v11, v12, v13, *v9, v9[1]);
}
return printf(") ");
}

original_code:
static void print_expr(proftalk_expr_t expr)
{
 if (expr.type == 3)
 {
  printf("( ");
  while(expr.expressions.head != ((void *)0))
   print_expr(*(proftalk_expr_t *)pop(&expr.expressions));
  printf(") ");
 }
 else
 {
  printf("%d ", expr.value);
 }
}

canonical_original_code:
static void print_expr(struct proftalk_expr_t expr)
{
 if (expr.type == 3)
 {
  printf("( ");
  while(expr.expressions.head != ((void *)0))
   print_expr(*(struct proftalk_expr_t *)pop(&expr.expressions));
  printf(") ");
 }
 else
 {
  printf("%d ", expr.value);
 }
}

variable_types: struct proftalk_expr_t { int type; int value; struct ll_t { struct node_t { void *data; struct node_t *next; } *head; struct node_t *back; } expressions; char *name; int line_number; }

user_defined_types: struct proftalk_expr_t { int type; int value; struct ll_t expressions; char *name; int line_number; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
__m128i v9; // [rsp+0h] [rbp-A8h] BYREF
__int64 v10; // [rsp+10h] [rbp-98h]
__int64 v11[2]; // [rsp+20h] [rbp-88h] BYREF
__int64 v12; // [rsp+50h] [rbp-58h] BYREF
__int64 v13[3]; // [rsp+80h] [rbp-28h] BYREF
char v14[12]; // [rsp+9Ch] [rbp-Ch] BYREF

v13[0] = parse(stdin, v14, envp);
v13[1] = v3;
lex(&v12, v13);
makeEnv(&v9, 0LL);
global_env = (__int128)_mm_loadu_si128(&v9);
*((_QWORD *)&global_env + 2) = v10;
eval(v11, &global_env);
print_expr((__int64)v11, (int)&global_env, v4, v5, v6, v7, v11[0], v11[1]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rdx
__int64 v4; // rdx
__int64 v5; // rcx
__int64 v6; // r8
__int64 v7; // r9
__m128i v9; // [rsp+0h] [rbp-A8h] BYREF
__int64 v10; // [rsp+10h] [rbp-98h]
__int64 v11[2]; // [rsp+20h] [rbp-88h] BYREF
__int64 v12; // [rsp+50h] [rbp-58h] BYREF
__int64 v13[3]; // [rsp+80h] [rbp-28h] BYREF
char v14[12]; // [rsp+9Ch] [rbp-Ch] BYREF

v13[0] = parse(stdin, v14, envp);
v13[1] = v3;
lex(&v12, v13);
makeEnv(&v9, 0LL);
global_env = (__int128)_mm_loadu_si128(&v9);
*((_QWORD *)&global_env + 2) = v10;
eval(v11, &global_env);
func0((__int64)v11, (int)&global_env, v4, v5, v6, v7, v11[0], v11[1]);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int tokenCount;
 ll_t tokens = parse(stdin, &tokenCount);
 proftalk_expr_t expr = lex(&tokens);
 global_env = makeEnv(((void *)0));
 print_expr(eval(expr, &global_env));
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int tokenCount;
 struct ll_t tokens = parse(stdin, &tokenCount);
 struct proftalk_expr_t expr = lex(&tokens);
 global_env = makeEnv(((void *)0));
 print_expr(eval(expr, &global_env));
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: tokenCount int


original_code:
int env_find(env_t *env, char *name, proftalk_expr_t *result)
{
 if (env == ((void *)0))
  return 0;
 node_t *var = env->vars.head;
 while (var != ((void *)0))
 {
  pair_t realvar = *(pair_t *)var->data;
  if (!strcmp(realvar.key, name))
  {
   *result = realvar.val;
   return 1;
  }
  var = var->next;
 }
 return env_find(env->parent, name, result);
}

canonical_original_code:
int env_find(struct env_t *env, char *name, struct proftalk_expr_t *result)
{
 if (env == ((void *)0))
  return 0;
 struct node_t *var = env->vars.head;
 while (var != ((void *)0))
 {
  struct pair_t realvar = *(pair_t *)var->data;
  if (!strcmp(realvar.key, name))
  {
   *result = realvar.val;
   return 1;
  }
  var = var->next;
 }
 return env_find(env->parent, name, result);
}

variable_types: struct env_t { struct ll_t { struct node_t { void *data; struct node_t *next; } *head; struct node_t *back; } vars; struct env_t *parent; } *

variable_types:
name
char *

variable_types: struct proftalk_expr_t { int type; int value; struct ll_t expressions; char *name; int line_number; } *

variable_types: struct pair_t { char *key; struct proftalk_expr_t { int type; int value; struct ll_t { struct node_t { void *data; struct node_t *next; } *head; struct node_t *back; } expressions; char *name; int line_number; } val; }

user_defined_types: struct pair_t { char *key; struct proftalk_expr_t val; }

user_defined_types: struct env_t { struct ll_t vars; struct env_t *parent; }


original_code:
void env_insert(env_t *env, char *name, proftalk_expr_t val)
{
 pair_t *newVar = malloc(sizeof(pair_t));
 newVar->key = name;
 newVar->val = val;
 pushBack(&env->vars, newVar);
}

canonical_original_code:
void env_insert(struct env_t *env, char *name, struct proftalk_expr_t val)
{
 struct pair_t *newVar = malloc(sizeof(pair_t));
 newVar->key = name;
 newVar->val = val;
 pushBack(&env->vars, newVar);
}

variable_types: struct proftalk_expr_t { int type; int value; struct ll_t expressions; char *name; int line_number; }

variable_types: struct pair_t { char *key; struct proftalk_expr_t { int type; int value; struct ll_t { struct node_t { void *data; struct node_t *next; } *head; struct node_t *back; } expressions; char *name; int line_number; } val; } *


decompiled_code:
__int64 __fastcall writeh5_nxm_(__int64 a1, __int64 a2, __int64 a3, int *a4, int *a5)
{
__int64 v8; // rbp
__int64 v9; // r13
__int64 v10; // rbx
__int64 v11; // r12
__int64 v13[7]; // [rsp+0h] [rbp-38h] BYREF

H5check_version(1LL, 10LL, 4LL);
H5open();
v8 = H5Fcreate(a1, 2LL, 0LL, 0LL);
v13[0] = *a4;
v13[1] = *a5;
v9 = H5Screate_simple(2LL, v13, 0LL);
H5open();
v10 = H5Tcopy(H5T_NATIVE_DOUBLE_g);
H5Tset_order(v10, 0LL);
v11 = H5Dcreate2(v8, a2, v10, v9, 0LL, 0LL, 0LL);
H5open();
H5Dwrite(v11, H5T_NATIVE_DOUBLE_g, 0LL, 0LL, 0LL, a3);
H5Sclose(v9);
H5Tclose(v10);
H5Dclose(v11);
return H5Fclose(v8);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3, int *a4, int *a5)
{
__int64 v8; // rbp
__int64 v9; // r13
__int64 v10; // rbx
__int64 v11; // r12
__int64 v13[7]; // [rsp+0h] [rbp-38h] BYREF

H5check_version(1LL, 10LL, 4LL);
H5open();
v8 = H5Fcreate(a1, 2LL, 0LL, 0LL);
v13[0] = *a4;
v13[1] = *a5;
v9 = H5Screate_simple(2LL, v13, 0LL);
H5open();
v10 = H5Tcopy(H5T_NATIVE_DOUBLE_g);
H5Tset_order(v10, 0LL);
v11 = H5Dcreate2(v8, a2, v10, v9, 0LL, 0LL, 0LL);
H5open();
H5Dwrite(v11, H5T_NATIVE_DOUBLE_g, 0LL, 0LL, 0LL, a3);
H5Sclose(v9);
H5Tclose(v10);
H5Dclose(v11);
return H5Fclose(v8);
}

original_code:
void writeh5_nxm_(char *filename, char *dsetname, double *vec1, int *num_vec, int *length){
  hid_t file, dataset;
  hid_t datatype, dataspace;
  hsize_t dimsf[2];
  herr_t status;
  file = H5Fcreate(filename, (H5check_version(1,10, 4), H5open(), 0x0002u), (hid_t)0, (hid_t)0);
  dimsf[0] = *num_vec;
  dimsf[1] = *length;
  dataspace = H5Screate_simple(2, dimsf, ((void *)0));
  datatype = H5Tcopy((H5open(), H5T_NATIVE_DOUBLE_g));
  status = H5Tset_order(datatype, H5T_ORDER_LE);
  dataset = H5Dcreate2(file, dsetname, datatype, dataspace, (hid_t)0, (hid_t)0, (hid_t)0);
  status = H5Dwrite(dataset, (H5open(), H5T_NATIVE_DOUBLE_g), (hid_t)0, (hid_t)0, (hid_t)0, (double*)vec1);
  H5Sclose(dataspace);
  H5Tclose(datatype);
  H5Dclose(dataset);
  H5Fclose(file);
  return;
}

canonical_original_code:
void writeh5_nxm_(char *filename, char *dsetname, double *vec1, int *num_vec, int *length){
  long file; long dataset;
  long datatype; long dataspace;
  unsigned long long dimsf[2];
  int status;
  file = H5Fcreate(filename, (H5check_version(1,10, 4), H5open(), 0x0002u), (long)0, (long)0);
  dimsf[0] = *num_vec;
  dimsf[1] = *length;
  dataspace = H5Screate_simple(2, dimsf, ((void *)0));
  datatype = H5Tcopy((H5open(), H5T_NATIVE_DOUBLE_g));
  status = H5Tset_order(datatype, H5T_ORDER_LE);
  dataset = H5Dcreate2(file, dsetname, datatype, dataspace, (long)0, (long)0, (long)0);
  status = H5Dwrite(dataset, (H5open(), H5T_NATIVE_DOUBLE_g), (long)0, (long)0, (long)0, (double *)vec1);
  H5Sclose(dataspace);
  H5Tclose(datatype);
  H5Dclose(dataset);
  H5Fclose(file);
  return;
}

variable_types:
filename
char *

variable_types:
dsetname
char *

variable_types:
length
int *

variable_types: file long

variable_types: dataset long

variable_types: datatype long

variable_types: dataspace long

variable_types:
dimsf
unsigned long long [2]

variable_types: status int


InitializeCharList

decompiled_code:
__int64 __fastcall InitializeCharList(__int64 a1)
{
void *v1; // rdx
__int64 result; // rax

*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 12) = 1048;
v1 = malloc(0x418uLL);
*(_QWORD *)a1 = v1;
result = 0LL;
memset(v1, 0, 0x418uLL);
return result;
}

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

*(_DWORD *)(a1 + 8) = 0;
*(_DWORD *)(a1 + 12) = 1048;
v1 = malloc(0x418uLL);
*(_QWORD *)a1 = v1;
result = 0LL;
memset(v1, 0, 0x418uLL);
return result;
}

original_code:
void InitializeCharList(charList* newCharList)
{
  newCharList->ItemCount = 0;
  newCharList->ListSize = 1048;
  newCharList->Items = (char*)malloc(newCharList->ListSize * sizeof(char));
  memset(newCharList->Items, '\0', newCharList->ListSize);
}

canonical_original_code:
void InitializeCharList(struct charList_item *newCharList)
{
  newCharList->ItemCount = 0;
  newCharList->ListSize = 1048;
  newCharList->Items = (char *)malloc(newCharList->ListSize * sizeof(char));
  memset(newCharList->Items, '\0', newCharList->ListSize);
}

variable_types: struct charList_item { char *Items; int ItemCount; int ListSize; union sem_t { char __size[32]; long __align; } ListLock; } *

user_defined_types: struct charList_item { char *Items; int ItemCount; int ListSize; union sem_t ListLock; }


CleanUpCharList

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

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

original_code:
void CleanUpCharList(charList* list)
{
  free(list->Items);
  free(list->Items = '\0');
  free(list);
  list = '\0';
}

canonical_original_code:
void CleanUpCharList(struct charList_item *list)
{
  free(list->Items);
  free(list->Items = '\0');
  free(list);
  list = '\0';
}

user_defined_types: union sem_t { char __size[32]; long __align; }


SizeCharList

decompiled_code:
unsigned __int64 __fastcall SizeCharList(__int64 a1, int a2)
{
int v4; // edi
int v5; // esi
int v6; // edx
unsigned __int64 result; // rax

v4 = *(_DWORD *)(a1 + 12);
if ( v4 >= a2 )
{
result = (unsigned int)(v4 / 2);
v6 = result;
if ( a2 >= (int)result )
return result;
}
else
{
v5 = v4;
do
{
v6 = v5;
v5 *= 2;
}
while ( v5 < a2 );
*(_DWORD *)(a1 + 12) = v5;
if ( a2 >= v6 )
{
LABEL_7:
result = (unsigned __int64)realloc(*(void **)a1, v5);
*(_QWORD *)a1 = result;
return result;
}
}
do
{
v5 = v6;
result = (unsigned int)(v6 / 2);
v6 = result;
}
while ( (int)result > a2 );
*(_DWORD *)(a1 + 12) = v5;
if ( v4 != v5 )
goto LABEL_7;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(__int64 a1, int a2)
{
int v4; // edi
int v5; // esi
int v6; // edx
unsigned __int64 result; // rax

v4 = *(_DWORD *)(a1 + 12);
if ( v4 >= a2 )
{
result = (unsigned int)(v4 / 2);
v6 = result;
if ( a2 >= (int)result )
return result;
}
else
{
v5 = v4;
do
{
v6 = v5;
v5 *= 2;
}
while ( v5 < a2 );
*(_DWORD *)(a1 + 12) = v5;
if ( a2 >= v6 )
{
LABEL_7:
result = (unsigned __int64)realloc(*(void **)a1, v5);
*(_QWORD *)a1 = result;
return result;
}
}
do
{
v5 = v6;
result = (unsigned int)(v6 / 2);
v6 = result;
}
while ( (int)result > a2 );
*(_DWORD *)(a1 + 12) = v5;
if ( v4 != v5 )
goto LABEL_7;
return result;
}

original_code:
void SizeCharList(charList* list, int desiredMinimumSize)
{
  int initialListSize = list->ListSize;
  while(list->ListSize < desiredMinimumSize)
  {
    list->ListSize = 2 * list->ListSize;
  }
  while(list->ListSize/2 > desiredMinimumSize)
  {
    list->ListSize = list->ListSize /2;
  }
  if(list->ListSize != initialListSize)
  {
    list->Items = (char*)realloc(list->Items, list->ListSize * sizeof(char));
  }
}

canonical_original_code:
void SizeCharList(struct charList_item *list, int desiredMinimumSize)
{
  int initialListSize = list->ListSize;
  while(list->ListSize < desiredMinimumSize)
  {
    list->ListSize = 2 * list->ListSize;
  }
  while(list->ListSize/2 > desiredMinimumSize)
  {
    list->ListSize = list->ListSize /2;
  }
  if(list->ListSize != initialListSize)
  {
    list->Items = (char *)realloc(list->Items, list->ListSize * sizeof(char));
  }
}

variable_types: desiredMinimumSize int

variable_types: initialListSize int


AddChars

decompiled_code:
void *__fastcall AddChars(__int64 a1, const void *a2, int a3)
{
void *result; // rax

SizeCharList(a1, *(_DWORD *)(a1 + 8) + a3);
result = memcpy((void *)(*(_QWORD *)a1 + *(int *)(a1 + 8)), a2, a3);
*(_DWORD *)(a1 + 8) += a3;
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, const void *a2, int a3)
{
void *result; // rax

func2(a1, *(_DWORD *)(a1 + 8) + a3);
result = memcpy((void *)(*(_QWORD *)a1 + *(int *)(a1 + 8)), a2, a3);
*(_DWORD *)(a1 + 8) += a3;
return result;
}

original_code:
void AddChars(charList* dest, char* newChars, int count)
{
  SizeCharList(dest, dest->ItemCount + count);
  memcpy(dest->Items + dest->ItemCount,newChars, count);
  dest->ItemCount += count;
}

canonical_original_code:
void AddChars(struct charList_item *dest, char *newChars, int count)
{
  SizeCharList(dest, dest->ItemCount + count);
  memcpy(dest->Items + dest->ItemCount,newChars, count);
  dest->ItemCount += count;
}

variable_types:
newChars
char *

variable_types: count int


RemoveChars

decompiled_code:
unsigned __int64 __fastcall RemoveChars(void *a1, __int64 a2, int a3)
{
unsigned __int64 result; // rax

if ( a1 )
memcpy(a1, *(const void **)a2, a3);
memmove(*(void **)a2, (const void *)(*(_QWORD *)a2 + a3), *(_DWORD *)(a2 + 12) - a3);
result = SizeCharList(a2, *(_DWORD *)(a2 + 8) - a3);
*(_DWORD *)(a2 + 8) -= a3;
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func4(void *a1, __int64 a2, int a3)
{
unsigned __int64 result; // rax

if ( a1 )
memcpy(a1, *(const void **)a2, a3);
memmove(*(void **)a2, (const void *)(*(_QWORD *)a2 + a3), *(_DWORD *)(a2 + 12) - a3);
result = func2(a2, *(_DWORD *)(a2 + 8) - a3);
*(_DWORD *)(a2 + 8) -= a3;
return result;
}

original_code:
void RemoveChars(char* dest, charList* source, int count)
{
  if(dest != ((void *)0))
    memcpy(dest, source->Items, count);
  memmove(source->Items, source->Items + count, source->ListSize - count);
  SizeCharList(source, source->ItemCount - count);
  source->ItemCount -= count;
}

canonical_original_code:
void RemoveChars(char *dest, struct charList_item *source, int count)
{
  if(dest != ((void *)0))
    memcpy(dest, source->Items, count);
  memmove(source->Items, source->Items + count, source->ListSize - count);
  SizeCharList(source, source->ItemCount - count);
  source->ItemCount -= count;
}

variable_types:
dest
char *


ClearChars

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

if ( *(_DWORD *)(a1 + 12) != 1048 )
{
*(_DWORD *)(a1 + 12) = 1048;
*(_QWORD *)a1 = realloc(*(void **)a1, 0x418uLL);
}
result = memset(*(void **)a1, 0, *(int *)(a1 + 12));
*(_DWORD *)(a1 + 8) = 0;
return result;
}

original_code:
void ClearChars(charList* source)
{
  if(source->ListSize != 1048)
  {
    source->ListSize = 1048;
    source->Items = (char*)realloc(source->Items, source->ListSize * sizeof(char));
  }
  memset(source->Items, '\0', source->ListSize);
  source->ItemCount = 0;
}

canonical_original_code:
void ClearChars(struct charList_item *source)
{
  if(source->ListSize != 1048)
  {
    source->ListSize = 1048;
    source->Items = (char *)realloc(source->Items, source->ListSize * sizeof(char));
  }
  memset(source->Items, '\0', source->ListSize);
  source->ItemCount = 0;
}


ReplaceChars

decompiled_code:
__int64 __fastcall ReplaceChars(__int64 a1, const char *a2, const char *a3)
{
void *v5; // rbp
char *v6; // rax
int v7; // ebx
const void *v8; // rsi
int v9; // er15
int v10; // eax
unsigned int v11; // er13

v5 = malloc(0x30uLL);
InitializeCharList((__int64)v5);
v6 = strstr(*(const char **)a1, a2);
if ( v6 )
{
v7 = 0;
do
{
v8 = (const void *)(*(_QWORD *)a1 + v7);
v9 = (_DWORD)v6 - (_DWORD)v8;
AddChars((__int64)v5, v8, (_DWORD)v6 - (_DWORD)v8);
v10 = strlen(a3);
AddChars((__int64)v5, a3, v10);
v7 += strlen(a2) + v9;
v6 = strstr((const char *)(*(_QWORD *)a1 + v7), a2);
}
while ( v6 );
v11 = 1;
}
else
{
v11 = 0;
v7 = 0;
}
if ( *(_DWORD *)(a1 + 8) - v7 > 0 )
AddChars((__int64)v5, (const void *)(*(_QWORD *)a1 + v7), *(_DWORD *)(a1 + 8) - v7);
ClearChars(a1);
AddChars(a1, *(const void **)v5, *((_DWORD *)v5 + 2));
CleanUpCharList(v5);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, const char *a2, const char *a3)
{
void *v5; // rbp
char *v6; // rax
int v7; // ebx
const void *v8; // rsi
int v9; // er15
int v10; // eax
unsigned int v11; // er13

v5 = malloc(0x30uLL);
func0((__int64)v5);
v6 = strstr(*(const char **)a1, a2);
if ( v6 )
{
v7 = 0;
do
{
v8 = (const void *)(*(_QWORD *)a1 + v7);
v9 = (_DWORD)v6 - (_DWORD)v8;
func3((__int64)v5, v8, (_DWORD)v6 - (_DWORD)v8);
v10 = strlen(a3);
func3((__int64)v5, a3, v10);
v7 += strlen(a2) + v9;
v6 = strstr((const char *)(*(_QWORD *)a1 + v7), a2);
}
while ( v6 );
v11 = 1;
}
else
{
v11 = 0;
v7 = 0;
}
if ( *(_DWORD *)(a1 + 8) - v7 > 0 )
func3((__int64)v5, (const void *)(*(_QWORD *)a1 + v7), *(_DWORD *)(a1 + 8) - v7);
func5(a1);
func3(a1, *(const void **)v5, *((_DWORD *)v5 + 2));
func1(v5);
return v11;
}

original_code:
int ReplaceChars(charList* source, char* value, char* replacement)
{
  charList* dest = (charList*)malloc(sizeof(charList));
  InitializeCharList(dest);
 int startChar = 0;
 int sectionLength = 0;
 char* startPtr = strstr(source->Items, value);
 int result = 0;
 while(startPtr != ((void *)0))
 {
  result = 1;
  sectionLength = startPtr -(source->Items + startChar);
  AddChars(dest, source->Items + startChar, sectionLength);
  AddChars(dest, replacement, strlen(replacement));
  startChar = startChar + sectionLength + strlen(value);
  startPtr = strstr(source->Items + startChar, value);
 }
 int remainingLeft = source->Items + source->ItemCount - (source->Items + startChar);
 if(remainingLeft > 0)
  AddChars(dest, source->Items + startChar, remainingLeft);
 ClearChars(source);
 AddChars(source, dest->Items, dest->ItemCount);
 CleanUpCharList(dest);
 return result;
}

canonical_original_code:
int ReplaceChars(struct charList_item *source, char *value, char *replacement)
{
  struct charList_item *dest = (charList*)malloc(sizeof(charList));
  InitializeCharList(dest);
 int startChar = 0;
 int sectionLength = 0;
 char *startPtr = strstr(source->Items, value);
 int result = 0;
 while(startPtr != ((void *)0))
 {
  result = 1;
  sectionLength = startPtr -(source->Items + startChar);
  AddChars(dest, source->Items + startChar, sectionLength);
  AddChars(dest, replacement, strlen(replacement));
  startChar = startChar + sectionLength + strlen(value);
  startPtr = strstr(source->Items + startChar, value);
 }
 int remainingLeft = source->Items + source->ItemCount - (source->Items + startChar);
 if(remainingLeft > 0)
  AddChars(dest, source->Items + startChar, remainingLeft);
 ClearChars(source);
 AddChars(source, dest->Items, dest->ItemCount);
 CleanUpCharList(dest);
 return result;
}

variable_types:
value
char *

variable_types:
replacement
char *

variable_types: startChar int

variable_types: sectionLength int

variable_types:
startPtr
char *

variable_types: result int

variable_types: remainingLeft int


Split

original_code:
int Split(char* source, char* delimiter, char*** dest, int startChar, int endChar)
{
 int strLen = endChar - startChar;
 char* splitStr = (char*)malloc(strLen * sizeof(char));
 splitStr = memcpy(splitStr ,source + startChar, strLen);
 int itemCount = 0;
  *dest = (char**)malloc(sizeof(char*));
 int sectionStartChar = 0;
 int sectionLength = 0;
 char* startPtr = strstr(splitStr, delimiter);
 while(startPtr != ((void *)0))
 {
  itemCount++;
   *dest = (char**)realloc(*dest, itemCount * sizeof(char*));
  sectionLength = startPtr -(splitStr + sectionStartChar);
  char* value = ((void *)0);
  if(sectionLength > 0)
  {
   value = (char*)malloc((sectionLength + 1) * sizeof(char));
   value = memcpy(value ,splitStr + sectionStartChar, sectionLength);
  }
  else
  {
   value = (char*)malloc(sizeof(char));
   value[0] = '\0';
  }
  value[sectionLength] = '\0';
  (*dest)[itemCount - 1] = value;
  sectionStartChar = sectionStartChar + sectionLength + strlen(delimiter);
  startPtr = strstr(splitStr + sectionStartChar, delimiter);
 }
 int remainingLeft = splitStr + strLen - (splitStr + sectionStartChar);
 if(remainingLeft > 0)
 {
  itemCount++;
  *dest = (char**)realloc(*dest, itemCount * sizeof(char*));
  char* value = (char*)malloc((remainingLeft + 1) * sizeof(char));
  if(remainingLeft == 1)
   value[0] = '\0';
  else
   value = memcpy(value ,splitStr + sectionStartChar, remainingLeft);
  value[remainingLeft] = '\0';
  (*dest)[itemCount - 1] = value;
 }
  free(splitStr);
 return itemCount;
}

canonical_original_code:
int Split(char *source, char *delimiter, char ***dest, int startChar, int endChar)
{
 int strLen = endChar - startChar;
 char *splitStr = (char*)malloc(strLen * sizeof(char));
 splitStr = memcpy(splitStr ,source + startChar, strLen);
 int itemCount = 0;
  *dest = (char **)malloc(sizeof(char *));
 int sectionStartChar = 0;
 int sectionLength = 0;
 char *startPtr = strstr(splitStr, delimiter);
 while(startPtr != ((void *)0))
 {
  itemCount++;
   *dest = (char **)realloc(*dest, itemCount * sizeof(char *));
  sectionLength = startPtr -(splitStr + sectionStartChar);
  char *value = ((void *)0);
  if(sectionLength > 0)
  {
   value = (char *)malloc((sectionLength + 1) * sizeof(char));
   value = memcpy(value ,splitStr + sectionStartChar, sectionLength);
  }
  else
  {
   value = (char *)malloc(sizeof(char));
   value[0] = '\0';
  }
  value[sectionLength] = '\0';
  (*dest)[itemCount - 1] = value;
  sectionStartChar = sectionStartChar + sectionLength + strlen(delimiter);
  startPtr = strstr(splitStr + sectionStartChar, delimiter);
 }
 int remainingLeft = splitStr + strLen - (splitStr + sectionStartChar);
 if(remainingLeft > 0)
 {
  itemCount++;
  *dest = (char **)realloc(*dest, itemCount * sizeof(char *));
  char *value = (char*)malloc((remainingLeft + 1) * sizeof(char));
  if(remainingLeft == 1)
   value[0] = '\0';
  else
   value = memcpy(value ,splitStr + sectionStartChar, remainingLeft);
  value[remainingLeft] = '\0';
  (*dest)[itemCount - 1] = value;
 }
  free(splitStr);
 return itemCount;
}

variable_types:
source
char *

variable_types:
delimiter
char *

variable_types:
dest
char ***

variable_types: endChar int

variable_types: strLen int

variable_types:
splitStr
char *

variable_types: itemCount int

variable_types: sectionStartChar int


CleanUpNode

decompiled_code:
void __fastcall CleanUpNode(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func9(void *a1)
{
free(a1);
}

original_code:
void CleanUpNode(node* nodeToCleanUp)
{
  nodeToCleanUp->NextNode = ((void *)0);
  free(nodeToCleanUp);
}

canonical_original_code:
void CleanUpNode(struct node_item *nodeToCleanUp)
{
  nodeToCleanUp->NextNode = ((void *)0);
  free(nodeToCleanUp);
}

variable_types: struct node_item { void *Value; struct node_item *NextNode; } *


InitializeQueue

decompiled_code:
void __fastcall InitializeQueue(__int64 a1)
{
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
*(_DWORD *)(a1 + 24) = 0;
}

original_code:
void InitializeQueue(queue* newQueue)
{
  newQueue->FirstNode = ((void *)0);
  newQueue->LastNode = ((void *)0);
  newQueue->IterateNode = ((void *)0);
  newQueue->Length = 0;
}

canonical_original_code:
void InitializeQueue(struct queue_item *newQueue)
{
  newQueue->FirstNode = ((void *)0);
  newQueue->LastNode = ((void *)0);
  newQueue->IterateNode = ((void *)0);
  newQueue->Length = 0;
}

variable_types: struct queue_item { struct node_item { void *Value; struct node_item *NextNode; } *FirstNode; struct node_item *LastNode; struct node_item *IterateNode; int Length; } *

user_defined_types: struct queue_item { struct node_item *FirstNode; struct node_item *LastNode; struct node_item *IterateNode; int Length; }


CleanUpQueue

decompiled_code:
void __fastcall CleanUpQueue(void *ptr)
{
_QWORD *v2; // rdi

v2 = *(_QWORD **)ptr;
if ( v2 )
{
do
{
*(_QWORD *)ptr = v2[1];
CleanUpNode(v2);
v2 = *(_QWORD **)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
_QWORD *v2; // rdi

v2 = *(_QWORD **)ptr;
if ( v2 )
{
do
{
*(_QWORD *)ptr = v2[1];
func9(v2);
v2 = *(_QWORD **)ptr;
}
while ( *(_QWORD *)ptr );
}
free(ptr);
}

original_code:
void CleanUpQueue(queue* queueToCleanUp)
{
  while(queueToCleanUp->FirstNode != ((void *)0))
  {
    node* nodeToCleanUp = queueToCleanUp->FirstNode;
    queueToCleanUp->FirstNode = nodeToCleanUp->NextNode;
    CleanUpNode(nodeToCleanUp);
  }
  queueToCleanUp->FirstNode = ((void *)0);
  queueToCleanUp->LastNode = ((void *)0);
  queueToCleanUp->IterateNode = ((void *)0);
  free(queueToCleanUp);
}

canonical_original_code:
void CleanUpQueue(struct queue_item *queueToCleanUp)
{
  while(queueToCleanUp->FirstNode != ((void *)0))
  {
    struct node_item *nodeToCleanUp = queueToCleanUp->FirstNode;
    queueToCleanUp->FirstNode = nodeToCleanUp->NextNode;
    CleanUpNode(nodeToCleanUp);
  }
  queueToCleanUp->FirstNode = ((void *)0);
  queueToCleanUp->LastNode = ((void *)0);
  queueToCleanUp->IterateNode = ((void *)0);
  free(queueToCleanUp);
}

user_defined_types: struct node_item { void *Value; struct node_item *NextNode; }


IsQueueEmpty

decompiled_code:
_BOOL8 __fastcall IsQueueEmpty(_QWORD *a1)
{
return *a1 == 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func12(_QWORD *a1)
{
return *a1 == 0LL;
}

original_code:
int IsQueueEmpty(queue* initializedQueue)
{
  if(initializedQueue->FirstNode == ((void *)0))
    return 1;
  else
    return 0;
}

canonical_original_code:
int IsQueueEmpty(struct queue_item *initializedQueue)
{
  if(initializedQueue->FirstNode == ((void *)0))
    return 1;
  else
    return 0;
}


CleanupStringArray

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

if ( a2 > 0 )
{
v2 = 0LL;
do
{
*(_QWORD *)(*a1 + v2) = 0LL;
free(*(void **)(*a1 + v2));
v2 += 8LL;
}
while ( v2 != 8LL * (unsigned int)a2 );
}
*a1 = 0LL;
}

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

if ( a2 > 0 )
{
v2 = 0LL;
do
{
*(_QWORD *)(*a1 + v2) = 0LL;
free(*(void **)(*a1 + v2));
v2 += 8LL;
}
while ( v2 != 8LL * (unsigned int)a2 );
}
*a1 = 0LL;
}

original_code:
void CleanupStringArray(char*** source, int itemCount)
{
 int i = 0;
 for(i = 0; i < itemCount; i++)
 {
  (*source)[i] = ((void *)0);
  free((*source)[i]);
 }
 *source = ((void *)0);
 free(*source);
}

canonical_original_code:
void CleanupStringArray(char ***source, int itemCount)
{
 int i = 0;
 for(i = 0; i < itemCount; i++)
 {
  (*source)[i] = ((void *)0);
  free((*source)[i]);
 }
 *source = ((void *)0);
 free(*source);
}

variable_types:
source
char ***

variable_types: i int


InitializeSockAddr

decompiled_code:
__int16 __fastcall InitializeSockAddr(__int64 a1, int a2, __int16 a3)
{
__int16 result; // ax

*(_QWORD *)(a1 + 8) = 0LL;
*(_WORD *)a1 = 2;
*(_DWORD *)(a1 + 4) = a2;
result = _bswap_16(a3);
*(_WORD *)(a1 + 2) = result;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func1(__int64 a1, int a2, __int16 a3)
{
__int16 result; // ax

*(_QWORD *)(a1 + 8) = 0LL;
*(_WORD *)a1 = 2;
*(_DWORD *)(a1 + 4) = a2;
result = func0(a3);
*(_WORD *)(a1 + 2) = result;
return result;
}

original_code:
void InitializeSockAddr(struct sockaddr_in *theAddress, in_addr_t path, int port)
{
  bzero(theAddress,sizeof(*theAddress));
  theAddress->sin_family = 2;
  theAddress->sin_addr.s_addr=path;
  theAddress->sin_port=htons(port);
}

canonical_original_code:
void InitializeSockAddr(struct sockaddr_in *theAddress, unsigned int path, int port)
{
  bzero(theAddress,sizeof(*theAddress));
  theAddress->sin_family = 2;
  theAddress->sin_addr.s_addr=path;
  theAddress->sin_port=htons(port);
}

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

variable_types:
path
unsigned int

variable_types: port int

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


CreateIncomingConnection

decompiled_code:
__int64 __fastcall CreateIncomingConnection(__int16 a1)
{
int v1; // ebx
int v2; // edx
__int64 result; // rax
int v4; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
InitializeSockAddr((__int64)&addr, 0, a1);
v2 = bind(v1, &addr, 0x10u);
result = 0LL;
if ( v2 >= 0 )
{
listen(v1, 1);
addr_len = 16;
v4 = accept(v1, &addr, &addr_len);
close(v1);
result = 0LL;
if ( v4 >= 0 )
result = (unsigned int)v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int16 a1)
{
int v1; // ebx
int v2; // edx
__int64 result; // rax
int v4; // ebp
socklen_t addr_len; // [rsp+Ch] [rbp-2Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
func1((__int64)&addr, 0, a1);
v2 = bind(v1, &addr, 0x10u);
result = 0LL;
if ( v2 >= 0 )
{
listen(v1, 1);
addr_len = 16;
v4 = accept(v1, &addr, &addr_len);
close(v1);
result = 0LL;
if ( v4 >= 0 )
result = (unsigned int)v4;
}
return result;
}

original_code:
int CreateIncomingConnection(int port)
{
  int bindingSocket = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in incomingAddress;
  InitializeSockAddr(&incomingAddress,((in_addr_t) 0x00000000),port);
 if(bind(bindingSocket, (struct sockaddr *) &incomingAddress,sizeof(incomingAddress)) < 0)
   return 0;
  listen(bindingSocket,1);
  socklen_t clilen = sizeof(incomingAddress);
  int acceptedSocket = accept(bindingSocket, (struct sockaddr *) &incomingAddress, &clilen);
  close(bindingSocket);
  if (acceptedSocket < 0)
    return 0;
  return acceptedSocket;
}

canonical_original_code:
int CreateIncomingConnection(int port)
{
  int bindingSocket = socket(2, SOCK_STREAM, 0);
 struct sockaddr_in incomingAddress;
  InitializeSockAddr(&incomingAddress,((unsigned int) 0x00000000),port);
 if(bind(bindingSocket, (struct sockaddr *) &incomingAddress,sizeof(incomingAddress)) < 0)
   return 0;
  listen(bindingSocket,1);
  unsigned int clilen = sizeof(incomingAddress);
  int acceptedSocket = accept(bindingSocket, (struct sockaddr *) &incomingAddress, &clilen);
  close(bindingSocket);
  if (acceptedSocket < 0)
    return 0;
  return acceptedSocket;
}

variable_types: bindingSocket 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]; }

variable_types:
clilen
unsigned int

variable_types: acceptedSocket int

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


CreateOutgoingConnection

decompiled_code:
__int64 __fastcall CreateOutgoingConnection(char *cp, __int16 a2)
{
unsigned int v2; // ebx
int v3; // eax
struct sockaddr v5[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
v3 = inet_addr(cp);
InitializeSockAddr((__int64)v5, v3, a2);
if ( connect(v2, v5, 0x10u) < 0 )
v2 = 0;
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *cp, __int16 a2)
{
unsigned int v2; // ebx
int v3; // eax
struct sockaddr v5[2]; // [rsp+0h] [rbp-28h] BYREF

v2 = socket(2, 1, 0);
v3 = inet_addr(cp);
func1((__int64)v5, v3, a2);
if ( connect(v2, v5, 0x10u) < 0 )
v2 = 0;
return v2;
}

original_code:
int CreateOutgoingConnection(char* path, int port)
{
  int connectedSocket =socket(2,SOCK_STREAM,0);
  struct sockaddr_in outgoingAddress;
  InitializeSockAddr(&outgoingAddress,inet_addr(path),port);
  int status = connect(connectedSocket, (struct sockaddr *)&outgoingAddress, sizeof(outgoingAddress));
  if(status < 0)
   return 0;
  return connectedSocket;
}

canonical_original_code:
int CreateOutgoingConnection(char *path, int port)
{
  int connectedSocket = socket(2,SOCK_STREAM,0);
  struct sockaddr_in outgoingAddress;
  InitializeSockAddr(&outgoingAddress,inet_addr(path),port);
  int status = connect(connectedSocket, (struct sockaddr *)&outgoingAddress, sizeof(outgoingAddress));
  if(status < 0)
   return 0;
  return connectedSocket;
}

variable_types:
path
char *

variable_types: connectedSocket int

variable_types: status int


isValidIpAddress

decompiled_code:
_BOOL8 __fastcall isValidIpAddress(char *cp)
{
char buf[20]; // [rsp+4h] [rbp-14h] BYREF

return inet_pton(2, cp, buf) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *cp)
{
char buf[20]; // [rsp+4h] [rbp-14h] BYREF

return inet_pton(2, cp, buf) != 0;
}

original_code:
int isValidIpAddress(char *ipAddress)
{
  struct sockaddr_in sa;
  if (inet_pton(2, ipAddress, &(sa.sin_addr)) == 0)
    return 0;
  else
    return 1;
}

variable_types:
ipAddress
char *


GetPrimaryIp

decompiled_code:
int __fastcall GetPrimaryIp(char *buf, socklen_t len)
{
int v2; // ebx
socklen_t lena; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr cp; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

v2 = socket(2, 2, 0);
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr("8.8.8.8");
*(_WORD *)addr.sa_data = _bswap_16(53);
connect(v2, &addr, 0x10u);
lena = 16;
getsockname(v2, &cp, &lena);
inet_ntop(2, &cp.sa_data[2], buf, len);
return close(v2);
}

canonical_decompiled_code:
int __fastcall func5(char *buf, socklen_t len)
{
int v2; // ebx
socklen_t lena; // [rsp+Ch] [rbp-3Ch] BYREF
struct sockaddr cp; // [rsp+10h] [rbp-38h] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-28h] BYREF

v2 = socket(2, 2, 0);
addr.sa_family = 2;
*(_QWORD *)&addr.sa_data[6] = 0LL;
*(_DWORD *)&addr.sa_data[2] = inet_addr("8.8.8.8");
*(_WORD *)addr.sa_data = func0(53);
connect(v2, &addr, 0x10u);
lena = 16;
getsockname(v2, &cp, &lena);
inet_ntop(2, &cp.sa_data[2], buf, len);
return close(v2);
}

original_code:
void GetPrimaryIp(char* buffer, size_t buflen)
{
  int sock = socket(2, SOCK_DGRAM, 0);
  const char* kGoogleDnsIp = "8.8.8.8";
  uint16_t kDnsPort = 53;
  struct sockaddr_in serv;
  memset(&serv, 0, sizeof(serv));
  serv.sin_family = 2;
  serv.sin_addr.s_addr = inet_addr(kGoogleDnsIp);
  serv.sin_port = htons(kDnsPort);
  int err = connect(sock, (const struct sockaddr *) &serv, sizeof(serv));
  struct sockaddr_in name;
  socklen_t namelen = sizeof(name);
  err = getsockname(sock, (struct sockaddr*) &name, &namelen);
  inet_ntop(2, &name.sin_addr, buffer, buflen);
  close(sock);
}

canonical_original_code:
void GetPrimaryIp(char *buffer, unsigned long buflen)
{
  int sock = socket(2, SOCK_DGRAM, 0);
  char *kGoogleDnsIp = "8.8.8.8";
  unsigned short kDnsPort = 53;
  struct sockaddr_in serv;
  memset(&serv, 0, sizeof(serv));
  serv.sin_family = 2;
  serv.sin_addr.s_addr = inet_addr(kGoogleDnsIp);
  serv.sin_port = htons(kDnsPort);
  int err = connect(sock, (const struct sockaddr *) &serv, sizeof(serv));
  struct sockaddr_in name;
  unsigned int namelen = sizeof(name);
  err = getsockname(sock, (struct sockaddr *) &name, &namelen);
  inet_ntop(2, &name.sin_addr, buffer, buflen);
  close(sock);
}

variable_types:
buffer
char *

variable_types:
buflen
unsigned long

variable_types: sock int

variable_types:
kGoogleDnsIp
char *

variable_types:
kDnsPort
unsigned short

variable_types: err int

variable_types:
namelen
unsigned int


decompiled_code:
__int64 __fastcall hostname_to_ip(const char *a1, char *a2)
{
int v2; // eax
unsigned int v3; // er12
struct addrinfo *i; // rbx
char *v5; // rax
const char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(a1, "http", &req, &pai);
v3 = v2;
if ( v2 )
{
v7 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v7);
v3 = 1;
}
else
{
for ( i = pai; i; i = i->ai_next )
{
v5 = inet_ntoa(*(struct in_addr *)&i->ai_addr->sa_data[2]);
strcpy(a2, v5);
}
freeaddrinfo(pai);
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, char *a2)
{
int v2; // eax
unsigned int v3; // er12
struct addrinfo *i; // rbx
char *v5; // rax
const char *v7; // rax
struct addrinfo *pai; // [rsp+8h] [rbp-50h] BYREF
struct addrinfo req; // [rsp+10h] [rbp-48h] BYREF

*(_QWORD *)&req.ai_flags = 0LL;
*(_QWORD *)&req.ai_socktype = 1LL;
*(_QWORD *)&req.ai_addrlen = 0LL;
req.ai_addr = 0LL;
req.ai_canonname = 0LL;
req.ai_next = 0LL;
v2 = getaddrinfo(a1, "http", &req, &pai);
v3 = v2;
if ( v2 )
{
v7 = gai_strerror(v2);
fprintf(stderr, "getaddrinfo: %s\n", v7);
v3 = 1;
}
else
{
for ( i = pai; i; i = i->ai_next )
{
v5 = inet_ntoa(*(struct in_addr *)&i->ai_addr->sa_data[2]);
strcpy(a2, v5);
}
freeaddrinfo(pai);
}
return v3;
}

original_code:
int hostname_to_ip(char *hostname , char *ip)
{
 int sockfd;
 struct addrinfo hints, *servinfo, *p;
 struct sockaddr_in *h;
 int rv;
 memset(&hints, 0, sizeof hints);
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 if ( (rv = getaddrinfo( hostname , "http" , &hints , &servinfo)) != 0)
 {
  fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
  return 1;
 }
 for(p = servinfo; p != ((void *)0); p = p->ai_next)
 {
  h = (struct sockaddr_in *) p->ai_addr;
  strcpy(ip , inet_ntoa( h->sin_addr ) );
 }
 freeaddrinfo(servinfo);
 return 0;
}

canonical_original_code:
int hostname_to_ip(char *hostname, char *ip)
{
 int sockfd;
 struct addrinfo hints; struct addrinfo *servinfo; struct addrinfo *p;
 struct sockaddr_in *h;
 int rv;
 memset(&hints, 0, sizeof hints);
 hints.ai_family = 0;
 hints.ai_socktype = SOCK_STREAM;
 if ( (rv = getaddrinfo( hostname , "http" , &hints , &servinfo)) != 0)
 {
  fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv));
  return 1;
 }
 for(p = servinfo; p != ((void *)0); p = p->ai_next)
 {
  h = (struct sockaddr_in *) p->ai_addr;
  strcpy(ip , inet_ntoa( h->sin_addr ) );
 }
 freeaddrinfo(servinfo);
 return 0;
}

variable_types:
hostname
char *

variable_types:
ip
char *

variable_types: sockfd int

variable_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr { unsigned short sa_family; char sa_data[14]; } *ai_addr; char *ai_canonname; struct addrinfo *ai_next; } *

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

variable_types: rv int

user_defined_types: struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; unsigned int ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }


readFromXML

decompiled_code:
char *__fastcall readFromXML(int a1)
{
char *v1; // rbp
char *result; // rax

v1 = (char *)malloc(a1 + 1);
result = strncpy(v1, (const char *)xmlArray + chrPtr - (__int64)a1, a1);
v1[a1] = 0;
return result;
}

canonical_decompiled_code:
char *__fastcall func1(int a1)
{
char *v1; // rbp
char *result; // rax

v1 = (char *)malloc(a1 + 1);
result = strncpy(v1, (const char *)xmlArray + chrPtr - (__int64)a1, a1);
v1[a1] = 0;
return result;
}

original_code:
char *readFromXML(int length)
{
  char *field = (char*)malloc((length + 1)* sizeof(char));
  strncpy(field, (xmlArray + chrPtr) - length, length);
  field[length] = '\0';
  return field;
}

variable_types: length int

variable_types:
field
char *


clearWhiteSpace

decompiled_code:
__int64 clearWhiteSpace()
{
__int64 result; // rax
char v1; // dl

result = (unsigned int)chrPtr;
v1 = *((_BYTE *)xmlArray + chrPtr);
if ( (unsigned __int8)(v1 - 9) <= 1u || v1 == 32 )
{
result = chrPtr + 1;
while ( v1 )
{
chrPtr = result;
v1 = *((_BYTE *)xmlArray + result++);
if ( (unsigned __int8)(v1 - 9) > 1u && v1 != 32 )
break;
}
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 result; // rax
char v1; // dl

result = (unsigned int)chrPtr;
v1 = *((_BYTE *)xmlArray + chrPtr);
if ( (unsigned __int8)(v1 - 9) <= 1u || v1 == 32 )
{
result = chrPtr + 1;
while ( v1 )
{
chrPtr = result;
v1 = *((_BYTE *)xmlArray + result++);
if ( (unsigned __int8)(v1 - 9) > 1u && v1 != 32 )
break;
}
}
return result;
}

original_code:
void clearWhiteSpace()
{
  while((xmlArray[chrPtr] == ' ' || xmlArray[chrPtr] == '\t' || xmlArray[chrPtr] == '\n') && xmlArray[chrPtr] != '\0')
  {
    chrPtr++;
  }
}


moveToChar

decompiled_code:
__int64 __fastcall moveToChar(char a1)
{
__int64 result; // rax
char v2; // dl
char v3; // dl

result = (unsigned int)chrPtr;
v2 = *((_BYTE *)xmlArray + chrPtr);
if ( v2 && v2 != a1 )
{
result = chrPtr + 1;
do
{
chrPtr = result;
v3 = *((_BYTE *)xmlArray + result++);
}
while ( v3 && v3 != a1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(char a1)
{
__int64 result; // rax
char v2; // dl
char v3; // dl

result = (unsigned int)chrPtr;
v2 = *((_BYTE *)xmlArray + chrPtr);
if ( v2 && v2 != a1 )
{
result = chrPtr + 1;
do
{
chrPtr = result;
v3 = *((_BYTE *)xmlArray + result++);
}
while ( v3 && v3 != a1 );
}
return result;
}

original_code:
void moveToChar(char target)
{
  while(xmlArray[chrPtr] != target && xmlArray[chrPtr] != '\0')
  {
    chrPtr++;
  }
}

variable_types: target char


getName

decompiled_code:
char *getName()
{
char v0; // dl
__int64 v1; // rax
int v2; // edi
char v3; // dl

clearWhiteSpace();
v0 = *((_BYTE *)xmlArray + chrPtr);
if ( v0 == 62 || v0 == 32 )
{
v2 = 0;
}
else
{
v1 = chrPtr + 1;
v2 = 0;
do
{
++v2;
chrPtr = v1;
v3 = *((_BYTE *)xmlArray + v1++);
}
while ( v3 != 62 && v3 != 32 );
}
return readFromXML(v2);
}

canonical_decompiled_code:
char *func4()
{
char v0; // dl
__int64 v1; // rax
int v2; // edi
char v3; // dl

func2();
v0 = *((_BYTE *)xmlArray + chrPtr);
if ( v0 == 62 || v0 == 32 )
{
v2 = 0;
}
else
{
v1 = chrPtr + 1;
v2 = 0;
do
{
++v2;
chrPtr = v1;
v3 = *((_BYTE *)xmlArray + v1++);
}
while ( v3 != 62 && v3 != 32 );
}
return func1(v2);
}

original_code:
char* getName()
{
  clearWhiteSpace();
  int nameLength = 0;
  while(xmlArray[chrPtr] != '>' && xmlArray[chrPtr] != ' ')
  {
    nameLength++;
    chrPtr++;
  }
  char* returnValue = readFromXML(nameLength);
  return returnValue;
}

canonical_original_code:
char *getName()
{
  clearWhiteSpace();
  int nameLength = 0;
  while(xmlArray[chrPtr] != '>' && xmlArray[chrPtr] != ' ')
  {
    nameLength++;
    chrPtr++;
  }
  char *returnValue = readFromXML(nameLength);
  return returnValue;
}

variable_types: nameLength int

variable_types:
returnValue
char *


getAttributes

decompiled_code:
__int64 __fastcall getAttributes(__int64 a1)
{
_BYTE *v2; // rcx
__int64 result; // rax
int v4; // edi
int v5; // edi
char *v6; // r12
int v7; // edx
__int64 v8; // rax
int v9; // edx
char *v10; // r13
char v11; // dl
__int64 v12; // rax
char v13; // dl

clearWhiteSpace();
v2 = xmlArray;
for ( result = chrPtr; *((_BYTE *)xmlArray + chrPtr) != 62; result = chrPtr )
{
v11 = v2[chrPtr];
if ( v11 == 32 || (v12 = chrPtr + 1, v5 = 0, v11 == 61) )
{
v5 = 0;
}
else
{
do
{
chrPtr = v12;
++v5;
v13 = v2[v12++];
}
while ( v13 != 32 && v13 != 61 );
}
v6 = readFromXML(v5);
moveToChar(61);
moveToChar(34);
v7 = chrPtr++;
if ( *((_BYTE *)xmlArray + chrPtr) == 34 )
{
v4 = 0;
}
else
{
v8 = v7 + 2;
v9 = ~v7;
do
{
chrPtr = v8;
v4 = v9 + v8++;
}
while ( *((char *)xmlArray + v8 - 1) != 34 );
}
v10 = readFromXML(v4);
xmlAddAttribute(a1, v6, v10);
free(v6);
free(v10);
++chrPtr;
clearWhiteSpace();
v2 = xmlArray;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_BYTE *v2; // rcx
__int64 result; // rax
int v4; // edi
int v5; // edi
char *v6; // r12
int v7; // edx
__int64 v8; // rax
int v9; // edx
char *v10; // r13
char v11; // dl
__int64 v12; // rax
char v13; // dl

func2();
v2 = xmlArray;
for ( result = chrPtr; *((_BYTE *)xmlArray + chrPtr) != 62; result = chrPtr )
{
v11 = v2[chrPtr];
if ( v11 == 32 || (v12 = chrPtr + 1, v5 = 0, v11 == 61) )
{
v5 = 0;
}
else
{
do
{
chrPtr = v12;
++v5;
v13 = v2[v12++];
}
while ( v13 != 32 && v13 != 61 );
}
v6 = func1(v5);
func3(61);
func3(34);
v7 = chrPtr++;
if ( *((_BYTE *)xmlArray + chrPtr) == 34 )
{
v4 = 0;
}
else
{
v8 = v7 + 2;
v9 = ~v7;
do
{
chrPtr = v8;
v4 = v9 + v8++;
}
while ( *((char *)xmlArray + v8 - 1) != 34 );
}
v10 = func1(v4);
xmlAddAttribute(a1, v6, v10);
free(v6);
free(v10);
++chrPtr;
func2();
v2 = xmlArray;
}
return result;
}

original_code:
void getAttributes(XMLNode *xmlNode)
{
  clearWhiteSpace();
  while(xmlArray[chrPtr] != '>')
  {
    int textLength = 0;
    while(xmlArray[chrPtr] != ' ' && xmlArray[chrPtr] != '=')
    {
      chrPtr++;
      textLength++;
    }
    char* attribute = readFromXML(textLength);
    moveToChar('=');
    moveToChar('"');
    chrPtr++;
    textLength =0;
    while(xmlArray[chrPtr] != '"')
    {
      chrPtr++;
      textLength++;
    }
    char * value = readFromXML(textLength);
    xmlAddAttribute(xmlNode, attribute, value);
    free(attribute);
    free(value);
    chrPtr++;
    clearWhiteSpace();
  }
}

canonical_original_code:
void getAttributes(struct XMLNode_item *xmlNode)
{
  clearWhiteSpace();
  while(xmlArray[chrPtr] != '>')
  {
    int textLength = 0;
    while(xmlArray[chrPtr] != ' ' && xmlArray[chrPtr] != '=')
    {
      chrPtr++;
      textLength++;
    }
    char *attribute = readFromXML(textLength);
    moveToChar('=');
    moveToChar('"');
    chrPtr++;
    textLength =0;
    while(xmlArray[chrPtr] != '"')
    {
      chrPtr++;
      textLength++;
    }
    char *value = readFromXML(textLength);
    xmlAddAttribute(xmlNode, attribute, value);
    free(attribute);
    free(value);
    chrPtr++;
    clearWhiteSpace();
  }
}

variable_types: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item { char *Name; char *Value; } **Attributes; } *

variable_types: textLength int

variable_types:
attribute
char *

variable_types:
value
char *

user_defined_types: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item **Attributes; }


getDeclerationValue

decompiled_code:
char *getDeclerationValue()
{
char v0; // dl
__int64 v1; // rax
int v2; // er8
int v3; // edi
char v4; // dl

clearWhiteSpace();
v0 = *((_BYTE *)xmlArray + chrPtr);
if ( v0 == 32 || v0 == 63 )
{
v3 = 0;
}
else
{
v1 = chrPtr + 1;
v2 = 0;
v3 = 0;
do
{
while ( 1 )
{
++v3;
chrPtr = v1;
v4 = *((_BYTE *)xmlArray + v1);
if ( v4 != 34 )
break;
v2 ^= 1u;
++v1;
}
++v1;
}
while ( v4 != 63 && v4 != 32 || v2 );
}
return readFromXML(v3);
}

original_code:
char* getDeclerationValue()
{
  clearWhiteSpace();
  int length = 0;
  int insideQuotation = 0;
  while((xmlArray[chrPtr] != ' ' && xmlArray[chrPtr] != '?') || insideQuotation == 1)
  {
    length++;
    chrPtr++;
    if(xmlArray[chrPtr] == '"')
    {
      if(insideQuotation == 1)
      {
        insideQuotation = 0;
      }
      else
      {
        insideQuotation = 1;
      }
    }
  }
  char *declerationvalue = readFromXML(length);
  return declerationvalue;
}

canonical_original_code:
char *getDeclerationValue()
{
  clearWhiteSpace();
  int length = 0;
  int insideQuotation = 0;
  while((xmlArray[chrPtr] != ' ' && xmlArray[chrPtr] != '?') || insideQuotation == 1)
  {
    length++;
    chrPtr++;
    if(xmlArray[chrPtr] == '"')
    {
      if(insideQuotation == 1)
      {
        insideQuotation = 0;
      }
      else
      {
        insideQuotation = 1;
      }
    }
  }
  char *declerationvalue = readFromXML(length);
  return declerationvalue;
}

variable_types: insideQuotation int

variable_types:
declerationvalue
char *


getTextValue

decompiled_code:
char *getTextValue()
{
__int64 v0; // rax
int v1; // edi

if ( *((_BYTE *)xmlArray + chrPtr) == 60 )
{
v1 = 0;
}
else
{
v0 = chrPtr + 1;
v1 = 0;
do
{
++v1;
chrPtr = v0++;
}
while ( *((char *)xmlArray + v0 - 1) != 60 );
}
return readFromXML(v1);
}

canonical_decompiled_code:
char *func7()
{
__int64 v0; // rax
int v1; // edi

if ( *((_BYTE *)xmlArray + chrPtr) == 60 )
{
v1 = 0;
}
else
{
v0 = chrPtr + 1;
v1 = 0;
do
{
++v1;
chrPtr = v0++;
}
while ( *((char *)xmlArray + v0 - 1) != 60 );
}
return func1(v1);
}

original_code:
char* getTextValue()
{
  int textLength = 0;
  while(xmlArray[chrPtr] != '<')
  {
    textLength++;
    chrPtr++;
  }
  char *textValue = readFromXML(textLength);
  return textValue;
}

canonical_original_code:
char *getTextValue()
{
  int textLength = 0;
  while(xmlArray[chrPtr] != '<')
  {
    textLength++;
    chrPtr++;
  }
  char *textValue = readFromXML(textLength);
  return textValue;
}

variable_types:
textValue
char *


readXMLDeclerationNode

decompiled_code:
__int64 readXMLDeclerationNode()
{
char *v0; // rbp
char *v1; // rbx
__int64 v2; // r12

v0 = getName();
v1 = getDeclerationValue();
v2 = xmlCreateNode("XmlDecleration", v0, v1);
free(v0);
free(v1);
return v2;
}

canonical_decompiled_code:
__int64 func8()
{
char *v0; // rbp
char *v1; // rbx
__int64 v2; // r12

v0 = func4();
v1 = func6();
v2 = xmlCreateNode("XmlDecleration", v0, v1);
free(v0);
free(v1);
return v2;
}

original_code:
XMLNode *readXMLDeclerationNode()
{
  char* name = getName();
  char* value = getDeclerationValue();
  XMLNode* newNode = xmlCreateNode("XmlDecleration", name, value);
  free(name);
  free(value);
  return newNode;
}

canonical_original_code:
struct XMLNode_item *readXMLDeclerationNode()
{
  char *name = getName();
  char *value = getDeclerationValue();
  struct XMLNode_item *newNode = xmlCreateNode("XmlDecleration", name, value);
  free(name);
  free(value);
  return newNode;
}

variable_types:
name
char *

return_type: struct XMLNode_item { char *Name; char *NodeType; char *Value; int ChildrenCount; int ChildrenArraySize; int AttributesCount; int AttributesArraySize; struct XMLNode_item **ChildNodes; struct Attribute_item { char *Name; char *Value; } **Attributes; } *


readXMLElementNode

decompiled_code:
__int64 readXMLElementNode()
{
char *v0; // rbx
__int64 v1; // rbp

v0 = getName();
v1 = xmlCreateNode("Element", v0, 0LL);
free(v0);
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
char *v0; // rbx
__int64 v1; // rbp

v0 = func4();
v1 = xmlCreateNode("Element", v0, 0LL);
free(v0);
return v1;
}

original_code:
XMLNode *readXMLElementNode()
{
  char* name = getName();
  XMLNode* newNode = xmlCreateNode("Element", name, ((void *)0));
  free(name);
  return newNode;
}

canonical_original_code:
struct XMLNode_item *readXMLElementNode()
{
  char *name = getName();
  struct XMLNode_item *newNode = xmlCreateNode("Element", name, ((void *)0));
  free(name);
  return newNode;
}

user_defined_types: struct Attribute_item { char *Name; char *Value; }


readXMLTextNode

decompiled_code:
__int64 readXMLTextNode()
{
char *v0; // rbx
__int64 v1; // rbp

v0 = getTextValue();
v1 = xmlCreateNode("Text", "#text", v0);
free(v0);
return v1;
}

canonical_decompiled_code:
__int64 func10()
{
char *v0; // rbx
__int64 v1; // rbp

v0 = func7();
v1 = xmlCreateNode("Text", "#text", v0);
free(v0);
return v1;
}

original_code:
XMLNode *readXMLTextNode()
{
  char* textValue = getTextValue();
  XMLNode* newNode = xmlCreateNode("Text", "#text", textValue);
  free(textValue);
  return newNode;
}

canonical_original_code:
struct XMLNode_item *readXMLTextNode()
{
  char *textValue = getTextValue();
  struct XMLNode_item *newNode = xmlCreateNode("Text", "#text", textValue);
  free(textValue);
  return newNode;
}