decompiled_code:
char *term_init()
{
char *result; // rax

result = getenv("TERM");
if ( !strcmp(result, "dumb") || !*result )
dumb_terminal = 1;
return result;
}

canonical_decompiled_code:
char *func6()
{
char *result; // rax

result = getenv("TERM");
if ( !strcmp(result, "dumb") || !*result )
dumb_terminal = 1;
return result;
}

original_code:
void term_init(void) {
 char *termenv = getenv("TERM");
 if ((strcmp(termenv, "dumb") == 0) || strcmp(termenv, "") == 0) {
  dumb_terminal = 1;
 }
}

canonical_original_code:
void term_init() {
 char *termenv = getenv("TERM");
 if ((strcmp(termenv, "dumb") == 0) || strcmp(termenv, "") == 0) {
  dumb_terminal = 1;
 }
}

variable_types:
termenv
char *


checksum

repo: aarzilli/minstrel

decompiled_code:
__int64 __fastcall checksum(char *a1)
{
char v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
do
{
v2 += v1;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func7(char *a1)
{
char v1; // al
__int64 v2; // rdx

v1 = *a1;
if ( !*a1 )
return 0LL;
v2 = 0LL;
do
{
v2 += v1;
v1 = *++a1;
}
while ( *a1 );
return v2;
}

original_code:
int64_t checksum(const char *a) {
 int64_t r = 0;
 for (const char *c = a; *c != '\0'; ++c) {
  r += *c;
 }
 return r;
}

canonical_original_code:
long checksum(char *a) {
 long r = 0;
 for (char *c = a; *c != '\0'; ++c) {
  r += *c;
 }
 return r;
}

variable_types:
a
char *

variable_types: r long

variable_types:
c
char *

return_type: long


decompiled_code:
__int64 __fastcall should_autoindex_file(const char *a1)
{
char *v1; // rax
unsigned int v2; // ebx
char *v3; // rbp
char v4; // bl
const __int32_t *v5; // rcx
char *v6; // rax
const char **v7; // rbx

v1 = strrchr(a1, 46);
v2 = 0;
if ( v1 )
{
v3 = strdup(v1 + 1);
oomp(v3);
v4 = *v3;
if ( *v3 )
{
v5 = *_ctype_tolower_loc();
v6 = v3;
do
{
*v6++ = v5[v4];
v4 = *v6;
}
while ( *v6 );
}
v7 = (const char **)&KNOWN_AUDIO_EXTENSIONS;
while ( strcmp(*v7, v3) )
{
if ( ++v7 == (const char **)(unsigned int)((_DWORD)&KNOWN_AUDIO_EXTENSIONS + 192) )
{
v2 = 0;
goto LABEL_10;
}
}
v2 = 1;
LABEL_10:
free(v3);
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
char *v1; // rax
unsigned int v2; // ebx
char *v3; // rbp
char v4; // bl
const __int32_t *v5; // rcx
char *v6; // rax
const char **v7; // rbx

v1 = strrchr(a1, 46);
v2 = 0;
if ( v1 )
{
v3 = strdup(v1 + 1);
oomp(v3);
v4 = *v3;
if ( *v3 )
{
v5 = *_ctype_tolower_loc();
v6 = v3;
do
{
*v6++ = v5[v4];
v4 = *v6;
}
while ( *v6 );
}
v7 = (const char **)&KNOWN_AUDIO_EXTENSIONS;
while ( strcmp(*v7, v3) )
{
if ( ++v7 == (const char **)(unsigned int)((_DWORD)&KNOWN_AUDIO_EXTENSIONS + 192) )
{
v2 = 0;
goto LABEL_10;
}
}
v2 = 1;
LABEL_10:
free(v3);
}
return v2;
}

original_code:
static _Bool should_autoindex_file(const char *full_file_name) {
 char *dot = strrchr(full_file_name, '.');
 if (dot == ((void *)0)) return 0;
 char *ext = strdup(dot+1);
 oomp(ext);
 for (char *c = ext; *c != '\0'; ++c) {
  *c = tolower(*c);
 }
 _Bool r = 0;
 for (int i = 0; i < sizeof(KNOWN_AUDIO_EXTENSIONS)/sizeof(const char *); ++i) {
  if (strcmp(KNOWN_AUDIO_EXTENSIONS[i], ext) == 0) {
   r = 1;
   break;
  }
 }
 free(ext);
 return r;
}

canonical_original_code:
static _Bool should_autoindex_file(char *full_file_name) {
 char *dot = strrchr(full_file_name, '.');
 if (dot == ((void *)0)) return 0;
 char *ext = strdup(dot+1);
 oomp(ext);
 for (char *c = ext; *c != '\0'; ++c) {
  *c = tolower(*c);
 }
 _Bool r = 0;
 for (int i = 0; i < sizeof(KNOWN_AUDIO_EXTENSIONS)/sizeof(char *); ++i) {
  if (strcmp(KNOWN_AUDIO_EXTENSIONS[i], ext) == 0) {
   r = 1;
   break;
  }
 }
 free(ext);
 return r;
}

variable_types:
dot
char *

variable_types:
ext
char *

variable_types: i int


decompiled_code:
__int64 rating_init()
{
__int64 result; // rax
const char *v1[2]; // [rsp+8h] [rbp-10h] BYREF

rating_db = open_or_create_db("rating");
sqlite3_exec(rating_db, "pragma foreign_keys = on;", 0LL, 0LL, v1);
if ( v1[0]
|| (sqlite3_exec(rating_db, "pragma synchronous = off;", 0LL, 0LL, v1), v1[0])
|| (result = sqlite3_exec(
rating_db,
"CREATE TABLE IF NOT EXISTS rating(filename text primary key, listened integer default 0, added integer default 0);",
0LL,
0LL,
v1),
v1[0]) )
{
fprintf(stderr, "Sqlite error building rating db: %s\n", v1[0]);
sqlite3_free(v1[0]);
sqlite3_close(rating_db);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
__int64 result; // rax
const char *v1[2]; // [rsp+8h] [rbp-10h] BYREF

rating_db = open_or_create_db("rating");
sqlite3_exec(rating_db, "pragma foreign_keys = on;", 0LL, 0LL, v1);
if ( v1[0]
|| (sqlite3_exec(rating_db, "pragma synchronous = off;", 0LL, 0LL, v1), v1[0])
|| (result = sqlite3_exec(
rating_db,
"CREATE TABLE IF NOT EXISTS rating(filename text primary key, listened integer default 0, added integer default 0);",
0LL,
0LL,
v1),
v1[0]) )
{
fprintf(stderr, "Sqlite error building rating db: %s\n", v1[0]);
sqlite3_free(v1[0]);
sqlite3_close(rating_db);
exit(1);
}
return result;
}

original_code:
void rating_init(void) {
 char *errmsg;
 rating_db = open_or_create_db("rating");
 sqlite3_exec(rating_db, "pragma foreign_keys = on;", ((void *)0), ((void *)0), &errmsg);
 if (errmsg != ((void *)0)) goto rating_init_failure;
 sqlite3_exec(rating_db, "pragma synchronous = off;", ((void *)0), ((void *)0), &errmsg);
 if (errmsg != ((void *)0)) goto rating_init_failure;
 sqlite3_exec(rating_db, "CREATE TABLE IF NOT EXISTS rating(filename text primary key, listened integer default 0, added integer default 0);", ((void *)0), ((void *)0), &errmsg);
 if (errmsg != ((void *)0)) goto rating_init_failure;
 return;
rating_init_failure:
 fprintf(stderr, "Sqlite error building rating db: %s\n", errmsg);
 sqlite3_free(errmsg);
 sqlite3_close(rating_db);
 exit(1);
}

canonical_original_code:
void rating_init() {
 char *errmsg;
 rating_db = open_or_create_db("rating");
 sqlite3_exec(rating_db, "pragma foreign_keys = on;", ((void *)0), ((void *)0), &errmsg);
 if (errmsg != ((void *)0)) goto rating_init_failure;
 sqlite3_exec(rating_db, "pragma synchronous = off;", ((void *)0), ((void *)0), &errmsg);
 if (errmsg != ((void *)0)) goto rating_init_failure;
 sqlite3_exec(rating_db, "CREATE TABLE IF NOT EXISTS rating(filename text primary key, listened integer default 0, added integer default 0);", ((void *)0), ((void *)0), &errmsg);
 if (errmsg != ((void *)0)) goto rating_init_failure;
 return;
rating_init_failure:
 fprintf(stderr, "Sqlite error building rating db: %s\n", errmsg);
 sqlite3_free(errmsg);
 sqlite3_close(rating_db);
 exit(1);
}

variable_types:
errmsg
char *

return_type: void


main

canonical_name: main

repo: aashishthite/OSCourse

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
Hash_Init();
Hash_Insert();
if ( Hash_Lookup() )
return 0;
puts("No val returned");
return -1;
}

original_code:
int main()
{
   int element = 255;
    unsigned int key = 127;
    hash_t hs;
    Hash_Init(&hs, 32);
    Hash_Insert(&hs, (void*)&element, key);
    void *val = Hash_Lookup(&hs, key);
    if (val)
 return 0;
    else
 {
  printf("No val returned\n");
  return -1;
 }
}

canonical_original_code:
int main()
{
   int element = 255;
    unsigned int key = 127;
    struct hash_t hs;
    Hash_Init(&hs, 32);
    Hash_Insert(&hs, (void *)&element, key);
    void *val = Hash_Lookup(&hs, key);
    if (val)
 return 0;
    else
 {
  printf("No val returned\n");
  return -1;
 }
}

variable_types: element int

variable_types:
key
unsigned int

variable_types: struct hash_t { unsigned int numBuckets; struct list_t { struct spinlock_t { int state; } lock; struct listItem { struct listItem *next; void *element; unsigned int key; } *head; } **buckets; }

variable_types:
val
void *

return_type: int

user_defined_types: struct hash_t { unsigned int numBuckets; struct list_t **buckets; }

user_defined_types: struct list_t { struct spinlock_t lock; struct listItem *head; }


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

if ( a1 )
{
spinlock_acquire();
*(_QWORD *)(a1 + 8) = 0LL;
result = spinlock_release();
}
return result;
}

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

if ( a1 )
{
spinlock_acquire();
*(_QWORD *)(a1 + 8) = 0LL;
result = spinlock_release();
}
return result;
}

original_code:
void List_Init(list_t *list)
{
 if(list)
 {
  spinlock_acquire(&list->lock);
  list->head = ((void *)0);
  spinlock_release(&list->lock);
 }
}

canonical_original_code:
void List_Init(struct list_t *list)
{
 if(list)
 {
  spinlock_acquire(&list->lock);
  list->head = ((void *)0);
  spinlock_release(&list->lock);
 }
}

variable_types: struct list_t { struct spinlock_t { int state; } lock; struct listItem { struct listItem *next; void *element; unsigned int key; } *head; } *


decompiled_code:
void __fastcall List_Insert(__int64 a1, __int64 a2, int a3)
{
_DWORD *v4; // rbp

if ( a1 )
{
v4 = malloc(0x18uLL);
v4[4] = a3;
*((_QWORD *)v4 + 1) = a2;
*(_QWORD *)v4 = 0LL;
spinlock_acquire();
*(_QWORD *)v4 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v4;
spinlock_release();
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, __int64 a2, int a3)
{
_DWORD *v4; // rbp

if ( a1 )
{
v4 = malloc(0x18uLL);
v4[4] = a3;
*((_QWORD *)v4 + 1) = a2;
*(_QWORD *)v4 = 0LL;
spinlock_acquire();
*(_QWORD *)v4 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = v4;
spinlock_release();
}
}

original_code:
void List_Insert(list_t *list, void *element, unsigned int key)
{
 if(list)
 {
  listItem * newItem = malloc(sizeof(listItem));
  newItem->key = key;
  newItem->element = element;
  newItem->next = ((void *)0);
  spinlock_acquire(&list->lock);
  newItem->next = list->head;
  list->head = newItem;
  spinlock_release(&list->lock);
 }
}

canonical_original_code:
void List_Insert(struct list_t *list, void *element, unsigned int key)
{
 if(list)
 {
  struct listItem *newItem = malloc(sizeof(listItem));
  newItem->key = key;
  newItem->element = element;
  newItem->next = ((void *)0);
  spinlock_acquire(&list->lock);
  newItem->next = list->head;
  list->head = newItem;
  spinlock_release(&list->lock);
 }
}

variable_types:
element
void *

variable_types: struct listItem { struct listItem *next; void *element; unsigned int key; } *


decompiled_code:
void __fastcall List_Delete(__int64 a1, int a2)
{
_DWORD *v2; // rbx
_QWORD *v3; // rax

if ( a1 )
{
spinlock_acquire();
v2 = *(_DWORD **)(a1 + 8);
if ( v2 )
{
if ( v2[4] == a2 )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)v2;
free(v2);
spinlock_release();
return;
}
while ( 1 )
{
v3 = v2;
v2 = *(_DWORD **)v2;
if ( !v2 )
break;
if ( v2[4] == a2 )
{
*v3 = *(_QWORD *)v2;
spinlock_release();
free(v2);
return;
}
}
}
spinlock_release();
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2)
{
_DWORD *v2; // rbx
_QWORD *v3; // rax

if ( a1 )
{
spinlock_acquire();
v2 = *(_DWORD **)(a1 + 8);
if ( v2 )
{
if ( v2[4] == a2 )
{
*(_QWORD *)(a1 + 8) = *(_QWORD *)v2;
free(v2);
spinlock_release();
return;
}
while ( 1 )
{
v3 = v2;
v2 = *(_DWORD **)v2;
if ( !v2 )
break;
if ( v2[4] == a2 )
{
*v3 = *(_QWORD *)v2;
spinlock_release();
free(v2);
return;
}
}
}
spinlock_release();
}
}

original_code:
void List_Delete(list_t *list, unsigned int key)
{
 if(list)
 {
  spinlock_acquire(&list->lock);
  listItem* temp = list->head;
  if(!temp)
  {
   spinlock_release(&list->lock);
    return;
  }
  if(temp && temp->key == key)
  {
   list->head = temp->next;
   free(temp);
   spinlock_release(&list->lock);
   return;
  }
  while(temp->next)
  {
   if(temp->next->key == key)
   {
    listItem * toFree = temp->next;
    temp->next = toFree->next;
    spinlock_release(&list->lock);
    free(toFree);
    return;
   }
   temp = temp -> next;
  }
  spinlock_release(&list->lock);
 }
}

canonical_original_code:
void List_Delete(struct list_t *list, unsigned int key)
{
 if(list)
 {
  spinlock_acquire(&list->lock);
  struct listItem *temp = list->head;
  if(!temp)
  {
   spinlock_release(&list->lock);
    return;
  }
  if(temp && temp->key == key)
  {
   list->head = temp->next;
   free(temp);
   spinlock_release(&list->lock);
   return;
  }
  while(temp->next)
  {
   if(temp->next->key == key)
   {
    struct listItem *toFree = temp->next;
    temp->next = toFree->next;
    spinlock_release(&list->lock);
    free(toFree);
    return;
   }
   temp = temp -> next;
  }
  spinlock_release(&list->lock);
 }
}

user_defined_types: struct listItem { struct listItem *next; void *element; unsigned int key; }


decompiled_code:
__int64 __fastcall List_Lookup(__int64 a1, int a2)
{
__int64 result; // rax
__int64 *v3; // rbx

result = a1;
if ( a1 )
{
spinlock_acquire();
v3 = *(__int64 **)(a1 + 8);
if ( v3 )
{
while ( *((_DWORD *)v3 + 4) != a2 )
{
v3 = (__int64 *)*v3;
if ( !v3 )
goto LABEL_5;
}
spinlock_release();
result = v3[1];
}
else
{
LABEL_5:
spinlock_release();
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, int a2)
{
__int64 result; // rax
__int64 *v3; // rbx

result = a1;
if ( a1 )
{
spinlock_acquire();
v3 = *(__int64 **)(a1 + 8);
if ( v3 )
{
while ( *((_DWORD *)v3 + 4) != a2 )
{
v3 = (__int64 *)*v3;
if ( !v3 )
goto LABEL_5;
}
spinlock_release();
result = v3[1];
}
else
{
LABEL_5:
spinlock_release();
result = 0LL;
}
}
return result;
}

original_code:
void *List_Lookup(list_t *list, unsigned int key)
{
 if(list)
 {
  listItem * temp;
  spinlock_acquire(&list->lock);
  temp = list->head;
  while(temp)
  {
   if(temp->key == key)
   {
    spinlock_release(&list->lock);
    return temp->element;
   }
   temp = temp->next;
  }
  spinlock_release(&list->lock);
 }
 return ((void *)0);
}

canonical_original_code:
void *List_Lookup(struct list_t *list, unsigned int key)
{
 if(list)
 {
  struct listItem *temp;
  spinlock_acquire(&list->lock);
  temp = list->head;
  while(temp)
  {
   if(temp->key == key)
   {
    spinlock_release(&list->lock);
    return temp->element;
   }
   temp = temp->next;
  }
  spinlock_release(&list->lock);
 }
 return ((void *)0);
}

return_type: void *


original_code:
void Hash_Init(hash_t *hash, int buckets)
{
 if(hash)
 {
  buckets=buckets>0?buckets:1;
  hash->numBuckets = buckets;
  hash->buckets = malloc(buckets* sizeof(list_t*));
  int i;
  for(i =0; i < buckets; ++i)
  {
   hash->buckets[i]=malloc(sizeof(list_t));
   List_Init(hash->buckets[i]);
  }
 }
}

canonical_original_code:
void Hash_Init(struct hash_t *hash, int buckets)
{
 if(hash)
 {
  buckets=buckets>0?buckets:1;
  hash->numBuckets = buckets;
  hash->buckets = malloc(buckets* sizeof(struct list_t *));
  int i;
  for(i =0; i < buckets; ++i)
  {
   hash->buckets[i]=malloc(sizeof(list_t));
   List_Init(hash->buckets[i]);
  }
 }
}

variable_types: struct hash_t { unsigned int numBuckets; struct list_t { struct spinlock_t { int state; } lock; struct listItem { struct listItem *next; void *element; unsigned int key; } *head; } **buckets; } *

variable_types: buckets int


getBucket

decompiled_code:
__int64 __fastcall getBucket(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (a2 % *(_DWORD *)a1));
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2)
{
return *(_QWORD *)(*(_QWORD *)(a1 + 8) + 8LL * (a2 % *(_DWORD *)a1));
}

original_code:
list_t* getBucket(hash_t * hash, unsigned int key)
{
 return hash->buckets[key%(hash->numBuckets)];
}

canonical_original_code:
struct list_t *getBucket(struct hash_t *hash, unsigned int key)
{
 return hash->buckets[key%(hash->numBuckets)];
}

variable_types: struct hash_t { unsigned int numBuckets; struct list_t **buckets; } *

return_type: struct list_t { struct spinlock_t { int state; } lock; struct listItem { struct listItem *next; void *element; unsigned int key; } *head; } *


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

if ( a1 )
{
getBucket(a1, a3);
result = List_Insert();
}
return result;
}

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

if ( a1 )
{
func7(a1, a3);
result = List_Insert();
}
return result;
}

original_code:
void Hash_Insert(hash_t *hash, void *element, unsigned int key)
{
 if(hash)
 {
  List_Insert(getBucket(hash,key), element, key);
 }
}

canonical_original_code:
void Hash_Insert(struct hash_t *hash, void *element, unsigned int key)
{
 if(hash)
 {
  List_Insert(getBucket(hash,key), element, key);
 }
}


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

if ( a1 )
{
getBucket(a1, a2);
result = List_Delete();
}
return result;
}

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

if ( a1 )
{
func7(a1, a2);
result = List_Delete();
}
return result;
}

original_code:
void Hash_Delete(hash_t *hash, unsigned int key)
{
 if(hash)
 {
  List_Delete(getBucket(hash,key), key);
 }
}

canonical_original_code:
void Hash_Delete(struct hash_t *hash, unsigned int key)
{
 if(hash)
 {
  List_Delete(getBucket(hash,key), key);
 }
}


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

result = a1;
if ( a1 )
{
getBucket(a1, a2);
result = List_Lookup();
}
return result;
}

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

result = a1;
if ( a1 )
{
func7(a1, a2);
result = List_Lookup();
}
return result;
}

original_code:
void *Hash_Lookup(hash_t *hash, unsigned int key)
{
 if(hash)
 {
  return List_Lookup(getBucket(hash,key),key);
 }
 return ((void *)0);
}

canonical_original_code:
void *Hash_Lookup(struct hash_t *hash, unsigned int key)
{
 if(hash)
 {
  return List_Lookup(getBucket(hash,key),key);
 }
 return ((void *)0);
}


decompiled_code:
__int64 __fastcall Mem_Init(int a1, unsigned int a2)
{
int v2; // ebx
int v3; // ebp
_DWORD *v4; // rax
unsigned int *v5; // rcx
__int64 result; // rax
int v7; // er13

if ( a1 <= 0 || (v2 = a1, freeList) || sizeMem >= 0 || a2 > 1 )
{
m_error = 4;
result = 0xFFFFFFFFLL;
}
else
{
v3 = open("/dev/zero", 2);
if ( a1 % getpagesize() )
{
v7 = getpagesize() + a1;
v2 = v7 - a1 % getpagesize();
}
v4 = mmap(0LL, v2, 3, 2, v3, 0LL);
sizeMem = v2;
startMem = v4;
if ( v4 == (_DWORD *)-1LL )
{
perror("mmap");
result = 0xFFFFFFFFLL;
}
else
{
freeList = v4;
*v4 = v2 - 24;
v5 = (unsigned int *)freeList;
*(_QWORD *)(freeList + 8LL) = 0LL;
*((_QWORD *)v5 + 2) = 0LL;
debugMode = a2;
if ( a2 )
fillMemWithPattern(v4 + 6, *v5, 3735928559LL);
close(v3);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1, unsigned int a2)
{
int v2; // ebx
int v3; // ebp
_DWORD *v4; // rax
unsigned int *v5; // rcx
__int64 result; // rax
int v7; // er13

if ( a1 <= 0 || (v2 = a1, freeList) || sizeMem >= 0 || a2 > 1 )
{
m_error = 4;
result = 0xFFFFFFFFLL;
}
else
{
v3 = open("/dev/zero", 2);
if ( a1 % getpagesize() )
{
v7 = getpagesize() + a1;
v2 = v7 - a1 % getpagesize();
}
v4 = mmap(0LL, v2, 3, 2, v3, 0LL);
sizeMem = v2;
startMem = v4;
if ( v4 == (_DWORD *)-1LL )
{
perror("mmap");
result = 0xFFFFFFFFLL;
}
else
{
freeList = v4;
*v4 = v2 - 24;
v5 = (unsigned int *)freeList;
*(_QWORD *)(freeList + 8LL) = 0LL;
*((_QWORD *)v5 + 2) = 0LL;
debugMode = a2;
if ( a2 )
func7(v4 + 6, *v5, 3735928559LL);
close(v3);
result = 0LL;
}
}
return result;
}

original_code:
int Mem_Init(int sizeOfRegion, int debug)
{
 if(sizeOfRegion <= 0 || freeList != ((void *)0) || sizeMem>=0 || (debug!=0 && debug!=1))
 {
  m_error = (4);
  return -1;
 }
 int fd = open("/dev/zero", 02);
 if(sizeOfRegion%getpagesize())
  sizeOfRegion = sizeOfRegion + getpagesize()-(sizeOfRegion%getpagesize());
 void* ptr = mmap(((void *)0), sizeOfRegion, 0x1 | 0x2, 0x02, fd, 0);
 sizeMem = sizeOfRegion;
 startMem = ptr;
 if(ptr == ((void *) -1))
 {
  perror("mmap");
  return -1;
 }
 freeList = ptr;
 freeList->size = sizeOfRegion - sizeof(memNode);
 freeList->next = ((void *)0);
 freeList->prev = ((void *)0);
 debugMode = debug;
 if(debugMode)
 {
  fillMemWithPattern((void*)ptr+sizeof(memNode), freeList->size,0xDEADBEEF);
 }
 close(fd);
 return 0;
}

canonical_original_code:
int Mem_Init(int sizeOfRegion, int debug)
{
 if(sizeOfRegion <= 0 || freeList != ((void *)0) || sizeMem>=0 || (debug!=0 && debug!=1))
 {
  m_error = (4);
  return -1;
 }
 int fd = open("/dev/zero", 02);
 if(sizeOfRegion%getpagesize())
  sizeOfRegion = sizeOfRegion + getpagesize()-(sizeOfRegion%getpagesize());
 void *ptr = mmap(((void *)0), sizeOfRegion, 0x1 | 0x2, 0x02, fd, 0);
 sizeMem = sizeOfRegion;
 startMem = ptr;
 if(ptr == ((void *) -1))
 {
  perror("mmap");
  return -1;
 }
 freeList = ptr;
 freeList->size = sizeOfRegion - sizeof(memNode);
 freeList->next = ((void *)0);
 freeList->prev = ((void *)0);
 debugMode = debug;
 if(debugMode)
 {
  fillMemWithPattern((void *)ptr+sizeof(memNode), freeList->size,0xDEADBEEF);
 }
 close(fd);
 return 0;
}

variable_types: sizeOfRegion int

variable_types: debug int

variable_types: fd int

variable_types:
ptr
void *


original_code:
void* Mem_Alloc(int size)
{
 if(size <= 0)
  return ((void *)0);
 if(!freeList)
 {
  m_error = (1);
  return ((void *)0);
 }
 size_t memNodeSize = sizeof(memNode);
 size_t allocHeaderSize = sizeof(allocHeader);
 if(size%4)
 {
  size = size + 4 - (size%4);
 }
 if(debugMode)
  size = size + 64 *2;
 size_t sizeplusheader = size + allocHeaderSize;
 memNode * firstFit = ((void *)0);
 memNode * temp = freeList;
 while(temp)
 {
  if(debugMode)
  {
   size_t len = temp->size;
   unsigned int* tempptr = (void*)temp+memNodeSize;
   while(len>4)
   {
    len = len - 4;
    if(*tempptr != 0xDEADBEEF)
    {
     m_error = (2);
     return ((void *)0);
    }
    ++tempptr;
   }
  }
  if(temp->size >= size)
  {
   firstFit = temp;
   break;
  }
  temp = temp->next;
 }
 if(firstFit == ((void *)0))
 {
  m_error = (1);
  return ((void *)0);
 }
 if(firstFit->size == size)
 {
  removeMemNode(firstFit);
 }
 else
 {
  memNode* newNode = (memNode*)((void*)firstFit + sizeplusheader);
  newNode->size = firstFit->size - sizeplusheader;
  newNode->next = firstFit->next;
  newNode->prev = firstFit;
  firstFit->next = newNode;
  if(newNode->next!=((void *)0))
  {
   newNode->next->prev = newNode;
  }
  removeMemNode(firstFit);
 }
 if(debugMode)
 {
  allocHeader* ff = (allocHeader*)firstFit;
  ff->size = size -64*2;
  ff->redundancy = 0xAAAAAAAA;
  fillMemWithPattern((void*)firstFit+allocHeaderSize, 64,0xABCDDCBA);
  fillMemWithPattern((void*)firstFit+sizeplusheader-64, 64,0xABCDDCBA);
  return (void*)firstFit + allocHeaderSize + 64;
 }
 allocHeader* ff = (allocHeader*)firstFit;
 ff->size = size;
 ff->redundancy = 0xAAAAAAAA;
 return (void*)firstFit + allocHeaderSize;
}

canonical_original_code:
void *Mem_Alloc(int size)
{
 if(size <= 0)
  return ((void *)0);
 if(!freeList)
 {
  m_error = (1);
  return ((void *)0);
 }
 unsigned long memNodeSize = sizeof(memNode);
 unsigned long allocHeaderSize = sizeof(allocHeader);
 if(size%4)
 {
  size = size + 4 - (size%4);
 }
 if(debugMode)
  size = size + 64 *2;
 unsigned long sizeplusheader = size + allocHeaderSize;
 struct memNode *firstFit = ((void *)0);
 struct memNode *temp = freeList;
 while(temp)
 {
  if(debugMode)
  {
   unsigned long len = temp->size;
   unsigned int *tempptr = (void*)temp+memNodeSize;
   while(len>4)
   {
    len = len - 4;
    if(*tempptr != 0xDEADBEEF)
    {
     m_error = (2);
     return ((void *)0);
    }
    ++tempptr;
   }
  }
  if(temp->size >= size)
  {
   firstFit = temp;
   break;
  }
  temp = temp->next;
 }
 if(firstFit == ((void *)0))
 {
  m_error = (1);
  return ((void *)0);
 }
 if(firstFit->size == size)
 {
  removeMemNode(firstFit);
 }
 else
 {
  struct memNode *newNode = (memNode*)((void*)firstFit + sizeplusheader);
  newNode->size = firstFit->size - sizeplusheader;
  newNode->next = firstFit->next;
  newNode->prev = firstFit;
  firstFit->next = newNode;
  if(newNode->next!=((void *)0))
  {
   newNode->next->prev = newNode;
  }
  removeMemNode(firstFit);
 }
 if(debugMode)
 {
  struct allocHeader *ff = (allocHeader*)firstFit;
  ff->size = size -64*2;
  ff->redundancy = 0xAAAAAAAA;
  fillMemWithPattern((void *)firstFit+allocHeaderSize, 64,0xABCDDCBA);
  fillMemWithPattern((void *)firstFit+sizeplusheader-64, 64,0xABCDDCBA);
  return (void *)firstFit + allocHeaderSize + 64;
 }
 struct allocHeader *ff = (allocHeader*)firstFit;
 ff->size = size;
 ff->redundancy = 0xAAAAAAAA;
 return (void *)firstFit + allocHeaderSize;
}

variable_types: size int

variable_types:
memNodeSize
unsigned long

variable_types:
allocHeaderSize
unsigned long

variable_types:
sizeplusheader
unsigned long

variable_types: struct memNode { unsigned int size; struct memNode *next; struct memNode *prev; } *

variable_types:
len
unsigned long

variable_types:
tempptr
unsigned int *

variable_types: struct allocHeader { unsigned int size; unsigned long long gap; unsigned int redundancy; } *


decompiled_code:
__int64 __fastcall Mem_Free(__int64 a1)
{
unsigned int *v1; // rax
unsigned int *v2; // rdi
__int64 v3; // rax
unsigned __int64 v4; // rax
int v5; // ecx
__int64 v6; // rax
__int64 result; // rax
unsigned __int64 v8; // rdx
int *v9; // rcx
int v10; // er9
int v11; // esi
unsigned int v12; // ebx
int v13; // er8
int v14; // eax
int v15; // eax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax

if ( !a1 )
return 0LL;
v1 = (unsigned int *)(a1 - 88);
v2 = (unsigned int *)(a1 - 24);
if ( debugMode )
v2 = v1;
if ( startMem > (unsigned __int64)v2 || (unsigned __int64)v2 >= sizeMem + startMem )
{
m_error = 5;
return 0xFFFFFFFFLL;
}
if ( v2[4] != -1431655766 )
{
m_error = 5;
return 0xFFFFFFFFLL;
}
v3 = 15LL;
if ( !debugMode )
{
LABEL_12:
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = 0LL;
v4 = *(_QWORD *)&freeList;
if ( !*(_QWORD *)&freeList )
{
*(_QWORD *)&freeList = v2;
result = debugMode;
if ( !debugMode )
return result;
goto LABEL_24;
}
if ( *(_QWORD *)&freeList > (unsigned __int64)v2 )
{
v5 = *v2;
if ( (int)((_DWORD)v2 + *v2 + 24 - freeList) > 0 )
{
m_error = 5;
return 0xFFFFFFFFLL;
}
if ( (int)((_DWORD)v2 + *v2 + 24 - freeList) >= 0 )
{
*v2 = v5 + **(_DWORD **)&freeList + 24;
v6 = *(_QWORD *)(*(_QWORD *)&freeList + 8LL);
*((_QWORD *)v2 + 1) = v6;
if ( v6 )
*(_QWORD *)(v6 + 16) = v2;
*(_QWORD *)&freeList = v2;
result = debugMode;
if ( debugMode )
{
fillMemWithPattern(v2 + 6, (unsigned int)(v5 + 24), 3735928559LL);
result = 0LL;
}
return result;
}
*((_QWORD *)v2 + 1) = *(_QWORD *)&freeList;
*(_QWORD *)(v4 + 16) = v2;
*(_QWORD *)&freeList = v2;
result = debugMode;
if ( !debugMode )
return result;
LABEL_24:
fillMemWithPattern(v2 + 6, *v2, 3735928559LL);
return 0LL;
}
do
{
v8 = v4;
v4 = *(_QWORD *)(v4 + 8);
}
while ( v4 && (unsigned __int64)v2 >= v8 );
if ( v4 || (unsigned __int64)v2 < v8 )
{
v9 = *(int **)(v8 + 16);
v10 = *v9;
v11 = (_DWORD)v9 + *v9 + 24;
v12 = (_DWORD)v2 - v11;
v13 = *v2;
v14 = (_DWORD)v2 + *v2 + 24 - v8;
if ( (_DWORD)v2 != v11 && v14 )
{
*((_QWORD *)v2 + 2) = v9;
*((_QWORD *)v2 + 1) = v8;
*((_QWORD *)v9 + 1) = v2;
*(_QWORD *)(v8 + 16) = v2;
result = debugMode;
if ( !debugMode )
return result;
goto LABEL_36;
}
if ( !(v12 | v14) )
{
*v9 = v13 + *(_DWORD *)v8 + 48 + v10;
v16 = *(_QWORD *)(v8 + 8);
*(_QWORD *)(*(_QWORD *)(v8 + 16) + 8LL) = v16;
if ( v16 )
*(_QWORD *)(v16 + 16) = *(_QWORD *)(v8 + 16);
result = debugMode;
if ( debugMode )
{
fillMemWithPattern(v2, *v2 + 48, 3735928559LL);
result = 0LL;
}
return result;
}
if ( v12 )
{
*v2 = *(_DWORD *)v8 + v13 + 24;
*((_QWORD *)v2 + 1) = *(_QWORD *)(v8 + 8);
*((_QWORD *)v2 + 2) = *(_QWORD *)(v8 + 16);
v17 = *(_QWORD *)(v8 + 8);
if ( v17 )
*(_QWORD *)(v17 + 16) = v2;
v18 = *(_QWORD *)(v8 + 16);
if ( v18 )
*(_QWORD *)(v18 + 8) = v2;
result = debugMode;
if ( debugMode )
{
fillMemWithPattern(v2 + 6, (unsigned int)(v13 + 24), 3735928559LL);
result = 0LL;
}
return result;
}
*v9 = v10 + v13 + 24;
result = debugMode;
if ( !debugMode )
return result;
}
else
{
v15 = (_DWORD)v2 - *(_DWORD *)v8 - 24;
v12 = v15 - v8;
if ( v15 != (_DWORD)v8 )
{
*(_QWORD *)(v8 + 8) = v2;
*((_QWORD *)v2 + 2) = v8;
result = debugMode;
if ( !debugMode )
return result;
LABEL_36:
fillMemWithPattern(v2 + 6, *v2, 3735928559LL);
return 0LL;
}
*(_DWORD *)v8 += *v2 + 24;
result = debugMode;
if ( !debugMode )
return result;
}
fillMemWithPattern(v2, *v2 + 24, 3735928559LL);
return v12;
}
while ( v2[v3 + 6] == -1412571974 && *(unsigned int *)((char *)&v2[v3 + 22] + *v2) == -1412571974 )
{
if ( --v3 == -1 )
{
*v2 += 128;
goto LABEL_12;
}
}
m_error = 3;
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int *v1; // rax
unsigned int *v2; // rdi
__int64 v3; // rax
unsigned __int64 v4; // rax
int v5; // ecx
__int64 v6; // rax
__int64 result; // rax
unsigned __int64 v8; // rdx
int *v9; // rcx
int v10; // er9
int v11; // esi
unsigned int v12; // ebx
int v13; // er8
int v14; // eax
int v15; // eax
__int64 v16; // rax
__int64 v17; // rax
__int64 v18; // rax

if ( !a1 )
return 0LL;
v1 = (unsigned int *)(a1 - 88);
v2 = (unsigned int *)(a1 - 24);
if ( debugMode )
v2 = v1;
if ( startMem > (unsigned __int64)v2 || (unsigned __int64)v2 >= sizeMem + startMem )
{
m_error = 5;
return 0xFFFFFFFFLL;
}
if ( v2[4] != -1431655766 )
{
m_error = 5;
return 0xFFFFFFFFLL;
}
v3 = 15LL;
if ( !debugMode )
{
LABEL_12:
*((_QWORD *)v2 + 1) = 0LL;
*((_QWORD *)v2 + 2) = 0LL;
v4 = *(_QWORD *)&freeList;
if ( !*(_QWORD *)&freeList )
{
*(_QWORD *)&freeList = v2;
result = debugMode;
if ( !debugMode )
return result;
goto LABEL_24;
}
if ( *(_QWORD *)&freeList > (unsigned __int64)v2 )
{
v5 = *v2;
if ( (int)((_DWORD)v2 + *v2 + 24 - freeList) > 0 )
{
m_error = 5;
return 0xFFFFFFFFLL;
}
if ( (int)((_DWORD)v2 + *v2 + 24 - freeList) >= 0 )
{
*v2 = v5 + **(_DWORD **)&freeList + 24;
v6 = *(_QWORD *)(*(_QWORD *)&freeList + 8LL);
*((_QWORD *)v2 + 1) = v6;
if ( v6 )
*(_QWORD *)(v6 + 16) = v2;
*(_QWORD *)&freeList = v2;
result = debugMode;
if ( debugMode )
{
func7(v2 + 6, (unsigned int)(v5 + 24), 3735928559LL);
result = 0LL;
}
return result;
}
*((_QWORD *)v2 + 1) = *(_QWORD *)&freeList;
*(_QWORD *)(v4 + 16) = v2;
*(_QWORD *)&freeList = v2;
result = debugMode;
if ( !debugMode )
return result;
LABEL_24:
func7(v2 + 6, *v2, 3735928559LL);
return 0LL;
}
do
{
v8 = v4;
v4 = *(_QWORD *)(v4 + 8);
}
while ( v4 && (unsigned __int64)v2 >= v8 );
if ( v4 || (unsigned __int64)v2 < v8 )
{
v9 = *(int **)(v8 + 16);
v10 = *v9;
v11 = (_DWORD)v9 + *v9 + 24;
v12 = (_DWORD)v2 - v11;
v13 = *v2;
v14 = (_DWORD)v2 + *v2 + 24 - v8;
if ( (_DWORD)v2 != v11 && v14 )
{
*((_QWORD *)v2 + 2) = v9;
*((_QWORD *)v2 + 1) = v8;
*((_QWORD *)v9 + 1) = v2;
*(_QWORD *)(v8 + 16) = v2;
result = debugMode;
if ( !debugMode )
return result;
goto LABEL_36;
}
if ( !(v12 | v14) )
{
*v9 = v13 + *(_DWORD *)v8 + 48 + v10;
v16 = *(_QWORD *)(v8 + 8);
*(_QWORD *)(*(_QWORD *)(v8 + 16) + 8LL) = v16;
if ( v16 )
*(_QWORD *)(v16 + 16) = *(_QWORD *)(v8 + 16);
result = debugMode;
if ( debugMode )
{
func7(v2, *v2 + 48, 3735928559LL);
result = 0LL;
}
return result;
}
if ( v12 )
{
*v2 = *(_DWORD *)v8 + v13 + 24;
*((_QWORD *)v2 + 1) = *(_QWORD *)(v8 + 8);
*((_QWORD *)v2 + 2) = *(_QWORD *)(v8 + 16);
v17 = *(_QWORD *)(v8 + 8);
if ( v17 )
*(_QWORD *)(v17 + 16) = v2;
v18 = *(_QWORD *)(v8 + 16);
if ( v18 )
*(_QWORD *)(v18 + 8) = v2;
result = debugMode;
if ( debugMode )
{
func7(v2 + 6, (unsigned int)(v13 + 24), 3735928559LL);
result = 0LL;
}
return result;
}
*v9 = v10 + v13 + 24;
result = debugMode;
if ( !debugMode )
return result;
}
else
{
v15 = (_DWORD)v2 - *(_DWORD *)v8 - 24;
v12 = v15 - v8;
if ( v15 != (_DWORD)v8 )
{
*(_QWORD *)(v8 + 8) = v2;
*((_QWORD *)v2 + 2) = v8;
result = debugMode;
if ( !debugMode )
return result;
LABEL_36:
func7(v2 + 6, *v2, 3735928559LL);
return 0LL;
}
*(_DWORD *)v8 += *v2 + 24;
result = debugMode;
if ( !debugMode )
return result;
}
func7(v2, *v2 + 24, 3735928559LL);
return v12;
}
while ( v2[v3 + 6] == -1412571974 && *(unsigned int *)((char *)&v2[v3 + 22] + *v2) == -1412571974 )
{
if ( --v3 == -1 )
{
*v2 += 128;
goto LABEL_12;
}
}
m_error = 3;
return 0xFFFFFFFFLL;
}

original_code:
int Mem_Free(void* ptr)
{
 if(ptr == ((void *)0))
  return 0;
 size_t memNodeSize = sizeof(memNode);
 size_t allocHeaderSize = sizeof(allocHeader);
 memNode* toFree;
 void* start;
 if(debugMode)
 {
  start = ptr - allocHeaderSize - 64;
 }
 else
  start = (ptr - allocHeaderSize);
 allocHeader* alloc = (allocHeader*) start;
 if(start< startMem || start >= startMem+sizeMem)
 {
  m_error = (5);
  return -1;
 }
 if(alloc->redundancy!= 0xAAAAAAAA)
 {
  m_error = (5);
  return -1;
 }
 int tempPadding = 60;
 while(tempPadding>=0 && debugMode)
 {
  if(*(int*)(start+allocHeaderSize+tempPadding) != 0xABCDDCBA || *(int*)(start+allocHeaderSize+alloc->size+64 +tempPadding) !=0xABCDDCBA)
  {
   m_error = (3);
   return -1;
  }
  tempPadding-=4;
 }
 size_t sizeOfChunk = alloc->size;
 toFree = start;
 if(debugMode)
  toFree->size = sizeOfChunk + allocHeaderSize + 2*64 -memNodeSize;
 else
  toFree->size = sizeOfChunk + allocHeaderSize - memNodeSize;
 toFree->next = ((void *)0);
 toFree->prev = ((void *)0);
 if(freeList ==((void *)0))
 {
  freeList = toFree;
  if(debugMode)
  {
   fillMemWithPattern((void*)toFree + memNodeSize, toFree->size,0xDEADBEEF);
  }
  return 0;
 }
 if((void*)toFree<(void*)freeList)
 {
  int diff = (void*)toFree + toFree->size + memNodeSize - (void*)freeList;
  if(diff > 0)
  {
   m_error = (5);
   return -1;
  }
  else if(diff<0)
  {
   toFree ->next = freeList;
   freeList->prev = toFree;
   freeList = toFree;
   if(debugMode)
   {
    fillMemWithPattern((void*)toFree + memNodeSize, toFree->size,0xDEADBEEF);
   }
  }
  else if(diff ==0)
  {
   int lengthToFree = toFree->size + memNodeSize;
   toFree->size = toFree->size + freeList->size + memNodeSize;
   toFree->next = freeList->next;
   if(freeList->next)
    freeList->next->prev = toFree;
   freeList = toFree;
   if(debugMode)
   {
    fillMemWithPattern((void*)toFree + memNodeSize, lengthToFree,0xDEADBEEF);
   }
  }
 }
 else
 {
  memNode* fit = freeList;
  while((fit->next) && (void*)fit <= (void*)toFree)
  {
   fit = fit -> next;
  }
  if(fit->next == ((void *)0) && (void*)fit <= (void*)toFree)
  {
   int diff = (void*) toFree - fit->size -memNodeSize -(void*) fit;
   if(diff==0)
   {
    fit->size = fit->size + toFree->size + memNodeSize;
    if(debugMode)
    {
     fillMemWithPattern((void*)toFree, toFree->size + memNodeSize,0xDEADBEEF);
    }
   }
   else
   {
    fit->next = toFree;
    toFree->prev = fit;
    if(debugMode)
    {
     fillMemWithPattern((void*)toFree + memNodeSize, toFree->size ,0xDEADBEEF);
    }
   }
  }
  else
  {
   int diff1 = (void*)toFree - ((void*) fit->prev + fit->prev->size + memNodeSize);
   int diff2 = (void*) toFree + toFree->size + memNodeSize - (void*)fit;
   if( diff1 == 0 || diff2 == 0)
   {
    if(diff1==0 && diff2==0)
    {
     fit->prev->size = fit->prev->size + toFree->size + fit->size + 2* memNodeSize;
     fit->prev->next = fit->next;
     if(fit->next)
      fit->next->prev = fit->prev;
     if(debugMode)
     {
      fillMemWithPattern((void*)toFree, toFree->size + 2*memNodeSize,0xDEADBEEF);
     }
    }
    else if(diff1==0)
    {
     fit->prev->size = fit->prev->size + toFree->size+ memNodeSize;
     if(debugMode)
     {
      fillMemWithPattern((void*)toFree, toFree->size + memNodeSize,0xDEADBEEF);
     }
    }
    else
    {
     int lenghtToFree = toFree->size +memNodeSize;
     toFree->size = toFree->size + fit->size + memNodeSize;
     toFree->next = fit->next;
     toFree -> prev = fit-> prev;
     if(fit->next)
      fit->next->prev = toFree;
     if(fit -> prev)
      fit->prev->next = toFree;
     if(debugMode)
     {
      fillMemWithPattern((void*)toFree + memNodeSize, lenghtToFree,0xDEADBEEF);
     }
    }
   }
   else
   {
    toFree->prev = fit->prev;
    toFree->next = fit;
    toFree->prev->next = toFree;
    fit->prev = toFree;
    if(debugMode)
    {
     fillMemWithPattern((void*)toFree + memNodeSize, toFree->size,0xDEADBEEF);
    }
   }
  }
 }
 return 0;
}

canonical_original_code:
int Mem_Free(void *ptr)
{
 if(ptr == ((void *)0))
  return 0;
 unsigned long memNodeSize = sizeof(memNode);
 unsigned long allocHeaderSize = sizeof(allocHeader);
 struct memNode *toFree;
 void *start;
 if(debugMode)
 {
  start = ptr - allocHeaderSize - 64;
 }
 else
  start = (ptr - allocHeaderSize);
 struct allocHeader *alloc = (allocHeader*) start;
 if(start< startMem || start >= startMem+sizeMem)
 {
  m_error = (5);
  return -1;
 }
 if(alloc->redundancy!= 0xAAAAAAAA)
 {
  m_error = (5);
  return -1;
 }
 int tempPadding = 60;
 while(tempPadding>=0 && debugMode)
 {
  if(*(int *)(start+allocHeaderSize+tempPadding) != 0xABCDDCBA || *(int *)(start+allocHeaderSize+alloc->size+64 +tempPadding) !=0xABCDDCBA)
  {
   m_error = (3);
   return -1;
  }
  tempPadding-=4;
 }
 unsigned long sizeOfChunk = alloc->size;
 toFree = start;
 if(debugMode)
  toFree->size = sizeOfChunk + allocHeaderSize + 2*64 -memNodeSize;
 else
  toFree->size = sizeOfChunk + allocHeaderSize - memNodeSize;
 toFree->next = ((void *)0);
 toFree->prev = ((void *)0);
 if(freeList ==((void *)0))
 {
  freeList = toFree;
  if(debugMode)
  {
   fillMemWithPattern((void *)toFree + memNodeSize, toFree->size,0xDEADBEEF);
  }
  return 0;
 }
 if((void *)toFree<(void *)freeList)
 {
  int diff = (void*)toFree + toFree->size + memNodeSize - (void*)freeList;
  if(diff > 0)
  {
   m_error = (5);
   return -1;
  }
  else if(diff<0)
  {
   toFree ->next = freeList;
   freeList->prev = toFree;
   freeList = toFree;
   if(debugMode)
   {
    fillMemWithPattern((void *)toFree + memNodeSize, toFree->size,0xDEADBEEF);
   }
  }
  else if(diff ==0)
  {
   int lengthToFree = toFree->size + memNodeSize;
   toFree->size = toFree->size + freeList->size + memNodeSize;
   toFree->next = freeList->next;
   if(freeList->next)
    freeList->next->prev = toFree;
   freeList = toFree;
   if(debugMode)
   {
    fillMemWithPattern((void *)toFree + memNodeSize, lengthToFree,0xDEADBEEF);
   }
  }
 }
 else
 {
  struct memNode *fit = freeList;
  while((fit->next) && (void *)fit <= (void *)toFree)
  {
   fit = fit -> next;
  }
  if(fit->next == ((void *)0) && (void *)fit <= (void *)toFree)
  {
   int diff = (void*) toFree - fit->size -memNodeSize -(void*) fit;
   if(diff==0)
   {
    fit->size = fit->size + toFree->size + memNodeSize;
    if(debugMode)
    {
     fillMemWithPattern((void *)toFree, toFree->size + memNodeSize,0xDEADBEEF);
    }
   }
   else
   {
    fit->next = toFree;
    toFree->prev = fit;
    if(debugMode)
    {
     fillMemWithPattern((void *)toFree + memNodeSize, toFree->size ,0xDEADBEEF);
    }
   }
  }
  else
  {
   int diff1 = (void*)toFree - ((void*) fit->prev + fit->prev->size + memNodeSize);
   int diff2 = (void*) toFree + toFree->size + memNodeSize - (void*)fit;
   if( diff1 == 0 || diff2 == 0)
   {
    if(diff1==0 && diff2==0)
    {
     fit->prev->size = fit->prev->size + toFree->size + fit->size + 2* memNodeSize;
     fit->prev->next = fit->next;
     if(fit->next)
      fit->next->prev = fit->prev;
     if(debugMode)
     {
      fillMemWithPattern((void *)toFree, toFree->size + 2*memNodeSize,0xDEADBEEF);
     }
    }
    else if(diff1==0)
    {
     fit->prev->size = fit->prev->size + toFree->size+ memNodeSize;
     if(debugMode)
     {
      fillMemWithPattern((void *)toFree, toFree->size + memNodeSize,0xDEADBEEF);
     }
    }
    else
    {
     int lenghtToFree = toFree->size +memNodeSize;
     toFree->size = toFree->size + fit->size + memNodeSize;
     toFree->next = fit->next;
     toFree -> prev = fit-> prev;
     if(fit->next)
      fit->next->prev = toFree;
     if(fit -> prev)
      fit->prev->next = toFree;
     if(debugMode)
     {
      fillMemWithPattern((void *)toFree + memNodeSize, lenghtToFree,0xDEADBEEF);
     }
    }
   }
   else
   {
    toFree->prev = fit->prev;
    toFree->next = fit;
    toFree->prev->next = toFree;
    fit->prev = toFree;
    if(debugMode)
    {
     fillMemWithPattern((void *)toFree + memNodeSize, toFree->size,0xDEADBEEF);
    }
   }
  }
 }
 return 0;
}

variable_types:
start
void *

variable_types: tempPadding int

variable_types:
sizeOfChunk
unsigned long

variable_types: diff int

variable_types: lengthToFree int

variable_types: lenghtToFree int

user_defined_types: struct memNode { unsigned int size; struct memNode *next; struct memNode *prev; }

user_defined_types: struct allocHeader { unsigned int size; unsigned long long gap; unsigned int redundancy; }


decompiled_code:
int Mem_Dump()
{
unsigned int *v0; // rbx

puts("\nMemory Dump:");
v0 = *(unsigned int **)&freeList;
if ( *(_QWORD *)&freeList )
{
do
{
printf("Start Address: %p\t Available space: %d bytes\n", v0 + 6, *v0);
v0 = (unsigned int *)*((_QWORD *)v0 + 1);
}
while ( v0 );
}
return puts("End of memdump");
}

canonical_decompiled_code:
int func11()
{
unsigned int *v0; // rbx

puts("\nMemory Dump:");
v0 = *(unsigned int **)&freeList;
if ( *(_QWORD *)&freeList )
{
do
{
printf("Start Address: %p\t Available space: %d bytes\n", v0 + 6, *v0);
v0 = (unsigned int *)*((_QWORD *)v0 + 1);
}
while ( v0 );
}
return puts("End of memdump");
}

original_code:
void Mem_Dump()
{
 printf("\nMemory Dump:\n");
 memNode* temp = freeList;
 while(temp)
 {
  printf("Start Address: %p\t Available space: %d bytes\n",(void*)temp+sizeof(memNode), temp->size);
  temp = temp->next;
 }
 printf("End of memdump\n");
}

canonical_original_code:
void Mem_Dump()
{
 printf("\nMemory Dump:\n");
 struct memNode *temp = freeList;
 while(temp)
 {
  printf("Start Address: %p\t Available space: %d bytes\n",(void *)temp+sizeof(memNode), temp->size);
  temp = temp->next;
 }
 printf("End of memdump\n");
}


decompiled_code:
__int64 __fastcall spinlock_acquire(volatile __int32 *a1)
{
while ( (unsigned int)xchg(a1, 1) == 1 )
;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(volatile __int32 *a1)
{
while ( (unsigned int)func5(a1, 1) == 1 )
;
return 0LL;
}

original_code:
int spinlock_acquire(spinlock_t* lock)
{
  while (xchg(&lock->state, 1) == 1)
    ;
  return 0;
}

canonical_original_code:
int spinlock_acquire(struct spinlock_t *lock)
{
  while (xchg(&lock->state, 1) == 1)
    ;
  return 0;
}

variable_types:
lock
struct spinlock_t { int state; } *


decompiled_code:
__int64 __fastcall spinlock_release(volatile __int32 *a1)
{
xchg(a1, 0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(volatile __int32 *a1)
{
func5(a1, 0);
return 0LL;
}

original_code:
int spinlock_release(spinlock_t* lock)
{
  xchg(&lock->state, 0);
  return 0;
}

canonical_original_code:
int spinlock_release(struct spinlock_t *lock)
{
  xchg(&lock->state, 0);
  return 0;
}


decompiled_code:
__int64 __fastcall Counter_GetValue(unsigned int *a1)
{
return *a1;
}

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

original_code:
int Counter_GetValue(counter_t *c)
{
  return c->value;
}

canonical_original_code:
int Counter_GetValue(struct counter_type *c)
{
  return c->value;
}

variable_types:
c
struct counter_type { int value; } *


decompiled_code:
__int64 __fastcall Counter_Increment(_DWORD *a1)
{
spinlock_acquire();
++*a1;
return spinlock_release();
}

canonical_decompiled_code:
__int64 __fastcall func8(_DWORD *a1)
{
spinlock_acquire();
++*a1;
return spinlock_release();
}

original_code:
void Counter_Increment(counter_t *c)
{
  spinlock_acquire(&slock);
  c->value += 1;
  spinlock_release(&slock);
}

canonical_original_code:
void Counter_Increment(struct counter_type *c)
{
  spinlock_acquire(&slock);
  c->value += 1;
  spinlock_release(&slock);
}


decompiled_code:
__int64 __fastcall Counter_Decrement(_DWORD *a1)
{
spinlock_acquire();
--*a1;
return spinlock_release();
}

canonical_decompiled_code:
__int64 __fastcall func9(_DWORD *a1)
{
spinlock_acquire();
--*a1;
return spinlock_release();
}

original_code:
void Counter_Decrement(counter_t *c)
{
  spinlock_acquire(&slock);
  c->value -= 1;
  spinlock_release(&slock);
}

canonical_original_code:
void Counter_Decrement(struct counter_type *c)
{
  spinlock_acquire(&slock);
  c->value -= 1;
  spinlock_release(&slock);
}


repo: aayvazyan-tgm/Sudoku

decompiled_code:
__int64 __fastcall char_to_value(char a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = 1LL;
while ( 1 )
{
v2 = v1;
if ( value_chars[v1] == a1 )
break;
if ( ++v1 == 10 )
return 0;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 v1; // rax
unsigned int v2; // edx

v1 = 1LL;
while ( 1 )
{
v2 = v1;
if ( value_chars[v1] == a1 )
break;
if ( ++v1 == 10 )
return 0;
}
return v2;
}

original_code:
value_t char_to_value(char c) {
 value_t value;
 for (value = 1; value <= psize; ++value) {
  if (value_chars[value] == c) {
   return value;
  }
 }
 return 0;
}

canonical_original_code:
unsigned char char_to_value(char c) {
 unsigned char value;
 for (value = 1; value <= psize; ++value) {
  if (value_chars[value] == c) {
   return value;
  }
 }
 return 0;
}

variable_types: c char

variable_types:
value
unsigned char

return_type: unsigned char


decompiled_code:
__int64 __fastcall puzzle_fill_cell(__int64 a1, unsigned int a2, unsigned int a3, char a4)
{
__int64 result; // rax

if ( a4 && *(_BYTE *)(a1 + 9LL * (int)a2 + (int)a3) )
{
fprintf(stderr, "cell (%d, %d) already has a value!", a2, a3);
exit(-1);
}
result = 9LL * (int)a2;
*(_BYTE *)(result + a1 + (int)a3) = a4;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3, char a4)
{
__int64 result; // rax

if ( a4 && *(_BYTE *)(a1 + 9LL * (int)a2 + (int)a3) )
{
fprintf(stderr, "cell (%d, %d) already has a value!", a2, a3);
exit(-1);
}
result = 9LL * (int)a2;
*(_BYTE *)(result + a1 + (int)a3) = a4;
return result;
}

original_code:
void puzzle_fill_cell(value_t puzzle[psize][psize], int row, int col,
  value_t value) {
 if (value && puzzle[row][col]) {
  fprintf(stderr, "cell (%d, %d) already has a value!", row, col);
  exit(-1);
 }
 puzzle[row][col] = value;
}

canonical_original_code:
void puzzle_fill_cell(unsigned char puzzle[-1][-1], int row, int col, unsigned char value) {
 if (value && puzzle[row][col]) {
  fprintf(stderr, "cell (%d, %d) already has a value!", row, col);
  exit(-1);
 }
 puzzle[row][col] = value;
}

variable_types:
puzzle
unsigned char [-1][-1]

variable_types: row int

variable_types: col int


decompiled_code:
__int64 __fastcall puzzle_find_empty(__int64 a1, _DWORD *a2, _DWORD *a3)
{
int i; // esi
__int64 j; // rax

for ( i = 0; i != 9; ++i )
{
for ( j = 0LL; j != 9; ++j )
{
if ( !*(_BYTE *)(a1 + j) )
{
*a2 = i;
*a3 = j;
return 1LL;
}
}
a1 += 9LL;
}
*a2 = 9;
*a3 = 9;
return 0LL;
}

original_code:
int puzzle_find_empty(value_t puzzle[psize][psize], int* row_out, int* col_out) {
 int row, col;
 for (row = 0; row < psize; ++row) {
  for (col = 0; col < psize; ++col) {
   value_t value = puzzle[row][col];
   if (!value) {
    *row_out = row;
    *col_out = col;
    return 1;
   }
  }
 }
 *row_out = psize;
 *col_out = psize;
 return 0;
}

canonical_original_code:
int puzzle_find_empty(unsigned char puzzle[-1][-1], int *row_out, int *col_out) {
 int row; int col;
 for (row = 0; row < psize; ++row) {
  for (col = 0; col < psize; ++col) {
   unsigned char value = puzzle[row][col];
   if (!value) {
    *row_out = row;
    *col_out = col;
    return 1;
   }
  }
 }
 *row_out = psize;
 *col_out = psize;
 return 0;
}


decompiled_code:
__int64 __fastcall region_check_and_mark(_WORD *a1, char a2)
{
__int64 result; // rax
int v3; // edx

result = 1LL;
if ( a2 )
{
v3 = 1 << (a2 - 1);
result = 0LL;
if ( ((unsigned __int16)v3 & *a1) == 0 )
{
*a1 |= v3;
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_WORD *a1, char a2)
{
__int64 result; // rax
int v3; // edx

result = 1LL;
if ( a2 )
{
v3 = 1 << (a2 - 1);
result = 0LL;
if ( ((unsigned __int16)v3 & *a1) == 0 )
{
*a1 |= v3;
result = 1LL;
}
}
return result;
}

original_code:
int region_check_and_mark(value_set_t* region, value_t value) {
 if (value) {
  int marker = (1 << (value - 1));
  if (*region & marker) {
   return 0;
  } else {
   *region = *region | marker;
  }
 }
 return 1;
}

canonical_original_code:
int region_check_and_mark(unsigned short *region, unsigned char value) {
 if (value) {
  int marker = (1 << (value - 1));
  if (*region & marker) {
   return 0;
  } else {
   *region = *region | marker;
  }
 }
 return 1;
}

variable_types:
region
unsigned short *

variable_types: marker int


decompiled_code:
__int64 __fastcall puzzle_is_valid(_BYTE *a1)
{
char *v1; // r13
char *v2; // r12
char *v3; // rbp
__int64 result; // rax
char *v5; // r13
char *v6; // rbp
__int64 v7; // r14
char *v8; // r12
int v9; // er13
char *v10; // rbp
int j; // edx
_BYTE *v12; // rcx
int i; // er8
_BYTE *v14; // r9
_BYTE *v15; // [rsp+0h] [rbp-50h]
int v16; // [rsp+Ch] [rbp-44h]
__int16 v17[25]; // [rsp+1Eh] [rbp-32h] BYREF

v1 = a1 + 9;
v2 = a1 + 90;
LABEL_3:
v17[0] = 0;
v3 = v1 - 9;
while ( 1 )
{
result = region_check_and_mark(v17, *v3);
if ( !(_DWORD)result )
return result;
if ( ++v3 == v1 )
{
v1 += 9;
if ( v1 != v2 )
goto LABEL_3;
v5 = a1 + 81;
LABEL_9:
v17[0] = 0;
v6 = v5 - 81;
while ( 1 )
{
result = region_check_and_mark(v17, *v6);
if ( !(_DWORD)result )
return result;
v6 += 9;
if ( v6 == v5 )
{
if ( ++v5 != v2 )
goto LABEL_9;
v15 = a1;
v16 = 0;
LABEL_14:
v7 = 0LL;
LABEL_15:
v17[0] = 0;
v8 = &v15[v7 + 3];
v9 = 3;
LABEL_17:
v10 = v8 - 3;
while ( 1 )
{
result = region_check_and_mark(v17, *v10);
if ( !(_DWORD)result )
return result;
if ( ++v10 == v8 )
{
v8 += 9;
if ( --v9 )
goto LABEL_17;
v7 += 3LL;
if ( v7 != 9 )
goto LABEL_15;
v16 += 3;
v15 += 27;
if ( v16 != 9 )
goto LABEL_14;
result = (unsigned int)xsudoku;
if ( xsudoku != 1 )
return 1LL;
v14 = a1;
for ( i = 0; i != 9; ++i )
{
v12 = a1;
for ( j = 0; j != 9; ++j )
{
if ( j != i && *v14 && *v14 == *v12 && *v12 )
return 0LL;
v12 += 10;
}
v14 += 10;
}
return result;
}
}
}
}
}
}
}

original_code:
int puzzle_is_valid(value_t puzzle[psize][psize]) {
 int row, col, start_row, start_col, block_row, block_col;
 value_set_t region;
 for (row = 0; row < psize; ++row) {
  region = 0;
  for (col = 0; col < psize; ++col) {
   if (!region_check_and_mark(&region, puzzle[row][col])) {
    return 0;
   }
  }
 }
 for (col = 0; col < psize; ++col) {
  region = 0;
  for (row = 0; row < psize; ++row) {
   if (!region_check_and_mark(&region, puzzle[row][col])) {
    return 0;
   }
  }
 }
 for (start_row = 0; start_row < psize; start_row += bsize) {
  for (start_col = 0; start_col < psize; start_col += bsize) {
   region = 0;
   for (block_row = 0; block_row < bsize; ++block_row) {
    for (block_col = 0; block_col < bsize; ++block_col) {
     row = start_row + block_row;
     col = start_col + block_col;
     if (!region_check_and_mark(&region, puzzle[row][col])) {
      return 0;
     }
    }
   }
  }
 }
 if(xsudoku==1){
  int horizontal;
  int vertikal;
  value_t zero=0;
  for(vertikal=0;vertikal<psize;vertikal++){
   for(horizontal=0;horizontal<psize;horizontal++){
    if(vertikal==horizontal)continue;
    if(puzzle[vertikal][vertikal]==zero)continue;
    if(puzzle[horizontal][horizontal]==zero)continue;
    if(puzzle[vertikal][vertikal]==puzzle[horizontal][horizontal])
     {
     return 0;
     }
   }
  }
  for(vertikal=psize;vertikal<psize;vertikal--){
   for(horizontal=0;horizontal<psize;horizontal++){
    if(vertikal==horizontal)continue;
    if(puzzle[vertikal][vertikal]==zero)continue;
    if(puzzle[horizontal-psize+1][horizontal]==zero)continue;
    if(puzzle[vertikal][vertikal]==puzzle[horizontal-psize+1][horizontal])return 0;
   }
  }
 }
 return 1;
}

canonical_original_code:
int puzzle_is_valid(unsigned char puzzle[-1][-1]) {
 int row; int col; int start_row; int start_col; int block_row; int block_col;
 unsigned short region;
 for (row = 0; row < psize; ++row) {
  region = 0;
  for (col = 0; col < psize; ++col) {
   if (!region_check_and_mark(&region, puzzle[row][col])) {
    return 0;
   }
  }
 }
 for (col = 0; col < psize; ++col) {
  region = 0;
  for (row = 0; row < psize; ++row) {
   if (!region_check_and_mark(&region, puzzle[row][col])) {
    return 0;
   }
  }
 }
 for (start_row = 0; start_row < psize; start_row += bsize) {
  for (start_col = 0; start_col < psize; start_col += bsize) {
   region = 0;
   for (block_row = 0; block_row < bsize; ++block_row) {
    for (block_col = 0; block_col < bsize; ++block_col) {
     row = start_row + block_row;
     col = start_col + block_col;
     if (!region_check_and_mark(&region, puzzle[row][col])) {
      return 0;
     }
    }
   }
  }
 }
 if(xsudoku==1){
  int horizontal;
  int vertikal;
  unsigned char zero = 0;
  for(vertikal=0;vertikal<psize;vertikal++){
   for(horizontal=0;horizontal<psize;horizontal++){
    if(vertikal==horizontal)continue;
    if(puzzle[vertikal][vertikal]==zero)continue;
    if(puzzle[horizontal][horizontal]==zero)continue;
    if(puzzle[vertikal][vertikal]==puzzle[horizontal][horizontal])
     {
     return 0;
     }
   }
  }
  for(vertikal=psize;vertikal<psize;vertikal--){
   for(horizontal=0;horizontal<psize;horizontal++){
    if(vertikal==horizontal)continue;
    if(puzzle[vertikal][vertikal]==zero)continue;
    if(puzzle[horizontal-psize+1][horizontal]==zero)continue;
    if(puzzle[vertikal][vertikal]==puzzle[horizontal-psize+1][horizontal])return 0;
   }
  }
 }
 return 1;
}

variable_types:
region
unsigned short

variable_types: horizontal int

variable_types: vertikal int

variable_types:
zero
unsigned char


repo: ab/stripe-ctf

decompiled_code:
__int64 __fastcall char_at(const char *a1, int a2)
{
size_t v2; // rdx
__int64 result; // rax

v2 = strlen(a1);
result = 0LL;
if ( a2 < v2 )
result = (unsigned __int8)a1[a2];
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, int a2)
{
size_t v2; // rdx
__int64 result; // rax

v2 = strlen(a1);
result = 0LL;
if ( a2 < v2 )
result = (unsigned __int8)a1[a2];
return result;
}

original_code:
char
char_at(char *str, int pos)
{
 return pos < strlen(str) ? str[pos] : 0;
}

variable_types:
str
char *

variable_types: pos int

return_type: char


taunt

decompiled_code:
__pid_t taunt()
{
__pid_t result; // eax

result = fork();
if ( !result )
{
execl("/bin/echo", "/bin/echo", "Ha ha, your password is incorrect!", 0LL);
exit(1);
}
return result;
}

canonical_decompiled_code:
__pid_t func8()
{
__pid_t result; // eax

result = fork();
if ( !result )
{
execl("/bin/echo", "/bin/echo", "Ha ha, your password is incorrect!", 0LL);
exit(1);
}
return result;
}

original_code:
void
taunt()
{
 if (!fork()) {
  execl("/bin/echo", "/bin/echo", "Ha ha, your password is incorrect!", ((void *)0));
  exit(1);
 }
}


decompiled_code:
__int64 __fastcall command_status(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return *(unsigned int *)(a1 + 4);
}

original_code:
int
command_status (command_t c)
{
  return c->status;
}

canonical_original_code:
int command_status(struct command *c)
{
  return c->status;
}

variable_types: struct command { enum command_type { AND_COMMAND=0, SEQUENCE_COMMAND=1, OR_COMMAND=2, PIPE_COMMAND=3, SIMPLE_COMMAND=4, START_SUBSHELL_COMMAND=5, END_SUBSHELL_COMMAND=6, SUBSHELL_COMMAND=7, NEWLINE_COMMAND=8, REDIRECT_FROM_COMMAND=9, REDIRECT_TO_COMMAND=10 } type; int status; char *input; char *output; union { struct command *command[2]; char **word; struct command *subshell_command; } u; } *

user_defined_types: struct command { enum command_type type; int status; char *input; char *output; union { struct command *command[2]; char **word; struct command *subshell_command; } u; }


decompiled_code:
int print_dependency_matrix()
{
__int64 v0; // rbp
int i; // er12
__int64 j; // rbx
int result; // eax

v0 = 0LL;
for ( i = 0; num_threads > i; v0 += 10000LL )
{
for ( j = 0LL; num_threads > (int)j; ++j )
printf(format, (unsigned int)dependency_table[j + v0]);
result = putchar(10);
++i;
}
return result;
}

canonical_decompiled_code:
int func1()
{
__int64 v0; // rbp
int i; // er12
__int64 j; // rbx
int result; // eax

v0 = 0LL;
for ( i = 0; num_threads > i; v0 += 10000LL )
{
for ( j = 0LL; num_threads > (int)j; ++j )
printf(format, (unsigned int)dependency_table[j + v0]);
result = putchar(10);
++i;
}
return result;
}

original_code:
void
print_dependency_matrix ()
{
 int i,j;
 for (i = 0; i < num_threads; i++)
 {
  for(j = 0; j < num_threads; j++)
  {
   printf("%i ",dependency_table[i][j]);
  }
  printf("\n");
 }
}

canonical_original_code:
void print_dependency_matrix()
{
 int i; int j;
 for (i = 0; i < num_threads; i++)
 {
  for(j = 0; j < num_threads; j++)
  {
   printf("%i ",dependency_table[i][j]);
  }
  printf("\n");
 }
}

variable_types: i int

variable_types: j int


decompiled_code:
__int64 __fastcall num_sequence_commands(__int64 a1)
{
__int64 result; // rax
int v2; // ebp

result = 0LL;
if ( *(_DWORD *)a1 == 1 )
{
v2 = num_sequence_commands(*(_QWORD *)(a1 + 24));
result = v2 + (unsigned int)num_sequence_commands(*(_QWORD *)(a1 + 32)) + 1;
}
return result;
}

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

result = 0LL;
if ( *(_DWORD *)a1 == 1 )
{
v2 = func2(*(_QWORD *)(a1 + 24));
result = v2 + (unsigned int)func2(*(_QWORD *)(a1 + 32)) + 1;
}
return result;
}

original_code:
int
num_sequence_commands(command_t c)
{
 if(c->type != SEQUENCE_COMMAND) {
  return 0;
 }
 else
 {
  return (1+num_sequence_commands(c->u.command[0])+num_sequence_commands(c->u.command[1]));
 }
}

canonical_original_code:
int num_sequence_commands(struct command *c)
{
 if(c->type != SEQUENCE_COMMAND) {
  return 0;
 }
 else
 {
  return (1+num_sequence_commands(c->u.command[0])+num_sequence_commands(c->u.command[1]));
 }
}

user_defined_types: enum command_type { AND_COMMAND=0, SEQUENCE_COMMAND=1, OR_COMMAND=2, PIPE_COMMAND=3, SIMPLE_COMMAND=4, START_SUBSHELL_COMMAND=5, END_SUBSHELL_COMMAND=6, SUBSHELL_COMMAND=7, NEWLINE_COMMAND=8, REDIRECT_FROM_COMMAND=9, REDIRECT_TO_COMMAND=10 }


decompiled_code:
__int64 __fastcall find_threads(__int64 a1)
{
int v1; // eax
__int64 result; // rax

if ( *(_DWORD *)a1 == 1 )
{
find_threads(*(_QWORD *)(a1 + 24));
result = find_threads(*(_QWORD *)(a1 + 32));
}
else
{
v1 = index_counter;
pthread_list[index_counter] = a1;
result = (unsigned int)(v1 + 1);
index_counter = result;
}
return result;
}

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

if ( *(_DWORD *)a1 == 1 )
{
func3(*(_QWORD *)(a1 + 24));
result = func3(*(_QWORD *)(a1 + 32));
}
else
{
v1 = index_counter;
pthread_list[index_counter] = a1;
result = (unsigned int)(v1 + 1);
index_counter = result;
}
return result;
}

original_code:
void
find_threads (command_t cmd)
{
 if(cmd->type != SEQUENCE_COMMAND)
 {
  pthread_list[index_counter] = cmd;
  index_counter++;
 }
 else
 {
  find_threads(cmd->u.command[0]);
  find_threads(cmd->u.command[1]);
 }
}

canonical_original_code:
void find_threads(struct command *cmd)
{
 if(cmd->type != SEQUENCE_COMMAND)
 {
  pthread_list[index_counter] = cmd;
  index_counter++;
 }
 else
 {
  find_threads(cmd->u.command[0]);
  find_threads(cmd->u.command[1]);
 }
}


decompiled_code:
__int64 __fastcall analyze_subtree(const char *a1, __int64 a2)
{
int v3; // er12
__int64 result; // rax
const char *v5; // rdi

if ( *(_DWORD *)a2 == 4 )
{
v5 = *(const char **)(a2 + 8);
if ( v5 )
result = strcmp(v5, a1) == 0;
else
result = 0LL;
}
else if ( *(_DWORD *)a2 == 7 )
{
result = analyze_subtree(a1, *(_QWORD *)(a2 + 24));
}
else
{
v3 = analyze_subtree(a1, *(_QWORD *)(a2 + 24));
result = v3 + (unsigned int)analyze_subtree(a1, *(_QWORD *)(a2 + 32));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1, __int64 a2)
{
int v3; // er12
__int64 result; // rax
const char *v5; // rdi

if ( *(_DWORD *)a2 == 4 )
{
v5 = *(const char **)(a2 + 8);
if ( v5 )
result = strcmp(v5, a1) == 0;
else
result = 0LL;
}
else if ( *(_DWORD *)a2 == 7 )
{
result = func4(a1, *(_QWORD *)(a2 + 24));
}
else
{
v3 = func4(a1, *(_QWORD *)(a2 + 24));
result = v3 + (unsigned int)func4(a1, *(_QWORD *)(a2 + 32));
}
return result;
}

original_code:
int
analyze_subtree (char * file, command_t cmd)
{
 if(cmd->type == SIMPLE_COMMAND)
 {
  if(cmd->input)
  {
   if(strcmp(cmd->input,file) == 0)
   {
    return 1;
   }
  }
  return 0;
 }
 else
 {
  switch(cmd->type)
  {
   case SUBSHELL_COMMAND:
    return analyze_subtree(file,cmd->u.subshell_command);
   default:
    return analyze_subtree(file,cmd->u.command[0]) + analyze_subtree(file,cmd->u.command[1]);
  }
 }
 return 0;
}

canonical_original_code:
int analyze_subtree(char *file, struct command *cmd)
{
 if(cmd->type == SIMPLE_COMMAND)
 {
  if(cmd->input)
  {
   if(strcmp(cmd->input,file) == 0)
   {
    return 1;
   }
  }
  return 0;
 }
 else
 {
  switch(cmd->type)
  {
   case SUBSHELL_COMMAND:
    return analyze_subtree(file,cmd->u.subshell_command);
   default:
    return analyze_subtree(file,cmd->u.command[0]) + analyze_subtree(file,cmd->u.command[1]);
  }
 }
 return 0;
}

variable_types:
file
char *


decompiled_code:
void __fastcall locate_dependencies(const char *a1, int a2)
{
__int64 v2; // rbx
int v3; // er13
int *v4; // rbp

LODWORD(v2) = a2 + 1;
v3 = index_counter;
if ( a2 + 1 < index_counter )
{
v2 = (int)v2;
v4 = &dependency_table[10001 * a2 + 10000];
do
{
if ( (unsigned int)analyze_subtree(a1, pthread_list[v2]) )
*v4 = 1;
++v2;
v4 += 10000;
}
while ( v3 > (int)v2 );
}
}

canonical_decompiled_code:
void __fastcall func5(const char *a1, int a2)
{
__int64 v2; // rbx
int v3; // er13
int *v4; // rbp

LODWORD(v2) = a2 + 1;
v3 = index_counter;
if ( a2 + 1 < index_counter )
{
v2 = (int)v2;
v4 = &dependency_table[10001 * a2 + 10000];
do
{
if ( (unsigned int)func4(a1, pthread_list[v2]) )
*v4 = 1;
++v2;
v4 += 10000;
}
while ( v3 > (int)v2 );
}
}

original_code:
void
locate_dependencies (char * file, int thread_id)
{
 int k = thread_id+1;
 int dependency_found;
 for(; k < index_counter; k++)
 {
  dependency_found = analyze_subtree(file, pthread_list[k]);
  if(dependency_found) {
   dependency_table[k][thread_id] = 1;
  }
 }
}

canonical_original_code:
void locate_dependencies(char *file, int thread_id)
{
 int k = thread_id+1;
 int dependency_found;
 for(; k < index_counter; k++)
 {
  dependency_found = analyze_subtree(file, pthread_list[k]);
  if(dependency_found) {
   dependency_table[k][thread_id] = 1;
  }
 }
}

variable_types: k int


decompiled_code:
void __fastcall extract_dependencies(__int64 a1, int a2)
{
const char *v2; // rdi

if ( *(_DWORD *)a1 == 4 )
{
v2 = *(const char **)(a1 + 16);
if ( v2 )
locate_dependencies(v2, a2);
}
else if ( *(_DWORD *)a1 == 7 )
{
extract_dependencies(*(_QWORD *)(a1 + 24));
}
else
{
extract_dependencies(*(_QWORD *)(a1 + 24));
extract_dependencies(*(_QWORD *)(a1 + 32));
}
}

original_code:
void
extract_dependencies (command_t cmd, int thread_id)
{
 if(cmd->type == SIMPLE_COMMAND)
 {
  if(cmd->output)
  {
   locate_dependencies(cmd->output, thread_id);
  }
  return;
 }
 else
 {
  switch(cmd->type)
  {
   case SUBSHELL_COMMAND:
    extract_dependencies(cmd->u.subshell_command,thread_id);
    break;
   default:
    extract_dependencies(cmd->u.command[0],thread_id);
    extract_dependencies(cmd->u.command[1],thread_id);
  }
 }
}

canonical_original_code:
void extract_dependencies(struct command *cmd, int thread_id)
{
 if(cmd->type == SIMPLE_COMMAND)
 {
  if(cmd->output)
  {
   locate_dependencies(cmd->output, thread_id);
  }
  return;
 }
 else
 {
  switch(cmd->type)
  {
   case SUBSHELL_COMMAND:
    extract_dependencies(cmd->u.subshell_command,thread_id);
    break;
   default:
    extract_dependencies(cmd->u.command[0],thread_id);
    extract_dependencies(cmd->u.command[1],thread_id);
  }
 }
}


decompiled_code:
void rmv_dependencies()
{
;
}

canonical_decompiled_code:
void func7()
{
;
}

original_code:
void
rmv_dependencies (int finished_thread_id)
{
}

canonical_original_code:
void rmv_dependencies(int finished_thread_id)
{
}


runnable

decompiled_code:
__int64 __fastcall runnable(int a1)
{
__int64 v1; // rdx

if ( index_counter <= 0 )
return 1LL;
v1 = 0LL;
while ( ((dependency_table[10000 * a1 + v1] + 1) & 0xFFFFFFFD) != 0 )
{
if ( ++v1 == index_counter )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
__int64 v1; // rdx

if ( index_counter <= 0 )
return 1LL;
v1 = 0LL;
while ( ((dependency_table[10000 * a1 + v1] + 1) & 0xFFFFFFFD) != 0 )
{
if ( ++v1 == index_counter )
return 1LL;
}
return 0LL;
}

original_code:
int
runnable (int thread_id)
{
 int i = 0;
 for(; i < index_counter; i++)
 {
  if(dependency_table[thread_id][i] == 1 || dependency_table[thread_id][i] == -1)
   return 0;
 }
 return 1;
}

canonical_original_code:
int runnable(int thread_id)
{
 int i = 0;
 for(; i < index_counter; i++)
 {
  if(dependency_table[thread_id][i] == 1 || dependency_table[thread_id][i] == -1)
   return 0;
 }
 return 1;
}


decompiled_code:
__int64 __fastcall execute_simple_command(__int64 a1)
{
int v2; // eax
const char *v3; // rdi
int v4; // eax
int v5; // ebp
const char *v6; // rdi
int v7; // eax
int v8; // ebp
__int64 result; // rax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = fork();
if ( v2 > 0 )
{
stat_loc = 0;
if ( waitpid(v2, &stat_loc, 0) != -1 )
{
result = BYTE1(stat_loc);
*(_DWORD *)(a1 + 4) = BYTE1(stat_loc);
return result;
}
error(1, 0, "Child process failed");
goto LABEL_16;
}
if ( !v2 )
{
v3 = *(const char **)(a1 + 8);
if ( !v3 )
goto LABEL_7;
v4 = open(v3, 0, 438LL);
v5 = v4;
if ( v4 != -1 )
{
if ( dup2(v4, 0) != -1 )
{
close(v5);
LABEL_7:
v6 = *(const char **)(a1 + 16);
if ( !v6 )
goto LABEL_11;
v7 = open(v6, 577, 438LL);
v8 = v7;
if ( v7 != -1 )
{
if ( dup2(v7, 1) != -1 )
{
close(v8);
LABEL_11:
execvp(**(const char ***)(a1 + 24), *(char *const **)(a1 + 24));
if ( execvp(**(const char ***)(a1 + 24), *(char *const **)(a1 + 24)) >= 0 )
exit(*(_DWORD *)(a1 + 4));
goto LABEL_20;
}
LABEL_19:
error(1, 0, "Output redirect failed");
LABEL_20:
error(1, 0, "Error in execution of simple command \n");
goto LABEL_21;
}
LABEL_18:
error(1, 0, "Output file could not be opened");
goto LABEL_19;
}
LABEL_17:
error(1, 0, "Input redirect failed");
goto LABEL_18;
}
LABEL_16:
error(1, 0, "Input file could not be opened");
goto LABEL_17;
}
LABEL_21:
error(1, 0, "You forked up");
return execute_subshell_command();
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
int v2; // eax
const char *v3; // rdi
int v4; // eax
int v5; // ebp
const char *v6; // rdi
int v7; // eax
int v8; // ebp
__int64 result; // rax
int stat_loc; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = fork();
if ( v2 > 0 )
{
stat_loc = 0;
if ( waitpid(v2, &stat_loc, 0) != -1 )
{
result = BYTE1(stat_loc);
*(_DWORD *)(a1 + 4) = BYTE1(stat_loc);
return result;
}
error(1, 0, "Child process failed");
goto LABEL_16;
}
if ( !v2 )
{
v3 = *(const char **)(a1 + 8);
if ( !v3 )
goto LABEL_7;
v4 = open(v3, 0, 438LL);
v5 = v4;
if ( v4 != -1 )
{
if ( dup2(v4, 0) != -1 )
{
close(v5);
LABEL_7:
v6 = *(const char **)(a1 + 16);
if ( !v6 )
goto LABEL_11;
v7 = open(v6, 577, 438LL);
v8 = v7;
if ( v7 != -1 )
{
if ( dup2(v7, 1) != -1 )
{
close(v8);
LABEL_11:
execvp(**(const char ***)(a1 + 24), *(char *const **)(a1 + 24));
if ( execvp(**(const char ***)(a1 + 24), *(char *const **)(a1 + 24)) >= 0 )
exit(*(_DWORD *)(a1 + 4));
goto LABEL_20;
}
LABEL_19:
error(1, 0, "Output redirect failed");
LABEL_20:
error(1, 0, "Error in execution of simple command \n");
goto LABEL_21;
}
LABEL_18:
error(1, 0, "Output file could not be opened");
goto LABEL_19;
}
LABEL_17:
error(1, 0, "Input redirect failed");
goto LABEL_18;
}
LABEL_16:
error(1, 0, "Input file could not be opened");
goto LABEL_17;
}
LABEL_21:
error(1, 0, "You forked up");
return func10();
}

original_code:
void
execute_simple_command (command_t c)
{
 pid_t pid = fork();
 if(pid > 0)
 {
  int status = 0;
  pid_t test = waitpid(pid,&status,0);
  if(test == -1)
   error(1,0,"Child process failed");
  c->status = (((status) & 0xff00) >> 8);
 }
 else if(pid == 0)
 {
  int fd_in,fd_out;
  if(c->input)
  {
   fd_in = open(c->input, 00, 0666);
   if(fd_in == -1)
    error(1,0,"Input file could not be opened");
   if(dup2(fd_in,0) == -1)
    error(1,0,"Input redirect failed");
   close(fd_in);
  }
  if(c->output)
  {
   fd_out = open(c->output, 01|0100|01000,0666);
   if(fd_out == -1)
    error(1,0,"Output file could not be opened");
   if(dup2(fd_out,1) == -1)
    error(1,0,"Output redirect failed");
   close(fd_out);
  }
  execvp(c->u.word[0],c->u.word);
  if(execvp(c->u.word[0],c->u.word) < 0)
  {
   error(1,0,"Error in execution of simple command \n");
   return;
  }
  exit(c->status);
 }
 else
 {
  error(1,0,"You forked up");
 }
}

canonical_original_code:
void execute_simple_command(struct command *c)
{
 int pid = fork();
 if(pid > 0)
 {
  int status = 0;
  int test = waitpid(pid,&status,0);
  if(test == -1)
   error(1,0,"Child process failed");
  c->status = (((status) & 0xff00) >> 8);
 }
 else if(pid == 0)
 {
  int fd_in; int fd_out;
  if(c->input)
  {
   fd_in = open(c->input, 00, 0666);
   if(fd_in == -1)
    error(1,0,"Input file could not be opened");
   if(dup2(fd_in,0) == -1)
    error(1,0,"Input redirect failed");
   close(fd_in);
  }
  if(c->output)
  {
   fd_out = open(c->output, 01|0100|01000,0666);
   if(fd_out == -1)
    error(1,0,"Output file could not be opened");
   if(dup2(fd_out,1) == -1)
    error(1,0,"Output redirect failed");
   close(fd_out);
  }
  execvp(c->u.word[0],c->u.word);
  if(execvp(c->u.word[0],c->u.word) < 0)
  {
   error(1,0,"Error in execution of simple command \n");
   return;
  }
  exit(c->status);
 }
 else
 {
  error(1,0,"You forked up");
 }
}

variable_types: pid int

variable_types: status int

variable_types: test int


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

do_command(*(_QWORD *)(a1 + 24));
result = *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL);
*(_DWORD *)(a1 + 4) = result;
return result;
}

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

func11(*(_QWORD *)(a1 + 24));
result = *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL);
*(_DWORD *)(a1 + 4) = result;
return result;
}

original_code:
void
execute_subshell_command (command_t c)
{
 do_command(c->u.subshell_command);
 c->status = c->u.subshell_command->status;
}

canonical_original_code:
void execute_subshell_command(struct command *c)
{
 do_command(c->u.subshell_command);
 c->status = c->u.subshell_command->status;
}


decompiled_code:
__int64 __fastcall do_command(_DWORD *a1)
{
__int64 result; // rax

switch ( *a1 )
{
case 0:
result = execute_and_operator();
break;
case 1:
result = execute_sequence_operator();
break;
case 2:
result = execute_or_operator();
break;
case 3:
result = execute_pipe_operator();
break;
case 4:
result = execute_simple_command((__int64)a1);
break;
case 7:
result = execute_subshell_command((__int64)a1);
break;
default:
error(1, 0, "Command not found. Try again fucker.");
result = execute_command();
break;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_DWORD *a1)
{
__int64 result; // rax

switch ( *a1 )
{
case 0:
result = func14();
break;
case 1:
result = func17();
break;
case 2:
result = func15();
break;
case 3:
result = func16();
break;
case 4:
result = func9((__int64)a1);
break;
case 7:
result = func10((__int64)a1);
break;
default:
error(1, 0, "Command not found. Try again fucker.");
result = func12();
break;
}
return result;
}

original_code:
void
do_command (command_t c)
{
 switch(c->type)
 {
  case AND_COMMAND:
   execute_and_operator(c);
   break;
  case OR_COMMAND:
   execute_or_operator(c);
   break;
  case PIPE_COMMAND:
   execute_pipe_operator(c);
   break;
  case SIMPLE_COMMAND:
   execute_simple_command(c);
   break;
  case SUBSHELL_COMMAND:
   execute_subshell_command(c);
   break;
  case SEQUENCE_COMMAND:
   execute_sequence_operator(c);
   break;
  default:
   error(1,0,"Command not found. Try again fucker.");
   break;
 }
}

canonical_original_code:
void do_command(struct command *c)
{
 switch(c->type)
 {
  case AND_COMMAND:
   execute_and_operator(c);
   break;
  case OR_COMMAND:
   execute_or_operator(c);
   break;
  case PIPE_COMMAND:
   execute_pipe_operator(c);
   break;
  case SIMPLE_COMMAND:
   execute_simple_command(c);
   break;
  case SUBSHELL_COMMAND:
   execute_subshell_command(c);
   break;
  case SEQUENCE_COMMAND:
   execute_sequence_operator(c);
   break;
  default:
   error(1,0,"Command not found. Try again fucker.");
   break;
 }
}


decompiled_code:
void __fastcall do_thread(void *a1)
{
execute_command(*(_DWORD **)a1, 0);
}

canonical_decompiled_code:
void __fastcall func13(void *a1)
{
func12(*(_DWORD **)a1, 0);
}

original_code:
void
do_thread (void* c)
{
 struct arg_struct * args = (struct arg_struct *)c;
 execute_command(args->cmd,0);
}

canonical_original_code:
void do_thread(void *c)
{
 struct arg_struct *args = (struct arg_struct *)c;
 execute_command(args->cmd,0);
}

variable_types:
c
void *

variable_types: struct arg_struct { struct command { enum command_type { AND_COMMAND=0, SEQUENCE_COMMAND=1, OR_COMMAND=2, PIPE_COMMAND=3, SIMPLE_COMMAND=4, START_SUBSHELL_COMMAND=5, END_SUBSHELL_COMMAND=6, SUBSHELL_COMMAND=7, NEWLINE_COMMAND=8, REDIRECT_FROM_COMMAND=9, REDIRECT_TO_COMMAND=10 } type; int status; char *input; char *output; union { struct command *command[2]; char **word; struct command *subshell_command; } u; } *cmd; int thread_index; } *

user_defined_types: struct arg_struct { struct command *cmd; int thread_index; }


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

do_command(*(_DWORD **)(a1 + 24));
result = *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL);
if ( !(_DWORD)result )
{
do_command(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
}
*(_DWORD *)(a1 + 4) = result;
return result;
}

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

func11(*(_DWORD **)(a1 + 24));
result = *(unsigned int *)(*(_QWORD *)(a1 + 24) + 4LL);
if ( !(_DWORD)result )
{
func11(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
}
*(_DWORD *)(a1 + 4) = result;
return result;
}

original_code:
void
execute_and_operator (command_t c)
{
 do_command(c->u.command[0]);
 if(c->u.command[0]->status == 0)
 {
  do_command(c->u.command[1]);
  c->status = c->u.command[1]->status;
 }
 else
 {
  c->status = c->u.command[0]->status;
 }
}

canonical_original_code:
void execute_and_operator(struct command *c)
{
 do_command(c->u.command[0]);
 if(c->u.command[0]->status == 0)
 {
  do_command(c->u.command[1]);
  c->status = c->u.command[1]->status;
 }
 else
 {
  c->status = c->u.command[0]->status;
 }
}


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

do_command(*(_DWORD **)(a1 + 24));
result = *(_QWORD *)(a1 + 24);
if ( *(_DWORD *)(result + 4) )
{
do_command(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
*(_DWORD *)(a1 + 4) = result;
}
else
{
*(_DWORD *)(a1 + 4) = 0;
}
return result;
}

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

func11(*(_DWORD **)(a1 + 24));
result = *(_QWORD *)(a1 + 24);
if ( *(_DWORD *)(result + 4) )
{
func11(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
*(_DWORD *)(a1 + 4) = result;
}
else
{
*(_DWORD *)(a1 + 4) = 0;
}
return result;
}

original_code:
void
execute_or_operator (command_t c)
{
 do_command(c->u.command[0]);
 if(!(c->u.command[0]->status))
 {
  c->status = c->u.command[0]->status;
 }
 else
 {
  do_command(c->u.command[1]);
  c->status = c->u.command[1]->status;
 }
}

canonical_original_code:
void execute_or_operator(struct command *c)
{
 do_command(c->u.command[0]);
 if(!(c->u.command[0]->status))
 {
  c->status = c->u.command[0]->status;
 }
 else
 {
  do_command(c->u.command[1]);
  c->status = c->u.command[1]->status;
 }
}


decompiled_code:
__int64 __fastcall execute_pipe_operator(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // ebx
__pid_t v3; // eax
__pid_t v4; // ebp
__int64 result; // rax
unsigned int v6; // [rsp+0h] [rbp-28h] BYREF
int stat_loc; // [rsp+4h] [rbp-24h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

pipe(pipedes);
v1 = fork();
if ( v1 == -1 )
{
error(1, 0, "You forked up the pipeline man");
LABEL_7:
close(1);
dup2(pipedes[1], 1);
close(pipedes[0]);
close(pipedes[1]);
do_command(*(_DWORD **)(a1 + 24));
exit(*(_DWORD *)(*(_QWORD *)(a1 + 24) + 4LL));
}
v2 = v1;
if ( !v1 )
goto LABEL_7;
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
error(1, 0, "You forked up the pipeline man");
LABEL_9:
close(0);
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
do_command(*(_DWORD **)(a1 + 32));
exit(*(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL));
}
if ( !v3 )
goto LABEL_9;
close(pipedes[0]);
close(pipedes[1]);
waitpid(v2, &stat_loc, 0);
waitpid(v4, (int *)&v6, 0);
result = v6;
*(_DWORD *)(a1 + 4) = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1)
{
__pid_t v1; // eax
__pid_t v2; // ebx
__pid_t v3; // eax
__pid_t v4; // ebp
__int64 result; // rax
unsigned int v6; // [rsp+0h] [rbp-28h] BYREF
int stat_loc; // [rsp+4h] [rbp-24h] BYREF
int pipedes[2]; // [rsp+8h] [rbp-20h] BYREF

pipe(pipedes);
v1 = fork();
if ( v1 == -1 )
{
error(1, 0, "You forked up the pipeline man");
LABEL_7:
close(1);
dup2(pipedes[1], 1);
close(pipedes[0]);
close(pipedes[1]);
func11(*(_DWORD **)(a1 + 24));
exit(*(_DWORD *)(*(_QWORD *)(a1 + 24) + 4LL));
}
v2 = v1;
if ( !v1 )
goto LABEL_7;
v3 = fork();
v4 = v3;
if ( v3 == -1 )
{
error(1, 0, "You forked up the pipeline man");
LABEL_9:
close(0);
dup2(pipedes[0], 0);
close(pipedes[0]);
close(pipedes[1]);
func11(*(_DWORD **)(a1 + 32));
exit(*(_DWORD *)(*(_QWORD *)(a1 + 32) + 4LL));
}
if ( !v3 )
goto LABEL_9;
close(pipedes[0]);
close(pipedes[1]);
waitpid(v2, &stat_loc, 0);
waitpid(v4, (int *)&v6, 0);
result = v6;
*(_DWORD *)(a1 + 4) = v6;
return result;
}

original_code:
void
execute_pipe_operator (command_t c)
{
 int fd[2];
 pipe(fd);
 pid_t l_pid;
 l_pid = fork();
 if(l_pid == -1)
 {
  error(1,0,"You forked up the pipeline man");
 }
 else if(l_pid == 0)
 {
  close(1);
  dup2(fd[1],1);
  close(fd[0]);
  close(fd[1]);
  do_command(c->u.command[0]);
  exit(c->u.command[0]->status);
 }
 pid_t r_pid;
 r_pid = fork();
 if(r_pid == -1)
 {
  error(1,0,"You forked up the pipeline man");
 }
 else if(r_pid == 0)
 {
  close(0);
  dup2(fd[0],0);
  close(fd[0]);
  close(fd[1]);
  do_command(c->u.command[1]);
  exit(c->u.command[1]->status);
 }
 close(fd[0]);
 close(fd[1]);
 int status_left_child,status_right_child;
 waitpid(l_pid,&status_left_child,0);
 waitpid(r_pid,&status_right_child,0);
 c->status = status_right_child;
}

canonical_original_code:
void execute_pipe_operator(struct command *c)
{
 int fd[2];
 pipe(fd);
 int l_pid;
 l_pid = fork();
 if(l_pid == -1)
 {
  error(1,0,"You forked up the pipeline man");
 }
 else if(l_pid == 0)
 {
  close(1);
  dup2(fd[1],1);
  close(fd[0]);
  close(fd[1]);
  do_command(c->u.command[0]);
  exit(c->u.command[0]->status);
 }
 int r_pid;
 r_pid = fork();
 if(r_pid == -1)
 {
  error(1,0,"You forked up the pipeline man");
 }
 else if(r_pid == 0)
 {
  close(0);
  dup2(fd[0],0);
  close(fd[0]);
  close(fd[1]);
  do_command(c->u.command[1]);
  exit(c->u.command[1]->status);
 }
 close(fd[0]);
 close(fd[1]);
 int status_left_child; int status_right_child;
 waitpid(l_pid,&status_left_child,0);
 waitpid(r_pid,&status_right_child,0);
 c->status = status_right_child;
}

variable_types:
fd
int [2]


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

do_command(*(_DWORD **)(a1 + 24));
do_command(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
*(_DWORD *)(a1 + 4) = result;
return result;
}

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

func11(*(_DWORD **)(a1 + 24));
func11(*(_DWORD **)(a1 + 32));
result = *(unsigned int *)(*(_QWORD *)(a1 + 32) + 4LL);
*(_DWORD *)(a1 + 4) = result;
return result;
}

original_code:
void
execute_sequence_operator (command_t c)
{
 do_command(c->u.command[0]);
 do_command(c->u.command[1]);
 c->status = c->u.command[1]->status;
}

canonical_original_code:
void execute_sequence_operator(struct command *c)
{
 do_command(c->u.command[0]);
 do_command(c->u.command[1]);
 c->status = c->u.command[1]->status;
}


cleanup

decompiled_code:
void cleanup()
{
;
}

canonical_decompiled_code:
void func18()
{
;
}

original_code:
void
cleanup()
{
}

canonical_original_code:
void cleanup()
{
}


decompiled_code:
__int64 __fastcall memory_exhausted(int errnum)
{
error(1, errnum, "memory exhausted");
return check_nonnull();
}

canonical_decompiled_code:
__int64 __fastcall func0(int errnum)
{
error(1, errnum, "memory exhausted");
return func1();
}

original_code:
static void
memory_exhausted (int errnum)
{
  error (1, errnum, "memory exhausted");
}

canonical_original_code:
static void memory_exhausted(int errnum)
{
  error (1, errnum, "memory exhausted");
}

variable_types: errnum int


decompiled_code:
__int64 __fastcall check_nonnull(__int64 a1)
{
int *v2; // rax

if ( a1 )
return a1;
v2 = _errno_location();
memory_exhausted(*v2);
return checked_malloc();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int *v2; // rax

if ( a1 )
return a1;
v2 = _errno_location();
func0(*v2);
return func2();
}

original_code:
static void *
check_nonnull (void *p)
{
  if (! p)
    memory_exhausted ((*__errno_location ()));
  return p;
}

canonical_original_code:
static void *check_nonnull(void *p)
{
  if (! p)
    memory_exhausted ((*__errno_location ()));
  return p;
}

variable_types:
p
void *


decompiled_code:
__int64 __fastcall checked_malloc(size_t a1)
{
void *v1; // rax

if ( !a1 )
a1 = 1LL;
v1 = malloc(a1);
return check_nonnull((__int64)v1);
}

canonical_decompiled_code:
__int64 __fastcall func2(size_t a1)
{
void *v1; // rax

if ( !a1 )
a1 = 1LL;
v1 = malloc(a1);
return func1((__int64)v1);
}

original_code:
void *
checked_malloc (size_t size)
{
  return check_nonnull (malloc (size ? size : 1));
}

canonical_original_code:
void *checked_malloc(unsigned long size)
{
  return check_nonnull (malloc (size ? size : 1));
}

variable_types:
size
unsigned long


decompiled_code:
__int64 __fastcall checked_realloc(void *a1, size_t a2)
{
void *v2; // rax

if ( !a2 )
a2 = 1LL;
v2 = realloc(a1, a2);
return check_nonnull((__int64)v2);
}

canonical_decompiled_code:
__int64 __fastcall func3(void *a1, size_t a2)
{
void *v2; // rax

if ( !a2 )
a2 = 1LL;
v2 = realloc(a1, a2);
return func1((__int64)v2);
}

original_code:
void *
checked_realloc (void *ptr, size_t size)
{
  return check_nonnull (realloc (ptr, size ? size : 1));
}

canonical_original_code:
void *checked_realloc(void *ptr, unsigned long size)
{
  return check_nonnull (realloc (ptr, size ? size : 1));
}

variable_types:
ptr
void *


decompiled_code:
__int64 __fastcall checked_grow_alloc(void *a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rdx
size_t v3; // rax

v2 = *a2;
if ( *a2 == -1LL )
{
memory_exhausted(0);
JUMPOUT(0xBALL);
}
v3 = 2 * v2;
if ( v2 > 0x7FFFFFFFFFFFFFFELL )
v3 = -1LL;
*a2 = v3;
return checked_realloc(a1, v3);
}

canonical_decompiled_code:
__int64 __fastcall func4(void *a1, unsigned __int64 *a2)
{
unsigned __int64 v2; // rdx
size_t v3; // rax

v2 = *a2;
if ( *a2 == -1LL )
{
func0(0);
JUMPOUT(0xBALL);
}
v3 = 2 * v2;
if ( v2 > 0x7FFFFFFFFFFFFFFELL )
v3 = -1LL;
*a2 = v3;
return func3(a1, v3);
}

original_code:
void *
checked_grow_alloc (void *ptr, size_t *size)
{
  size_t max = -1;
  if (*size == max)
    memory_exhausted (0);
  *size = *size < max / 2 ? 2 * *size : max;
  return checked_realloc (ptr, *size);
}

canonical_original_code:
void *checked_grow_alloc(void *ptr, unsigned long *size)
{
  unsigned long max = -1;
  if (*size == max)
    memory_exhausted (0);
  *size = *size < max / 2 ? 2 * *size : max;
  return checked_realloc (ptr, *size);
}

variable_types:
size
unsigned long *

variable_types:
max
unsigned long


decompiled_code:
int __fastcall command_indented_print(int a1, unsigned int *a2)
{
unsigned int v3; // eax
int result; // eax
const char *v5; // rsi
const char *v6; // rsi
const char **v7; // r12
const char **v8; // rbx
const char *v9; // rsi

v3 = *a2;
if ( *a2 == 4 )
{
v7 = (const char **)*((_QWORD *)a2 + 3);
result = printf("%*s%s", a1, (const char *)&unk_14B, *v7);
v8 = v7 + 1;
v9 = v7[1];
if ( v9 )
{
do
{
result = printf(" %s", v9);
v9 = *++v8;
}
while ( *v8 );
}
}
else if ( v3 <= 4 )
{
command_indented_print(a1 + 2 * (unsigned int)(v3 != **((_DWORD **)a2 + 3)));
printf(" \\\n%*s%s\n", a1, (const char *)&unk_14B, &command_label_0[3 * *a2]);
result = command_indented_print(a1 + 2 * (unsigned int)(**((_DWORD **)a2 + 4) != *a2));
}
else
{
if ( v3 != 7 )
abort();
printf("%*s(\n", a1, (const char *)&unk_14B);
command_indented_print((unsigned int)(a1 + 1));
result = printf("\n%*s)", a1, (const char *)&unk_14B);
}
v5 = (const char *)*((_QWORD *)a2 + 1);
if ( v5 )
result = printf("<%s", v5);
v6 = (const char *)*((_QWORD *)a2 + 2);
if ( v6 )
result = printf(">%s", v6);
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, unsigned int *a2)
{
unsigned int v3; // eax
int result; // eax
const char *v5; // rsi
const char *v6; // rsi
const char **v7; // r12
const char **v8; // rbx
const char *v9; // rsi

v3 = *a2;
if ( *a2 == 4 )
{
v7 = (const char **)*((_QWORD *)a2 + 3);
result = printf("%*s%s", a1, (const char *)&unk_14B, *v7);
v8 = v7 + 1;
v9 = v7[1];
if ( v9 )
{
do
{
result = printf(" %s", v9);
v9 = *++v8;
}
while ( *v8 );
}
}
else if ( v3 <= 4 )
{
func0(a1 + 2 * (unsigned int)(v3 != **((_DWORD **)a2 + 3)));
printf(" \\\n%*s%s\n", a1, (const char *)&unk_14B, &command_label_0[3 * *a2]);
result = func0(a1 + 2 * (unsigned int)(**((_DWORD **)a2 + 4) != *a2));
}
else
{
if ( v3 != 7 )
abort();
printf("%*s(\n", a1, (const char *)&unk_14B);
func0((unsigned int)(a1 + 1));
result = printf("\n%*s)", a1, (const char *)&unk_14B);
}
v5 = (const char *)*((_QWORD *)a2 + 1);
if ( v5 )
result = printf("<%s", v5);
v6 = (const char *)*((_QWORD *)a2 + 2);
if ( v6 )
result = printf(">%s", v6);
return result;
}

original_code:
static void
command_indented_print (int indent, command_t c)
{
  switch (c->type)
    {
    case AND_COMMAND:
    case SEQUENCE_COMMAND:
    case OR_COMMAND:
    case PIPE_COMMAND:
      {
 command_indented_print (indent + 2 * (c->u.command[0]->type != c->type),
    c->u.command[0]);
 static char const command_label[][3] = { "&&", ";", "||", "|" };
 printf (" \\\n%*s%s\n", indent, "", command_label[c->type]);
 command_indented_print (indent + 2 * (c->u.command[1]->type != c->type),
    c->u.command[1]);
 break;
      }
    case SIMPLE_COMMAND:
      {
 char **w = c->u.word;
 printf ("%*s%s", indent, "", *w);
 while (*++w)
   printf (" %s", *w);
 break;
      }
    case SUBSHELL_COMMAND:
      printf ("%*s(\n", indent, "");
      command_indented_print (indent + 1, c->u.subshell_command);
      printf ("\n%*s)", indent, "");
      break;
    default:
      abort ();
    }
  if (c->input)
    printf ("<%s", c->input);
  if (c->output)
    printf (">%s", c->output);
}

canonical_original_code:
static void command_indented_print(int indent, struct command *c)
{
  switch (c->type)
    {
    case AND_COMMAND:
    case SEQUENCE_COMMAND:
    case OR_COMMAND:
    case PIPE_COMMAND:
      {
 command_indented_print (indent + 2 * (c->u.command[0]->type != c->type),
    c->u.command[0]);
 static char command_label[][3] = { "&&", ";", "||", "|" };
 printf (" \\\n%*s%s\n", indent, "", command_label[c->type]);
 command_indented_print (indent + 2 * (c->u.command[1]->type != c->type),
    c->u.command[1]);
 break;
      }
    case SIMPLE_COMMAND:
      {
 char **w = c->u.word;
 printf ("%*s%s", indent, "", *w);
 while (*++w)
   printf (" %s", *w);
 break;
      }
    case SUBSHELL_COMMAND:
      printf ("%*s(\n", indent, "");
      command_indented_print (indent + 1, c->u.subshell_command);
      printf ("\n%*s)", indent, "");
      break;
    default:
      abort ();
    }
  if (c->input)
    printf ("<%s", c->input);
  if (c->output)
    printf (">%s", c->output);
}

variable_types: indent int

variable_types: struct command { enum command_type { AND_COMMAND=0, SEQUENCE_COMMAND=1, OR_COMMAND=2, PIPE_COMMAND=3, SIMPLE_COMMAND=4, START_SUBSHELL_COMMAND=5, END_SUBSHELL_COMMAND=6, SUBSHELL_COMMAND=7, NEWLINE_COMMAND=8, REDIRECT_FROM_COMMAND=9, REDIRECT_TO_COMMAND=10 } type; int status; char *input; char *output; union { struct command *command[2]; char **word; struct command *subshell_command; } u; } *

variable_types:
w
char **


decompiled_code:
int __fastcall print_command(unsigned int *a1)
{
command_indented_print(2, a1);
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func1(unsigned int *a1)
{
func0(2, a1);
return putchar(10);
}

original_code:
void
print_command (command_t c)
{
  command_indented_print (2, c);
  putchar ('\n');
}

canonical_original_code:
void print_command(struct command *c)
{
  command_indented_print (2, c);
  putchar ('\n');
}


decompiled_code:
int __fastcall get_next_byte(FILE *a1)
{
return getc(a1);
}

canonical_decompiled_code:
int __fastcall func0(FILE *a1)
{
return getc(a1);
}

original_code:
static int
get_next_byte (void *stream)
{
  return getc (stream);
}

canonical_original_code:
static int get_next_byte(void *stream)
{
  return getc (stream);
}

variable_types:
stream
void *


usage

decompiled_code:
int usage()
{
const char **v0; // rdx

error(1, 0, "usage: %s [-pt] SCRIPT-FILE", (const char *)program_name);
return main(1, 0LL, v0);
}

canonical_decompiled_code:
int func1()
{
const char **v0; // rdx

error(1, 0, "usage: %s [-pt] SCRIPT-FILE", (const char *)program_name);
return main(1, 0LL, v0);
}

original_code:
static void
usage (void)
{
  error (1, 0, "usage: %s [-pt] SCRIPT-FILE", program_name);
}

canonical_original_code:
static void usage()
{
  error (1, 0, "usage: %s [-pt] SCRIPT-FILE", program_name);
}


repo: abellong/httptest

original_code:
static void
l_remove( Timer* t )
    {
    int h = t->hash;
    if ( t->prev == (Timer*) 0 )
 timers[h] = t->next;
    else
 t->prev->next = t->next;
    if ( t->next != (Timer*) 0 )
 t->next->prev = t->prev;
    }

canonical_original_code:
static void l_remove(struct TimerStruct *t)
    {
    int h = t->hash;
    if ( t->prev == (struct TimerStruct *) 0 )
 timers[h] = t->next;
    else
 t->prev->next = t->next;
    if ( t->next != (struct TimerStruct *) 0 )
 t->next->prev = t->prev;
    }

variable_types: struct TimerStruct { void (*timer_proc)(struct timeval { long tv_sec; long tv_usec; } *nowP); long msecs; int periodic; struct timeval time; struct TimerStruct *prev; struct TimerStruct *next; int hash; } *

variable_types: h int

user_defined_types: struct TimerStruct { void (*timer_proc)(struct timeval *nowP); long msecs; int periodic; struct timeval time; struct TimerStruct *prev; struct TimerStruct *next; int hash; }


decompiled_code:
__int64 *tmr_init()
{
__int64 *result; // rax

result = timers;
do
*result++ = 0LL;
while ( result != (__int64 *)&unk_798 );
return result;
}

canonical_decompiled_code:
__int64 *func4()
{
__int64 *result; // rax

result = timers;
do
*result++ = 0LL;
while ( result != (__int64 *)&unk_798 );
return result;
}

original_code:
void
tmr_init( void )
    {
    int h;
    for ( h = 0; h < 67; ++h )
 timers[h] = (Timer*) 0;
    }

canonical_original_code:
void tmr_init()
    {
    int h;
    for ( h = 0; h < 67; ++h )
 timers[h] = (struct TimerStruct *) 0;
    }

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


original_code:
Timer*
tmr_create(
    struct timeval* nowP, TimerProc* timer_proc, long msecs, int periodic )
    {
    Timer* t;
    if ( free_timers != (Timer*) 0 )
 {
 t = free_timers;
 free_timers = t->next;
 }
    else
 {
 t = (Timer*) malloc( sizeof(Timer) );
 if ( t == (Timer*) 0 )
     return (Timer*) 0;
 }
    t->timer_proc = timer_proc;
    t->msecs = msecs;
    t->periodic = periodic;
    if ( nowP != (struct timeval*) 0 )
 t->time = *nowP;
    else
 (void) gettimeofday( &t->time, (struct timezone*) 0 );
    t->time.tv_sec += msecs / 1000000L;
    t->time.tv_usec += msecs % 1000000L;
    if ( t->time.tv_usec >= 1000000L )
 {
 t->time.tv_sec += t->time.tv_usec / 1000000L;
 t->time.tv_usec %= 1000000L;
 }
    t->hash = hash( t );
    l_add( t );
    return t;
    }

canonical_original_code:
struct TimerStruct *tmr_create(struct timeval *nowP, void (*timer_proc)(struct timeval *nowP), long msecs, int periodic)
    {
    struct TimerStruct *t;
    if ( free_timers != (struct TimerStruct *) 0 )
 {
 t = free_timers;
 free_timers = t->next;
 }
    else
 {
 t = (struct TimerStruct *) malloc( sizeof(Timer) );
 if ( t == (struct TimerStruct *) 0 )
     return (struct TimerStruct *) 0;
 }
    t->timer_proc = timer_proc;
    t->msecs = msecs;
    t->periodic = periodic;
    if ( nowP != (struct timeval *) 0 )
 t->time = *nowP;
    else
 (void) gettimeofday( &t->time, (struct timezone *) 0 );
    t->time.tv_sec += msecs / 1000000L;
    t->time.tv_usec += msecs % 1000000L;
    if ( t->time.tv_usec >= 1000000L )
 {
 t->time.tv_sec += t->time.tv_usec / 1000000L;
 t->time.tv_usec %= 1000000L;
 }
    t->hash = hash( t );
    l_add( t );
    return t;
    }

variable_types:
nowP
struct timeval *

variable_types: msecs long

variable_types: periodic int

return_type: struct TimerStruct { void (*timer_proc)(struct timeval { long tv_sec; long tv_usec; } *nowP); long msecs; int periodic; struct timeval time; struct TimerStruct *prev; struct TimerStruct *next; int hash; } *

user_defined_types: struct timezone { int tz_minuteswest; int tz_dsttime; }


original_code:
long
tmr_mstimeout( struct timeval* nowP )
    {
    int h;
    int gotone;
    long msecs, m;
    register Timer* t;
    gotone = 0;
    msecs = 0;
    for ( h = 0; h < 67; ++h )
 {
 t = timers[h];
 if ( t != (Timer*) 0 )
     {
     m = ( t->time.tv_sec - nowP->tv_sec ) * 1000L +
  ( t->time.tv_usec - nowP->tv_usec ) / 1000L;
     if ( ! gotone )
  {
  msecs = m;
  gotone = 1;
  }
     else if ( m < msecs )
  msecs = m;
     }
 }
    if ( ! gotone )
 return -1;
    if ( msecs <= 0 )
 msecs = 0;
    return msecs;
    }

canonical_original_code:
long tmr_mstimeout(struct timeval *nowP)
    {
    int h;
    int gotone;
    long msecs; long m;
    register struct TimerStruct *t;
    gotone = 0;
    msecs = 0;
    for ( h = 0; h < 67; ++h )
 {
 t = timers[h];
 if ( t != (struct TimerStruct *) 0 )
     {
     m = ( t->time.tv_sec - nowP->tv_sec ) * 1000L +
  ( t->time.tv_usec - nowP->tv_usec ) / 1000L;
     if ( ! gotone )
  {
  msecs = m;
  gotone = 1;
  }
     else if ( m < msecs )
  msecs = m;
     }
 }
    if ( ! gotone )
 return -1;
    if ( msecs <= 0 )
 msecs = 0;
    return msecs;
    }

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

variable_types: gotone int

variable_types: m long


decompiled_code:
void *__fastcall tmr_cancel(_QWORD *a1)
{
void *result; // rax

l_remove((__int64)a1);
result = free_timers;
a1[6] = free_timers;
free_timers = a1;
a1[5] = 0LL;
return result;
}

canonical_decompiled_code:
void *__fastcall func8(_QWORD *a1)
{
void *result; // rax

func2((__int64)a1);
result = free_timers;
a1[6] = free_timers;
free_timers = a1;
a1[5] = 0LL;
return result;
}

original_code:
void
tmr_cancel( Timer* t )
    {
    l_remove( t );
    t->next = free_timers;
    free_timers = t;
    t->prev = (Timer*) 0;
    }

canonical_original_code:
void tmr_cancel(struct TimerStruct *t)
    {
    l_remove( t );
    t->next = free_timers;
    free_timers = t;
    t->prev = (struct TimerStruct *) 0;
    }


original_code:
void
tmr_run( struct timeval* nowP )
    {
    int h;
    Timer* t;
    Timer* next;
    for ( h = 0; h < 67; ++h )
 for ( t = timers[h]; t != (Timer*) 0; t = next )
     {
     next = t->next;
     if ( t->time.tv_sec > nowP->tv_sec ||
   ( t->time.tv_sec == nowP->tv_sec &&
     t->time.tv_usec > nowP->tv_usec ) )
  break;
     (t->timer_proc)(nowP );
     if ( t->periodic )
  {
  t->time.tv_sec += t->msecs / 1000000L;
  t->time.tv_usec += t->msecs % 1000000L;
  if ( t->time.tv_usec >= 1000000L )
      {
      t->time.tv_sec += t->time.tv_usec / 1000000L;
      t->time.tv_usec %= 1000000L;
      }
  l_resort( t );
  }
     else
  tmr_cancel( t );
     }
    }

canonical_original_code:
void tmr_run(struct timeval *nowP)
    {
    int h;
    struct TimerStruct *t;
    struct TimerStruct *next;
    for ( h = 0; h < 67; ++h )
 for ( t = timers[h]; t != (struct TimerStruct *) 0; t = next )
     {
     next = t->next;
     if ( t->time.tv_sec > nowP->tv_sec ||
   ( t->time.tv_sec == nowP->tv_sec &&
     t->time.tv_usec > nowP->tv_usec ) )
  break;
     (t->timer_proc)(nowP );
     if ( t->periodic )
  {
  t->time.tv_sec += t->msecs / 1000000L;
  t->time.tv_usec += t->msecs % 1000000L;
  if ( t->time.tv_usec >= 1000000L )
      {
      t->time.tv_sec += t->time.tv_usec / 1000000L;
      t->time.tv_usec %= 1000000L;
      }
  l_resort( t );
  }
     else
  tmr_cancel( t );
     }
    }


decompiled_code:
void tmr_cleanup()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = free_timers;
if ( free_timers )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[6];
free_timers = v0;
free(v1);
}
while ( v0 );
}
}

canonical_decompiled_code:
void func10()
{
_QWORD *v0; // rbx
void *v1; // rdi

v0 = free_timers;
if ( free_timers )
{
do
{
v1 = v0;
v0 = (_QWORD *)v0[6];
free_timers = v0;
free(v1);
}
while ( v0 );
}
}

original_code:
void
tmr_cleanup( void )
    {
    Timer* t;
    while ( free_timers != (Timer*) 0 )
 {
 t = free_timers;
 free_timers = t->next;
 free( (void*) t );
 }
    }

canonical_original_code:
void tmr_cleanup()
    {
    struct TimerStruct *t;
    while ( free_timers != (struct TimerStruct *) 0 )
 {
 t = free_timers;
 free_timers = t->next;
 free( (void *) t );
 }
    }


decompiled_code:
void tmr_destroy()
{
__int64 *v0; // rbp
_QWORD *i; // rdi

v0 = timers;
do
{
for ( i = (_QWORD *)*v0; *v0; i = (_QWORD *)*v0 )
tmr_cancel(i);
++v0;
}
while ( v0 != (__int64 *)&unk_798 );
tmr_cleanup();
}

original_code:
void
tmr_destroy( void )
    {
    int h;
    for ( h = 0; h < 67; ++h )
 while ( timers[h] != (Timer*) 0 )
     tmr_cancel( timers[h] );
    tmr_cleanup();
    }

canonical_original_code:
void tmr_destroy()
    {
    int h;
    for ( h = 0; h < 67; ++h )
 while ( timers[h] != (struct TimerStruct *) 0 )
     tmr_cancel( timers[h] );
    tmr_cleanup();
    }