decompiled_code:
unsigned __int64 __fastcall rb_Digest_MD5_Finish(int *a1, __int64 a2)
{
unsigned __int64 i; // rax
unsigned __int64 result; // rax
__m128i v4; // [rsp+8h] [rbp-20h] BYREF

for ( i = 0LL; i != 8; ++i )
v4.m128i_i8[i] = (unsigned int)a1[i >> 2] >> ((8 * i) & 0x18);
rb_Digest_MD5_Update(a1, pad_0, ((55 - (unsigned __int8)((unsigned int)*a1 >> 3)) & 0x3F) + 1LL);
rb_Digest_MD5_Update(a1, &v4, 8uLL);
for ( result = 0LL; result != 16; ++result )
*(_BYTE *)(a2 + result) = (unsigned int)a1[(result >> 2) + 2] >> ((8 * result) & 0x18);
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func3(int *a1, __int64 a2)
{
unsigned __int64 i; // rax
unsigned __int64 result; // rax
__m128i v4; // [rsp+8h] [rbp-20h] BYREF

for ( i = 0LL; i != 8; ++i )
v4.m128i_i8[i] = (unsigned int)a1[i >> 2] >> ((8 * i) & 0x18);
func2(a1, pad_0, ((55 - (unsigned __int8)((unsigned int)*a1 >> 3)) & 0x3F) + 1LL);
func2(a1, &v4, 8uLL);
for ( result = 0LL; result != 16; ++result )
*(_BYTE *)(a2 + result) = (unsigned int)a1[(result >> 2) + 2] >> ((8 * result) & 0x18);
return result;
}

variable_types:
digest
unsigned char *

variable_types:
pad
unsigned char [64]

variable_types:
data
unsigned char [8]

variable_types:
i
unsigned long

user_defined_types: struct md5_state_s { unsigned int count[2]; unsigned int state[4]; unsigned char buffer[64]; }


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

if ( (a1 & 3) != 0 )
{
result = 21LL;
if ( (a1 & 1) == 0 )
{
if ( a1 == 2 )
{
result = 18LL;
}
else if ( (_BYTE)a1 == 14 )
{
result = 20LL;
}
else
{
if ( a1 != 6 )
return *(_QWORD *)a1 & 0x1FLL;
result = 27LL;
}
}
}
else
{
if ( (a1 & 0xFFFFFFFFFFFFFFFBLL) != 0 )
return *(_QWORD *)a1 & 0x1FLL;
if ( a1 == 4 )
{
result = 17LL;
}
else
{
result = 19LL;
if ( a1 )
return *(_QWORD *)a1 & 0x1FLL;
}
}
return result;
}

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

if ( (a1 & 3) != 0 )
{
result = 21LL;
if ( (a1 & 1) == 0 )
{
if ( a1 == 2 )
{
result = 18LL;
}
else if ( (_BYTE)a1 == 14 )
{
result = 20LL;
}
else
{
if ( a1 != 6 )
return *(_QWORD *)a1 & 0x1FLL;
result = 27LL;
}
}
}
else
{
if ( (a1 & 0xFFFFFFFFFFFFFFFBLL) != 0 )
return *(_QWORD *)a1 & 0x1FLL;
if ( a1 == 4 )
{
result = 17LL;
}
else
{
result = 19LL;
if ( a1 )
return *(_QWORD *)a1 & 0x1FLL;
}
}
return result;
}

original_code:
static inline int
rb_type(VALUE obj)
{
    if (((VALUE)(obj) & RUBY_IMMEDIATE_MASK)) {
 if ((((long)(obj))&RUBY_FIXNUM_FLAG)) return RUBY_T_FIXNUM;
 if (obj == ((VALUE)RUBY_Qtrue)) return RUBY_T_TRUE;
 if ((((VALUE)(obj)&~(~(VALUE)0<<RUBY_SPECIAL_SHIFT))==RUBY_SYMBOL_FLAG)) return RUBY_T_SYMBOL;
 if (obj == ((VALUE)RUBY_Qundef)) return RUBY_T_UNDEF;
    }
    else if (!(((VALUE)(obj) & ~((VALUE)RUBY_Qnil)) != 0)) {
 if (obj == ((VALUE)RUBY_Qnil)) return RUBY_T_NIL;
 if (obj == ((VALUE)RUBY_Qfalse)) return RUBY_T_FALSE;
    }
    return (((struct RBasic*)(obj))->flags & RUBY_T_MASK);
}

canonical_original_code:
static inline int rb_type(unsigned long obj)
{
    if (((VALUE)(obj) & RUBY_IMMEDIATE_MASK)) {
 if ((((long)(obj))&RUBY_FIXNUM_FLAG)) return RUBY_T_FIXNUM;
 if (obj == ((unsigned long)RUBY_Qtrue)) return RUBY_T_TRUE;
 if ((((VALUE)(obj)&~(~(unsigned long)0<<RUBY_SPECIAL_SHIFT))==RUBY_SYMBOL_FLAG)) return RUBY_T_SYMBOL;
 if (obj == ((unsigned long)RUBY_Qundef)) return RUBY_T_UNDEF;
    }
    else if (!(((VALUE)(obj) & ~((unsigned long)RUBY_Qnil)) != 0)) {
 if (obj == ((unsigned long)RUBY_Qnil)) return RUBY_T_NIL;
 if (obj == ((unsigned long)RUBY_Qfalse)) return RUBY_T_FALSE;
    }
    return (((struct RBasic *)(obj))->flags & RUBY_T_MASK);
}

variable_types:
obj
unsigned long

return_type: int

user_defined_types: struct RBasic { unsigned long flags; unsigned long klass; }


repo: masak/git-learning

decompiled_code:
__int64 __fastcall verify_path(char *a1)
{
char v1; // al
_BYTE *v2; // rdi
_BYTE *v3; // rdx
char v4; // al

v1 = *a1;
if ( (unsigned __int8)(*a1 - 46) <= 1u )
return 0LL;
v2 = a1 + 1;
if ( !v1 )
return 0LL;
while ( 1 )
{
v3 = v2++;
v4 = *(v2 - 1);
if ( !v4 )
break;
if ( v4 == 47 )
{
if ( (unsigned __int8)(*v2 - 46) <= 1u || !*v2 )
return 0LL;
v2 = v3 + 2;
}
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
char v1; // al
_BYTE *v2; // rdi
_BYTE *v3; // rdx
char v4; // al

v1 = *a1;
if ( (unsigned __int8)(*a1 - 46) <= 1u )
return 0LL;
v2 = a1 + 1;
if ( !v1 )
return 0LL;
while ( 1 )
{
v3 = v2++;
v4 = *(v2 - 1);
if ( !v4 )
break;
if ( v4 == 47 )
{
if ( (unsigned __int8)(*v2 - 46) <= 1u || !*v2 )
return 0LL;
v2 = v3 + 2;
}
}
return 1LL;
}

original_code:
static int verify_path(char *path)
{
 char c;
 goto inside;
 for (;;) {
  if (!c)
   return 1;
  if (c == '/') {
inside:
   c = *path++;
   if (c != '/' && c != '.' && c != '\0')
    continue;
   return 0;
  }
  c = *path++;
 }
}

variable_types:
path
char *

variable_types: c char


decompiled_code:
__int64 __fastcall cache_name_compare(const void *a1, signed int a2, const void *a3, signed int a4)
{
size_t v7; // rdx
unsigned int v8; // edx

v7 = (unsigned int)a2;
if ( a4 <= a2 )
v7 = (unsigned int)a4;
v8 = memcmp(a1, a3, v7);
if ( !v8 )
{
if ( a4 > a2 )
v8 = -1;
else
v8 = a4 < a2;
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func1(const void *a1, signed int a2, const void *a3, signed int a4)
{
size_t v7; // rdx
unsigned int v8; // edx

v7 = (unsigned int)a2;
if ( a4 <= a2 )
v7 = (unsigned int)a4;
v8 = memcmp(a1, a3, v7);
if ( !v8 )
{
if ( a4 > a2 )
v8 = -1;
else
v8 = a4 < a2;
}
return v8;
}

original_code:
static int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
{
 int len = len1 < len2 ? len1 : len2;
 int cmp;
 cmp = memcmp(name1, name2, len);
 if (cmp)
  return cmp;
 if (len1 < len2)
  return -1;
 if (len1 > len2)
  return 1;
 return 0;
}

canonical_original_code:
static int cache_name_compare(char *name1, int len1, char *name2, int len2)
{
 int len = len1 < len2 ? len1 : len2;
 int cmp;
 cmp = memcmp(name1, name2, len);
 if (cmp)
  return cmp;
 if (len1 < len2)
  return -1;
 if (len1 > len2)
  return 1;
 return 0;
}

variable_types: len int

variable_types: cmp int


decompiled_code:
__int64 __fastcall cache_name_pos(const void *a1, signed int a2)
{
int v2; // er12
_QWORD *v3; // r15
int v4; // ebp
int v6; // ebx
int v7; // eax

v2 = active_nr;
v3 = active_cache;
v4 = 0;
while ( v2 > v4 )
{
v6 = (v2 + v4) >> 1;
v7 = cache_name_compare(a1, a2, (const void *)(v3[v6] + 62LL), *(unsigned __int16 *)(v3[v6] + 60LL));
if ( !v7 )
return (unsigned int)~v6;
if ( v7 < 0 )
v2 = (v2 + v4) >> 1;
else
v4 = v6 + 1;
}
return (unsigned int)v4;
}

canonical_decompiled_code:
__int64 __fastcall func2(const void *a1, signed int a2)
{
int v2; // er12
_QWORD *v3; // r15
int v4; // ebp
int v6; // ebx
int v7; // eax

v2 = active_nr;
v3 = active_cache;
v4 = 0;
while ( v2 > v4 )
{
v6 = (v2 + v4) >> 1;
v7 = func1(a1, a2, (const void *)(v3[v6] + 62LL), *(unsigned __int16 *)(v3[v6] + 60LL));
if ( !v7 )
return (unsigned int)~v6;
if ( v7 < 0 )
v2 = (v2 + v4) >> 1;
else
v4 = v6 + 1;
}
return (unsigned int)v4;
}

original_code:
static int cache_name_pos(const char *name, int namelen)
{
 int first, last;
 first = 0;
 last = active_nr;
 while (last > first) {
  int next = (last + first) >> 1;
  struct cache_entry *ce = active_cache[next];
  int cmp = cache_name_compare(name, namelen, ce->name, ce->namelen);
  if (!cmp)
   return -next-1;
  if (cmp < 0) {
   last = next;
   continue;
  }
  first = next+1;
 }
 return first;
}

canonical_original_code:
static int cache_name_pos(char *name, int namelen)
{
 int first; int last;
 first = 0;
 last = active_nr;
 while (last > first) {
  int next = (last + first) >> 1;
  struct cache_entry *ce = active_cache[next];
  int cmp = cache_name_compare(name, namelen, ce->name, ce->namelen);
  if (!cmp)
   return -next-1;
  if (cmp < 0) {
   last = next;
   continue;
  }
  first = next+1;
 }
 return first;
}

variable_types:
name
char *

variable_types: namelen int

variable_types: first int

variable_types: last int

variable_types: next int

variable_types: struct cache_entry { struct cache_time { unsigned int sec; unsigned int nsec; } ctime; struct cache_time mtime; unsigned int st_dev; unsigned int st_ino; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; unsigned int st_size; unsigned char sha1[20]; unsigned short namelen; unsigned char name[]; } *

user_defined_types: struct cache_entry { struct cache_time ctime; struct cache_time mtime; unsigned int st_dev; unsigned int st_ino; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; unsigned int st_size; unsigned char sha1[20]; unsigned short namelen; unsigned char name[]; }


decompiled_code:
__int64 __fastcall remove_file_from_cache(const char *a1)
{
signed int v1; // eax
__int64 result; // rax
int v3; // edx

v1 = strlen(a1);
result = cache_name_pos(a1, v1);
if ( (int)result < 0 )
{
result = (unsigned int)~(_DWORD)result;
v3 = active_nr--;
if ( active_nr > (unsigned int)result )
result = (__int64)memmove(
(char *)active_cache + 8 * (int)result,
(char *)active_cache + 8 * (int)result + 8,
8LL * (unsigned int)(v3 - 2 - result));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
signed int v1; // eax
__int64 result; // rax
int v3; // edx

v1 = strlen(a1);
result = func2(a1, v1);
if ( (int)result < 0 )
{
result = (unsigned int)~(_DWORD)result;
v3 = active_nr--;
if ( active_nr > (unsigned int)result )
result = (__int64)memmove(
(char *)active_cache + 8 * (int)result,
(char *)active_cache + 8 * (int)result + 8,
8LL * (unsigned int)(v3 - 2 - result));
}
return result;
}

original_code:
static int remove_file_from_cache(char *path)
{
 int pos = cache_name_pos(path, strlen(path));
 if (pos < 0) {
  pos = -pos-1;
  active_nr--;
  if (pos < active_nr)
   memmove(active_cache + pos, active_cache + pos + 1, (active_nr - pos - 1) * sizeof(struct cache_entry *));
 }
}

variable_types: pos int

user_defined_types: struct cache_time { unsigned int sec; unsigned int nsec; }


decompiled_code:
__int64 __fastcall add_cache_entry(__int64 a1)
{
int v1; // ebx
int v2; // edx

v1 = cache_name_pos((const void *)(a1 + 62), *(unsigned __int16 *)(a1 + 60));
if ( v1 < 0 )
{
*((_QWORD *)active_cache - v1 - 1) = a1;
}
else
{
if ( active_nr == active_alloc )
{
active_alloc = (unsigned int)(3 * active_alloc + 48) >> 1;
active_cache = realloc(active_cache, 8LL * (unsigned int)active_alloc);
}
v2 = active_nr++;
if ( active_nr > (unsigned int)v1 )
memmove((char *)active_cache + 8 * v1 + 8, (char *)active_cache + 8 * v1, 8LL * (unsigned int)(v2 - v1));
*((_QWORD *)active_cache + v1) = a1;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // ebx
int v2; // edx

v1 = func2((const void *)(a1 + 62), *(unsigned __int16 *)(a1 + 60));
if ( v1 < 0 )
{
*((_QWORD *)active_cache - v1 - 1) = a1;
}
else
{
if ( active_nr == active_alloc )
{
active_alloc = (unsigned int)(3 * active_alloc + 48) >> 1;
active_cache = realloc(active_cache, 8LL * (unsigned int)active_alloc);
}
v2 = active_nr++;
if ( active_nr > (unsigned int)v1 )
memmove((char *)active_cache + 8 * v1 + 8, (char *)active_cache + 8 * v1, 8LL * (unsigned int)(v2 - v1));
*((_QWORD *)active_cache + v1) = a1;
}
return 0LL;
}

original_code:
static int add_cache_entry(struct cache_entry *ce)
{
 int pos;
 pos = cache_name_pos(ce->name, ce->namelen);
 if (pos < 0) {
  active_cache[-pos-1] = ce;
  return 0;
 }
 if (active_nr == active_alloc) {
  active_alloc = (((active_alloc)+16)*3/2);
  active_cache = realloc(active_cache, active_alloc * sizeof(struct cache_entry *));
 }
 active_nr++;
 if (active_nr > pos)
  memmove(active_cache + pos + 1, active_cache + pos, (active_nr - pos - 1) * sizeof(ce));
 active_cache[pos] = ce;
 return 0;
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
char **i; // rbx
int result; // eax
char *v6; // rbp

if ( (int)read_cache(argc, argv, envp) < 0 )
{
perror("cache corrupted");
result = -1;
}
else
{
v3 = open(".dircache/index.lock", 194, 384LL);
if ( v3 < 0 )
{
perror("unable to create new cachefile");
result = -1;
}
else
{
if ( argc > 1 )
{
for ( i = (char **)(argv + 1); i != (char **)&argv[(unsigned int)(argc - 2) + 2]; ++i )
{
v6 = *i;
if ( (unsigned int)verify_path(*i) )
{
if ( (unsigned int)add_file_to_cache(v6) )
{
fprintf(stderr, "Unable to add %s to database\n", v6);
goto LABEL_13;
}
}
else
{
fprintf(stderr, "Ignoring path %s\n", v6);
}
}
}
if ( (unsigned int)write_cache(v3, active_cache, active_nr)
|| (result = rename(".dircache/index.lock", ".dircache/index")) != 0 )
{
LABEL_13:
unlink(".dircache/index.lock");
result = 0;
}
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er13
char **i; // rbx
int result; // eax
char *v6; // rbp

if ( (int)read_cache(argc, argv, envp) < 0 )
{
perror("cache corrupted");
result = -1;
}
else
{
v3 = open(".dircache/index.lock", 194, 384LL);
if ( v3 < 0 )
{
perror("unable to create new cachefile");
result = -1;
}
else
{
if ( argc > 1 )
{
for ( i = (char **)(argv + 1); i != (char **)&argv[(unsigned int)(argc - 2) + 2]; ++i )
{
v6 = *i;
if ( (unsigned int)func0(*i) )
{
if ( (unsigned int)func6(v6) )
{
fprintf(stderr, "Unable to add %s to database\n", v6);
goto LABEL_13;
}
}
else
{
fprintf(stderr, "Ignoring path %s\n", v6);
}
}
}
if ( (unsigned int)func7(v3, active_cache, active_nr)
|| (result = rename(".dircache/index.lock", ".dircache/index")) != 0 )
{
LABEL_13:
unlink(".dircache/index.lock");
result = 0;
}
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
 int i, newfd, entries;
 entries = read_cache();
 if (entries < 0) {
  perror("cache corrupted");
  return -1;
 }
 newfd = open(".dircache/index.lock", 02 | 0100 | 0200, 0600);
 if (newfd < 0) {
  perror("unable to create new cachefile");
  return -1;
 }
 for (i = 1 ; i < argc; i++) {
  char *path = argv[i];
  if (!verify_path(path)) {
   fprintf(stderr, "Ignoring path %s\n", argv[i]);
   continue;
  }
  if (add_file_to_cache(path)) {
   fprintf(stderr, "Unable to add %s to database\n", path);
   goto out;
  }
 }
 if (!write_cache(newfd, active_cache, active_nr) && !rename(".dircache/index.lock", ".dircache/index"))
  return 0;
out:
 unlink(".dircache/index.lock");
}

canonical_original_code:
int main(int argc, char **argv)
{
 int i; int newfd; int entries;
 entries = read_cache();
 if (entries < 0) {
  perror("cache corrupted");
  return -1;
 }
 newfd = open(".dircache/index.lock", 02 | 0100 | 0200, 0600);
 if (newfd < 0) {
  perror("unable to create new cachefile");
  return -1;
 }
 for (i = 1 ; i < argc; i++) {
  char *path = argv[i];
  if (!verify_path(path)) {
   fprintf(stderr, "Ignoring path %s\n", argv[i]);
   continue;
  }
  if (add_file_to_cache(path)) {
   fprintf(stderr, "Unable to add %s to database\n", path);
   goto out;
  }
 }
 if (!write_cache(newfd, active_cache, active_nr) && !rename(".dircache/index.lock", ".dircache/index"))
  return 0;
out:
 unlink(".dircache/index.lock");
}

variable_types: argc int

variable_types:
argv
char **

variable_types: i int

variable_types: newfd int

variable_types: entries int


hexval

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

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 97) <= 5u )
return (unsigned int)(a1 - 87);
result = (unsigned int)(a1 - 55);
if ( (unsigned __int8)(a1 - 65) >= 6u )
result = 0xFFFFFFFFLL;
return result;
}

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

if ( (unsigned __int8)(a1 - 48) <= 9u )
return (unsigned int)(a1 - 48);
if ( (unsigned __int8)(a1 - 97) <= 5u )
return (unsigned int)(a1 - 87);
result = (unsigned int)(a1 - 55);
if ( (unsigned __int8)(a1 - 65) >= 6u )
result = 0xFFFFFFFFLL;
return result;
}

original_code:
static unsigned hexval(char c)
{
 if (c >= '0' && c <= '9')
  return c - '0';
 if (c >= 'a' && c <= 'f')
  return c - 'a' + 10;
 if (c >= 'A' && c <= 'F')
  return c - 'A' + 10;
 return ~0;
}

canonical_original_code:
static unsigned int hexval(char c)
{
 if (c >= '0' && c <= '9')
  return c - '0';
 if (c >= 'a' && c <= 'f')
  return c - 'a' + 10;
 if (c >= 'A' && c <= 'F')
  return c - 'A' + 10;
 return ~0;
}

return_type: unsigned int


error

decompiled_code:
__int64 __fastcall error(const char *a1)
{
fprintf(stderr, "error: %s\n", a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
fprintf(stderr, "error: %s\n", a1);
return 0xFFFFFFFFLL;
}

original_code:
static int error(const char * string)
{
 fprintf(stderr, "error: %s\n", string);
 return -1;
}

canonical_original_code:
static int error(char *string)
{
 fprintf(stderr, "error: %s\n", string);
 return -1;
}

variable_types:
string
char *


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fprintf(stderr, "read-tree: %s\n", a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
fprintf(stderr, "read-tree: %s\n", a1);
exit(1);
}

original_code:
void usage(const char *err)
{
 fprintf(stderr, "read-tree: %s\n", err);
 exit(1);
}

canonical_original_code:
void usage(char *err)
{
 fprintf(stderr, "read-tree: %s\n", err);
 exit(1);
}

variable_types:
err
char *

return_type: void


decompiled_code:
__int64 __fastcall get_sha1_hex(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
int v3; // ebx
int v4; // eax

v2 = 0LL;
while ( 1 )
{
v3 = hexval(*(_BYTE *)(a1 + 2 * v2));
v4 = hexval(*(_BYTE *)(a1 + 2 * v2 + 1)) | (16 * v3);
if ( (v4 & 0xFFFFFF00) != 0 )
break;
*(_BYTE *)(a2 + v2++) = v4;
if ( v2 == 20 )
return 0LL;
}
return 0xFFFFFFFFLL;
}

original_code:
int get_sha1_hex(char *hex, unsigned char *sha1)
{
 int i;
 for (i = 0; i < 20; i++) {
  unsigned int val = (hexval(hex[0]) << 4) | hexval(hex[1]);
  if (val & ~0xff)
   return -1;
  *sha1++ = val;
  hex += 2;
 }
 return 0;
}

variable_types:
hex
char *

variable_types:
val
unsigned int


decompiled_code:
__int64 __fastcall write_sha1_buffer(__int64 a1, const void *a2, unsigned int a3)
{
const char *v4; // rax
int v5; // eax
int v6; // ebx

v4 = (const char *)sha1_file_name(a1);
v5 = open(v4, 193, 438LL);
if ( v5 < 0 )
return (unsigned int)-(*_errno_location() != 17);
v6 = v5;
write(v5, a2, a3);
close(v6);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const void *a2, unsigned int a3)
{
const char *v4; // rax
int v5; // eax
int v6; // ebx

v4 = (const char *)func6(a1);
v5 = open(v4, 193, 438LL);
if ( v5 < 0 )
return (unsigned int)-(*_errno_location() != 17);
v6 = v5;
write(v5, a2, a3);
close(v6);
return 0LL;
}

original_code:
int write_sha1_buffer(unsigned char *sha1, void *buf, unsigned int size)
{
 char *filename = sha1_file_name(sha1);
 int i, fd;
 fd = open(filename, 01 | 0100 | 0200, 0666);
 if (fd < 0)
  return ((*__errno_location ()) == 17) ? 0 : -1;
 write(fd, buf, size);
 close(fd);
 return 0;
}

canonical_original_code:
int write_sha1_buffer(unsigned char *sha1, void *buf, unsigned int size)
{
 char *filename = sha1_file_name(sha1);
 int i; int fd;
 fd = open(filename, 01 | 0100 | 0200, 0666);
 if (fd < 0)
  return ((*__errno_location ()) == 17) ? 0 : -1;
 write(fd, buf, size);
 close(fd);
 return 0;
}

variable_types:
buf
void *

variable_types:
size
unsigned int

variable_types:
filename
char *

variable_types: fd int


decompiled_code:
__int64 check_valid_sha1()
{
const char *v0; // rbp
unsigned int v1; // ebx

v0 = (const char *)sha1_file_name();
v1 = access(v0, 4);
if ( v1 )
perror(v0);
return v1;
}

canonical_decompiled_code:
__int64 func1()
{
const char *v0; // rbp
unsigned int v1; // ebx

v0 = (const char *)sha1_file_name();
v1 = access(v0, 4);
if ( v1 )
perror(v0);
return v1;
}

original_code:
static int check_valid_sha1(unsigned char *sha1)
{
 char *filename = sha1_file_name(sha1);
 int ret;
 ret = access(filename, 4);
 if (ret)
  perror(filename);
 return ret;
}

variable_types: ret int


decompiled_code:
__int64 __fastcall match_stat(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 1LL;
if ( a1[2] == a2[22] )
result = a1[3] != a2[24];
if ( *a1 != a2[26] || a1[1] != a2[28] )
result = (unsigned int)result | 2;
if ( a1[7] != a2[7] || a1[8] != a2[8] )
result = (unsigned int)result | 4;
if ( a1[6] != a2[6] )
result = (unsigned int)result | 8;
if ( a1[4] != *a2 || a1[5] != a2[2] )
result = (unsigned int)result | 0x10;
if ( a1[9] != a2[12] )
result = (unsigned int)result | 0x20;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_DWORD *a1, _DWORD *a2)
{
__int64 result; // rax

result = 1LL;
if ( a1[2] == a2[22] )
result = a1[3] != a2[24];
if ( *a1 != a2[26] || a1[1] != a2[28] )
result = (unsigned int)result | 2;
if ( a1[7] != a2[7] || a1[8] != a2[8] )
result = (unsigned int)result | 4;
if ( a1[6] != a2[6] )
result = (unsigned int)result | 8;
if ( a1[4] != *a2 || a1[5] != a2[2] )
result = (unsigned int)result | 0x10;
if ( a1[9] != a2[12] )
result = (unsigned int)result | 0x20;
return result;
}

original_code:
static int match_stat(struct cache_entry *ce, struct stat *st)
{
 unsigned int changed = 0;
 if (ce->mtime.sec != (unsigned int)st->st_mtim.tv_sec ||
     ce->mtime.nsec != (unsigned int)st->st_mtim.tv_nsec)
  changed |= 0x0001;
 if (ce->ctime.sec != (unsigned int)st->st_ctim.tv_sec ||
     ce->ctime.nsec != (unsigned int)st->st_ctim.tv_nsec)
  changed |= 0x0002;
 if (ce->st_uid != (unsigned int)st->st_uid ||
     ce->st_gid != (unsigned int)st->st_gid)
  changed |= 0x0004;
 if (ce->st_mode != (unsigned int)st->st_mode)
  changed |= 0x0008;
 if (ce->st_dev != (unsigned int)st->st_dev ||
     ce->st_ino != (unsigned int)st->st_ino)
  changed |= 0x0010;
 if (ce->st_size != (unsigned int)st->st_size)
  changed |= 0x0020;
 return changed;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *

variable_types:
changed
unsigned int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // r14
__int64 v5; // r13
int *v7; // rax
unsigned int v8; // eax
unsigned __int8 *v9; // rbx
void *v10; // rbx
__int64 v11; // r12
size_t v12; // [rsp+8h] [rbp-E0h] BYREF
char v13[32]; // [rsp+10h] [rbp-D8h] BYREF
struct stat v14; // [rsp+30h] [rbp-B8h] BYREF

v3 = read_cache(argc, argv, envp);
if ( v3 < 0 )
{
perror("read_cache");
exit(1);
}
v4 = 8LL * (unsigned int)v3;
v5 = 0LL;
if ( v3 > 0 )
{
do
{
v11 = *(_QWORD *)(active_cache + v5);
if ( stat((const char *)(v11 + 62), &v14) < 0 )
{
v7 = _errno_location();
v8 = (unsigned int)strerror(*v7);
printf("%s: %s\n", (const char *)(v11 + 62), (const char *)v8);
}
else if ( (unsigned int)match_stat((_DWORD *)v11, &v14) )
{
printf("%.*s: ", *(unsigned __int16 *)(v11 + 60), (const char *)(v11 + 62));
v9 = (unsigned __int8 *)(v11 + 40);
do
printf("%02x", *v9++);
while ( v9 != (unsigned __int8 *)(v11 + 60) );
putchar(10);
v10 = (void *)read_sha1_file(v11 + 40, v13, &v12);
show_differences(v11, (__int64)&v14, v10, v12);
free(v10);
}
else
{
printf("%s: ok\n", (const char *)(v11 + 62));
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
__int64 v4; // r14
__int64 v5; // r13
int *v7; // rax
unsigned int v8; // eax
unsigned __int8 *v9; // rbx
void *v10; // rbx
__int64 v11; // r12
size_t v12; // [rsp+8h] [rbp-E0h] BYREF
char v13[32]; // [rsp+10h] [rbp-D8h] BYREF
struct stat v14; // [rsp+30h] [rbp-B8h] BYREF

v3 = read_cache(argc, argv, envp);
if ( v3 < 0 )
{
perror("read_cache");
exit(1);
}
v4 = 8LL * (unsigned int)v3;
v5 = 0LL;
if ( v3 > 0 )
{
do
{
v11 = *(_QWORD *)(active_cache + v5);
if ( stat((const char *)(v11 + 62), &v14) < 0 )
{
v7 = _errno_location();
v8 = (unsigned int)strerror(*v7);
printf("%s: %s\n", (const char *)(v11 + 62), (const char *)v8);
}
else if ( (unsigned int)func0((_DWORD *)v11, &v14) )
{
printf("%.*s: ", *(unsigned __int16 *)(v11 + 60), (const char *)(v11 + 62));
v9 = (unsigned __int8 *)(v11 + 40);
do
printf("%02x", *v9++);
while ( v9 != (unsigned __int8 *)(v11 + 60) );
putchar(10);
v10 = (void *)read_sha1_file(v11 + 40, v13, &v12);
func1(v11, (__int64)&v14, v10, v12);
free(v10);
}
else
{
printf("%s: ok\n", (const char *)(v11 + 62));
}
v5 += 8LL;
}
while ( v5 != v4 );
}
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int entries = read_cache();
 int i;
 if (entries < 0) {
  perror("read_cache");
  exit(1);
 }
 for (i = 0; i < entries; i++) {
  struct stat st;
  struct cache_entry *ce = active_cache[i];
  int n, changed;
  unsigned int mode;
  unsigned long size;
  char type[20];
  void *new;
  if (stat(ce->name, &st) < 0) {
   printf("%s: %s\n", ce->name, strerror((*__errno_location ())));
   continue;
  }
  changed = match_stat(ce, &st);
  if (!changed) {
   printf("%s: ok\n", ce->name);
   continue;
  }
  printf("%.*s:  ", ce->namelen, ce->name);
  for (n = 0; n < 20; n++)
   printf("%02x", ce->sha1[n]);
  printf("\n");
  new = read_sha1_file(ce->sha1, type, &size);
  show_differences(ce, &st, new, size);
  free(new);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int entries = read_cache();
 int i;
 if (entries < 0) {
  perror("read_cache");
  exit(1);
 }
 for (i = 0; i < entries; i++) {
  struct stat st;
  struct cache_entry *ce = active_cache[i];
  int n; int changed;
  unsigned int mode;
  unsigned long size;
  char type[20];
  void *new;
  if (stat(ce->name, &st) < 0) {
   printf("%s: %s\n", ce->name, strerror((*__errno_location ())));
   continue;
  }
  changed = match_stat(ce, &st);
  if (!changed) {
   printf("%s: ok\n", ce->name);
   continue;
  }
  printf("%.*s:  ", ce->namelen, ce->name);
  for (n = 0; n < 20; n++)
   printf("%02x", ce->sha1[n]);
  printf("\n");
  new = read_sha1_file(ce->sha1, type, &size);
  show_differences(ce, &st, new, size);
  free(new);
 }
 return 0;
}

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types: struct cache_entry { struct cache_time { unsigned int sec; unsigned int nsec; } ctime; struct cache_time mtime; unsigned int st_dev; unsigned int st_ino; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; unsigned int st_size; unsigned char sha1[20]; unsigned short namelen; unsigned char name[]; } *

variable_types: n int

variable_types: changed int

variable_types:
mode
unsigned int

variable_types:
size
unsigned long

variable_types:
type
char [20]

variable_types:
new
void *


decompiled_code:
unsigned __int8 *__fastcall remove_special(unsigned __int8 *a1)
{
unsigned __int8 *result; // rax
unsigned __int8 *v2; // rdx
unsigned __int8 v3; // cl

for ( result = a1; ; result = v2 )
{
v3 = *a1++;
if ( v3 <= 0x3Eu && ((1LL << v3) & 0x5000000000000400LL) != 0 )
{
v2 = result;
continue;
}
v2 = result + 1;
*result = v3;
if ( !v3 )
break;
}
return result;
}

canonical_decompiled_code:
unsigned __int8 *__fastcall func1(unsigned __int8 *a1)
{
unsigned __int8 *result; // rax
unsigned __int8 *v2; // rdx
unsigned __int8 v3; // cl

for ( result = a1; ; result = v2 )
{
v3 = *a1++;
if ( v3 <= 0x3Eu && ((1LL << v3) & 0x5000000000000400LL) != 0 )
{
v2 = result;
continue;
}
v2 = result + 1;
*result = v3;
if ( !v3 )
break;
}
return result;
}

original_code:
static void remove_special(char *p)
{
 char c;
 char *dst = p;
 for (;;) {
  c = *p;
  p++;
  switch(c) {
  case '\n': case '<': case '>':
   continue;
  }
  *dst++ = c;
  if (!c)
   break;
 }
}

variable_types:
p
char *

variable_types: c char

variable_types:
dst
char *


decompiled_code:
void *add_buffer(void **a1, _DWORD *a2, const char *a3, ...)
{
int v4; // eax
__int64 v5; // r13
size_t v6; // rbx
unsigned __int64 v7; // r14
char *v8; // rdi
gcc_va_list arg; // [rsp+8h] [rbp-8F0h] BYREF
char s[2048]; // [rsp+20h] [rbp-8D8h] BYREF

va_start(arg, a3);
v4 = vsnprintf(s, 0x800uLL, a3, arg);
v5 = (unsigned int)*a2;
v6 = v4;
v7 = v4 + v5;
v8 = (char *)*a1;
if ( v7 > ((v5 + 0x7FFF) & 0xFFFFFFFFFFFF8000LL) )
{
v8 = (char *)realloc(v8, (v7 + 0x7FFF) & 0xFFFFFFFFFFFF8000LL);
*a1 = v8;
}
*a2 = v7;
return memcpy(&v8[v5], s, v6);
}

canonical_decompiled_code:
void *func3(void **a1, _DWORD *a2, const char *a3, ...)
{
int v4; // eax
__int64 v5; // r13
size_t v6; // rbx
unsigned __int64 v7; // r14
char *v8; // rdi
gcc_va_list arg; // [rsp+8h] [rbp-8F0h] BYREF
char s[2048]; // [rsp+20h] [rbp-8D8h] BYREF

va_start(arg, a3);
v4 = vsnprintf(s, 0x800uLL, a3, arg);
v5 = (unsigned int)*a2;
v6 = v4;
v7 = v4 + v5;
v8 = (char *)*a1;
if ( v7 > ((v5 + 0x7FFF) & 0xFFFFFFFFFFFF8000LL) )
{
v8 = (char *)realloc(v8, (v7 + 0x7FFF) & 0xFFFFFFFFFFFF8000LL);
*a1 = v8;
}
*a2 = v7;
return memcpy(&v8[v5], s, v6);
}

original_code:
static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
{
 char one_line[2048];
 va_list args;
 int len;
 unsigned long alloc, size, newsize;
 char *buf;
 __builtin_va_start(args,fmt);
 len = vsnprintf(one_line, sizeof(one_line), fmt, args);
 __builtin_va_end(args);
 size = *sizep;
 newsize = size + len;
 alloc = (size + 32767) & ~32767;
 buf = *bufp;
 if (newsize > alloc) {
  alloc = (newsize + 32767) & ~32767;
  buf = realloc(buf, alloc);
  *bufp = buf;
 }
 *sizep = newsize;
 memcpy(buf + size, one_line, len);
}

canonical_original_code:
static void add_buffer(char **bufp, unsigned int *sizep, char *fmt, ...)
{
 char one_line[2048];
 __builtin_va_list args;
 int len;
 unsigned long alloc; unsigned long size; unsigned long newsize;
 char *buf;
 __builtin_va_start(args,fmt);
 len = vsnprintf(one_line, sizeof(one_line), fmt, args);
 __builtin_va_end(args);
 size = *sizep;
 newsize = size + len;
 alloc = (size + 32767) & ~32767;
 buf = *bufp;
 if (newsize > alloc) {
  alloc = (newsize + 32767) & ~32767;
  buf = realloc(buf, alloc);
  *bufp = buf;
 }
 *sizep = newsize;
 memcpy(buf + size, one_line, len);
}

variable_types:
bufp
char **

variable_types:
sizep
unsigned int *

variable_types:
fmt
char *

variable_types: len int

variable_types:
alloc
unsigned long

variable_types:
newsize
unsigned long

variable_types:
buf
char *


unpack

decompiled_code:
__int64 __fastcall unpack(__int64 a1)
{
const char *v1; // r12
unsigned __int64 i; // r14
const char *v4; // rax
int v5; // ebx
const char *v6; // rbp
const char *v7; // r13
unsigned __int64 v8; // rbx
unsigned int v9; // [rsp+Ch] [rbp-4Ch] BYREF
char v10[24]; // [rsp+10h] [rbp-48h] BYREF
unsigned __int64 v11[6]; // [rsp+28h] [rbp-30h] BYREF

v1 = (const char *)read_sha1_file(a1, v10, v11);
if ( !v1 )
usage("unable to read sha1 file");
if ( strcmp(v10, "tree") )
usage("expected a 'tree' node");
for ( i = v11[0]; v11[0]; i = v11[0] )
{
v5 = strlen(v1);
v6 = &v1[v5 + 1];
v7 = strchr(v1, 32) + 1;
v8 = v5 + 21;
if ( v8 > i || (unsigned int)_isoc99_sscanf(v1, "%o", &v9) != 1 )
usage("corrupt 'tree' file");
v1 = v6 + 20;
v11[0] -= v8;
v4 = (const char *)sha1_to_hex(v6);
printf("%o %s (%s)\n", v9, v7, v4);
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
const char *v1; // r12
unsigned __int64 i; // r14
const char *v4; // rax
int v5; // ebx
const char *v6; // rbp
const char *v7; // r13
unsigned __int64 v8; // rbx
unsigned int v9; // [rsp+Ch] [rbp-4Ch] BYREF
char v10[24]; // [rsp+10h] [rbp-48h] BYREF
unsigned __int64 v11[6]; // [rsp+28h] [rbp-30h] BYREF

v1 = (const char *)read_sha1_file(a1, v10, v11);
if ( !v1 )
usage("unable to read sha1 file");
if ( strcmp(v10, "tree") )
usage("expected a 'tree' node");
for ( i = v11[0]; v11[0]; i = v11[0] )
{
v5 = strlen(v1);
v6 = &v1[v5 + 1];
v7 = strchr(v1, 32) + 1;
v8 = v5 + 21;
if ( v8 > i || (unsigned int)_isoc99_sscanf(v1, "%o", &v9) != 1 )
usage("corrupt 'tree' file");
v1 = v6 + 20;
v11[0] -= v8;
v4 = (const char *)sha1_to_hex(v6);
printf("%o %s (%s)\n", v9, v7, v4);
}
return 0LL;
}

original_code:
static int unpack(unsigned char *sha1)
{
 void *buffer;
 unsigned long size;
 char type[20];
 buffer = read_sha1_file(sha1, type, &size);
 if (!buffer)
  usage("unable to read sha1 file");
 if (strcmp(type, "tree"))
  usage("expected a 'tree' node");
 while (size) {
  int len = strlen(buffer)+1;
  unsigned char *sha1 = buffer + len;
  char *path = strchr(buffer, ' ')+1;
  unsigned int mode;
  if (size < len + 20 || sscanf(buffer, "%o", &mode) != 1)
   usage("corrupt 'tree' file");
  buffer = sha1 + 20;
  size -= len + 20;
  printf("%o %s (%s)\n", mode, path, sha1_to_hex(sha1));
 }
 return 0;
}

variable_types:
buffer
void *

variable_types:
path
char *


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
_BYTE v5[40]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 2 )
usage("read-tree <key>");
if ( (int)get_sha1_hex(argv[1], v5, envp) < 0 )
usage("read-tree <key>");
v3 = getenv("SHA1_FILE_DIRECTORY");
if ( !v3 )
v3 = ".dircache/objects";
sha1_file_directory = (__int64)v3;
if ( (int)unpack((__int64)v5) < 0 )
usage("unpack failed");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char *v3; // rax
_BYTE v5[40]; // [rsp+0h] [rbp-28h] BYREF

if ( argc != 2 )
usage("read-tree <key>");
if ( (int)get_sha1_hex(argv[1], v5, envp) < 0 )
usage("read-tree <key>");
v3 = getenv("SHA1_FILE_DIRECTORY");
if ( !v3 )
v3 = ".dircache/objects";
sha1_file_directory = (__int64)v3;
if ( (int)func0((__int64)v5) < 0 )
usage("unpack failed");
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int fd;
 unsigned char sha1[20];
 if (argc != 2)
  usage("read-tree <key>");
 if (get_sha1_hex(argv[1], sha1) < 0)
  usage("read-tree <key>");
 sha1_file_directory = getenv("SHA1_FILE_DIRECTORY");
 if (!sha1_file_directory)
  sha1_file_directory = ".dircache/objects";
 if (unpack(sha1) < 0)
  usage("unpack failed");
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: fd int


decompiled_code:
_BOOL8 __fastcall get_pixel(int a1, int a2, int a3)
{
return ((unsigned int)read_mem(a1 + (((a3 << 7) + a2 / 8) & 0xFFFFFFFC)) & (1 << ~(_BYTE)a2)) != 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(int a1, int a2, int a3)
{
return ((unsigned int)read_mem(a1 + (((a3 << 7) + a2 / 8) & 0xFFFFFFFC)) & (1 << ~(_BYTE)a2)) != 0;
}

original_code:
int get_pixel(uint32_t base_addr, int x, int y) {
 uint32_t addr = base_addr +
  (((x / 8) + (y * (1024 / 8))) & (-sizeof(uint32_t)));
 int bit = 31 - x % (sizeof(uint32_t) * 8);
 uint32_t data = read_mem(addr);
 return (((data) & (1 << (bit))) != 0);
}

canonical_original_code:
int get_pixel(unsigned int base_addr, int x, int y) {
 unsigned int addr = base_addr +
  (((x / 8) + (y * (1024 / 8))) & (-sizeof(uint32_t)));
 int bit = 31 - x % (sizeof(uint32_t) * 8);
 unsigned int data = read_mem(addr);
 return (((data) & (1 << (bit))) != 0);
}

variable_types: x int

variable_types: y int

variable_types:
addr
unsigned int

variable_types: bit int

variable_types:
data
unsigned int


decompiled_code:
__int64 __fastcall set_pixel(int a1, int a2, int a3, int a4)
{
unsigned int v5; // ebx
char v6; // bp
__int64 v7; // rsi

v5 = (((a3 << 7) + a2 / 8) & 0xFFFFFFFC) + a1;
v6 = ~(_BYTE)a2 & 0x1F;
v7 = (unsigned int)read_mem(v5);
if ( a4 )
LODWORD(v7) = v7 | (1 << v6);
else
LODWORD(v7) = v7 & ~(1 << v6);
return write_mem(v5, v7);
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2, int a3, int a4)
{
unsigned int v5; // ebx
char v6; // bp
__int64 v7; // rsi

v5 = (((a3 << 7) + a2 / 8) & 0xFFFFFFFC) + a1;
v6 = ~(_BYTE)a2 & 0x1F;
v7 = (unsigned int)read_mem(v5);
if ( a4 )
LODWORD(v7) = v7 | (1 << v6);
else
LODWORD(v7) = v7 & ~(1 << v6);
return write_mem(v5, v7);
}

original_code:
void set_pixel(uint32_t base_addr, int x, int y, int value) {
 uint32_t addr = base_addr +
  (((x / 8) + (y * (1024 / 8))) & (-sizeof(uint32_t)));
 int bit = 31 - x % (sizeof(uint32_t) * 8);
 uint32_t data = read_mem(addr);
 if(value) {
  do { (data) |= (1 << (bit)); } while(0);
 }
 else {
  do { (data) &= ~(1 << (bit)); } while(0);
 }
 write_mem(addr, data);
}

canonical_original_code:
void set_pixel(unsigned int base_addr, int x, int y, int value) {
 unsigned int addr = base_addr +
  (((x / 8) + (y * (1024 / 8))) & (-sizeof(uint32_t)));
 int bit = 31 - x % (sizeof(uint32_t) * 8);
 unsigned int data = read_mem(addr);
 if(value) {
  do { (data) |= (1 << (bit)); } while(0);
 }
 else {
  do { (data) &= ~(1 << (bit)); } while(0);
 }
 write_mem(addr, data);
}

variable_types: value int


decompiled_code:
__int64 __fastcall clr_screen(unsigned int a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = a1;
do
{
result = write_mem(v1, 0LL);
v1 += 4;
}
while ( a1 + 61440 != v1 );
return result;
}

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

v1 = a1;
do
{
result = write_mem(v1, 0LL);
v1 += 4;
}
while ( a1 + 61440 != v1 );
return result;
}

original_code:
void clr_screen(uint32_t base_addr) {
 int i;
 int nbytes = (1024 * 480) / 8;
 for(i = 0; i < nbytes; i += sizeof(uint32_t)) {
  write_mem(base_addr + i, 0);
 }
}

canonical_original_code:
void clr_screen(unsigned int base_addr) {
 int i;
 int nbytes = (1024 * 480) / 8;
 for(i = 0; i < nbytes; i += sizeof(unsigned int)) {
  write_mem(base_addr + i, 0);
 }
}

variable_types: i int

variable_types: nbytes int


decompiled_code:
__int64 __fastcall blank_screen(unsigned int a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = a1;
do
{
result = write_mem(v1, 0xFFFFFFFFLL);
v1 += 4;
}
while ( a1 + 61440 != v1 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
unsigned int v1; // ebx
__int64 result; // rax

v1 = a1;
do
{
result = write_mem(v1, 0xFFFFFFFFLL);
v1 += 4;
}
while ( a1 + 61440 != v1 );
return result;
}

original_code:
void blank_screen(uint32_t base_addr) {
 int i;
 int nbytes = (1024 * 480) / 8;
 for(i = 0; i < nbytes; i += sizeof(uint32_t)) {
  write_mem(base_addr + i, 0xFFFFFFFF);
 }
}

canonical_original_code:
void blank_screen(unsigned int base_addr) {
 int i;
 int nbytes = (1024 * 480) / 8;
 for(i = 0; i < nbytes; i += sizeof(unsigned int)) {
  write_mem(base_addr + i, 0xFFFFFFFF);
 }
}


neighbors

original_code:
int neighbors(uint32_t base_addr, int x, int y) {
 int n = 0;
 if(x > 0) {
  if(y > 0) {
   n += get_pixel(base_addr, x - 1, y - 1);
  }
  n += get_pixel(base_addr, x - 1, y);
  if(y < 480/4 -1) {
   n += get_pixel(base_addr, x - 1, y + 1);
  }
 }
 if(y > 0) {
  n += get_pixel(base_addr, x, y - 1);
 }
 if(y < 480/4 -1) {
  n += get_pixel(base_addr, x, y + 1);
 }
 if(x < 640/4 -1) {
  if(y > 0) {
   n += get_pixel(base_addr, x + 1, y - 1);
  }
  n += get_pixel(base_addr, x + 1, y);
  if(y < 480/4 -1) {
   n += get_pixel(base_addr, x + 1, y + 1);
  }
 }
 return n;
}

canonical_original_code:
int neighbors(unsigned int base_addr, int x, int y) {
 int n = 0;
 if(x > 0) {
  if(y > 0) {
   n += get_pixel(base_addr, x - 1, y - 1);
  }
  n += get_pixel(base_addr, x - 1, y);
  if(y < 480/4 -1) {
   n += get_pixel(base_addr, x - 1, y + 1);
  }
 }
 if(y > 0) {
  n += get_pixel(base_addr, x, y - 1);
 }
 if(y < 480/4 -1) {
  n += get_pixel(base_addr, x, y + 1);
 }
 if(x < 640/4 -1) {
  if(y > 0) {
   n += get_pixel(base_addr, x + 1, y - 1);
  }
  n += get_pixel(base_addr, x + 1, y);
  if(y < 480/4 -1) {
   n += get_pixel(base_addr, x + 1, y + 1);
  }
 }
 return n;
}

variable_types: n int


decompiled_code:
__int64 game_of_life()
{
int v0; // er12
__int64 result; // rax
int i; // ebx
int v3; // ebp

v0 = 0;
while ( 2 )
{
for ( i = 0; i != 120; ++i )
{
v3 = neighbors(old_img_addr, v0, i);
if ( get_pixel(old_img_addr, v0, i) )
{
if ( (unsigned int)(v3 - 2) <= 1 )
{
LABEL_2:
result = set_pixel(new_img_addr, v0, i, 1);
continue;
}
}
else if ( v3 == 3 )
{
goto LABEL_2;
}
result = set_pixel(new_img_addr, v0, i, 0);
}
if ( ++v0 != 160 )
continue;
return result;
}
}

canonical_decompiled_code:
__int64 func5()
{
int v0; // er12
__int64 result; // rax
int i; // ebx
int v3; // ebp

v0 = 0;
while ( 2 )
{
for ( i = 0; i != 120; ++i )
{
v3 = func4(old_img_addr, v0, i);
if ( func0(old_img_addr, v0, i) )
{
if ( (unsigned int)(v3 - 2) <= 1 )
{
LABEL_2:
result = func1(new_img_addr, v0, i, 1);
continue;
}
}
else if ( v3 == 3 )
{
goto LABEL_2;
}
result = func1(new_img_addr, v0, i, 0);
}
if ( ++v0 != 160 )
continue;
return result;
}
}

original_code:
void game_of_life() {
 int x;
 int y;
 for(x = 0; x < 640/4; ++x) {
  for(y = 0; y < 480/4; ++y) {
   int n = neighbors(old_img_addr, x, y);
   if(get_pixel(old_img_addr, x, y)) {
    if((n < 2) || (n > 3)) {
     set_pixel(new_img_addr, x, y, 0);
    }
    else {
     set_pixel(new_img_addr, x, y, 1);
    }
   }
   else {
    if(n == 3) {
     set_pixel(new_img_addr, x, y, 1);
    }
    else {
     set_pixel(new_img_addr, x, y, 0);
    }
   }
  }
 }
}


decompiled_code:
__int64 __fastcall draw_gun(int a1, int a2)
{
set_pixel(old_img_addr, a1, a2 + 5, 1);
set_pixel(old_img_addr, a1, a2 + 6, 1);
set_pixel(old_img_addr, a1 + 1, a2 + 5, 1);
set_pixel(old_img_addr, a1 + 1, a2 + 6, 1);
set_pixel(old_img_addr, a1 + 11, a2 + 5, 1);
set_pixel(old_img_addr, a1 + 11, a2 + 6, 1);
set_pixel(old_img_addr, a1 + 11, a2 + 7, 1);
set_pixel(old_img_addr, a1 + 12, a2 + 4, 1);
set_pixel(old_img_addr, a1 + 12, a2 + 8, 1);
set_pixel(old_img_addr, a1 + 13, a2 + 3, 1);
set_pixel(old_img_addr, a1 + 13, a2 + 9, 1);
set_pixel(old_img_addr, a1 + 14, a2 + 3, 1);
set_pixel(old_img_addr, a1 + 14, a2 + 9, 1);
set_pixel(old_img_addr, a1 + 15, a2 + 6, 1);
set_pixel(old_img_addr, a1 + 16, a2 + 4, 1);
set_pixel(old_img_addr, a1 + 16, a2 + 8, 1);
set_pixel(old_img_addr, a1 + 17, a2 + 5, 1);
set_pixel(old_img_addr, a1 + 17, a2 + 6, 1);
set_pixel(old_img_addr, a1 + 17, a2 + 7, 1);
set_pixel(old_img_addr, a1 + 18, a2 + 6, 1);
set_pixel(old_img_addr, a1 + 21, a2 + 3, 1);
set_pixel(old_img_addr, a1 + 21, a2 + 4, 1);
set_pixel(old_img_addr, a1 + 21, a2 + 5, 1);
set_pixel(old_img_addr, a1 + 22, a2 + 3, 1);
set_pixel(old_img_addr, a1 + 22, a2 + 4, 1);
set_pixel(old_img_addr, a1 + 22, a2 + 5, 1);
set_pixel(old_img_addr, a1 + 23, a2 + 2, 1);
set_pixel(old_img_addr, a1 + 23, a2 + 6, 1);
set_pixel(old_img_addr, a1 + 25, a2 + 1, 1);
set_pixel(old_img_addr, a1 + 25, a2 + 2, 1);
set_pixel(old_img_addr, a1 + 25, a2 + 6, 1);
set_pixel(old_img_addr, a1 + 25, a2 + 7, 1);
set_pixel(old_img_addr, a1 + 35, a2 + 3, 1);
set_pixel(old_img_addr, a1 + 35, a2 + 4, 1);
set_pixel(old_img_addr, a1 + 36, a2 + 3, 1);
return set_pixel(old_img_addr, a1 + 36, a2 + 4, 1);
}

original_code:
void draw_gun(int x, int y) {
 set_pixel(old_img_addr, x + 0, y + 5, 1);
 set_pixel(old_img_addr, x + 0, y + 6, 1);
 set_pixel(old_img_addr, x + 1, y + 5, 1);
 set_pixel(old_img_addr, x + 1, y + 6, 1);
 set_pixel(old_img_addr, x + 11, y + 5, 1);
 set_pixel(old_img_addr, x + 11, y + 6, 1);
 set_pixel(old_img_addr, x + 11, y + 7, 1);
 set_pixel(old_img_addr, x + 12, y + 4, 1);
 set_pixel(old_img_addr, x + 12, y + 8, 1);
 set_pixel(old_img_addr, x + 13, y + 3, 1);
 set_pixel(old_img_addr, x + 13, y + 9, 1);
 set_pixel(old_img_addr, x + 14, y + 3, 1);
 set_pixel(old_img_addr, x + 14, y + 9, 1);
 set_pixel(old_img_addr, x + 15, y + 6, 1);
 set_pixel(old_img_addr, x + 16, y + 4, 1);
 set_pixel(old_img_addr, x + 16, y + 8, 1);
 set_pixel(old_img_addr, x + 17, y + 5, 1);
 set_pixel(old_img_addr, x + 17, y + 6, 1);
 set_pixel(old_img_addr, x + 17, y + 7, 1);
 set_pixel(old_img_addr, x + 18, y + 6, 1);
 set_pixel(old_img_addr, x + 21, y + 3, 1);
 set_pixel(old_img_addr, x + 21, y + 4, 1);
 set_pixel(old_img_addr, x + 21, y + 5, 1);
 set_pixel(old_img_addr, x + 22, y + 3, 1);
 set_pixel(old_img_addr, x + 22, y + 4, 1);
 set_pixel(old_img_addr, x + 22, y + 5, 1);
 set_pixel(old_img_addr, x + 23, y + 2, 1);
 set_pixel(old_img_addr, x + 23, y + 6, 1);
 set_pixel(old_img_addr, x + 25, y + 1, 1);
 set_pixel(old_img_addr, x + 25, y + 2, 1);
 set_pixel(old_img_addr, x + 25, y + 6, 1);
 set_pixel(old_img_addr, x + 25, y + 7, 1);
 set_pixel(old_img_addr, x + 35, y + 3, 1);
 set_pixel(old_img_addr, x + 35, y + 4, 1);
 set_pixel(old_img_addr, x + 36, y + 3, 1);
 set_pixel(old_img_addr, x + 36, y + 4, 1);
}


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

if ( refresh )
{
refresh = 0;
puts("vga_isr: double buffer flip\r");
result = write_mem(1939865600LL, (unsigned int)old_img_addr);
}
return result;
}

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

if ( refresh )
{
refresh = 0;
puts("vga_isr: double buffer flip\r");
result = write_mem(1939865600LL, (unsigned int)old_img_addr);
}
return result;
}

original_code:
void vga_isr() {
 if(refresh) {
  refresh = 0;
  printf("vga_isr: double buffer flip\r\n");
  write_mem(0x73A00000 + 0x0, old_img_addr);
 }
}


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

puts("timer_0_isr\r");
game_of_life();
result = (unsigned int)old_img_addr;
old_img_addr = new_img_addr;
new_img_addr = result;
refresh = 1;
return result;
}

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

puts("timer_0_isr\r");
func5();
result = (unsigned int)old_img_addr;
old_img_addr = new_img_addr;
new_img_addr = result;
refresh = 1;
return result;
}

original_code:
void timer_0_isr() {
 printf("timer_0_isr\r\n");
 game_of_life();
 uint32_t tmp = old_img_addr;
 old_img_addr = new_img_addr;
 new_img_addr = tmp;
 refresh = 1;
}

canonical_original_code:
void timer_0_isr() {
 printf("timer_0_isr\r\n");
 game_of_life();
 unsigned int tmp = old_img_addr;
 old_img_addr = new_img_addr;
 new_img_addr = tmp;
 refresh = 1;
}

variable_types:
tmp
unsigned int


decompiled_code:
int timer_1_isr()
{
return puts("timer_1_isr");
}

canonical_decompiled_code:
int func10()
{
return puts("timer_1_isr");
}

original_code:
void timer_1_isr() {
 printf("timer_1_isr\n");
}


expand

repo: masriamir/vect

decompiled_code:
char __fastcall expand(__int64 a1)
{
int v1; // edx
char result; // al
void *v3; // rbp

v1 = *(_DWORD *)(a1 + 4);
result = (double)*(int *)a1 == (double)v1 * 0.75;
if ( (double)*(int *)a1 == (double)v1 * 0.75 && v1 <= 127 )
{
v3 = realloc(*(void **)(a1 + 8), 8LL * (v1 + 8));
result = check_null(v3);
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 4) += 8;
}
return result;
}

canonical_decompiled_code:
char __fastcall func7(__int64 a1)
{
int v1; // edx
char result; // al
void *v3; // rbp

v1 = *(_DWORD *)(a1 + 4);
result = (double)*(int *)a1 == (double)v1 * 0.75;
if ( (double)*(int *)a1 == (double)v1 * 0.75 && v1 <= 127 )
{
v3 = realloc(*(void **)(a1 + 8), 8LL * (v1 + 8));
result = func23(v3);
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 4) += 8;
}
return result;
}

original_code:
static void expand(Vector *v) {
 if (v->size == v->total * 0.75 && v->total < 128) {
  char **new_elements = realloc(v->elements, (v->total + 8) * sizeof(char *));
  check_null(new_elements);
  v->elements = new_elements;
  v->total += 8;
 }
}

canonical_original_code:
static void expand(struct Vector *v) {
 if (v->size == v->total * 0.75 && v->total < 128) {
  char **new_elements = realloc(v->elements, (v->total + 8) * sizeof(char *));
  check_null(new_elements);
  v->elements = new_elements;
  v->total += 8;
 }
}

variable_types: struct Vector { int size; int total; char **elements; } *


shrink

decompiled_code:
char __fastcall shrink(__int64 a1)
{
int v1; // edx
char result; // al
void *v3; // rbp

v1 = *(_DWORD *)(a1 + 4);
result = (double)*(int *)a1 == (double)v1 * 0.5;
if ( (double)*(int *)a1 == (double)v1 * 0.5 && v1 > 8 )
{
v3 = realloc(*(void **)(a1 + 8), 8LL * (v1 - 8));
result = check_null(v3);
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 4) -= 8;
}
return result;
}

canonical_decompiled_code:
char __fastcall func8(__int64 a1)
{
int v1; // edx
char result; // al
void *v3; // rbp

v1 = *(_DWORD *)(a1 + 4);
result = (double)*(int *)a1 == (double)v1 * 0.5;
if ( (double)*(int *)a1 == (double)v1 * 0.5 && v1 > 8 )
{
v3 = realloc(*(void **)(a1 + 8), 8LL * (v1 - 8));
result = func23(v3);
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)(a1 + 4) -= 8;
}
return result;
}

original_code:
static void shrink(Vector *v) {
 if (v->size == v->total * 0.50 && v->total > 8) {
  char **new_elements = realloc(v->elements, (v->total - 8) * sizeof(char *));
  check_null(new_elements);
  v->elements = new_elements;
  v->total -= 8;
 }
}

canonical_original_code:
static void shrink(struct Vector *v) {
 if (v->size == v->total * 0.50 && v->total > 8) {
  char **new_elements = realloc(v->elements, (v->total - 8) * sizeof(char *));
  check_null(new_elements);
  v->elements = new_elements;
  v->total -= 8;
 }
}

user_defined_types: struct Vector { int size; int total; char **elements; }


new

decompiled_code:
_DWORD *new()
{
_DWORD *v0; // rbx
void *v1; // rbp

v0 = calloc(1uLL, 0x10uLL);
check_null(v0);
v1 = calloc(8uLL, 8uLL);
check_null(v1);
*v0 = 0;
v0[1] = 8;
*((_QWORD *)v0 + 1) = v1;
return v0;
}

canonical_decompiled_code:
_DWORD *func9()
{
_DWORD *v0; // rbx
void *v1; // rbp

v0 = calloc(1uLL, 0x10uLL);
func23(v0);
v1 = calloc(8uLL, 8uLL);
func23(v1);
*v0 = 0;
v0[1] = 8;
*((_QWORD *)v0 + 1) = v1;
return v0;
}

original_code:
Vector *new() {
 Vector *v = calloc(1, sizeof(Vector));
 check_null(v);
 char **elements = calloc(8, sizeof(char *));
 check_null(elements);
 v->size = 0;
 v->total = 8;
 v->elements = elements;
 return v;
}

canonical_original_code:
struct Vector *new() {
 struct Vector *v = calloc(1, sizeof(Vector));
 check_null(v);
 char **elements = calloc(8, sizeof(char *));
 check_null(elements);
 v->size = 0;
 v->total = 8;
 v->elements = elements;
 return v;
}

variable_types:
elements
char **

return_type: struct Vector { int size; int total; char **elements; } *


decompiled_code:
bool __fastcall is_empty(_DWORD *a1)
{
return *a1 <= 0;
}

canonical_decompiled_code:
bool __fastcall func10(_DWORD *a1)
{
return *a1 <= 0;
}

original_code:
_Bool is_empty(const Vector *v) {
 return v->size <= 0;
}

canonical_original_code:
_Bool is_empty(struct Vector *v) {
 return v->size <= 0;
}


decompiled_code:
bool __fastcall is_full(_DWORD *a1)
{
return *a1 == 128;
}

canonical_decompiled_code:
bool __fastcall func11(_DWORD *a1)
{
return *a1 == 128;
}

original_code:
_Bool is_full(const Vector *v) {
 return v->size == 128;
}

canonical_original_code:
_Bool is_full(struct Vector *v) {
 return v->size == 128;
}


push

decompiled_code:
char __fastcall push(__int64 a1, const char *a2)
{
char result; // al
char *v3; // r12

check_null(a1);
result = is_full((_DWORD *)a1);
if ( !result )
{
v3 = (char *)calloc(8uLL, 1uLL);
check_null(v3);
strcpy(v3, a2);
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)(*(_DWORD *)a1)++) = v3;
result = expand(a1);
}
return result;
}

canonical_decompiled_code:
char __fastcall func12(__int64 a1, const char *a2)
{
char result; // al
char *v3; // r12

func23(a1);
result = func11((_DWORD *)a1);
if ( !result )
{
v3 = (char *)calloc(8uLL, 1uLL);
func23(v3);
strcpy(v3, a2);
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)(*(_DWORD *)a1)++) = v3;
result = func7(a1);
}
return result;
}

original_code:
void push(Vector *v, const char *data) {
 check_null(v);
 if (!is_full(v)) {
  char *data_ptr = calloc(sizeof(data), sizeof(char));
  check_null(data_ptr);
  strcpy(data_ptr, data);
  v->elements[v->size] = data_ptr;
  v->size ++;
  expand(v);
 }
}

canonical_original_code:
void push(struct Vector *v, char *data) {
 check_null(v);
 if (!is_full(v)) {
  char *data_ptr = calloc(sizeof(data), sizeof(char));
  check_null(data_ptr);
  strcpy(data_ptr, data);
  v->elements[v->size] = data_ptr;
  v->size ++;
  expand(v);
 }
}

variable_types:
data
char *


pop

decompiled_code:
char __fastcall pop(__int64 a1)
{
char result; // al

check_null(a1);
result = is_empty((_DWORD *)a1);
if ( !result )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)(*(_DWORD *)a1)-- - 8) = 0LL;
result = shrink(a1);
}
return result;
}

canonical_decompiled_code:
char __fastcall func13(__int64 a1)
{
char result; // al

func23(a1);
result = func10((_DWORD *)a1);
if ( !result )
{
*(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (int)(*(_DWORD *)a1)-- - 8) = 0LL;
result = func8(a1);
}
return result;
}

original_code:
void pop(Vector *v) {
 check_null(v);
 if (!is_empty(v)) {
  v->elements[v->size - 1] = '\0';
  v->size --;
  shrink(v);
 }
}

canonical_original_code:
void pop(struct Vector *v) {
 check_null(v);
 if (!is_empty(v)) {
  v->elements[v->size - 1] = '\0';
  v->size --;
  shrink(v);
 }
}


get

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

check_null(a1);
check_index(*a1, a2);
if ( is_empty(a1) )
result = 0LL;
else
result = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * (int)a2);
return result;
}

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

func23(a1);
func24(*a1, a2);
if ( func10(a1) )
result = 0LL;
else
result = *(_QWORD *)(*((_QWORD *)a1 + 1) + 8LL * (int)a2);
return result;
}

original_code:
char *get(const Vector *v, const int index) {
 check_null(v);
 check_index(v->size, index);
 if (is_empty(v)) {
  return ((void *)0);
 }
 return v->elements[index];
}

canonical_original_code:
char *get(struct Vector *v, int index) {
 check_null(v);
 check_index(v->size, index);
 if (is_empty(v)) {
  return ((void *)0);
 }
 return v->elements[index];
}

variable_types: index int

return_type: char *


find

decompiled_code:
__int64 __fastcall find(__int64 a1, const char *a2)
{
int v2; // er12
__int64 v3; // r13
__int64 v4; // rbx
unsigned int v5; // er14

check_null(a1);
check_null(a2);
v2 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
return (unsigned int)-1;
v3 = *(_QWORD *)(a1 + 8);
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( !strcmp(*(const char **)(v3 + 8 * v4), a2) )
break;
if ( ++v4 == v2 )
return (unsigned int)-1;
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1, const char *a2)
{
int v2; // er12
__int64 v3; // r13
__int64 v4; // rbx
unsigned int v5; // er14

func23(a1);
func23(a2);
v2 = *(_DWORD *)a1;
if ( *(int *)a1 <= 0 )
return (unsigned int)-1;
v3 = *(_QWORD *)(a1 + 8);
v4 = 0LL;
while ( 1 )
{
v5 = v4;
if ( !strcmp(*(const char **)(v3 + 8 * v4), a2) )
break;
if ( ++v4 == v2 )
return (unsigned int)-1;
}
return v5;
}

original_code:
int find(const Vector *v, const char *data) {
 check_null(v);
 check_null(data);
 for (int i = 0; i < v->size; ++ i) {
  if (!strcmp(v->elements[i], data)) {
   return i;
  }
 }
 return -1;
}

canonical_original_code:
int find(struct Vector *v, char *data) {
 check_null(v);
 check_null(data);
 for (int i = 0; i < v->size; ++ i) {
  if (!strcmp(v->elements[i], data)) {
   return i;
  }
 }
 return -1;
}


decompiled_code:
__int64 __fastcall find_n(__int64 a1, const char *a2)
{
const char **v2; // rbx
__int64 v3; // r13
unsigned int v4; // ebp

check_null(a1);
check_null(a2);
if ( *(int *)a1 <= 0 )
return 0;
v2 = *(const char ***)(a1 + 8);
v3 = (__int64)&v2[(unsigned int)(*(_DWORD *)a1 - 1) + 1];
v4 = 0;
do
v4 += strcmp(*v2++, a2) == 0;
while ( v2 != (const char **)v3 );
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, const char *a2)
{
const char **v2; // rbx
__int64 v3; // r13
unsigned int v4; // ebp

func23(a1);
func23(a2);
if ( *(int *)a1 <= 0 )
return 0;
v2 = *(const char ***)(a1 + 8);
v3 = (__int64)&v2[(unsigned int)(*(_DWORD *)a1 - 1) + 1];
v4 = 0;
do
v4 += strcmp(*v2++, a2) == 0;
while ( v2 != (const char **)v3 );
return v4;
}

original_code:
int find_n(const Vector *v, const char *data) {
 check_null(v);
 check_null(data);
 int count = 0;
 for (int i = 0; i < v->size; ++ i) {
  if (!strcmp(v->elements[i], data)) {
   count ++;;
  }
 }
 return count;
}

canonical_original_code:
int find_n(struct Vector *v, char *data) {
 check_null(v);
 check_null(data);
 int count = 0;
 for (int i = 0; i < v->size; ++ i) {
  if (!strcmp(v->elements[i], data)) {
   count ++;;
  }
 }
 return count;
}

variable_types: count int


replace

decompiled_code:
__int64 __fastcall replace(unsigned int *a1, unsigned int a2, const char *a3)
{
char *v4; // r12
__int64 result; // rax

check_null(a1);
check_null(a3);
check_index(*a1, a2);
v4 = (char *)calloc(8uLL, 1uLL);
check_null(v4);
strcpy(v4, a3);
free(*(void **)(*((_QWORD *)a1 + 1) + 8LL * (int)a2));
result = *((_QWORD *)a1 + 1);
*(_QWORD *)(result + 8LL * (int)a2) = v4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(unsigned int *a1, unsigned int a2, const char *a3)
{
char *v4; // r12
__int64 result; // rax

func23(a1);
func23(a3);
func24(*a1, a2);
v4 = (char *)calloc(8uLL, 1uLL);
func23(v4);
strcpy(v4, a3);
free(*(void **)(*((_QWORD *)a1 + 1) + 8LL * (int)a2));
result = *((_QWORD *)a1 + 1);
*(_QWORD *)(result + 8LL * (int)a2) = v4;
return result;
}

original_code:
void replace(Vector *v, const int index, const char *data) {
 check_null(v);
 check_null(data);
 check_index(v->size, index);
 char *data_ptr = calloc(sizeof(data), sizeof(char));
 check_null(data_ptr);
 strcpy(data_ptr, data);
 free(v->elements[index]);
 v->elements[index] = data_ptr;
}

canonical_original_code:
void replace(struct Vector *v, int index, char *data) {
 check_null(v);
 check_null(data);
 check_index(v->size, index);
 char *data_ptr = calloc(sizeof(data), sizeof(char));
 check_null(data_ptr);
 strcpy(data_ptr, data);
 free(v->elements[index]);
 v->elements[index] = data_ptr;
}


print

decompiled_code:
int __fastcall print(signed int *a1)
{
signed int v1; // ebx
const char *v2; // rax

check_null(a1);
if ( is_empty(a1) )
return puts("[]");
printf("[ ");
if ( *a1 > 0 )
{
v1 = 0;
do
{
v2 = (const char *)get((unsigned int *)a1, v1);
printf("%s", v2);
if ( *a1 - 1 != v1 )
printf(", ");
++v1;
}
while ( *a1 > v1 );
}
return puts(" ]");
}

canonical_decompiled_code:
int __fastcall func19(signed int *a1)
{
signed int v1; // ebx
const char *v2; // rax

func23(a1);
if ( func10(a1) )
return puts("[]");
printf("[ ");
if ( *a1 > 0 )
{
v1 = 0;
do
{
v2 = (const char *)func14((unsigned int *)a1, v1);
printf("%s", v2);
if ( *a1 - 1 != v1 )
printf(", ");
++v1;
}
while ( *a1 > v1 );
}
return puts(" ]");
}

original_code:
void print(const Vector *v) {
 check_null(v);
 if (!is_empty(v)) {
  printf("[ ");
  for (int i = 0; i < v->size; ++ i) {
   printf("%s", get(v, i));
   if (i != v->size - 1) {
    printf(", ");
   }
  }
  printf(" ]\n");
 } else {
  printf("[]\n");
 }
}

canonical_original_code:
void print(struct Vector *v) {
 check_null(v);
 if (!is_empty(v)) {
  printf("[ ");
  for (int i = 0; i < v->size; ++ i) {
   printf("%s", get(v, i));
   if (i != v->size - 1) {
    printf(", ");
   }
  }
  printf(" ]\n");
 } else {
  printf("[]\n");
 }
}


decompiled_code:
bool __fastcall is_null(__int64 a1)
{
return a1 == 0;
}

canonical_decompiled_code:
bool __fastcall func20(__int64 a1)
{
return a1 == 0;
}

original_code:
static _Bool is_null(const void *ptr) {
 return !ptr;
}

canonical_original_code:
static _Bool is_null(void *ptr) {
 return !ptr;
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall is_valid_index(int a1, int a2)
{
return (a2 >= 0) & (unsigned __int8)(a2 < a1);
}

canonical_decompiled_code:
__int64 __fastcall func21(int a1, int a2)
{
return (a2 >= 0) & (unsigned __int8)(a2 < a1);
}

original_code:
static _Bool is_valid_index(const int size, const int index) {
 return !(index < 0 || index >= size);
}

canonical_original_code:
static _Bool is_valid_index(int size, int index) {
 return !(index < 0 || index >= size);
}

variable_types: size int


error

decompiled_code:
void __fastcall __noreturn error(int a1)
{
const char *v1; // rdx

v1 = "Null pointer reference.";
if ( a1 )
{
v1 = "Unhandled error.";
if ( a1 == 1 )
v1 = "Index out of bounds.";
}
fprintf(stderr, "%s\n", v1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func22(int a1)
{
const char *v1; // rdx

v1 = "Null pointer reference.";
if ( a1 )
{
v1 = "Unhandled error.";
if ( a1 == 1 )
v1 = "Index out of bounds.";
}
fprintf(stderr, "%s\n", v1);
exit(1);
}

original_code:
static void error(const error_code e) {
 char *msg;
 switch (e) {
  case E_NULL:
   msg = "Null pointer reference.";
   break;
  case E_INDEX:
   msg = "Index out of bounds.";
   break;
  default:
   msg = "Unhandled error.";
 }
 fprintf(stderr, "%s\n", msg);
 exit(1);
}

canonical_original_code:
static void error(enum error_code e) {
 char *msg;
 switch (e) {
  case E_NULL:
   msg = "Null pointer reference.";
   break;
  case E_INDEX:
   msg = "Index out of bounds.";
   break;
  default:
   msg = "Unhandled error.";
 }
 fprintf(stderr, "%s\n", msg);
 exit(1);
}

variable_types:
e
enum error_code { E_NULL=0, E_INDEX=1 }

variable_types:
msg
char *


decompiled_code:
bool __fastcall check_null(__int64 a1)
{
bool result; // al

result = is_null(a1);
if ( result )
error(0);
return result;
}

canonical_decompiled_code:
bool __fastcall func23(__int64 a1)
{
bool result; // al

result = func20(a1);
if ( result )
func22(0);
return result;
}

original_code:
void check_null(const void *ptr) {
 if (is_null(ptr)) {
  error(E_NULL);
 }
}

canonical_original_code:
void check_null(void *ptr) {
 if (is_null(ptr)) {
  error(E_NULL);
 }
}


decompiled_code:
__int64 __fastcall check_index(int a1, int a2)
{
__int64 result; // rax

result = is_valid_index(a1, a2);
if ( !(_BYTE)result )
error(1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func24(int a1, int a2)
{
__int64 result; // rax

result = func21(a1, a2);
if ( !(_BYTE)result )
func22(1);
return result;
}

original_code:
void check_index(const int size, const int index) {
 if (!is_valid_index(size, index)) {
  error(E_INDEX);
 }
}

canonical_original_code:
void check_index(int size, int index) {
 if (!is_valid_index(size, index)) {
  error(E_INDEX);
 }
}


main

original_code:
int main(int argc, char *argv[]) {
 Vector *v = new();
 debug(v);
 push(v, "e1");
 push(v, "e2");
 debug(v);
 pop(v);
 debug(v);
 push(v, "e3");
 push(v, "e4");
 debug(v);
 clear(v);
 debug(v);
 push(v, "e5");
 push(v, "e6");
 debug(v);
 push(v, "e7");
 push(v, "e8");
 push(v, "e9");
 debug(v);
 push(v, "e10");
 push(v, "e11");
 push(v, "e12");
 debug(v);
 pop(v);
 pop(v);
 push(v, "e13");
 debug(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 debug(v);
 clear(v);
 debug(v);
 for (int i = 0; i < 128 / 4 + 4; ++ i) {
  char *buf;
  sprintf(buf, "e%d", i);
  push(v, buf);
 }
 debug(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 debug(v);
 replace(v, find(v, "e6"), "e93");
 replace(v, find(v, "e11"), "");
 replace(v, 0, "e44");
 replace(v, 4, "e44");
 replace(v, 12, "e44");
 debug(v);
 printf("# of 'e881': %d\n", find_n(v, "e881"));
 printf("# of 'e12': %d\n", find_n(v, "e12"));
 printf("# of '': %d\n", find_n(v, ""));
 printf("# of 'e44': %d\n\n", find_n(v, "e44"));
 char *e7 = get(v, 7);
 printf("v[7]: %s\n", e7);
 free(v);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 struct Vector *v = new();
 debug(v);
 push(v, "e1");
 push(v, "e2");
 debug(v);
 pop(v);
 debug(v);
 push(v, "e3");
 push(v, "e4");
 debug(v);
 clear(v);
 debug(v);
 push(v, "e5");
 push(v, "e6");
 debug(v);
 push(v, "e7");
 push(v, "e8");
 push(v, "e9");
 debug(v);
 push(v, "e10");
 push(v, "e11");
 push(v, "e12");
 debug(v);
 pop(v);
 pop(v);
 push(v, "e13");
 debug(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 debug(v);
 clear(v);
 debug(v);
 for (int i = 0; i < 128 / 4 + 4; ++ i) {
  char *buf;
  sprintf(buf, "e%d", i);
  push(v, buf);
 }
 debug(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 pop(v);
 debug(v);
 replace(v, find(v, "e6"), "e93");
 replace(v, find(v, "e11"), "");
 replace(v, 0, "e44");
 replace(v, 4, "e44");
 replace(v, 12, "e44");
 debug(v);
 printf("# of 'e881': %d\n", find_n(v, "e881"));
 printf("# of 'e12': %d\n", find_n(v, "e12"));
 printf("# of '': %d\n", find_n(v, ""));
 printf("# of 'e44': %d\n\n", find_n(v, "e44"));
 char *e7 = get(v, 7);
 printf("v[7]: %s\n", e7);
 free(v);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
buf
char *


debug

decompiled_code:
int __fastcall debug(unsigned int *a1)
{
print((signed int *)a1);
return printf("Size: %d, Total: %d\n\n", *a1, a1[1]);
}

canonical_decompiled_code:
int __fastcall func25(unsigned int *a1)
{
func19((signed int *)a1);
return printf("Size: %d, Total: %d\n\n", *a1, a1[1]);
}

original_code:
void debug(const Vector *v) {
 print(v);
 printf("Size: %d, Total: %d\n\n", v->size, v->total);
}

canonical_original_code:
void debug(struct Vector *v) {
 print(v);
 printf("Size: %d, Total: %d\n\n", v->size, v->total);
}


repo: massar/ecmh

decompiled_code:
void *listnode_new()
{
return calloc(1uLL, 0x18uLL);
}

canonical_decompiled_code:
void *func0()
{
return calloc(1uLL, 0x18uLL);
}

original_code:
static struct listnode *listnode_new(void)
{
 struct listnode *node;
 node = calloc(1, sizeof(*node));
 if (!node) return ((void *)0);
 return node;
}

canonical_original_code:
static struct listnode *listnode_new()
{
 struct listnode *node;
 node = calloc(1, sizeof(*node));
 if (!node) return ((void *)0);
 return node;
}

variable_types: struct listnode { struct listnode *next; struct listnode *prev; void *data; } *


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

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

original_code:
static void listnode_free(struct listnode *node)
{
 free(node);
}

user_defined_types: struct listnode { struct listnode *next; struct listnode *prev; void *data; }


decompiled_code:
void *list_new()
{
return calloc(1uLL, 0x20uLL);
}

canonical_decompiled_code:
void *func2()
{
return calloc(1uLL, 0x20uLL);
}

original_code:
struct list *list_new()
{
 struct list *new;
 new = calloc(1, sizeof(*new));
 if (!new) return ((void *)0);
 return new;
}

variable_types: struct list { struct listnode { struct listnode *next; struct listnode *prev; void *data; } *head; struct listnode *tail; long count; void (*del)(void *val); } *

user_defined_types: struct list { struct listnode *head; struct listnode *tail; long count; void (*del)(void *val); }


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

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

original_code:
void list_free(struct list *l)
{
 if (l) free(l);
}


decompiled_code:
void __fastcall list_delete_all_node(__int64 a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void (__fastcall *v3)(_QWORD); // rax

v1 = *(_QWORD **)a1;
if ( *(_QWORD *)a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
v3 = *(void (__fastcall **)(_QWORD))(a1 + 24);
if ( v3 )
v3(v2[2]);
listnode_free(v2);
}
while ( v1 );
}
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void list_delete_all_node(struct list *list)
{
 struct listnode *node;
 struct listnode *next;
 for (node = list->head; node; node = next)
 {
  next = node->next;
  if (list->del) (*list->del)(node->data);
  listnode_free(node);
 }
 list->head = list->tail = ((void *)0);
 list->count = 0;
}


decompiled_code:
void __fastcall list_delete(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void (__fastcall *v3)(_QWORD); // rax

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
v3 = (void (__fastcall *)(_QWORD))a1[3];
if ( v3 )
v3(v2[2]);
listnode_free(v2);
}
while ( v1 );
}
list_free(a1);
}

canonical_decompiled_code:
void __fastcall func5(_QWORD *a1)
{
_QWORD *v1; // rbx
_QWORD *v2; // rbp
void (__fastcall *v3)(_QWORD); // rax

v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v2 = v1;
v1 = (_QWORD *)*v1;
v3 = (void (__fastcall *)(_QWORD))a1[3];
if ( v3 )
v3(v2[2]);
func1(v2);
}
while ( v1 );
}
func3(a1);
}

original_code:
void list_delete(struct list *list)
{
 struct listnode *node;
 struct listnode *next;
 for (node = list->head; node; node = next)
 {
  next = node->next;
  if (list->del) (*list->del)(node->data);
  listnode_free(node);
 }
 list_free (list);
}


decompiled_code:
void __fastcall list_delete_node(_QWORD *a1, _QWORD *a2)
{
_QWORD *v2; // rdx

v2 = (_QWORD *)a2[1];
if ( v2 )
*v2 = *a2;
else
*a1 = *a2;
if ( *a2 )
*(_QWORD *)(*a2 + 8LL) = v2;
else
a1[1] = v2;
--a1[2];
listnode_free(a2);
}

original_code:
void list_delete_node(struct list *list, struct listnode *node)
{
 if (node->prev) node->prev->next = node->next;
 else list->head = node->next;
 if (node->next) node->next->prev = node->prev;
 else list->tail = node->prev;
 list->count--;
 listnode_free(node);
}

variable_types:
node
struct listnode *


decompiled_code:
void __fastcall group_destroy(void *ptr)
{
if ( ptr )
{
list_delete_all_node(*((_QWORD *)ptr + 2));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
list_delete_all_node(*((_QWORD *)ptr + 2));
free(ptr);
}
}

original_code:
void group_destroy(struct groupnode *groupn)
{
 if (!groupn) return;
{}
 list_delete_all_node(groupn->interfaces);
 free(groupn);
}

variable_types: struct groupnode { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } mca; struct list { struct listnode { struct listnode *next; struct listnode *prev; void *data; } *head; struct listnode *tail; long count; void (*del)(void *val); } *interfaces; long lastforward; unsigned long bytes; unsigned long packets; } *

user_defined_types: struct groupnode { struct in6_addr mca; struct list *interfaces; long lastforward; unsigned long bytes; unsigned long packets; }


dolog

decompiled_code:
void dolog(int a1, const char *a2, ...)
{
const char *v3; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !g_conf || *(_QWORD *)(g_conf + 56LL) || a1 != 7 )
{
va_start(arg, a2);
if ( g_conf )
{
if ( *(_QWORD *)(g_conf + 48LL) )
{
LOBYTE(a1) = a1 | 0xB8;
vsyslog(a1, a2, arg);
return;
}
if ( *(_QWORD *)(g_conf + 56LL) )
{
v3 = "debug";
if ( a1 != 7 )
{
v3 = "error";
if ( a1 != 3 )
{
v3 = "warn";
if ( a1 != 4 )
{
v3 = "info";
if ( a1 != 6 )
v3 = (const char *)&unk_23A;
}
}
}
printf("[%6s] ", v3);
}
}
vprintf(a2, arg);
}
}

canonical_decompiled_code:
void func0(int a1, const char *a2, ...)
{
const char *v3; // rsi
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( !g_conf || *(_QWORD *)(g_conf + 56LL) || a1 != 7 )
{
va_start(arg, a2);
if ( g_conf )
{
if ( *(_QWORD *)(g_conf + 48LL) )
{
LOBYTE(a1) = a1 | 0xB8;
vsyslog(a1, a2, arg);
return;
}
if ( *(_QWORD *)(g_conf + 56LL) )
{
v3 = "debug";
if ( a1 != 7 )
{
v3 = "error";
if ( a1 != 3 )
{
v3 = "warn";
if ( a1 != 4 )
{
v3 = "info";
if ( a1 != 6 )
v3 = (const char *)&unk_23A;
}
}
}
printf("[%6s] ", v3);
}
}
vprintf(a2, arg);
}
}

original_code:
void dolog(int level, const char *fmt, ...)
{
 va_list ap;
 if (g_conf && !g_conf->verbose && level == 7) return;
 __builtin_va_start(ap,fmt);
 if (g_conf && g_conf->daemonize)
 {
  vsyslog((23<<3)|level, fmt, ap);
 }
 else
 {
  if (g_conf && g_conf->verbose)
  {
   printf("[%6s] ",
    level == 7 ? "debug" :
    (level == 3 ? "error" :
    (level == 4 ? "warn" :
    (level == 6 ? "info" : ""))));
  }
  vprintf(fmt, ap);
 }
 __builtin_va_end(ap);
}

canonical_original_code:
void dolog(int level, char *fmt, ...)
{
 __builtin_va_list ap;
 if (g_conf && !g_conf->verbose && level == 7) return;
 __builtin_va_start(ap,fmt);
 if (g_conf && g_conf->daemonize)
 {
  vsyslog((23<<3)|level, fmt, ap);
 }
 else
 {
  if (g_conf && g_conf->verbose)
  {
   printf("[%6s] ",
    level == 7 ? "debug" :
    (level == 3 ? "error" :
    (level == 4 ? "warn" :
    (level == 6 ? "info" : ""))));
  }
  vprintf(fmt, ap);
 }
 __builtin_va_end(ap);
}

variable_types: level int

variable_types:
fmt
char *


cleanpid

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

dolog(6, "Trying to exit, got signal %d...\n", a1);
unlink("/var/run/ecmh.pid");
result = g_conf;
if ( g_conf )
*(_QWORD *)(g_conf + 64LL) = 1LL;
return result;
}

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

func0(6, "Trying to exit, got signal %d...\n", a1);
unlink("/var/run/ecmh.pid");
result = g_conf;
if ( g_conf )
*(_QWORD *)(g_conf + 64LL) = 1LL;
return result;
}

original_code:
void cleanpid(int i)
{
 dolog(6, "Trying to exit, got signal %d...\n", i);
 unlink("/var/run/ecmh.pid");
 if (g_conf) g_conf->quit = (!0);
}

variable_types: i int


gettimes

decompiled_code:
__time_t gettimes()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v1);
return v1.tv_sec;
}

canonical_decompiled_code:
__time_t func4()
{
struct timespec v1; // [rsp+0h] [rbp-18h] BYREF

clock_gettime(0, &v1);
return v1.tv_sec;
}

original_code:
uint64_t gettimes(void)
{
 struct timespec ts;
 clock_gettime(0, &ts);
 return (ts.tv_sec);
}

canonical_original_code:
unsigned long gettimes()
{
 struct timespec ts;
 clock_gettime(0, &ts);
 return (ts.tv_sec);
}

variable_types: struct timespec { long tv_sec; long tv_nsec; }

return_type: unsigned long


decompiled_code:
void __fastcall int_destroy(__int64 a1)
{
*(_QWORD *)(a1 + 32) = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
*(_QWORD *)(a1 + 32) = 0LL;
}

original_code:
void int_destroy(struct intnode *intn)
{
{}
 intn->mtu = 0;
}

variable_types: struct intnode { unsigned long ifindex; char name[16]; unsigned long groupcount; unsigned long mtu; unsigned long mld_version; unsigned long mld_last_v1; struct sockaddr { unsigned short sa_family; char sa_data[14]; } hwaddr; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } linklocal; struct in6_addr global; unsigned long stat_packets_received; unsigned long stat_packets_sent; unsigned long stat_bytes_received; unsigned long stat_bytes_sent; unsigned long stat_icmp_received; unsigned long stat_icmp_sent; unsigned long upstream; } *

user_defined_types: struct intnode { unsigned long ifindex; char name[16]; unsigned long groupcount; unsigned long mtu; unsigned long mld_version; unsigned long mld_last_v1; struct sockaddr hwaddr; struct in6_addr linklocal; struct in6_addr global; unsigned long stat_packets_received; unsigned long stat_packets_sent; unsigned long stat_bytes_received; unsigned long stat_bytes_sent; unsigned long stat_icmp_received; unsigned long stat_icmp_sent; unsigned long upstream; }


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

if ( (unsigned __int64)a1 >= *(_QWORD *)(g_conf + 8LL) )
return 0LL;
result = *(_QWORD *)(g_conf + 16LL) + 160LL * a1;
if ( !*(_QWORD *)(result + 32) )
result = 0LL;
return result;
}

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

if ( (unsigned __int64)a1 >= *(_QWORD *)(g_conf + 8LL) )
return 0LL;
result = *(_QWORD *)(g_conf + 16LL) + 160LL * a1;
if ( !*(_QWORD *)(result + 32) )
result = 0LL;
return result;
}

original_code:
struct intnode *int_find(unsigned int ifindex)
{
 if (ifindex >= g_conf->maxinterfaces || g_conf->ints[ifindex].mtu == 0) return ((void *)0);
 return &g_conf->ints[ifindex];
}

variable_types:
ifindex
unsigned int

return_type: struct intnode { unsigned long ifindex; char name[16]; unsigned long groupcount; unsigned long mtu; unsigned long mld_version; unsigned long mld_last_v1; struct sockaddr { unsigned short sa_family; char sa_data[14]; } hwaddr; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } linklocal; struct in6_addr global; unsigned long stat_packets_received; unsigned long stat_packets_sent; unsigned long stat_bytes_received; unsigned long stat_bytes_sent; unsigned long stat_icmp_received; unsigned long stat_icmp_sent; unsigned long upstream; } *


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

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

original_code:
void subscr_destroy(struct subscrnode *subscrn)
{
 if (!subscrn) return;
{}
 free(subscrn);
}

variable_types: struct subscrnode { struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } ipv6; unsigned long mode; long refreshtime; } *

user_defined_types: struct subscrnode { struct in6_addr ipv6; unsigned long mode; long refreshtime; }


decompiled_code:
__int64 __fastcall subscr_unsub(_QWORD *a1, _DWORD *a2)
{
_QWORD *v3; // rsi
_DWORD *v4; // rbx

v3 = (_QWORD *)*a1;
if ( !*a1 )
return 0LL;
do
{
v4 = (_DWORD *)v3[2];
if ( v4 && *a2 == *v4 && a2[1] == v4[1] && a2[2] == v4[2] && a2[3] == v4[3] )
{
list_delete_node();
subscr_destroy(v4);
return 1LL;
}
v3 = (_QWORD *)*v3;
}
while ( v3 );
return 0LL;
}

original_code:
uint64_t subscr_unsub(struct list *list, const struct in6_addr *ipv6)
{
 struct subscrnode *subscrn;
 struct listnode *ln;
 for ((ln) = (list)->head; (ln); (ln) = (ln)->next) if (((subscrn) = (ln)->data) != ((void *)0))
 {
  if ((__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (ipv6); const struct in6_addr *__b = (const struct in6_addr *) (&subscrn->ipv6); __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; })))
  {
   list_delete_node(list, ln);
   subscr_destroy(subscrn);
   return (!0);
  }
 }
 return 0;
}

canonical_original_code:
unsigned long subscr_unsub(struct list *list, struct in6_addr *ipv6)
{
 struct subscrnode *subscrn;
 struct listnode *ln;
 for ((ln) = (list)->head; (ln); (ln) = (ln)->next) if (((subscrn) = (ln)->data) != ((void *)0))
 {
  if ((__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (ipv6); struct in6_addr *__b = (const struct in6_addr *) (&subscrn->ipv6); __a->__in6_u.__u6_addr32[0] == __b->__in6_u.__u6_addr32[0] && __a->__in6_u.__u6_addr32[1] == __b->__in6_u.__u6_addr32[1] && __a->__in6_u.__u6_addr32[2] == __b->__in6_u.__u6_addr32[2] && __a->__in6_u.__u6_addr32[3] == __b->__in6_u.__u6_addr32[3]; })))
  {
   list_delete_node(list, ln);
   subscr_destroy(subscrn);
   return (!0);
  }
 }
 return 0;
}

variable_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } *


decompiled_code:
void __fastcall grpint_destroy(void *ptr)
{
if ( ptr )
{
list_delete_all_node(*((_QWORD *)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( ptr )
{
list_delete_all_node(*((_QWORD *)ptr + 1));
free(ptr);
}
}

original_code:
void grpint_destroy(struct grpintnode *grpintn)
{
 if (!grpintn) return;
 list_delete_all_node(grpintn->subscriptions);
 free(grpintn);
}

variable_types: struct grpintnode { unsigned long ifindex; struct list { struct listnode { struct listnode *next; struct listnode *prev; void *data; } *head; struct listnode *tail; long count; void (*del)(void *val); } *subscriptions; } *

user_defined_types: struct grpintnode { unsigned long ifindex; struct list *subscriptions; }


decompiled_code:
__int64 __fastcall grpint_refresh(__int64 a1, _DWORD *a2, unsigned int a3)
{
__int64 v4; // rbx
__int64 v5; // rdx
__int64 result; // rax

v4 = subscr_find(*(_QWORD *)(a1 + 8));
if ( a3 != 2 || *a2 || a2[1] || a2[2] || (result = 1LL, a2[3]) )
{
if ( !v4 )
{
v4 = subscr_create(a2, a3);
result = 0LL;
if ( !v4 )
return result;
listnode_add(*(_QWORD *)(a1 + 8), v4);
}
v5 = *(_QWORD *)(v4 + 16);
if ( a3 != v5 )
{
dolog(7LL, "grpint_refresh() - Mode changed from %lu to %u\n", v5, a3);
*(_QWORD *)(v4 + 16) = a3;
}
*(_QWORD *)(v4 + 24) = time(0LL);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, _DWORD *a2, unsigned int a3)
{
__int64 v4; // rbx
__int64 v5; // rdx
__int64 result; // rax

v4 = subscr_find(*(_QWORD *)(a1 + 8));
if ( a3 != 2 || *a2 || a2[1] || a2[2] || (result = 1LL, a2[3]) )
{
if ( !v4 )
{
v4 = subscr_create(a2, a3);
result = 0LL;
if ( !v4 )
return result;
listnode_add(*(_QWORD *)(a1 + 8), v4);
}
v5 = *(_QWORD *)(v4 + 16);
if ( a3 != v5 )
{
dolog(7LL, "grpint_refresh() - Mode changed from %lu to %u\n", v5, a3);
*(_QWORD *)(v4 + 16) = a3;
}
*(_QWORD *)(v4 + 24) = time(0LL);
result = 1LL;
}
return result;
}

original_code:
uint64_t grpint_refresh(struct grpintnode *grpintn, const struct in6_addr *ipv6, unsigned int mode)
{
 struct subscrnode *subscrn;
 subscrn = subscr_find(grpintn->subscriptions, ipv6);
 if ( mode == 2 &&
  (__extension__ ({ const struct in6_addr *__a = (const struct in6_addr *) (ipv6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == 0; })))
 {
  return (!0);
 }
 if (!subscrn)
 {
  subscrn = subscr_create(ipv6, mode);
  if (subscrn)
  {
   listnode_add(grpintn->subscriptions, (void *)subscrn);
  }
 }
 if (!subscrn) return 0;
 if (mode != subscrn->mode)
 {
  dolog(7, "grpint_refresh() - Mode changed from %" "l" "u" " to %u\n", subscrn->mode, mode);
  subscrn->mode = mode;
 }
 subscrn->refreshtime = time(((void *)0));
 return (!0);
}

canonical_original_code:
unsigned long grpint_refresh(struct grpintnode *grpintn, struct in6_addr *ipv6, unsigned int mode)
{
 struct subscrnode *subscrn;
 subscrn = subscr_find(grpintn->subscriptions, ipv6);
 if ( mode == 2 &&
  (__extension__ ({ struct in6_addr *__a = (const struct in6_addr *) (ipv6); __a->__in6_u.__u6_addr32[0] == 0 && __a->__in6_u.__u6_addr32[1] == 0 && __a->__in6_u.__u6_addr32[2] == 0 && __a->__in6_u.__u6_addr32[3] == 0; })))
 {
  return (!0);
 }
 if (!subscrn)
 {
  subscrn = subscr_create(ipv6, mode);
  if (subscrn)
  {
   listnode_add(grpintn->subscriptions, (void *)subscrn);
  }
 }
 if (!subscrn) return 0;
 if (mode != subscrn->mode)
 {
  dolog(7, "grpint_refresh() - Mode changed from %" "l" "u" " to %u\n", subscrn->mode, mode);
  subscrn->mode = mode;
 }
 subscrn->refreshtime = time(((void *)0));
 return (!0);
}

variable_types:
mode
unsigned int

user_defined_types: struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; }


repo: masterdriverz/geekcode

decompiled_code:
__int64 __fastcall process_line(__int64 a1, char *a2)
{
char *v3; // r13
const char **v4; // r12
const char *v5; // rbp
int v6; // er14
int v7; // eax
char *v8; // rax
__int64 result; // rax
_BYTE **v10; // rcx
_BYTE *v11; // rdx
const unsigned __int16 *v12; // rdx
char i; // [rsp+Fh] [rbp-139h] BYREF
char s[264]; // [rsp+10h] [rbp-138h] BYREF
char *save_ptr[6]; // [rsp+118h] [rbp-30h] BYREF

v3 = strtok_r(a2, " ", save_ptr);
if ( !v3 )
goto LABEL_17;
while ( 2 )
{
if ( !*(_DWORD *)a1 )
{
v12 = *_ctype_b_loc();
result = 0LL;
if ( (v12[(unsigned __int8)*v3] & 8) != 0 )
goto LABEL_18;
return result;
}
for ( i = 0; !*(_DWORD *)(a1 + 4); a1 += 32LL )
;
v4 = *(const char ***)(a1 + 24);
v5 = *v4;
if ( !*v4 )
return 2LL;
v6 = 0;
while ( *(_DWORD *)(a1 + 8) )
{
if ( (unsigned int)_isoc99_sscanf(v3, v5, &i) )
{
snprintf(s, 0x100uLL, *v4, (unsigned int)i);
v5 = s;
break;
}
LABEL_11:
++v6;
v4 += 2;
v5 = *v4;
if ( !*v4 )
return 2LL;
}
v8 = strchr(v3, 10);
if ( v8 )
*v8 = 0;
v7 = strcmp(v5, v3);
if ( v7 )
goto LABEL_11;
*(_DWORD *)a1 = v6 + 1;
if ( i )
{
v10 = *(_BYTE ***)(a1 - 8);
v11 = *v10;
if ( *v10 )
{
while ( i != *v11 )
{
v10 += 2;
++v7;
v11 = *v10;
if ( !*v10 )
return 3LL;
}
*(_DWORD *)(a1 - 32) = v7 + 1;
goto LABEL_16;
}
result = 3LL;
}
else
{
LABEL_16:
v3 = strtok_r(0LL, " ", save_ptr);
a1 += 32LL;
if ( v3 )
continue;
LABEL_17:
result = 0LL;
if ( *(_DWORD *)a1 )
LABEL_18:
result = 1LL;
}
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, char *a2)
{
char *v3; // r13
const char **v4; // r12
const char *v5; // rbp
int v6; // er14
int v7; // eax
char *v8; // rax
__int64 result; // rax
_BYTE **v10; // rcx
_BYTE *v11; // rdx
const unsigned __int16 *v12; // rdx
char i; // [rsp+Fh] [rbp-139h] BYREF
char s[264]; // [rsp+10h] [rbp-138h] BYREF
char *save_ptr[6]; // [rsp+118h] [rbp-30h] BYREF

v3 = strtok_r(a2, " ", save_ptr);
if ( !v3 )
goto LABEL_17;
while ( 2 )
{
if ( !*(_DWORD *)a1 )
{
v12 = *_ctype_b_loc();
result = 0LL;
if ( (v12[(unsigned __int8)*v3] & 8) != 0 )
goto LABEL_18;
return result;
}
for ( i = 0; !*(_DWORD *)(a1 + 4); a1 += 32LL )
;
v4 = *(const char ***)(a1 + 24);
v5 = *v4;
if ( !*v4 )
return 2LL;
v6 = 0;
while ( *(_DWORD *)(a1 + 8) )
{
if ( (unsigned int)_isoc99_sscanf(v3, v5, &i) )
{
snprintf(s, 0x100uLL, *v4, (unsigned int)i);
v5 = s;
break;
}
LABEL_11:
++v6;
v4 += 2;
v5 = *v4;
if ( !*v4 )
return 2LL;
}
v8 = strchr(v3, 10);
if ( v8 )
*v8 = 0;
v7 = strcmp(v5, v3);
if ( v7 )
goto LABEL_11;
*(_DWORD *)a1 = v6 + 1;
if ( i )
{
v10 = *(_BYTE ***)(a1 - 8);
v11 = *v10;
if ( *v10 )
{
while ( i != *v11 )
{
v10 += 2;
++v7;
v11 = *v10;
if ( !*v10 )
return 3LL;
}
*(_DWORD *)(a1 - 32) = v7 + 1;
goto LABEL_16;
}
result = 3LL;
}
else
{
LABEL_16:
v3 = strtok_r(0LL, " ", save_ptr);
a1 += 32LL;
if ( v3 )
continue;
LABEL_17:
result = 0LL;
if ( *(_DWORD *)a1 )
LABEL_18:
result = 1LL;
}
return result;
}
}

original_code:
static enum parse_errors_t process_line(struct answer *line, char *data)
{
 char *last, *p;
 for ((p = strtok_r(data, " ", &last)); p && line->answer;
  (p = strtok_r(((void *)0), " ", &last)), line++) {
  int i;
  const struct elem *temp;
  char c=0;
  while (!line->display)
   line++;
  for (temp = line->contents, i=0; temp[i].alias; i++) {
   char *n, buf[256];
   const char *s;
   if (line->dependant) {
    if (sscanf(p, temp[i].alias, &c))
     snprintf(buf, sizeof(buf), temp[i].alias, c);
    else
     continue;
    s = (const char *)&buf;
   } else {
    s = temp[i].alias;
   }
   n = strchr(p, '\n');
   if (n)
    *n = '\0';
   if (!strcmp(s, p))
    goto out;
  }
  return EALIAS;
out:
  line->answer = i+1;
  if (c) {
   const struct elem *temp;
   int i;
   for (temp = (line-1)->contents, i = 0; temp->alias; temp++, i++)
    if (*(temp->alias) == c)
     goto found;
   return EDEPENDANT;
found:
   (line-1)->answer = i+1;
  }
 }
 if ((p && ((*__ctype_b_loc ())[(int) (((unsigned char )*p))] & (unsigned short int) _ISalnum)) || line->answer)
  return ETRAILING;
 return SUCCESS;
}

canonical_original_code:
static enum parse_errors_t process_line(struct answer *line, char *data)
{
 char *last; char *p;
 for ((p = strtok_r(data, " ", &last)); p && line->answer;
  (p = strtok_r(((void *)0), " ", &last)), line++) {
  int i;
  struct elem *temp;
  char c = 0;
  while (!line->display)
   line++;
  for (temp = line->contents, i=0; temp[i].alias; i++) {
   char *n; char buf[256];
   char *s;
   if (line->dependant) {
    if (sscanf(p, temp[i].alias, &c))
     snprintf(buf, sizeof(buf), temp[i].alias, c);
    else
     continue;
    s = (char *)&buf;
   } else {
    s = temp[i].alias;
   }
   n = strchr(p, '\n');
   if (n)
    *n = '\0';
   if (!strcmp(s, p))
    goto out;
  }
  return EALIAS;
out:
  line->answer = i+1;
  if (c) {
   struct elem *temp;
   int i;
   for (temp = (line-1)->contents, i = 0; temp->alias; temp++, i++)
    if (*(temp->alias) == c)
     goto found;
   return EDEPENDANT;
found:
   (line-1)->answer = i+1;
  }
 }
 if ((p && ((*__ctype_b_loc ())[(int) (((unsigned char )*p))] & (unsigned short) _ISalnum)) || line->answer)
  return ETRAILING;
 return SUCCESS;
}

variable_types: struct answer { int answer; char *name; struct elem { char *alias; } *contents; } *

variable_types:
data
char *

variable_types:
last
char *

variable_types:
p
char *

variable_types:
temp
struct elem { char *alias; } *

variable_types: c char

variable_types:
n
char *

variable_types:
buf
char [256]

variable_types:
s
char *

return_type: enum parse_errors_t { SUCCESS=0, ETRAILING=1, EALIAS=2, EDEPENDANT=3, ESYNTAX=4, EEOF=5, EFERROR=6 }

user_defined_types: struct answer { int answer; char *name; struct elem *contents; }


getcontent

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

if ( *a1 <= 0 )
result = 0LL;
else
result = *((_QWORD *)a1 + 3) + 16LL * *a1 - 16;
return result;
}

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

if ( *a1 <= 0 )
result = 0LL;
else
result = *((_QWORD *)a1 + 3) + 16LL * *a1 - 16;
return result;
}

original_code:
static inline const struct elem *getcontent(const struct answer *obj)
{
 if (obj->answer <= 0)
  return ((void *)0);
 return &obj->contents[obj->answer-1];
}

canonical_original_code:
static inline struct elem *getcontent(struct answer *obj)
{
 if (obj->answer <= 0)
  return ((void *)0);
 return &obj->contents[obj->answer-1];
}

variable_types: struct answer { int answer; char *name; struct elem *contents; } *

return_type: struct elem { char *alias; } *


version

decompiled_code:
int version()
{
return puts("Geekcode version v2");
}

canonical_decompiled_code:
int func2()
{
return puts("Geekcode version v2");
}

original_code:
static inline void version(void)
{
 puts(version_str);
}

canonical_original_code:
static inline void version()
{
 puts(version_str);
}


decompiled_code:
int list_sections()
{
__int64 v0; // rbx
_QWORD *v1; // rbp
int result; // eax

v0 = lines;
v1 = &lines;
if ( lines )
{
do
{
for ( ; *(_DWORD *)v0; v0 += 32LL )
result = puts(*(const char **)(v0 + 16));
v0 = *++v1;
}
while ( *v1 );
}
return result;
}

canonical_decompiled_code:
int func3()
{
__int64 v0; // rbx
_QWORD *v1; // rbp
int result; // eax

v0 = lines;
v1 = &lines;
if ( lines )
{
do
{
for ( ; *(_DWORD *)v0; v0 += 32LL )
result = puts(*(const char **)(v0 + 16));
v0 = *++v1;
}
while ( *v1 );
}
return result;
}

original_code:
static void list_sections(void)
{
 struct answer **cur_line;
 for (cur_line = lines; *cur_line; cur_line++) {
  struct answer *cur_question;
  for (cur_question = *cur_line; cur_question->answer; cur_question++)
   puts(cur_question->name);
 }
}

canonical_original_code:
static void list_sections()
{
 struct answer **cur_line;
 for (cur_line = lines; *cur_line; cur_line++) {
  struct answer *cur_question;
  for (cur_question = *cur_line; cur_question->answer; cur_question++)
   puts(cur_question->name);
 }
}

variable_types: struct answer { int answer; char *name; struct elem { char *alias; } *contents; } **


decompiled_code:
void __fastcall __noreturn file_error(const char *a1, const char *a2)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x100uLL, "Error while %s file \"%s\"", a2, a1);
perror(v2);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func4(const char *a1, const char *a2)
{
char v2[264]; // [rsp+0h] [rbp-108h] BYREF

snprintf(v2, 0x100uLL, "Error while %s file \"%s\"", a2, a1);
perror(v2);
exit(1);
}

original_code:
static void file_error(const char *filename, const char *action)
{
 char error[256];
 snprintf(error, sizeof(error), "Error while %s file \"%s\"",
  action, filename);
 perror(error);
 exit(1);
}

canonical_original_code:
static void file_error(char *filename, char *action)
{
 char error[256];
 snprintf(error, sizeof(error), "Error while %s file \"%s\"",
  action, filename);
 perror(error);
 exit(1);
}

variable_types:
filename
char *

variable_types:
action
char *

variable_types:
error
char [256]


decompiled_code:
_DWORD *create_code()
{
_DWORD *result; // rax
unsigned int v1; // er12
_DWORD **v2; // r14
int *v3; // rbx

result = (_DWORD *)lines;
v1 = 1;
v2 = (_DWORD **)&lines;
if ( lines )
{
do
{
v3 = result - 8;
if ( *result )
{
do
{
if ( v3[10] )
xgetcontent(v3, "function: %s; line %d\n", "create_code", 80LL);
v3[8] = getanswer(*((_QWORD *)v3 + 6), v1++, *((_QWORD *)v3 + 7));
v3 += 8;
}
while ( v3[8] );
}
result = *++v2;
}
while ( *v2 );
}
return result;
}

canonical_decompiled_code:
_DWORD *func8()
{
_DWORD *result; // rax
unsigned int v1; // er12
_DWORD **v2; // r14
int *v3; // rbx

result = (_DWORD *)lines;
v1 = 1;
v2 = (_DWORD **)&lines;
if ( lines )
{
do
{
v3 = result - 8;
if ( *result )
{
do
{
if ( v3[10] )
func5(v3, "function: %s; line %d\n", "create_code", 80LL);
v3[8] = getanswer(*((_QWORD *)v3 + 6), v1++, *((_QWORD *)v3 + 7));
v3 += 8;
}
while ( v3[8] );
}
result = *++v2;
}
while ( *v2 );
}
return result;
}

original_code:
static void create_code(void)
{
 struct answer **cur_line;
 int page_num=1;
 for (cur_line = lines; *cur_line; cur_line++) {
  struct answer *cur_question;
  for (cur_question = *cur_line;
    cur_question->answer;
    cur_question++, page_num++) {
   const char *aux_string=((void *)0);
   if (cur_question->dependant) {
    const struct elem *aux = xgetcontent(cur_question-1,
     "function: %s; line %d\n", __func__, 80);
    aux_string = aux->alias;
   }
   cur_question->answer =
    getanswer(cur_question->name, page_num,
     cur_question->contents, aux_string);
  }
 }
}

canonical_original_code:
static void create_code()
{
 struct answer **cur_line;
 int page_num = 1;
 for (cur_line = lines; *cur_line; cur_line++) {
  struct answer *cur_question;
  for (cur_question = *cur_line;
    cur_question->answer;
    cur_question++, page_num++) {
   char *aux_string = ((void *)0);
   if (cur_question->dependant) {
    struct elem *aux = xgetcontent(cur_question-1,
     "function: %s; line %d\n", __func__, 80);
    aux_string = aux->alias;
   }
   cur_question->answer =
    getanswer(cur_question->name, page_num,
     cur_question->contents, aux_string);
  }
 }
}

variable_types:
aux
struct elem { char *alias; } *


original_code:
static unsigned int print_page(const char *name, int page_num,
  const struct elem *objects,
  const char *additional)
{
 unsigned int i;
 printf("\nPage %i of %i: %s\n", page_num, 37, name);
 puts("===============================================================================");
 for (i = 0; objects[i].comment; i++) {
  const char *alias = objects[i].alias;
  if (additional) {
   char *s = malloc(strlen(objects[i].alias));
   if (!s) {
    perror(((void *)0));
    exit(-1);
   }
   sprintf(s, objects[i].alias, *additional);
   alias = s;
  }
  printf("%2d %-5s %s\n", i+1, alias, objects[i].comment);
  if (additional)
   free((void *)alias);
 }
 return i;
}

canonical_original_code:
static unsigned int print_page(char *name, int page_num, struct elem *objects, char *additional)
{
 unsigned int i;
 printf("\nPage %i of %i: %s\n", page_num, 37, name);
 puts("===============================================================================");
 for (i = 0; objects[i].comment; i++) {
  char *alias = objects[i].alias;
  if (additional) {
   char *s = malloc(strlen(objects[i].alias));
   if (!s) {
    perror(((void *)0));
    exit(-1);
   }
   sprintf(s, objects[i].alias, *additional);
   alias = s;
  }
  printf("%2d %-5s %s\n", i+1, alias, objects[i].comment);
  if (additional)
   free((void *)alias);
 }
 return i;
}

variable_types:
name
char *

variable_types:
objects
struct elem { char *alias; } *

variable_types:
additional
char *

variable_types:
i
unsigned int

variable_types:
alias
char *