decompiled_code:
int __fastcall bz_trace_log(const char *a1, const char *a2, __int64 a3, __int64 a4)
{
return fprintf(bz_trace_log_file, "%s\t\t%s\t\t%12li\t\t%12li\n", a1, a2, a3, a4);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1, const char *a2, __int64 a3, __int64 a4)
{
return fprintf(bz_trace_log_file, "%s\t\t%s\t\t%12li\t\t%12li\n", a1, a2, a3, a4);
}

original_code:
void bz_trace_log(const char* file, const char* function,long time1,long time2)
{
  fprintf(bz_trace_log_file,"%s\t\t%s\t\t%12li\t\t%12li\n",file,function,time1,time2);
}

canonical_original_code:
void bz_trace_log(char *file, char *function, long time1, long time2)
{
  fprintf(bz_trace_log_file,"%s\t\t%s\t\t%12li\t\t%12li\n",file,function,time1,time2);
}

variable_types:
file
char *

variable_types:
function
char *


repo: sambeau/burp

decompiled_code:
int __fastcall bz_trace_push(__time_t a1, __suseconds_t a2)
{
struct timeval *v2; // rax
__int64 v3; // rdx

v2 = (struct timeval *)GC_malloc(72LL);
if ( !v2 )
{
fprintf(stderr, "[!] %s: Error in trace.c '%s'\n", (const char *)prog_name, "Out of memory");
exit(0);
}
v3 = tstack;
v2->tv_sec = a1;
v2->tv_usec = a2;
v2[3].tv_usec = 0LL;
v2[4].tv_sec = v3;
tstack = (__int64)v2;
return gettimeofday(v2 + 1, &tz);
}

canonical_decompiled_code:
int __fastcall func2(__time_t a1, __suseconds_t a2)
{
struct timeval *v2; // rax
__int64 v3; // rdx

v2 = (struct timeval *)GC_malloc(72LL);
if ( !v2 )
{
fprintf(stderr, "[!] %s: Error in trace.c '%s'\n", (const char *)prog_name, "Out of memory");
exit(0);
}
v3 = tstack;
v2->tv_sec = a1;
v2->tv_usec = a2;
v2[3].tv_usec = 0LL;
v2[4].tv_sec = v3;
tstack = (__int64)v2;
return gettimeofday(v2 + 1, &tz);
}

original_code:
void bz_trace_push(const char *file, const char* function)
{
  bz_trace_stack *ts;
  ts = GC_malloc(sizeof(bz_trace_stack));
  if (!ts) {fprintf(stderr,"[!] %s: Error in trace.c '%s'\n",prog_name,"Out of memory");exit(0);};
  ts->file = file;
  ts->function = function;
  ts->tot_child_time = 0;
  ts->prev = tstack;
  tstack = ts;
  gettimeofday(&ts->start,&tz);
}

canonical_original_code:
void bz_trace_push(char *file, char *function)
{
  struct bz_trace_rec *ts;
  ts = GC_malloc(sizeof(bz_trace_stack));
  if (!ts) {fprintf(stderr,"[!] %s: Error in trace.c '%s'\n",prog_name,"Out of memory");exit(0);};
  ts->file = file;
  ts->function = function;
  ts->tot_child_time = 0;
  ts->prev = tstack;
  tstack = ts;
  gettimeofday(&ts->start,&tz);
}

variable_types: struct bz_trace_rec { char *file; char *function; struct timeval { long tv_sec; long tv_usec; } start; struct timeval stop; long tot_time; long tot_child_time; struct bz_trace_rec *prev; } *

return_type: void

user_defined_types: struct bz_trace_rec { char *file; char *function; struct timeval start; struct timeval stop; long tot_time; long tot_child_time; struct bz_trace_rec *prev; }


decompiled_code:
__int64 bz_trace_pop()
{
__int64 v0; // rbx
__int64 v1; // rdx
const char *v2; // rsi
const char *v3; // rdi
__int64 result; // rax

v0 = tstack;
if ( !tstack )
{
fprintf(stderr, "[!] %s: Error in trace.c '%s'\n", (const char *)prog_name, "Tried to pop an empty trace stack");
exit(0);
}
gettimeofday((struct timeval *)(tstack + 32), &tz);
v1 = *(_QWORD *)(v0 + 40)
+ 1000000LL * *(_QWORD *)(v0 + 32)
- (*(_QWORD *)(v0 + 24)
+ 1000000LL * *(_QWORD *)(v0 + 16));
v2 = *(const char **)(v0 + 8);
v3 = *(const char **)v0;
*(_QWORD *)(v0 + 48) = v1;
bz_trace_log(v3, v2, v1, v1 - *(_QWORD *)(v0 + 56));
result = *(_QWORD *)(v0 + 64);
tstack = result;
if ( result )
*(_QWORD *)(result + 56) += *(_QWORD *)(v0 + 48);
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 v0; // rbx
__int64 v1; // rdx
const char *v2; // rsi
const char *v3; // rdi
__int64 result; // rax

v0 = tstack;
if ( !tstack )
{
fprintf(stderr, "[!] %s: Error in trace.c '%s'\n", (const char *)prog_name, "Tried to pop an empty trace stack");
exit(0);
}
gettimeofday((struct timeval *)(tstack + 32), &tz);
v1 = *(_QWORD *)(v0 + 40)
+ 1000000LL * *(_QWORD *)(v0 + 32)
- (*(_QWORD *)(v0 + 24)
+ 1000000LL * *(_QWORD *)(v0 + 16));
v2 = *(const char **)(v0 + 8);
v3 = *(const char **)v0;
*(_QWORD *)(v0 + 48) = v1;
func1(v3, v2, v1, v1 - *(_QWORD *)(v0 + 56));
result = *(_QWORD *)(v0 + 64);
tstack = result;
if ( result )
*(_QWORD *)(result + 56) += *(_QWORD *)(v0 + 48);
return result;
}

original_code:
void bz_trace_pop(void)
{
  bz_trace_stack *ts;
  ts = tstack;
   if (ts) {
      gettimeofday(&ts->stop,&tz);
      ts->tot_time =
         ((long)ts->stop.tv_sec*1000000 + (long)ts->stop.tv_usec)
            - ((long)ts->start.tv_sec * 1000000 + (long)ts->start.tv_usec);
      bz_trace_log(ts->file, ts->function, ts->tot_time, ts->tot_time - ts->tot_child_time);
      tstack = ts->prev;
      if (tstack) {
         tstack->tot_child_time += ts->tot_time;
      }
   } else {
     {fprintf(stderr,"[!] %s: Error in trace.c '%s'\n",prog_name,"Tried to pop an empty trace stack");exit(0);};
   }
}

canonical_original_code:
void bz_trace_pop()
{
  struct bz_trace_rec *ts;
  ts = tstack;
   if (ts) {
      gettimeofday(&ts->stop,&tz);
      ts->tot_time =
         ((long)ts->stop.tv_sec*1000000 + (long)ts->stop.tv_usec)
            - ((long)ts->start.tv_sec * 1000000 + (long)ts->start.tv_usec);
      bz_trace_log(ts->file, ts->function, ts->tot_time, ts->tot_time - ts->tot_child_time);
      tstack = ts->prev;
      if (tstack) {
         tstack->tot_child_time += ts->tot_time;
      }
   } else {
     {fprintf(stderr,"[!] %s: Error in trace.c '%s'\n",prog_name,"Tried to pop an empty trace stack");exit(0);};
   }
}

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


decompiled_code:
_QWORD *bz_barf_stack_new()
{
_QWORD *result; // rax

result = (_QWORD *)GC_malloc(16LL);
if ( !result )
{
fprintf(stderr, "[!] %s: Error in barf.c '%s'\n", (const char *)prog_name, "Out of memory");
exit(0);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *result; // rax

result = (_QWORD *)GC_malloc(16LL);
if ( !result )
{
fprintf(stderr, "[!] %s: Error in barf.c '%s'\n", (const char *)prog_name, "Out of memory");
exit(0);
}
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
static inline bz_barf_stack* bz_barf_stack_new()
{
   bz_barf_stack* new;
   new = GC_malloc(sizeof(bz_barf_stack));
   if(new==((void *)0))
      {fprintf(stderr,"[!] %s: Error in barf.c '%s'\n",prog_name,"Out of memory");exit(0);};
   new->barf_data = ((void *)0);
   new->next = ((void *)0);
   return new;
}

canonical_original_code:
static inline struct bz_barf_stack_node *bz_barf_stack_new()
{
   struct bz_barf_stack_node *new;
   new = GC_malloc(sizeof(bz_barf_stack));
   if(new==((void *)0))
      {fprintf(stderr,"[!] %s: Error in barf.c '%s'\n",prog_name,"Out of memory");exit(0);};
   new->barf_data = ((void *)0);
   new->next = ((void *)0);
   return new;
}

variable_types: struct bz_barf_stack_node { void *barf_data; struct bz_barf_stack_node *next; } *


decompiled_code:
__sighandler_t set_signals()
{
signal(4, signal_handler);
signal(8, signal_handler);
signal(7, signal_handler);
signal(11, signal_handler);
signal(15, signal_handler);
return signal(2, signal_handler);
}

canonical_decompiled_code:
__sighandler_t func1()
{
signal(4, signal_handler);
signal(8, signal_handler);
signal(7, signal_handler);
signal(11, signal_handler);
signal(15, signal_handler);
return signal(2, signal_handler);
}

original_code:
static void set_signals(void)
{
   signal(4, signal_handler);
   signal(8, signal_handler);
   signal(7, signal_handler);
   signal(11, signal_handler);
   signal(15, signal_handler);
   signal(2, signal_handler);
}

canonical_original_code:
static void set_signals()
{
   signal(4, signal_handler);
   signal(8, signal_handler);
   signal(7, signal_handler);
   signal(11, signal_handler);
   signal(15, signal_handler);
   signal(2, signal_handler);
}


decompiled_code:
__int64 bz_barf_prog_name()
{
return prog_name;
}

canonical_decompiled_code:
__int64 func4()
{
return prog_name;
}

original_code:
inline const char* bz_barf_prog_name(void)
{
   return prog_name;
}

canonical_original_code:
inline char *bz_barf_prog_name()
{
   return prog_name;
}

return_type: char *


decompiled_code:
_QWORD *bz_barf_pop_function()
{
_QWORD *result; // rax

result = bz_barf_stack_pop_isra_0(*(_QWORD **)(pfs + 8));
pfs = (__int64)result;
return result;
}

canonical_decompiled_code:
_QWORD *func5()
{
_QWORD *result; // rax

result = bz_barf_stack_pop_isra_0(*(_QWORD **)(pfs + 8));
pfs = (__int64)result;
return result;
}

original_code:
inline void bz_barf_pop_function()
{
   pfs = (bz_barf_stack*) bz_barf_stack_pop(pfs);
}

canonical_original_code:
inline void bz_barf_pop_function()
{
   pfs = (struct bz_barf_stack_node *) bz_barf_stack_pop(pfs);
}

user_defined_types: struct bz_barf_stack_node { void *barf_data; struct bz_barf_stack_node *next; }


decompiled_code:
void __fastcall __noreturn bz_barf(const char *a1)
{
const char *v1; // rax
const char *v2; // rax

already_barfing = 1;
fwrite("\n**ERROR****************************************************************\n", 1uLL, 0x49uLL, stderr);
fprintf(stderr, "Program: %s\n", (const char *)prog_name);
fprintf(stderr, "Error: %s\n", a1);
v1 = (const char *)bz_barf_stack_top_isra_0(*(_QWORD *)(pfs + 8));
fprintf(stderr, "In: %s()\n", v1);
v2 = bz_barf_stack_show_constprop_0((const char **)pfs);
fprintf(stderr, "Trace: error%s\n", v2);
fwrite("***********************************************************************\n", 1uLL, 0x48uLL, stderr);
exit(0);
}


decompiled_code:
void __fastcall signal_handler(int a1)
{
if ( !already_barfing )
{
switch ( a1 )
{
case 2:
break;
case 4:
bz_barf("Illegal instruction");
case 7:
bz_barf("Bus error");
case 8:
bz_barf("Floating point exception");
case 11:
bz_barf("Segmentation violation");
case 15:
bz_barf("Terminated");
default:
return;
}
}
exit(1);
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
if ( !already_barfing )
{
switch ( a1 )
{
case 2:
break;
case 4:
func6("Illegal instruction");
case 7:
func6("Bus error");
case 8:
func6("Floating point exception");
case 11:
func6("Segmentation violation");
case 15:
func6("Terminated");
default:
return;
}
}
exit(1);
}

original_code:
static void signal_handler(int sig)
{
   if(already_barfing) {
      exit(1);
   }
   switch (sig)
   {
   case 15:
      bz_barf("Terminated");
      break;
   case 2:
      exit(1);
      break;
   case 7:
      bz_barf("Bus error");
      break;
   case 11:
      bz_barf("Segmentation violation");
      break;
   case 4:
      bz_barf("Illegal instruction");
      break;
   case 8:
      bz_barf("Floating point exception");
      break;
   }
}

variable_types: sig int


main

canonical_name: main

repo: sameenjalal/Linux-File-System

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
format_fs("ssjfs_disk", 800LL, envp);
open_fs("ssjfs_disk");
test_fs();
close_fs("ssjfs_disk");
return 0;
}

original_code:
int main(){
 format_fs("ssjfs_disk", 800);
 open_fs("ssjfs_disk");
 test_fs();
 close_fs("ssjfs_disk");
 return 0;
}

return_type: int


decompiled_code:
__int64 __fastcall file_open(char *src)
{
__int64 v1; // rbx
_DWORD *v2; // r12
char *v3; // rax
char *v4; // rax
__int64 v5; // rsi

v1 = (unsigned int)path_to_inumber();
printf("path_to_inumber returned %d\n", v1);
if ( (int)v1 <= 0 )
return 4294967293LL;
v2 = (_DWORD *)get_inode((unsigned int)v1);
printf("get_inode returned %p\n", v2);
if ( v2[3] )
return 4294967291LL;
v3 = (char *)malloc(0x6CuLL);
v4 = strcpy(v3, src);
v5 = open_files;
*((_DWORD *)v4 + 25) = v1;
*((_DWORD *)v4 + 26) = 0;
return arraylist_add(v4, v5);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *src)
{
__int64 v1; // rbx
_DWORD *v2; // r12
char *v3; // rax
char *v4; // rax
__int64 v5; // rsi

v1 = (unsigned int)path_to_inumber();
printf("path_to_inumber returned %d\n", v1);
if ( (int)v1 <= 0 )
return 4294967293LL;
v2 = (_DWORD *)get_inode((unsigned int)v1);
printf("get_inode returned %p\n", v2);
if ( v2[3] )
return 4294967291LL;
v3 = (char *)malloc(0x6CuLL);
v4 = strcpy(v3, src);
v5 = open_files;
*((_DWORD *)v4 + 25) = v1;
*((_DWORD *)v4 + 26) = 0;
return arraylist_add(v4, v5);
}

original_code:
int
file_open(char *path)
{
 int file_num;
    int inumber = path_to_inumber(path);
 printf("path_to_inumber returned %d\n", inumber);
 if ( inumber <= 0 )
        return -3;
 inode *in = get_inode(inumber);
 printf("get_inode returned %p\n", in);
 if ( in->directory_flag )
  return -5;
 file_info *new_file = (file_info *) malloc(sizeof(file_info));
 strcpy(new_file->filepath, path);
 new_file->inumber = inumber;
 new_file->cursor = 0;
 file_num = arraylist_add(new_file,open_files);
 return file_num;
}

canonical_original_code:
int file_open(char *path)
{
 int file_num;
    int inumber = path_to_inumber(path);
 printf("path_to_inumber returned %d\n", inumber);
 if ( inumber <= 0 )
        return -3;
 struct inode *in = get_inode(inumber);
 printf("get_inode returned %p\n", in);
 if ( in->directory_flag )
  return -5;
 struct file_info *new_file = (file_info *) malloc(sizeof(file_info));
 strcpy(new_file->filepath, path);
 new_file->inumber = inumber;
 new_file->cursor = 0;
 file_num = arraylist_add(new_file,open_files);
 return file_num;
}

variable_types:
path
char *

variable_types: inumber int

variable_types: struct inode { int next_free; int prev_free; int filesize; int directory_flag; int block_pointers[10]; int indirect_pointer; int double_indirect_pointer; } *

variable_types: struct file_info { char filepath[100]; int inumber; int cursor; } *


decompiled_code:
__int64 __fastcall file_close(__int64 a1)
{
return arraylist_delete(a1, open_files);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return arraylist_delete(a1, open_files);
}

original_code:
void
file_close(int file_number)
{
 if ( !arraylist_delete(file_number, open_files) )
  return;
}


decompiled_code:
__int64 __fastcall file_mkdir(__int64 a1)
{
return file_create_generic(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return file_create_generic(a1, 1LL);
}

original_code:
int file_mkdir(char *path)
{
 return file_create_generic(path, 1);
}


decompiled_code:
__int64 __fastcall file_rmdir(__int64 a1)
{
return file_delete_generic(a1, 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return file_delete_generic(a1, 1LL);
}

original_code:
int file_rmdir(char *path)
{
 return file_delete_generic(path, 1);
}


decompiled_code:
int file_printdir()
{
const char **v0; // rax
const char *v1; // rdx
const char **v2; // rbx

v0 = (const char **)file_listdir();
v1 = *v0;
if ( *v0 )
{
v2 = v0 + 1;
do
{
++v2;
LODWORD(v0) = fprintf(stdout, "%s\n", v1);
v1 = *(v2 - 1);
}
while ( v1 );
}
return (int)v0;
}

canonical_decompiled_code:
int func3()
{
const char **v0; // rax
const char *v1; // rdx
const char **v2; // rbx

v0 = (const char **)func2();
v1 = *v0;
if ( *v0 )
{
v2 = v0 + 1;
do
{
++v2;
LODWORD(v0) = fprintf(stdout, "%s\n", v1);
v1 = *(v2 - 1);
}
while ( v1 );
}
return (int)v0;
}

original_code:
void file_printdir(char *path)
{
 char **names;
 char *ptr;
 int i;
 names = file_listdir(path);
 for (i = 0; names[i] != ((void *)0); i++){
  fprintf(stdout, "%s\n", names[i]);
 }
}

variable_types:
names
char **

variable_types:
ptr
char *

variable_types: i int


original_code:
int arraylist_add(void * new_value, arraylist *list){
 void * *data_array;
 int size = list->size;
 int index;
 if (size == list->capacity){
  data_array = (void * *)malloc(sizeof(void *) * (size * 2));
  for (index = 0; index < size; index++){
   data_array[index] = list->data[index];
  }
  free(list->data);
  list->data = data_array;
  list->capacity = size * 2;
 }
 else{
  data_array = list->data;
 }
 data_array[size] = new_value;
 list->size++;
 return size;
}

canonical_original_code:
int arraylist_add(void *new_value, struct arraylist *list){
 void **data_array;
 int size = list->size;
 int index;
 if (size == list->capacity){
  data_array = (void **)malloc(sizeof(void *) * (size * 2));
  for (index = 0; index < size; index++){
   data_array[index] = list->data[index];
  }
  free(list->data);
  list->data = data_array;
  list->capacity = size * 2;
 }
 else{
  data_array = list->data;
 }
 data_array[size] = new_value;
 list->size++;
 return size;
}

variable_types: struct arraylist { void **data; int size; int capacity; } *

variable_types: size int

variable_types: index int


decompiled_code:
__int64 __fastcall arraylist_set(int a1, __int64 a2, __int64 a3)
{
if ( *(_DWORD *)(a3 + 8) <= a1 || a1 < 0 )
return 1LL;
*(_QWORD *)(*(_QWORD *)a3 + 8LL * a1) = a2;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, __int64 a2, __int64 a3)
{
if ( *(_DWORD *)(a3 + 8) <= a1 || a1 < 0 )
return 1LL;
*(_QWORD *)(*(_QWORD *)a3 + 8LL * a1) = a2;
return 0LL;
}

original_code:
int arraylist_set(int index, void * data, arraylist *list){
 if (index >= list->size || index < 0){
  return 1;
 }
 list->data[index] = data;
 return 0;
}

canonical_original_code:
int arraylist_set(int index, void *data, struct arraylist *list){
 if (index >= list->size || index < 0){
  return 1;
 }
 list->data[index] = data;
 return 0;
}

variable_types:
data
void *

user_defined_types: struct arraylist { void **data; int size; int capacity; }


decompiled_code:
__int64 __fastcall arraylist_delete(int a1, __int64 a2)
{
__int64 result; // rax
int v3; // edx
__int64 v4; // rax
unsigned __int64 v5; // rdi

result = 1LL;
if ( a1 >= 0 )
{
v3 = *(_DWORD *)(a2 + 8);
if ( v3 > a1 )
{
if ( a1 < v3 - 1 )
{
v4 = 8LL * a1 + 8;
v5 = 8 * (a1 + (unsigned __int64)(unsigned int)(v3 - 2 - a1) + 2);
do
{
*(_QWORD *)(*(_QWORD *)a2 + v4 - 8) = *(_QWORD *)(*(_QWORD *)a2 + v4);
v4 += 8LL;
}
while ( v4 != v5 );
}
*(_DWORD *)(a2 + 8) = v3 - 1;
result = 0LL;
}
}
return result;
}

original_code:
int arraylist_delete(int index, arraylist *list){
 int i;
 if (index < 0 || index >= list->size){
  return 1;
 }
 for (i = index; i < list->size - 1; i++){
  list->data[i] = list->data[i + 1];
 }
 list->size--;
 return 0;
}

canonical_original_code:
int arraylist_delete(int index, struct arraylist *list){
 int i;
 if (index < 0 || index >= list->size){
  return 1;
 }
 for (i = index; i < list->size - 1; i++){
  list->data[i] = list->data[i + 1];
 }
 list->size--;
 return 0;
}


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

if ( *(_DWORD *)(a2 + 8) <= a1 || a1 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a2 + 8LL * a1);
return result;
}

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

if ( *(_DWORD *)(a2 + 8) <= a1 || a1 < 0 )
result = 0LL;
else
result = *(_QWORD *)(*(_QWORD *)a2 + 8LL * a1);
return result;
}

original_code:
void * arraylist_get(int index, arraylist *list){
 void * ret;
 if (index >= list->size || index < 0){
  return ((void *)0);
 }
 ret = list->data[index];
 return ret;
}

canonical_original_code:
void *arraylist_get(int index, struct arraylist *list){
 void *ret;
 if (index >= list->size || index < 0){
  return ((void *)0);
 }
 ret = list->data[index];
 return ret;
}

variable_types:
ret
void *

return_type: void *


decompiled_code:
__int64 __fastcall arraylist_size(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(unsigned int *)(a1 + 8);
}

original_code:
int arraylist_size(arraylist *list){
 return list->size;
}

canonical_original_code:
int arraylist_size(struct arraylist *list){
 return list->size;
}


decompiled_code:
__int64 __fastcall arraylist_capacity(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
return *(unsigned int *)(a1 + 12);
}

original_code:
int arraylist_capacity(arraylist *list){
 return list->capacity;
}

canonical_original_code:
int arraylist_capacity(struct arraylist *list){
 return list->capacity;
}


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

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

original_code:
void arraylist_destroy(arraylist *list){
 free(list->data);
 free(list);
}

canonical_original_code:
void arraylist_destroy(struct arraylist *list){
 free(list->data);
 free(list);
}


decompiled_code:
__int64 __fastcall file_create(__int64 a1)
{
return file_create_generic(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return file_create_generic(a1, 0LL);
}

original_code:
int file_create(char *path)
{
 int st = file_create_generic(path, 0);
 return st;
}

variable_types: st int


decompiled_code:
__int64 __fastcall file_delete(__int64 a1)
{
return file_delete_generic(a1, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return file_delete_generic(a1, 0LL);
}

original_code:
int file_delete(char *path){
 return file_delete_generic(path, 0);
}


decompiled_code:
__int64 __fastcall open_fs(const char *a1)
{
__int64 result; // rax

fs_disk = open(a1, 2050);
if ( fs_disk )
{
open_files = arraylist_new(10LL);
printf("open_files list : %p\n", (const void *)open_files);
result = 0LL;
}
else
{
fwrite("Filesystem could not be opened!\n", 1uLL, 0x20uLL, stderr);
result = 1LL;
}
return result;
}

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

fs_disk = open(a1, 2050);
if ( fs_disk )
{
open_files = arraylist_new(10LL);
printf("open_files list : %p\n", (const void *)open_files);
result = 0LL;
}
else
{
fwrite("Filesystem could not be opened!\n", 1uLL, 0x20uLL, stderr);
result = 1LL;
}
return result;
}

original_code:
int
open_fs(char *fs_path)
{
    if ( (fs_disk = open(fs_path, 02 | 04000)) )
    {
        open_files = arraylist_new(10);
  printf("open_files list : %p\n", open_files);
        return 0;
    }
    else
    {
        fprintf(stderr, "Filesystem could not be opened!\n");
        return 1;
    }
}


decompiled_code:
int close_fs()
{
int result; // eax

arraylist_destroy(open_files);
result = close(fs_disk);
if ( result )
{
fwrite("Filesystem could not be closed!\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
int func1()
{
int result; // eax

arraylist_destroy(open_files);
result = close(fs_disk);
if ( result )
{
fwrite("Filesystem could not be closed!\n", 1uLL, 0x20uLL, stderr);
exit(1);
}
return result;
}

original_code:
void
close_fs()
{
    arraylist_destroy(open_files);
    int status = close(fs_disk);
    if ( status != 0 )
    {
        fprintf(stderr, "Filesystem could not be closed!\n");
        exit(1);
    }
}

variable_types: status int


decompiled_code:
__int64 __fastcall format_fs(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // ebp
int v4; // er14
void *v5; // r12
int v6; // eax
int v7; // ebx
unsigned int v8; // er15
int *v9; // rax
int v10; // edx
int *v11; // rbp
int v12; // eax
int v13; // ebx
int v14; // eax
__int64 v15; // rdi
unsigned int v16; // er13
__int64 v17; // rax
int v19[142]; // [rsp+0h] [rbp-238h] BYREF

v2 = open(a1, 66, 511LL);
fs_disk = v2;
if ( v2 == -1 )
{
fwrite("Filesystem could not be opened for creation!\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
v3 = v2;
v4 = 0;
v5 = malloc(0x200uLL);
strcpy((char *)v5, "ssjfs");
*((_DWORD *)v5 + 6) = a2;
*((_DWORD *)v5 + 7) = 0;
*((_DWORD *)v5 + 10) = 0;
v6 = a2 / 20 + 1;
*((_DWORD *)v5 + 8) = 8 * (a2 / 20);
*((_DWORD *)v5 + 9) = v6;
*((_DWORD *)v5 + 11) = v6;
mylseek(v3, 0LL, 0LL);
mywrite((unsigned int)fs_disk, v5, 1LL);
v7 = *((_DWORD *)v5 + 8);
if ( v7 > 0 )
{
do
{
v8 = v4++;
v9 = (int *)malloc(0x40uLL);
v10 = 0;
v11 = v9;
*((_QWORD *)v9 + 1) = 0LL;
v12 = v7 - 1;
if ( v7 - 1 != v8 )
v10 = v4;
*v11 = v10;
if ( v8 )
v12 = v8 - 1;
v11[1] = v12;
write_inode(v11, v8);
free(v11);
v7 = *((_DWORD *)v5 + 8);
}
while ( v7 > v4 );
}
v13 = *((_DWORD *)v5 + 9);
if ( v13 < *((_DWORD *)v5 + 6) )
{
do
{
mylseek((unsigned int)fs_disk, (unsigned int)v13, 0LL);
memset(v19, 0, 0x200uLL);
v14 = v13 - 1;
if ( *((_DWORD *)v5 + 9) == v13 )
v14 = *((_DWORD *)v5 + 6) - 1;
++v13;
v19[1] = v14;
v19[0] = v13;
mywrite((unsigned int)fs_disk, v19, 1LL);
}
while ( v13 < *((_DWORD *)v5 + 6) );
v13 = *((_DWORD *)v5 + 9);
}
do
{
v15 = (unsigned int)v13++;
load_free_block(v15);
}
while ( *((_DWORD *)v5 + 9) + 4 >= v13 );
mylseek((unsigned int)fs_disk, 0LL, 0LL);
mywrite((unsigned int)fs_disk, v5, 1LL);
v16 = get_new_inode();
if ( v16 )
{
v16 = -5;
fwrite("get_new_inode() didnt return 0 on the format call?", 1uLL, 0x32uLL, stderr);
}
else
{
v17 = get_inode(0LL);
*(_DWORD *)(v17 + 12) = 1;
write_inode(v17, 0LL);
free(v5);
close(fs_disk);
puts("Exiting formatfs");
}
return v16;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // ebp
int v4; // er14
void *v5; // r12
int v6; // eax
int v7; // ebx
unsigned int v8; // er15
int *v9; // rax
int v10; // edx
int *v11; // rbp
int v12; // eax
int v13; // ebx
int v14; // eax
__int64 v15; // rdi
unsigned int v16; // er13
__int64 v17; // rax
int v19[142]; // [rsp+0h] [rbp-238h] BYREF

v2 = open(a1, 66, 511LL);
fs_disk = v2;
if ( v2 == -1 )
{
fwrite("Filesystem could not be opened for creation!\n", 1uLL, 0x2DuLL, stderr);
exit(1);
}
v3 = v2;
v4 = 0;
v5 = malloc(0x200uLL);
strcpy((char *)v5, "ssjfs");
*((_DWORD *)v5 + 6) = a2;
*((_DWORD *)v5 + 7) = 0;
*((_DWORD *)v5 + 10) = 0;
v6 = a2 / 20 + 1;
*((_DWORD *)v5 + 8) = 8 * (a2 / 20);
*((_DWORD *)v5 + 9) = v6;
*((_DWORD *)v5 + 11) = v6;
mylseek(v3, 0LL, 0LL);
mywrite((unsigned int)fs_disk, v5, 1LL);
v7 = *((_DWORD *)v5 + 8);
if ( v7 > 0 )
{
do
{
v8 = v4++;
v9 = (int *)malloc(0x40uLL);
v10 = 0;
v11 = v9;
*((_QWORD *)v9 + 1) = 0LL;
v12 = v7 - 1;
if ( v7 - 1 != v8 )
v10 = v4;
*v11 = v10;
if ( v8 )
v12 = v8 - 1;
v11[1] = v12;
write_inode(v11, v8);
free(v11);
v7 = *((_DWORD *)v5 + 8);
}
while ( v7 > v4 );
}
v13 = *((_DWORD *)v5 + 9);
if ( v13 < *((_DWORD *)v5 + 6) )
{
do
{
mylseek((unsigned int)fs_disk, (unsigned int)v13, 0LL);
memset(v19, 0, 0x200uLL);
v14 = v13 - 1;
if ( *((_DWORD *)v5 + 9) == v13 )
v14 = *((_DWORD *)v5 + 6) - 1;
++v13;
v19[1] = v14;
v19[0] = v13;
mywrite((unsigned int)fs_disk, v19, 1LL);
}
while ( v13 < *((_DWORD *)v5 + 6) );
v13 = *((_DWORD *)v5 + 9);
}
do
{
v15 = (unsigned int)v13++;
load_free_block(v15);
}
while ( *((_DWORD *)v5 + 9) + 4 >= v13 );
mylseek((unsigned int)fs_disk, 0LL, 0LL);
mywrite((unsigned int)fs_disk, v5, 1LL);
v16 = get_new_inode();
if ( v16 )
{
v16 = -5;
fwrite("get_new_inode() didnt return 0 on the format call?", 1uLL, 0x32uLL, stderr);
}
else
{
v17 = get_inode(0LL);
*(_DWORD *)(v17 + 12) = 1;
write_inode(v17, 0LL);
free(v5);
close(fs_disk);
puts("Exiting formatfs");
}
return v16;
}

original_code:
int
format_fs(char *fs_path, int num_blocks)
{
 superblock *sb;
 inode *iptr;
 free_block *bptr;
 char buffer[512];
 int total_inode_blocks;
 int block_pointer, dbn;
 int i;
    fs_disk = open(fs_path, 02 | 0100, (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3));
 if (fs_disk == -1)
    {
        fprintf(stderr, "Filesystem could not be opened for creation!\n");
        exit(1);
    }
 sb = (superblock *)malloc(sizeof(superblock));
 strcpy(sb->fs_type, "ssjfs");
 sb->block_count = num_blocks;
 sb->current_files = 0;
 total_inode_blocks = num_blocks / 20;
 sb->max_files = total_inode_blocks * (512 / 64);
 sb->allocated_blocks = 1 + total_inode_blocks;
 sb->first_free_block = 1 + total_inode_blocks;
 sb->first_free_inode = 0;
 mylseek(fs_disk, 0, 0);
 mywrite(fs_disk, sb, 1);
 for (i = 0; i < sb->max_files; i++){
  iptr = (inode *)malloc(64);
  iptr->filesize = 0;
  iptr->directory_flag = 0;
  if (i == sb->max_files - 1) iptr->next_free = 0;
  else iptr->next_free = i + 1;
  if (i == 0) iptr->prev_free = sb->max_files - 1;
  else iptr->prev_free = i - 1;
  write_inode(iptr, i);
  free(iptr);
 }
 for (block_pointer = sb->allocated_blocks; block_pointer < sb->block_count; block_pointer++){
  bptr = (free_block *)buffer;
  mylseek(fs_disk, block_pointer, 0);
  memset(bptr, 0, 512);
  if (block_pointer == sb->allocated_blocks) bptr->prev_free = sb->block_count -1;
  else bptr->prev_free = block_pointer - 1 ;
  if (block_pointer == sb->block_count - 1) bptr->next_free = sb->allocated_blocks;
  bptr->next_free = block_pointer + 1;
  mywrite(fs_disk, bptr, 1);
 }
 for (block_pointer = sb->allocated_blocks; block_pointer < sb->allocated_blocks + 5; block_pointer++){
  bptr = load_free_block(block_pointer);
 }
 mylseek(fs_disk, 0, 0);
 mywrite(fs_disk, sb, 1);
 i = get_new_inode();
 if (i != 0){
  fprintf(stderr, "get_new_inode() didnt return 0 on the format call?");
  return -5;
 }
 iptr = get_inode(i);
 iptr->directory_flag = 1;
 write_inode(iptr, i);
 free(sb);
 close(fs_disk);
 printf("Exiting formatfs\n");
 return 0;
}

canonical_original_code:
int format_fs(char *fs_path, int num_blocks)
{
 struct superblock *sb;
 struct inode *iptr;
 struct free_block *bptr;
 char buffer[512];
 int total_inode_blocks;
 int block_pointer; int dbn;
 int i;
    fs_disk = open(fs_path, 02 | 0100, (0400|0200|0100) | ((0400|0200|0100) >> 3) | (((0400|0200|0100) >> 3) >> 3));
 if (fs_disk == -1)
    {
        fprintf(stderr, "Filesystem could not be opened for creation!\n");
        exit(1);
    }
 sb = (struct superblock *)malloc(sizeof(superblock));
 strcpy(sb->fs_type, "ssjfs");
 sb->block_count = num_blocks;
 sb->current_files = 0;
 total_inode_blocks = num_blocks / 20;
 sb->max_files = total_inode_blocks * (512 / 64);
 sb->allocated_blocks = 1 + total_inode_blocks;
 sb->first_free_block = 1 + total_inode_blocks;
 sb->first_free_inode = 0;
 mylseek(fs_disk, 0, 0);
 mywrite(fs_disk, sb, 1);
 for (i = 0; i < sb->max_files; i++){
  iptr = (struct inode *)malloc(64);
  iptr->filesize = 0;
  iptr->directory_flag = 0;
  if (i == sb->max_files - 1) iptr->next_free = 0;
  else iptr->next_free = i + 1;
  if (i == 0) iptr->prev_free = sb->max_files - 1;
  else iptr->prev_free = i - 1;
  write_inode(iptr, i);
  free(iptr);
 }
 for (block_pointer = sb->allocated_blocks; block_pointer < sb->block_count; block_pointer++){
  bptr = (struct free_block *)buffer;
  mylseek(fs_disk, block_pointer, 0);
  memset(bptr, 0, 512);
  if (block_pointer == sb->allocated_blocks) bptr->prev_free = sb->block_count -1;
  else bptr->prev_free = block_pointer - 1 ;
  if (block_pointer == sb->block_count - 1) bptr->next_free = sb->allocated_blocks;
  bptr->next_free = block_pointer + 1;
  mywrite(fs_disk, bptr, 1);
 }
 for (block_pointer = sb->allocated_blocks; block_pointer < sb->allocated_blocks + 5; block_pointer++){
  bptr = load_free_block(block_pointer);
 }
 mylseek(fs_disk, 0, 0);
 mywrite(fs_disk, sb, 1);
 i = get_new_inode();
 if (i != 0){
  fprintf(stderr, "get_new_inode() didnt return 0 on the format call?");
  return -5;
 }
 iptr = get_inode(i);
 iptr->directory_flag = 1;
 write_inode(iptr, i);
 free(sb);
 close(fs_disk);
 printf("Exiting formatfs\n");
 return 0;
}

variable_types: struct superblock { char fs_type[24]; int block_count; int current_files; int max_files; int allocated_blocks; int first_free_inode; int first_free_block; char padding[-1]; } *

variable_types: struct free_block { int next_free; int prev_free; char data[-1]; } *

variable_types:
buffer
char [512]

variable_types: dbn int

user_defined_types: struct inode { int next_free; int prev_free; int filesize; int directory_flag; int block_pointers[10]; int indirect_pointer; int double_indirect_pointer; }


repo: samgiles/C-Snippets

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax

v3 = mm_alloc(1LL, argv, envp);
mm_free(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax

v3 = func13(1LL, argv, envp);
func11(v3);
return 0;
}

original_code:
int main(int argc, char* argv[]) {
  MEM_BLOCK* mem = mm_alloc(sizeof(char));
  mm_free(mem);
}

canonical_original_code:
int main(int argc, char *argv[]) {
  struct mem_block *mem = mm_alloc(sizeof(char));
  mm_free(mem);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct mem_block { void *memory; unsigned long blocksize; } *


emalloc

decompiled_code:
void *__fastcall emalloc(size_t size)
{
void *result; // rax

result = malloc((unsigned int)size);
if ( !result )
{
fwrite("Out of memory!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func7(size_t size)
{
void *result; // rax

result = malloc((unsigned int)size);
if ( !result )
{
fwrite("Out of memory!\n", 1uLL, 0xFuLL, stderr);
exit(1);
}
return result;
}

original_code:
void *emalloc(unsigned size)
{
    void *p = malloc(size);
    if (p == ((void *)0)) {
        fprintf(stderr, "Out of memory!\n");
        exit(1);
    }
    return p;
}

canonical_original_code:
void *emalloc(unsigned int size)
{
    void *p = malloc(size);
    if (p == ((void *)0)) {
        fprintf(stderr, "Out of memory!\n");
        exit(1);
    }
    return p;
}

variable_types:
size
unsigned int

variable_types:
p
void *


decompiled_code:
_QWORD *create_storage_area()
{
_QWORD *v0; // rbx
_QWORD *result; // rax
void *v2; // rax
_DWORD *v3; // rdx

v0 = memory_manager;
if ( *(_QWORD *)memory_manager )
return increase_store_areas();
v2 = emalloc(0x20uLL);
v3 = memory_manager;
*v0 = v2;
result = *(_QWORD **)v3;
result[3] = v3;
*result = 0LL;
result[2] = 0LL;
v3[2] = 1;
return result;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // rbx
_QWORD *result; // rax
void *v2; // rax
_DWORD *v3; // rdx

v0 = memory_manager;
if ( *(_QWORD *)memory_manager )
return increase_store_areas();
v2 = func7(0x20uLL);
v3 = memory_manager;
*v0 = v2;
result = *(_QWORD **)v3;
result[3] = v3;
*result = 0LL;
result[2] = 0LL;
v3[2] = 1;
return result;
}

original_code:
STORE_AREA* create_storage_area() {
  if (memory_manager->areas == ((void *)0)) {
    memory_manager->areas = (STORE_AREA*)emalloc(sizeof(STORE_AREA));
    memory_manager->areas->prev.manager = memory_manager;
    memory_manager->areas->head = ((void *)0);
    memory_manager->areas->next = ((void *)0);
    memory_manager->area_count = 1;
    return memory_manager->areas;
  } else {
    return increase_store_areas();
  }
}

canonical_original_code:
struct storage_area *create_storage_area() {
  if (memory_manager->areas == ((void *)0)) {
    memory_manager->areas = (struct storage_area *)emalloc(sizeof(STORE_AREA));
    memory_manager->areas->prev.manager = memory_manager;
    memory_manager->areas->head = ((void *)0);
    memory_manager->areas->next = ((void *)0);
    memory_manager->area_count = 1;
    return memory_manager->areas;
  } else {
    return increase_store_areas();
  }
}

return_type: struct storage_area { struct storage_block { struct mem_block { void *memory; unsigned long blocksize; } *memory; unsigned int refcount; struct storage_block *next; } *head; unsigned int count; struct storage_area *next; union node { struct mem_manager { struct storage_area *areas; unsigned int area_count; } *manager; struct storage_area *area; } prev; } *

user_defined_types: struct storage_area { struct storage_block *head; unsigned int count; struct storage_area *next; union node prev; }

user_defined_types: union node { struct mem_manager *manager; struct storage_area *area; }

user_defined_types: struct storage_block { struct mem_block *memory; unsigned int refcount; struct storage_block *next; }


decompiled_code:
__int64 __fastcall remove_storage_area(_QWORD *a1)
{
_QWORD *v1; // rdx
__int64 v2; // rax

v1 = (_QWORD *)a1[3];
v2 = a1[2];
if ( !v1 )
{
MEMORY[0x10] = a1[2];
BUG();
}
*v1 = v2;
if ( v2 )
*(_QWORD *)(v2 + 24) = a1[3];
--*((_DWORD *)memory_manager + 2);
free(a1);
return 1LL;
}

original_code:
int remove_storage_area(STORE_AREA* area) {
    if (area->prev.manager == ((void *)0)) {
      area->prev.area->next = (area->next == ((void *)0))? ((void *)0) : area->next;
    } else {
      area->prev.manager->areas = (area->next == ((void *)0))? ((void *)0) : area->next;
    }
    if (area->next != ((void *)0)) {
       area->next->prev = area->prev;
    }
    memory_manager->area_count--;
    free(area);
    return 1;
}

canonical_original_code:
int remove_storage_area(struct storage_area *area) {
    if (area->prev.manager == ((void *)0)) {
      area->prev.area->next = (area->next == ((void *)0))? ((void *)0) : area->next;
    } else {
      area->prev.manager->areas = (area->next == ((void *)0))? ((void *)0) : area->next;
    }
    if (area->next != ((void *)0)) {
       area->next->prev = area->prev;
    }
    memory_manager->area_count--;
    free(area);
    return 1;
}

variable_types: struct storage_area { struct storage_block { struct mem_block { void *memory; unsigned long blocksize; } *memory; unsigned int refcount; struct storage_block *next; } *head; unsigned int count; struct storage_area *next; union node { struct mem_manager { struct storage_area *areas; unsigned int area_count; } *manager; struct storage_area *area; } prev; } *


decompiled_code:
void *create_storage_block()
{
return emalloc(0x18uLL);
}

canonical_decompiled_code:
void *func10()
{
return func7(0x18uLL);
}

original_code:
STORE_BLOCK* create_storage_block(STORE_AREA* store_area) {
  STORE_BLOCK* block = (STORE_BLOCK*)emalloc(sizeof(STORE_BLOCK));
  return block;
}

canonical_original_code:
struct storage_block *create_storage_block(struct storage_area *store_area) {
  struct storage_block *block = (STORE_BLOCK*)emalloc(sizeof(STORE_BLOCK));
  return block;
}

variable_types: struct storage_area { struct storage_block *head; unsigned int count; struct storage_area *next; union node { struct mem_manager { struct storage_area *areas; unsigned int area_count; } *manager; struct storage_area *area; } prev; } *

variable_types: struct storage_block { struct mem_block { void *memory; unsigned long blocksize; } *memory; unsigned int refcount; struct storage_block *next; } *


decompiled_code:
void mm_free()
{
free(memory_manager);
}

canonical_decompiled_code:
void func11()
{
free(memory_manager);
}

original_code:
void mm_free(MEM_BLOCK* block) {
   free(memory_manager);
}

canonical_original_code:
void mm_free(struct mem_block *block) {
   free(memory_manager);
}

user_defined_types: struct mem_block { void *memory; unsigned long blocksize; }


decompiled_code:
__int64 initialise_manager()
{
_DWORD *v1; // rax

if ( memory_manager )
return 0LL;
v1 = emalloc(0x10uLL);
memory_manager = v1;
v1[2] = 0;
*(_QWORD *)v1 = 0LL;
return 1LL;
}

canonical_decompiled_code:
__int64 func12()
{
_DWORD *v1; // rax

if ( memory_manager )
return 0LL;
v1 = func7(0x10uLL);
memory_manager = v1;
v1[2] = 0;
*(_QWORD *)v1 = 0LL;
return 1LL;
}

original_code:
int initialise_manager() {
  if (memory_manager == ((void *)0)) {
     memory_manager = (struct mem_manager*)emalloc(sizeof(struct mem_manager));
     memory_manager->area_count = 0;
     memory_manager->areas = ((void *)0);
     return 1;
  }
  return 0;
}

canonical_original_code:
int initialise_manager() {
  if (memory_manager == ((void *)0)) {
     memory_manager = (struct mem_manager *)emalloc(sizeof(struct mem_manager));
     memory_manager->area_count = 0;
     memory_manager->areas = ((void *)0);
     return 1;
  }
  return 0;
}

user_defined_types: struct mem_manager { struct storage_area *areas; unsigned int area_count; }


decompiled_code:
int mm_alloc()
{
__int64 v0; // rsi

initialise_manager();
v0 = *((unsigned int *)memory_manager + 2);
if ( !(_DWORD)v0 )
{
create_storage_area();
v0 = *((unsigned int *)memory_manager + 2);
}
return printf("Store Count: %d", v0);
}

canonical_decompiled_code:
int func13()
{
__int64 v0; // rsi

func12();
v0 = *((unsigned int *)memory_manager + 2);
if ( !(_DWORD)v0 )
{
func8();
v0 = *((unsigned int *)memory_manager + 2);
}
return printf("Store Count: %d", v0);
}

original_code:
MEM_BLOCK* mm_alloc(size_t size) {
  initialise_manager();
  STORE_AREA* area = ((void *)0);
  if (memory_manager->area_count == 0) {
    area = create_storage_area();
  }
  printf("Store Count: %d", memory_manager->area_count);
}

canonical_original_code:
struct mem_block *mm_alloc(unsigned long size) {
  initialise_manager();
  struct storage_area *area = ((void *)0);
  if (memory_manager->area_count == 0) {
    area = create_storage_area();
  }
  printf("Store Count: %d", memory_manager->area_count);
}

variable_types:
size
unsigned long

return_type: struct mem_block { void *memory; unsigned long blocksize; } *


decompiled_code:
__int64 __fastcall count_threes(__int64 a1, int a2)
{
int v2; // edx
unsigned int v3; // er8
_DWORD *v4; // rax
__int64 v5; // rcx
int v6; // edx

v2 = a2 - 1;
if ( !a2 )
return 0LL;
v3 = 0;
v4 = (_DWORD *)(a1 + 4LL * v2);
v5 = (__int64)&v4[-v2 - 1];
do
{
v6 = *v4-- == 3;
v3 += v6;
}
while ( v4 != (_DWORD *)v5 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, int a2)
{
int v2; // edx
unsigned int v3; // er8
_DWORD *v4; // rax
__int64 v5; // rcx
int v6; // edx

v2 = a2 - 1;
if ( !a2 )
return 0LL;
v3 = 0;
v4 = (_DWORD *)(a1 + 4LL * v2);
v5 = (__int64)&v4[-v2 - 1];
do
{
v6 = *v4-- == 3;
v3 += v6;
}
while ( v4 != (_DWORD *)v5 );
return v3;
}

original_code:
int count_threes(int* array, int length) {
        int count = 0;
        while(length--) {
                if (3 == array[length]) {
                        ++count;
                }
        }
        return count;
}

canonical_original_code:
int count_threes(int *array, int length) {
        int count = 0;
        while(length--) {
                if (3 == array[length]) {
                        ++count;
                }
        }
        return count;
}

variable_types:
array
int *

variable_types: length int

variable_types: count int


arrContainsStr

repo: samhorlbeck/ArgList

decompiled_code:
__int64 __fastcall arrContainsStr(const char **a1, const char *a2)
{
const char *v2; // rbx
const char *v3; // r12

v2 = *a1;
if ( !*a1 )
return 0LL;
v3 = v2 + 100;
while ( strcmp(v2, a2) )
{
if ( v3 == ++v2 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(const char **a1, const char *a2)
{
const char *v2; // rbx
const char *v3; // r12

v2 = *a1;
if ( !*a1 )
return 0LL;
v3 = v2 + 100;
while ( strcmp(v2, a2) )
{
if ( v3 == ++v2 )
return 0LL;
}
return 1LL;
}

original_code:
int arrContainsStr(char *arr[], char *str)
{
    char *curr = arr[0];
    int i;
    for(i = 0; curr && i < 100; curr++, i++)
    {
        if(strcmp(curr, str) == 0)
            return 1;
    }
    return 0;
}

variable_types:
arr
char *[]

variable_types:
str
char *

variable_types:
curr
char *

variable_types: i int


decompiled_code:
_BOOL8 __fastcall AL_Contains(__int64 ***a1, const char *a2)
{
return AL_NodeForKey(a1, a2) != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func3(__int64 ***a1, const char *a2)
{
return AL_NodeForKey(a1, a2) != 0LL;
}

original_code:
int AL_Contains(ArgList *lst, char *key)
{
    return AL_NodeForKey(lst, key) != ((void *)0);
}

canonical_original_code:
int AL_Contains(struct ArgList *lst, char *key)
{
    return AL_NodeForKey(lst, key) != ((void *)0);
}

variable_types: struct ArgList { struct ALChain { struct ALChain *next; struct node { char *value; struct node *next; } *list; char *key; } *head; } *

variable_types:
key
char *

user_defined_types: struct ArgList { struct ALChain *head; }

user_defined_types: struct ALChain { struct ALChain *next; struct node *list; char *key; }


decompiled_code:
__int64 __fastcall AL_ForEachValueWithKey(__int64 ***a1, const char *a2, __int64 (__fastcall *a3)(_QWORD))
{
__int64 **v4; // rax

v4 = AL_NodeForKey(a1, a2);
return AL_ForEachValueInNode(v4, a3);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 ***a1, const char *a2, __int64 (__fastcall *a3)(_QWORD))
{
__int64 **v4; // rax

v4 = AL_NodeForKey(a1, a2);
return func5(v4, a3);
}

original_code:
void AL_ForEachValueWithKey(ArgList *lst, char *key, ALSwitchFunction switchfunc)
{
    AL_ForEachValueInNode(AL_NodeForKey(lst, key), switchfunc);
}

canonical_original_code:
void AL_ForEachValueWithKey(struct ArgList *lst, char *key, void (*switchfunc)(char *value))
{
    AL_ForEachValueInNode(AL_NodeForKey(lst, key), switchfunc);
}

variable_types:
switchfunc
void (*)(char *value)

user_defined_types: struct node { char *value; struct node *next; }


repo: samirahmed/bogosort

canonical_decompiled_code:
void func0()
{
PROTO_DEBUG = 1;
}

original_code: static inline void proto_debug_on(void) { PROTO_DEBUG = 1; }

canonical_original_code: static inline void proto_debug_on() { PROTO_DEBUG = 1; }


canonical_decompiled_code:
void func1()
{
PROTO_DEBUG = 0;
}

original_code: static inline void proto_debug_off(void) { PROTO_DEBUG = 0; }

canonical_original_code: static inline void proto_debug_off() { PROTO_DEBUG = 0; }


decompiled_code:
__int64 proto_debug()
{
return PROTO_DEBUG;
}

canonical_decompiled_code:
__int64 func2()
{
return PROTO_DEBUG;
}

original_code: static inline int proto_debug(void) {return PROTO_DEBUG; }

canonical_original_code: static inline int proto_debug() {return PROTO_DEBUG; }


slog

decompiled_code:
int __fastcall slog(const char *a1, unsigned int *a2, unsigned int a3, unsigned int *a4, unsigned int *a5, int a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, long double a15, _QWORD *a16)
{
struct tm *v11; // rax
double v12; // xmm0_8
__int64 v13; // rax
__int64 v14; // r9
time_t timer; // [rsp+18h] [rbp-60h] BYREF
char s[88]; // [rsp+20h] [rbp-58h] BYREF

time(&timer);
v11 = localtime(&timer);
sprintf(timestr, "%.2d:%.2d:%.2d", (unsigned int)v11->tm_hour, (unsigned int)v11->tm_min, (unsigned int)v11->tm_sec);
if ( a6 < 0 )
sprintf(s, "\x1B[91m%d\x1B[0m", (unsigned int)a6);
else
sprintf(s, "\x1B[92m%d\x1B[0m", (unsigned int)a6);
v12 = (double)(tick() - a15) * 1000.0;
if ( a4 && a5 )
{
v13 = *a5;
v14 = *a4;
if ( a2 )
{
if ( a16 )
fprintf(
stdout,
"%s\t\x1B[33m%s\x1B[0m\t[%1d]\tfd:%05d\tteam:\x1B[34m%1d\x1B[0m\tid:\x1B[34m%03d\x1B[0m\trc:%s\t%.1fms\t[%lld]\n",
timestr,
a1,
*a2,
a3,
v14,
v13,
s,
v12,
*a16);
else
fprintf(
stdout,
"%s\t\x1B[33m%s\x1B[0m\t[%1d]\tfd:%05d\tteam:\x1B[34m%1d\x1B[0m\tid:\x1B[34m%03d\x1B[0m\trc:%s\t%.1fms\n",
timestr,
a1,
*a2,
a3,
v14,
v13,
s,
v12);
}
else if ( a16 )
{
fprintf(
stdout,
"%s\t\x1B[33m%s\x1B[0m\t\tfd:%05d\tteam:\x1B[34m%1d\x1B[0m\tid:\x1B[34m%03d\x1B[0m\trc:%s\t%.1fms\t[%lld]\n",
timestr,
a1,
a3,
v14,
v13,
s,
v12,
*a16);
}
else
{
fprintf(
stdout,
"%s\t\x1B[33m%s\x1B[0m\t\tfd:%05d\tteam:\x1B[34m%1d\x1B[0m\tid:\x1B[34m%03d\x1B[0m\trc:%s\t%.1fms\n",
timestr,
a1,
a3,
v14,
v13,
s,
v12);
}
}
else
{
fprintf(stdout, "%s\t\x1B[33m%s\x1B[0m\t\tfd:%05d\tteam:_\tid:___\trc:%s\t%.1fms\n", timestr, a1, a3, s, v12);
}
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func3(const char *a1, unsigned int *a2, unsigned int a3, unsigned int *a4, unsigned int *a5, int a6, double a7, double a8, double a9, double a10, double a11, double a12, double a13, double a14, long double a15, _QWORD *a16)
{
struct tm *v11; // rax
double v12; // xmm0_8
__int64 v13; // rax
__int64 v14; // r9
time_t timer; // [rsp+18h] [rbp-60h] BYREF
char s[88]; // [rsp+20h] [rbp-58h] BYREF

time(&timer);
v11 = localtime(&timer);
sprintf(timestr, "%.2d:%.2d:%.2d", (unsigned int)v11->tm_hour, (unsigned int)v11->tm_min, (unsigned int)v11->tm_sec);
if ( a6 < 0 )
sprintf(s, "\x1B[91m%d\x1B[0m", (unsigned int)a6);
else
sprintf(s, "\x1B[92m%d\x1B[0m", (unsigned int)a6);
v12 = (double)(tick() - a15) * 1000.0;
if ( a4 && a5 )
{
v13 = *a5;
v14 = *a4;
if ( a2 )
{
if ( a16 )
fprintf(
stdout,
"%s\t\x1B[33m%s\x1B[0m\t[%1d]\tfd:%05d\tteam:\x1B[34m%1d\x1B[0m\tid:\x1B[34m%03d\x1B[0m\trc:%s\t%.1fms\t[%lld]\n",
timestr,
a1,
*a2,
a3,
v14,
v13,
s,
v12,
*a16);
else
fprintf(
stdout,
"%s\t\x1B[33m%s\x1B[0m\t[%1d]\tfd:%05d\tteam:\x1B[34m%1d\x1B[0m\tid:\x1B[34m%03d\x1B[0m\trc:%s\t%.1fms\n",
timestr,
a1,
*a2,
a3,
v14,
v13,
s,
v12);
}
else if ( a16 )
{
fprintf(
stdout,
"%s\t\x1B[33m%s\x1B[0m\t\tfd:%05d\tteam:\x1B[34m%1d\x1B[0m\tid:\x1B[34m%03d\x1B[0m\trc:%s\t%.1fms\t[%lld]\n",
timestr,
a1,
a3,
v14,
v13,
s,
v12,
*a16);
}
else
{
fprintf(
stdout,
"%s\t\x1B[33m%s\x1B[0m\t\tfd:%05d\tteam:\x1B[34m%1d\x1B[0m\tid:\x1B[34m%03d\x1B[0m\trc:%s\t%.1fms\n",
timestr,
a1,
a3,
v14,
v13,
s,
v12);
}
}
else
{
fprintf(stdout, "%s\t\x1B[33m%s\x1B[0m\t\tfd:%05d\tteam:_\tid:___\trc:%s\t%.1fms\n", timestr, a1, a3, s, v12);
}
return fflush(stdout);
}

original_code:
void slog(char*cmd,int*action,int fd,int* team,int* id,int rc,long double start,long long* timestamp)
{
  time_t raw;
  double sec;
  struct tm * tt;
  char rcstr[25];
  time(&raw);
  tt = localtime(&raw);
  sprintf(timestr,"%.2d:%.2d:%.2d",tt->tm_hour,tt->tm_min,tt->tm_sec);
  if (rc >= 0)
    sprintf(rcstr,"\033[92m" "%d" "\033[0m" , rc);
  else
    sprintf(rcstr,"\033[91m" "%d" "\033[0m" , rc);
  long double stop = tick();
  sec = (double) (stop-start)*1000.0;
  if (team && id && action && timestamp)
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m"
    "\t[%1d]\tfd:%05d\tteam:"
    "\033[34m""%1d""\033[0m""\tid:"
    "\033[34m""%03d""\033[0m""\trc:%s\t%.1fms\t[%lld]\n",
   timestr,cmd,*action,fd,*team,*id,rcstr,sec,*timestamp);
  else if (team && id && action )
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m"
    "\t[%1d]\tfd:%05d\tteam:"
    "\033[34m""%1d""\033[0m""\tid:"
    "\033[34m""%03d""\033[0m""\trc:%s\t%.1fms\n",
   timestr,cmd,*action,fd,*team,*id,rcstr,sec);
  else if (team && id && timestamp)
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m"
    "\t\tfd:%05d\tteam:"
    "\033[34m""%1d""\033[0m""\tid:"
    "\033[34m""%03d""\033[0m""\trc:%s\t%.1fms\t[%lld]\n",
    timestr,cmd,fd,*team,*id,rcstr,sec,*timestamp);
  else if (team && id)
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m"
    "\t\tfd:%05d\tteam:"
    "\033[34m""%1d""\033[0m""\tid:"
    "\033[34m""%03d""\033[0m""\trc:%s\t%.1fms\n",
    timestr,cmd,fd,*team,*id,rcstr,sec);
  else
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m""\t\tfd:%05d\tteam:_\tid:___\trc:%s\t%.1fms\n",
    timestr,cmd,fd,rcstr,sec);
  fflush(stdout);
}

canonical_original_code:
void slog(char *cmd, int *action, int fd, int *team, int *id, int rc, long double start, long long *timestamp)
{
  long raw;
  double sec;
  struct tm *tt;
  char rcstr[25];
  time(&raw);
  tt = localtime(&raw);
  sprintf(timestr,"%.2d:%.2d:%.2d",tt->tm_hour,tt->tm_min,tt->tm_sec);
  if (rc >= 0)
    sprintf(rcstr,"\033[92m" "%d" "\033[0m" , rc);
  else
    sprintf(rcstr,"\033[91m" "%d" "\033[0m" , rc);
  long double stop = tick();
  sec = (double) (stop-start)*1000.0;
  if (team && id && action && timestamp)
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m"
    "\t[%1d]\tfd:%05d\tteam:"
    "\033[34m""%1d""\033[0m""\tid:"
    "\033[34m""%03d""\033[0m""\trc:%s\t%.1fms\t[%lld]\n",
   timestr,cmd,*action,fd,*team,*id,rcstr,sec,*timestamp);
  else if (team && id && action )
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m"
    "\t[%1d]\tfd:%05d\tteam:"
    "\033[34m""%1d""\033[0m""\tid:"
    "\033[34m""%03d""\033[0m""\trc:%s\t%.1fms\n",
   timestr,cmd,*action,fd,*team,*id,rcstr,sec);
  else if (team && id && timestamp)
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m"
    "\t\tfd:%05d\tteam:"
    "\033[34m""%1d""\033[0m""\tid:"
    "\033[34m""%03d""\033[0m""\trc:%s\t%.1fms\t[%lld]\n",
    timestr,cmd,fd,*team,*id,rcstr,sec,*timestamp);
  else if (team && id)
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m"
    "\t\tfd:%05d\tteam:"
    "\033[34m""%1d""\033[0m""\tid:"
    "\033[34m""%03d""\033[0m""\trc:%s\t%.1fms\n",
    timestr,cmd,fd,*team,*id,rcstr,sec);
  else
 fprintf(stdout,
    "%s\t""\033[33m""%s""\033[0m""\t\tfd:%05d\tteam:_\tid:___\trc:%s\t%.1fms\n",
    timestr,cmd,fd,rcstr,sec);
  fflush(stdout);
}

variable_types:
cmd
char *

variable_types:
action
int *

variable_types: fd int

variable_types:
team
int *

variable_types:
id
int *

variable_types: rc int

variable_types:
start
long double

variable_types:
timestamp
long long *

variable_types: raw long

variable_types: sec double

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
rcstr
char [25]

variable_types:
stop
long double


decompiled_code:
__int64 __fastcall sync_handler(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
__int64 v9; // rbp
unsigned int *v10; // r12
unsigned int *v11; // r13
unsigned int *v12; // r14
__int64 v13; // rsi
__int64 v14; // rbp
__int64 v15; // rsi
__int64 v16; // rbp
__int64 v17; // rsi
double v18; // xmm0_8
unsigned int v19; // eax
unsigned int v20; // er12
double v21; // xmm4_8
double v22; // xmm5_8
long double v24; // [rsp+0h] [rbp-88h]
int v25; // [rsp+14h] [rbp-74h] BYREF
int v26; // [rsp+18h] [rbp-70h] BYREF
int v27; // [rsp+1Ch] [rbp-6Ch] BYREF
unsigned int v28; // [rsp+20h] [rbp-68h] BYREF
unsigned int v29; // [rsp+24h] [rbp-64h] BYREF
unsigned int v30; // [rsp+28h] [rbp-60h] BYREF
unsigned int v31; // [rsp+2Ch] [rbp-5Ch] BYREF
__int128 v32; // [rsp+30h] [rbp-58h] BYREF
__int128 v33; // [rsp+40h] [rbp-48h]
__int128 v34; // [rsp+50h] [rbp-38h]

v9 = 0LL;
v24 = tick();
v32 = 0LL;
v33 = 0LL;
v34 = 0LL;
v10 = (unsigned int *)server_request_walls(&maze, &v27);
v11 = (unsigned int *)server_request_plist(&maze, 0LL, &v26);
v12 = (unsigned int *)server_request_plist(&maze, 1LL, &v25);
while ( v27 > (int)v9 )
{
v13 = v10[v9++];
put_int(a1, v13);
}
v14 = 0LL;
if ( v26 > 0 )
{
do
{
v15 = v11[v14++];
put_int(a1, v15);
}
while ( v26 > (int)v14 );
if ( v26 > 0 )
{
v16 = 0LL;
do
{
v17 = v12[v16++];
put_int(a1, v17);
}
while ( v26 > (int)v16 );
}
}
free(v10);
free(v11);
free(v12);
server_request_objects(&maze, &v28, &v31, &v29, &v30);
put_int(a1, v31);
put_int(a1, v30);
put_int(a1, v28);
put_int(a1, v29);
DWORD1(v32) = 10;
DWORD2(v33) = v27;
LODWORD(v34) = 0;
HIDWORD(v33) = v26 + v25;
put_hdr(a1, &v32);
v18 = reply(a1, 0LL, 0LL, 0LL);
v20 = v19;
slog("SYN", 0LL, *a1, 0LL, 0LL, 0, v18, a3, a4, a5, v21, v22, a8, a9, v24, 0LL);
return v20;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
__int64 v9; // rbp
unsigned int *v10; // r12
unsigned int *v11; // r13
unsigned int *v12; // r14
__int64 v13; // rsi
__int64 v14; // rbp
__int64 v15; // rsi
__int64 v16; // rbp
__int64 v17; // rsi
double v18; // xmm0_8
unsigned int v19; // eax
unsigned int v20; // er12
double v21; // xmm4_8
double v22; // xmm5_8
long double v24; // [rsp+0h] [rbp-88h]
int v25; // [rsp+14h] [rbp-74h] BYREF
int v26; // [rsp+18h] [rbp-70h] BYREF
int v27; // [rsp+1Ch] [rbp-6Ch] BYREF
unsigned int v28; // [rsp+20h] [rbp-68h] BYREF
unsigned int v29; // [rsp+24h] [rbp-64h] BYREF
unsigned int v30; // [rsp+28h] [rbp-60h] BYREF
unsigned int v31; // [rsp+2Ch] [rbp-5Ch] BYREF
__int128 v32; // [rsp+30h] [rbp-58h] BYREF
__int128 v33; // [rsp+40h] [rbp-48h]
__int128 v34; // [rsp+50h] [rbp-38h]

v9 = 0LL;
v24 = tick();
v32 = 0LL;
v33 = 0LL;
v34 = 0LL;
v10 = (unsigned int *)server_request_walls(&maze, &v27);
v11 = (unsigned int *)server_request_plist(&maze, 0LL, &v26);
v12 = (unsigned int *)server_request_plist(&maze, 1LL, &v25);
while ( v27 > (int)v9 )
{
v13 = v10[v9++];
put_int(a1, v13);
}
v14 = 0LL;
if ( v26 > 0 )
{
do
{
v15 = v11[v14++];
put_int(a1, v15);
}
while ( v26 > (int)v14 );
if ( v26 > 0 )
{
v16 = 0LL;
do
{
v17 = v12[v16++];
put_int(a1, v17);
}
while ( v26 > (int)v16 );
}
}
free(v10);
free(v11);
free(v12);
server_request_objects(&maze, &v28, &v31, &v29, &v30);
put_int(a1, v31);
put_int(a1, v30);
put_int(a1, v28);
put_int(a1, v29);
DWORD1(v32) = 10;
DWORD2(v33) = v27;
LODWORD(v34) = 0;
HIDWORD(v33) = v26 + v25;
put_hdr(a1, &v32);
v18 = reply(a1, 0LL, 0LL, 0LL);
v20 = v19;
func3("SYN", 0LL, *a1, 0LL, 0LL, 0, v18, a3, a4, a5, v21, v22, a8, a9, v24, 0LL);
return v20;
}

original_code:
int sync_handler( Proto_Session *s)
{
  long double clk = tick();
  Proto_Msg_Hdr h;
  bzero(&h, sizeof(Proto_Msg_Hdr));
  int *walls, *rlist, *blist, blen, rlen, wlen,
      rshovel, bshovel, bflag, rflag, rc,ii,rpc;
  rc = 0;
  walls = server_request_walls(&maze, &wlen);
  rlist = server_request_plist(&maze, TEAM_RED, &rlen);
  blist = server_request_plist(&maze, TEAM_BLUE, &blen);
  for (ii=0 ; ii<wlen ;ii++) put_int(s,walls[ii]);
  for (ii=0 ; ii<rlen ;ii++) put_int(s,rlist[ii]);
  for (ii=0 ; ii<rlen ;ii++) put_int(s,blist[ii]);
  free(walls);
  free(rlist);
  free(blist);
  server_request_objects(&maze,&rshovel,&rflag,&bshovel,&bflag);
  put_int(s,rflag);
  put_int(s,bflag);
  put_int(s,rshovel);
  put_int(s,bshovel);
  h.type = PROTO_MT_REP_SYNC;
  h.gstate.v0.raw = rc;
  h.pstate.v2.raw = wlen;
  h.pstate.v3.raw = rlen+blen;
  put_hdr(s,&h);
  rpc = reply(s,(size_t)((void *)0),(size_t)((void *)0),(size_t)((void *)0));
  slog("SYN",((void *)0),s->fd,((void *)0),((void *)0),0,clk,((void *)0));
  return rpc;
}

canonical_original_code:
int sync_handler(struct Proto_Session *s)
{
  long double clk = tick();
  struct Proto_Msg_Hdr h;
  bzero(&h, sizeof(Proto_Msg_Hdr));
  int *walls; int *rlist; int *blist; int blen; int rlen; int wlen; int rshovel; int bshovel; int bflag; int rflag; int rc; int ii; int rpc;
  rc = 0;
  walls = server_request_walls(&maze, &wlen);
  rlist = server_request_plist(&maze, TEAM_RED, &rlen);
  blist = server_request_plist(&maze, TEAM_BLUE, &blen);
  for (ii=0 ; ii<wlen ;ii++) put_int(s,walls[ii]);
  for (ii=0 ; ii<rlen ;ii++) put_int(s,rlist[ii]);
  for (ii=0 ; ii<rlen ;ii++) put_int(s,blist[ii]);
  free(walls);
  free(rlist);
  free(blist);
  server_request_objects(&maze,&rshovel,&rflag,&bshovel,&bflag);
  put_int(s,rflag);
  put_int(s,bflag);
  put_int(s,rshovel);
  put_int(s,bshovel);
  h.type = PROTO_MT_REP_SYNC;
  h.gstate.v0.raw = rc;
  h.pstate.v2.raw = wlen;
  h.pstate.v3.raw = rlen+blen;
  put_hdr(s,&h);
  rpc = reply(s,(unsigned long)((void *)0),(unsigned long)((void *)0),(unsigned long)((void *)0));
  slog("SYN",((void *)0),s->fd,((void *)0),((void *)0),0,clk,((void *)0));
  return rpc;
}

variable_types: struct Proto_Session { int fd; void *extra; int slen; int rlen; struct Proto_Msg_Hdr { int version; enum Proto_Msg_Types { PROTO_MT_REQ_BASE_RESERVED_FIRST=0, PROTO_MT_REQ_HELLO=1, PROTO_MT_REQ_GOODBYE=2, PROTO_MT_REQ_ACTION=3, PROTO_MT_REQ_SYNC=4, PROTO_MT_REQ_BASE_RESERVED_LAST=5, PROTO_MT_REP_BASE_RESERVED_FIRST=6, PROTO_MT_REP_HELLO=7, PROTO_MT_REP_GOODBYE=8, PROTO_MT_REP_ACTION=9, PROTO_MT_REP_SYNC=10, PROTO_MT_REP_BASE_RESERVED_LAST=11, PROTO_MT_EVENT_BASE_RESERVED_FIRST=12, PROTO_MT_EVENT_UPDATE=13, PROTO_MT_EVENT_BASE_RESERVED_LAST=14 } type; union Proto_StateVersion { unsigned long long raw; } sver; struct Proto_Player_State { union Proto_PV0 { int raw; } v0; union Proto_PV1 { int raw; } v1; union Proto_PV2 { int raw; } v2; union Proto_PV3 { int raw; } v3; } pstate; struct Proto_Game_State { union Proto_GV0 { int raw; } v0; union Proto_GV1 { int raw; } v1; union Proto_GV2 { int raw; } v2; } gstate; int blen; } shdr; struct Proto_Msg_Hdr rhdr; char sbuf[-1]; char rbuf[-1]; } *

variable_types:
clk
long double

variable_types:
walls
int *

variable_types:
rlist
int *

variable_types:
blist
int *

variable_types: blen int

variable_types: rlen int

variable_types: wlen int

variable_types: rshovel int

variable_types: bshovel int

variable_types: bflag int

variable_types: rflag int

variable_types: ii int

variable_types: rpc int

user_defined_types: struct Proto_Msg_Hdr { int version; enum Proto_Msg_Types type; union Proto_StateVersion sver; struct Proto_Player_State pstate; struct Proto_Game_State gstate; int blen; }

user_defined_types: struct Proto_Session { int fd; void *extra; int slen; int rlen; struct Proto_Msg_Hdr shdr; struct Proto_Msg_Hdr rhdr; char sbuf[-1]; char rbuf[-1]; }

user_defined_types: struct Proto_Player_State { union Proto_PV0 v0; union Proto_PV1 v1; union Proto_PV2 v2; union Proto_PV3 v3; }

user_defined_types: struct Proto_Game_State { union Proto_GV0 v0; union Proto_GV1 v1; union Proto_GV2 v2; }


doUpdateClients

decompiled_code:
__int64 __fastcall doUpdateClients(__int64 a1)
{
_QWORD *v1; // rbp
int v2; // ebx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
int v7; // [rsp+0h] [rbp-4Ch] BYREF
__int128 v8; // [rsp+4h] [rbp-48h] BYREF
__int128 v9; // [rsp+14h] [rbp-38h]
__int128 v10; // [rsp+24h] [rbp-28h]

v1 = (_QWORD *)(a1 + 216);
v2 = 0;
v3 = *(_QWORD *)(a1 + 208);
*(_QWORD *)&v8 = 0LL;
*((_QWORD *)&v8 + 1) = v3;
LODWORD(v3) = *(_DWORD *)(a1 + 204);
v10 = 0LL;
LODWORD(v10) = v3;
v4 = *(_QWORD *)(a1 + 192);
v9 = 0LL;
*(_QWORD *)((char *)&v10 + 4) = v4;
do
{
if ( *v1 )
{
compress_object(v1, &v7);
switch ( v2 )
{
case 2:
DWORD2(v9) = v7;
break;
case 3:
HIDWORD(v9) = v7;
break;
case 1:
DWORD1(v9) = v7;
break;
default:
LODWORD(v9) = v7;
break;
}
}
++v2;
v1 += 12;
}
while ( v2 != 4 );
v5 = proto_server_event_session();
DWORD1(v8) = 13;
proto_session_hdr_marshall(v5, &v8);
server_update_wait(&maze, *(_QWORD *)(a1 + 208));
proto_server_post_event();
server_update_signal(&maze, *(_QWORD *)(a1 + 208));
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_QWORD *v1; // rbp
int v2; // ebx
__int64 v3; // rax
__int64 v4; // rax
__int64 v5; // rax
int v7; // [rsp+0h] [rbp-4Ch] BYREF
__int128 v8; // [rsp+4h] [rbp-48h] BYREF
__int128 v9; // [rsp+14h] [rbp-38h]
__int128 v10; // [rsp+24h] [rbp-28h]

v1 = (_QWORD *)(a1 + 216);
v2 = 0;
v3 = *(_QWORD *)(a1 + 208);
*(_QWORD *)&v8 = 0LL;
*((_QWORD *)&v8 + 1) = v3;
LODWORD(v3) = *(_DWORD *)(a1 + 204);
v10 = 0LL;
LODWORD(v10) = v3;
v4 = *(_QWORD *)(a1 + 192);
v9 = 0LL;
*(_QWORD *)((char *)&v10 + 4) = v4;
do
{
if ( *v1 )
{
compress_object(v1, &v7);
switch ( v2 )
{
case 2:
DWORD2(v9) = v7;
break;
case 3:
HIDWORD(v9) = v7;
break;
case 1:
DWORD1(v9) = v7;
break;
default:
LODWORD(v9) = v7;
break;
}
}
++v2;
v1 += 12;
}
while ( v2 != 4 );
v5 = proto_server_event_session();
DWORD1(v8) = 13;
proto_session_hdr_marshall(v5, &v8);
server_update_wait(&maze, *(_QWORD *)(a1 + 208));
proto_server_post_event();
server_update_signal(&maze, *(_QWORD *)(a1 + 208));
return 1LL;
}

original_code:
int doUpdateClients(Update *update)
{
  Proto_Session *s;
  Proto_Msg_Hdr hdr;
  bzero(&hdr, sizeof(Proto_Msg_Hdr));
  hdr.sver.raw = update->timestamp;
  hdr.gstate.v0.raw = update->game_state_update;
  hdr.gstate.v1.raw = update->compress_player_a;
  hdr.gstate.v2.raw = update->compress_player_b;
  int ii;
  for(ii=0; ii<4; ii++)
  {
    Object*object = &update->objects[ii];
    if (object->cell)
    {
      int compress;
      compress_object(object, &compress);
      switch(ii)
      {
        case 0: hdr.pstate.v0.raw = compress; break;
        case 1: hdr.pstate.v1.raw = compress; break;
        case 2: hdr.pstate.v2.raw = compress; break;
        case 3: hdr.pstate.v3.raw = compress; break;
        default: break;
      }
    }
  }
  s = proto_server_event_session();
  hdr.type = PROTO_MT_EVENT_UPDATE;
  proto_session_hdr_marshall(s, &hdr);
  server_update_wait(&maze,update->timestamp);
  proto_server_post_event();
  server_update_signal(&maze,update->timestamp);
  return 1;
}

canonical_original_code:
int doUpdateClients(struct Update *update)
{
  struct Proto_Session *s;
  struct Proto_Msg_Hdr hdr;
  bzero(&hdr, sizeof(Proto_Msg_Hdr));
  hdr.sver.raw = update->timestamp;
  hdr.gstate.v0.raw = update->game_state_update;
  hdr.gstate.v1.raw = update->compress_player_a;
  hdr.gstate.v2.raw = update->compress_player_b;
  int ii;
  for(ii=0; ii<4; ii++)
  {
    struct Object *object = &update->objects[ii];
    if (object->cell)
    {
      int compress;
      compress_object(object, &compress);
      switch(ii)
      {
        case 0: hdr.pstate.v0.raw = compress; break;
        case 1: hdr.pstate.v1.raw = compress; break;
        case 2: hdr.pstate.v2.raw = compress; break;
        case 3: hdr.pstate.v3.raw = compress; break;
        default: break;
      }
    }
  }
  s = proto_server_event_session();
  hdr.type = PROTO_MT_EVENT_UPDATE;
  proto_session_hdr_marshall(s, &hdr);
  server_update_wait(&maze,update->timestamp);
  proto_server_post_event();
  server_update_signal(&maze,update->timestamp);
  return 1;
}

variable_types: struct Update { struct PlayerStruct { struct CellStruct { struct Pos { unsigned short x; unsigned short y; } pos; enum Cell_Types { CELL_WALL=0, CELL_FLOOR=1, CELL_JAIL=2, CELL_HOME=3 } type; enum Cell_State_Types { CELLSTATE_EMPTY=0, CELLSTATE_OCCUPIED=1, CELLSTATE_HOLDING=2, CELLSTATE_OCCUPIED_HOLDING=3 } cell_state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } turf; enum Mutable_Types { CELLTYPE_IMMUTABLE=0, CELLTYPE_MUTABLE=1 } is_mutable; struct PlayerStruct *player; struct Object { struct CellStruct *cell; struct PlayerStruct *player; enum Object_Types { OBJECT_FLAG=0, OBJECT_SHOVEL=1 } type; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; enum Visible_Types { OBJECT_VISIBLE=0, OBJECT_INVISIBLE=1 } visiblity; struct Pos client_position; int client_player_id; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } client_player_team; int client_has_player; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned int thread; } *object; union pthread_mutex_t lock; unsigned int thread; } *cell; struct Object *shovel; struct Object *flag; enum Player_State_Types { PLAYER_FREE=0, PLAYER_JAILED=1 } state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; unsigned short id; int fd; struct Pos client_position; union pthread_mutex_t lock; unsigned int thread; } player_a; struct PlayerStruct player_b; int compress_player_a; int compress_player_b; struct Pos broken_wall; int game_state_update; long long timestamp; struct Object objects[4]; } *

variable_types: struct Proto_Msg_Hdr { int version; enum Proto_Msg_Types { PROTO_MT_REQ_BASE_RESERVED_FIRST=0, PROTO_MT_REQ_HELLO=1, PROTO_MT_REQ_GOODBYE=2, PROTO_MT_REQ_ACTION=3, PROTO_MT_REQ_SYNC=4, PROTO_MT_REQ_BASE_RESERVED_LAST=5, PROTO_MT_REP_BASE_RESERVED_FIRST=6, PROTO_MT_REP_HELLO=7, PROTO_MT_REP_GOODBYE=8, PROTO_MT_REP_ACTION=9, PROTO_MT_REP_SYNC=10, PROTO_MT_REP_BASE_RESERVED_LAST=11, PROTO_MT_EVENT_BASE_RESERVED_FIRST=12, PROTO_MT_EVENT_UPDATE=13, PROTO_MT_EVENT_BASE_RESERVED_LAST=14 } type; union Proto_StateVersion { unsigned long long raw; } sver; struct Proto_Player_State { union Proto_PV0 { int raw; } v0; union Proto_PV1 { int raw; } v1; union Proto_PV2 { int raw; } v2; union Proto_PV3 { int raw; } v3; } pstate; struct Proto_Game_State { union Proto_GV0 { int raw; } v0; union Proto_GV1 { int raw; } v1; union Proto_GV2 { int raw; } v2; } gstate; int blen; }

variable_types: struct Object { struct CellStruct { struct Pos { unsigned short x; unsigned short y; } pos; enum Cell_Types { CELL_WALL=0, CELL_FLOOR=1, CELL_JAIL=2, CELL_HOME=3 } type; enum Cell_State_Types { CELLSTATE_EMPTY=0, CELLSTATE_OCCUPIED=1, CELLSTATE_HOLDING=2, CELLSTATE_OCCUPIED_HOLDING=3 } cell_state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } turf; enum Mutable_Types { CELLTYPE_IMMUTABLE=0, CELLTYPE_MUTABLE=1 } is_mutable; struct PlayerStruct { struct CellStruct *cell; struct Object *shovel; struct Object *flag; enum Player_State_Types { PLAYER_FREE=0, PLAYER_JAILED=1 } state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; unsigned short id; int fd; struct Pos client_position; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned int thread; } *player; struct Object *object; union pthread_mutex_t lock; unsigned int thread; } *cell; struct PlayerStruct *player; enum Object_Types { OBJECT_FLAG=0, OBJECT_SHOVEL=1 } type; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; enum Visible_Types { OBJECT_VISIBLE=0, OBJECT_INVISIBLE=1 } visiblity; struct Pos client_position; int client_player_id; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } client_player_team; int client_has_player; union pthread_mutex_t lock; unsigned int thread; } *

variable_types: compress int

user_defined_types: struct Update { struct PlayerStruct player_a; struct PlayerStruct player_b; int compress_player_a; int compress_player_b; struct Pos broken_wall; int game_state_update; long long timestamp; struct Object objects[4]; }

user_defined_types: struct Object { struct CellStruct *cell; struct PlayerStruct *player; enum Object_Types type; enum Team_Types team; enum Visible_Types visiblity; struct Pos client_position; int client_player_id; enum Team_Types client_player_team; int client_has_player; union pthread_mutex_t lock; unsigned int thread; }

user_defined_types: struct PlayerStruct { struct CellStruct *cell; struct Object *shovel; struct Object *flag; enum Player_State_Types state; enum Team_Types team; unsigned short id; int fd; struct Pos client_position; union pthread_mutex_t lock; unsigned int thread; }

user_defined_types: struct CellStruct { struct Pos pos; enum Cell_Types type; enum Cell_State_Types cell_state; enum Team_Types turf; enum Mutable_Types is_mutable; struct PlayerStruct *player; struct Object *object; union pthread_mutex_t lock; unsigned int thread; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall client_lost_handler(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
long double v9; // fst7
unsigned int v10; // er13
double v11; // xmm4_8
double v12; // xmm5_8
double v13; // xmm4_8
double v14; // xmm5_8
unsigned int v16; // [rsp+18h] [rbp-280h] BYREF
unsigned int v17; // [rsp+1Ch] [rbp-27Ch] BYREF
_QWORD v18[79]; // [rsp+20h] [rbp-278h] BYREF

v9 = tick();
v10 = *a1;
if ( (int)server_fd_to_id_and_team(&maze, *a1, &v17, &v16) < 0 )
{
slog("DIS", 0LL, v10, 0LL, 0LL, 0, a2, a3, a4, a5, v11, v12, a8, a9, v9, 0LL);
}
else
{
memset(v18, 0, 0x258uLL);
server_game_drop_player(&maze, v17, v16, v18);
if ( (unsigned int)proto_debug() )
proto_session_dump(a1);
doUpdateClients((__int64)v18);
slog("DRP", 0LL, v10, &v17, &v16, 0, a2, a3, a4, a5, v13, v14, a8, a9, v9, &v18[26]);
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
long double v9; // fst7
unsigned int v10; // er13
double v11; // xmm4_8
double v12; // xmm5_8
double v13; // xmm4_8
double v14; // xmm5_8
unsigned int v16; // [rsp+18h] [rbp-280h] BYREF
unsigned int v17; // [rsp+1Ch] [rbp-27Ch] BYREF
_QWORD v18[79]; // [rsp+20h] [rbp-278h] BYREF

v9 = tick();
v10 = *a1;
if ( (int)server_fd_to_id_and_team(&maze, *a1, &v17, &v16) < 0 )
{
func3("DIS", 0LL, v10, 0LL, 0LL, 0, a2, a3, a4, a5, v11, v12, a8, a9, v9, 0LL);
}
else
{
memset(v18, 0, 0x258uLL);
server_game_drop_player(&maze, v17, v16, v18);
if ( (unsigned int)func2() )
proto_session_dump(a1);
func5((__int64)v18);
func3("DRP", 0LL, v10, &v17, &v16, 0, a2, a3, a4, a5, v13, v14, a8, a9, v9, &v18[26]);
}
return 0xFFFFFFFFLL;
}

original_code:
int client_lost_handler( Proto_Session * s)
{
  int id,team,rc,fd;
  long double clk = tick();
  fd = (int)s->fd;
  rc =server_fd_to_id_and_team(&maze,fd,&team,&id);
  if (rc <0)
  {
    slog("DIS",((void *)0),fd,((void *)0),((void *)0),0,clk,((void *)0));
    return -1;
  }
  Update update;
  bzero(&update,sizeof(Update));
  server_game_drop_player(&maze, team, id, &update);
  if (proto_debug()) proto_session_dump(s);
  doUpdateClients(&update);
  slog("DRP",((void *)0),fd,&team,&id,0,clk,&update.timestamp);
  return -1;
}

canonical_original_code:
int client_lost_handler(struct Proto_Session *s)
{
  int id; int team; int rc; int fd;
  long double clk = tick();
  fd = (int)s->fd;
  rc =server_fd_to_id_and_team(&maze,fd,&team,&id);
  if (rc <0)
  {
    slog("DIS",((void *)0),fd,((void *)0),((void *)0),0,clk,((void *)0));
    return -1;
  }
  struct Update update;
  bzero(&update,sizeof(Update));
  server_game_drop_player(&maze, team, id, &update);
  if (proto_debug()) proto_session_dump(s);
  doUpdateClients(&update);
  slog("DRP",((void *)0),fd,&team,&id,0,clk,&update.timestamp);
  return -1;
}

variable_types: struct Proto_Session { int fd; void *extra; int slen; int rlen; struct Proto_Msg_Hdr { int version; enum Proto_Msg_Types { PROTO_MT_REQ_BASE_RESERVED_FIRST=0, PROTO_MT_REQ_HELLO=1, PROTO_MT_REQ_GOODBYE=2, PROTO_MT_REQ_ACTION=3, PROTO_MT_REQ_SYNC=4, PROTO_MT_REQ_BASE_RESERVED_LAST=5, PROTO_MT_REP_BASE_RESERVED_FIRST=6, PROTO_MT_REP_HELLO=7, PROTO_MT_REP_GOODBYE=8, PROTO_MT_REP_ACTION=9, PROTO_MT_REP_SYNC=10, PROTO_MT_REP_BASE_RESERVED_LAST=11, PROTO_MT_EVENT_BASE_RESERVED_FIRST=12, PROTO_MT_EVENT_UPDATE=13, PROTO_MT_EVENT_BASE_RESERVED_LAST=14 } type; union Proto_StateVersion { unsigned long long raw; } sver; struct Proto_Player_State { union Proto_PV0 { int raw; } v0; union Proto_PV1 { int raw; } v1; union Proto_PV2 { int raw; } v2; union Proto_PV3 { int raw; } v3; } pstate; struct Proto_Game_State { union Proto_GV0 { int raw; } v0; union Proto_GV1 { int raw; } v1; union Proto_GV2 { int raw; } v2; } gstate; int blen; } shdr; struct Proto_Msg_Hdr rhdr; char sbuf[-1]; char rbuf[-1]; } *

variable_types: id int

variable_types: team int

variable_types: rc int

variable_types: fd int

variable_types:
clk
long double

variable_types: struct Update { struct PlayerStruct { struct CellStruct { struct Pos { unsigned short x; unsigned short y; } pos; enum Cell_Types { CELL_WALL=0, CELL_FLOOR=1, CELL_JAIL=2, CELL_HOME=3 } type; enum Cell_State_Types { CELLSTATE_EMPTY=0, CELLSTATE_OCCUPIED=1, CELLSTATE_HOLDING=2, CELLSTATE_OCCUPIED_HOLDING=3 } cell_state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } turf; enum Mutable_Types { CELLTYPE_IMMUTABLE=0, CELLTYPE_MUTABLE=1 } is_mutable; struct PlayerStruct *player; struct Object { struct CellStruct *cell; struct PlayerStruct *player; enum Object_Types { OBJECT_FLAG=0, OBJECT_SHOVEL=1 } type; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; enum Visible_Types { OBJECT_VISIBLE=0, OBJECT_INVISIBLE=1 } visiblity; struct Pos client_position; int client_player_id; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } client_player_team; int client_has_player; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned int thread; } *object; union pthread_mutex_t lock; unsigned int thread; } *cell; struct Object *shovel; struct Object *flag; enum Player_State_Types { PLAYER_FREE=0, PLAYER_JAILED=1 } state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; unsigned short id; int fd; struct Pos client_position; union pthread_mutex_t lock; unsigned int thread; } player_a; struct PlayerStruct player_b; int compress_player_a; int compress_player_b; struct Pos broken_wall; int game_state_update; long long timestamp; struct Object objects[4]; }


decompiled_code:
__int64 __fastcall goodbye_handler(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
client_lost_handler(a1, a2, a3, a4, a5, a6, a7, a8, a9);
reply(a1, 8LL, 0LL, 0LL);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
func6(a1, a2, a3, a4, a5, a6, a7, a8, a9);
reply(a1, 8LL, 0LL, 0LL);
return 0xFFFFFFFFLL;
}

original_code:
int goodbye_handler( Proto_Session *s)
{
  client_lost_handler(s);
  reply(s,PROTO_MT_REP_GOODBYE,0,(size_t)((void *)0));
  return -1;
}

canonical_original_code:
int goodbye_handler(struct Proto_Session *s)
{
  client_lost_handler(s);
  reply(s,PROTO_MT_REP_GOODBYE,0,(unsigned long)((void *)0));
  return -1;
}

user_defined_types: enum Proto_Msg_Types { PROTO_MT_REQ_BASE_RESERVED_FIRST=0, PROTO_MT_REQ_HELLO=1, PROTO_MT_REQ_GOODBYE=2, PROTO_MT_REQ_ACTION=3, PROTO_MT_REQ_SYNC=4, PROTO_MT_REQ_BASE_RESERVED_LAST=5, PROTO_MT_REP_BASE_RESERVED_FIRST=6, PROTO_MT_REP_HELLO=7, PROTO_MT_REP_GOODBYE=8, PROTO_MT_REP_ACTION=9, PROTO_MT_REP_SYNC=10, PROTO_MT_REP_BASE_RESERVED_LAST=11, PROTO_MT_EVENT_BASE_RESERVED_FIRST=12, PROTO_MT_EVENT_UPDATE=13, PROTO_MT_EVENT_BASE_RESERVED_LAST=14 }

user_defined_types: union Proto_StateVersion { unsigned long long raw; }


decompiled_code:
__int64 __fastcall hello_handler(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
long double v9; // fst7
__int64 v10; // rsi
int v11; // eax
int v12; // ebp
unsigned int v13; // edx
unsigned int v14; // eax
double v15; // xmm0_8
unsigned int v16; // eax
unsigned int v17; // er12
double v18; // xmm4_8
double v19; // xmm5_8
double v21; // xmm0_8
unsigned int v22; // eax
double v23; // xmm4_8
double v24; // xmm5_8
__int64 v25; // [rsp+18h] [rbp-2B0h] BYREF
__int128 v26; // [rsp+20h] [rbp-2A8h] BYREF
__int128 v27; // [rsp+30h] [rbp-298h]
__int128 v28; // [rsp+40h] [rbp-288h]
_QWORD v29[79]; // [rsp+50h] [rbp-278h] BYREF

v9 = tick();
v10 = *a1;
memset(v29, 0, 0x258uLL);
v11 = server_game_add_player(&maze, v10, &v25, v29);
v12 = v11;
if ( v11 < 0 )
{
v21 = reply(a1, 7LL, (unsigned int)v11, 0LL);
v17 = v22;
slog(
"HEL",
0LL,
*a1,
(unsigned int *)(v25 + 28),
(unsigned int *)(v25 + 32),
v12,
v21,
a3,
a4,
a5,
v23,
v24,
a8,
a9,
v9,
0LL);
}
else
{
v27 = 0LL;
v26 = 0LL;
v28 = 0LL;
v13 = *(unsigned __int16 *)(v25 + 32);
v14 = *(_DWORD *)(v25 + 28);
DWORD1(v26) = 7;
*(_QWORD *)&v27 = __PAIR64__(v14, v13);
LODWORD(v28) = v12;
put_hdr(a1, &v26);
doUpdateClients((__int64)v29);
v15 = reply(a1, 0LL, 0LL, 0LL);
v17 = v16;
slog(
"HEL",
0LL,
*a1,
(unsigned int *)(v25 + 28),
(unsigned int *)(v25 + 32),
v12,
v15,
a3,
a4,
a5,
v18,
v19,
a8,
a9,
v9,
&v29[26]);
}
return v17;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
long double v9; // fst7
__int64 v10; // rsi
int v11; // eax
int v12; // ebp
unsigned int v13; // edx
unsigned int v14; // eax
double v15; // xmm0_8
unsigned int v16; // eax
unsigned int v17; // er12
double v18; // xmm4_8
double v19; // xmm5_8
double v21; // xmm0_8
unsigned int v22; // eax
double v23; // xmm4_8
double v24; // xmm5_8
__int64 v25; // [rsp+18h] [rbp-2B0h] BYREF
__int128 v26; // [rsp+20h] [rbp-2A8h] BYREF
__int128 v27; // [rsp+30h] [rbp-298h]
__int128 v28; // [rsp+40h] [rbp-288h]
_QWORD v29[79]; // [rsp+50h] [rbp-278h] BYREF

v9 = tick();
v10 = *a1;
memset(v29, 0, 0x258uLL);
v11 = server_game_add_player(&maze, v10, &v25, v29);
v12 = v11;
if ( v11 < 0 )
{
v21 = reply(a1, 7LL, (unsigned int)v11, 0LL);
v17 = v22;
func3(
"HEL",
0LL,
*a1,
(unsigned int *)(v25 + 28),
(unsigned int *)(v25 + 32),
v12,
v21,
a3,
a4,
a5,
v23,
v24,
a8,
a9,
v9,
0LL);
}
else
{
v27 = 0LL;
v26 = 0LL;
v28 = 0LL;
v13 = *(unsigned __int16 *)(v25 + 32);
v14 = *(_DWORD *)(v25 + 28);
DWORD1(v26) = 7;
*(_QWORD *)&v27 = __PAIR64__(v14, v13);
LODWORD(v28) = v12;
put_hdr(a1, &v26);
func5((__int64)v29);
v15 = reply(a1, 0LL, 0LL, 0LL);
v17 = v16;
func3(
"HEL",
0LL,
*a1,
(unsigned int *)(v25 + 28),
(unsigned int *)(v25 + 32),
v12,
v15,
a3,
a4,
a5,
v18,
v19,
a8,
a9,
v9,
&v29[26]);
}
return v17;
}

original_code:
int hello_handler( Proto_Session *s)
{
  int rc,rpc;
  long double clk = tick();
  Player*player;
  Update update;
  bzero(&update,sizeof(Update));
  rc = server_game_add_player(&maze,s->fd,&player,&update);
  if(rc<0)
  {
    rpc = reply(s,PROTO_MT_REP_HELLO,rc,(size_t)((void *)0));
   slog("HEL",((void *)0),s->fd,(int*)&player->team,(int*)&player->id,rc,clk,((void *)0));
    return rpc;
  }
  Proto_Msg_Hdr h;
  bzero(&h, sizeof(Proto_Msg_Hdr));
  h.type = PROTO_MT_REP_HELLO;
  h.pstate.v0.raw = player->id;
  h.pstate.v1.raw = player->team;
  h.gstate.v0.raw = rc;
  put_hdr(s,&h);
  doUpdateClients(&update);
  rpc= reply(s,(size_t)((void *)0),(size_t)((void *)0),(size_t)((void *)0));
 slog("HEL",((void *)0),s->fd,(int*)&player->team,(int*)&player->id,rc,clk,&update.timestamp);
  return rpc;
}

canonical_original_code:
int hello_handler(struct Proto_Session *s)
{
  int rc; int rpc;
  long double clk = tick();
  struct PlayerStruct *player;
  struct Update update;
  bzero(&update,sizeof(Update));
  rc = server_game_add_player(&maze,s->fd,&player,&update);
  if(rc<0)
  {
    rpc = reply(s,PROTO_MT_REP_HELLO,rc,(unsigned long)((void *)0));
   slog("HEL",((void *)0),s->fd,(int *)&player->team,(int *)&player->id,rc,clk,((void *)0));
    return rpc;
  }
  struct Proto_Msg_Hdr h;
  bzero(&h, sizeof(Proto_Msg_Hdr));
  h.type = PROTO_MT_REP_HELLO;
  h.pstate.v0.raw = player->id;
  h.pstate.v1.raw = player->team;
  h.gstate.v0.raw = rc;
  put_hdr(s,&h);
  doUpdateClients(&update);
  rpc= reply(s,(unsigned long)((void *)0),(unsigned long)((void *)0),(unsigned long)((void *)0));
 slog("HEL",((void *)0),s->fd,(int *)&player->team,(int *)&player->id,rc,clk,&update.timestamp);
  return rpc;
}

variable_types: struct PlayerStruct { struct CellStruct { struct Pos { unsigned short x; unsigned short y; } pos; enum Cell_Types { CELL_WALL=0, CELL_FLOOR=1, CELL_JAIL=2, CELL_HOME=3 } type; enum Cell_State_Types { CELLSTATE_EMPTY=0, CELLSTATE_OCCUPIED=1, CELLSTATE_HOLDING=2, CELLSTATE_OCCUPIED_HOLDING=3 } cell_state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } turf; enum Mutable_Types { CELLTYPE_IMMUTABLE=0, CELLTYPE_MUTABLE=1 } is_mutable; struct PlayerStruct *player; struct Object { struct CellStruct *cell; struct PlayerStruct *player; enum Object_Types { OBJECT_FLAG=0, OBJECT_SHOVEL=1 } type; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; enum Visible_Types { OBJECT_VISIBLE=0, OBJECT_INVISIBLE=1 } visiblity; struct Pos client_position; int client_player_id; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } client_player_team; int client_has_player; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned int thread; } *object; union pthread_mutex_t lock; unsigned int thread; } *cell; struct Object *shovel; struct Object *flag; enum Player_State_Types { PLAYER_FREE=0, PLAYER_JAILED=1 } state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; unsigned short id; int fd; struct Pos client_position; union pthread_mutex_t lock; unsigned int thread; } *


decompiled_code:
__int64 __fastcall action_handler(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
long double v9; // fst7
unsigned int v10; // er12
int v11; // ebx
double v12; // xmm0_8
unsigned int v13; // eax
unsigned int v14; // er13
double v15; // xmm4_8
double v16; // xmm5_8
double v18; // xmm0_8
unsigned int v19; // eax
double v20; // xmm4_8
double v21; // xmm5_8
__int64 v22; // [rsp+1Ch] [rbp-2DCh] BYREF
unsigned int v23; // [rsp+24h] [rbp-2D4h] BYREF
char v24[4]; // [rsp+28h] [rbp-2D0h] BYREF
__int16 v25[2]; // [rsp+2Ch] [rbp-2CCh] BYREF
__int128 v26; // [rsp+30h] [rbp-2C8h] BYREF
__int128 v27; // [rsp+40h] [rbp-2B8h]
__int128 v28; // [rsp+50h] [rbp-2A8h]
char v29[20]; // [rsp+60h] [rbp-298h] BYREF
int v30; // [rsp+74h] [rbp-284h]
char v31[208]; // [rsp+78h] [rbp-280h] BYREF
__int64 v32[54]; // [rsp+148h] [rbp-1B0h] BYREF

v9 = tick();
v10 = *a1;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
proto_session_hdr_unmarshall(a1, &v26);
v23 = DWORD1(v28);
v22 = v27;
if ( (unsigned int)proto_debug() )
fprintf(stderr, "len %d\n", HIDWORD(v28));
proto_session_body_unmarshall_bytes(a1, 0LL, 4LL, v24);
proto_session_body_unmarshall_bytes(a1, 4LL, 4LL, v25);
v11 = server_request_init(&maze, v29, v10, v23, (unsigned __int16)v25[0], (unsigned __int16)v25[1]);
v30 = teleport;
if ( v11 < 0 || (v11 = server_game_action(&maze, v29), v11 < 0) )
{
v18 = reply(a1, 9LL, (unsigned int)v11, 0xFFFFFFFFLL);
v14 = v19;
slog(
"ACT",
&v23,
v10,
(unsigned int *)&v22 + 1,
(unsigned int *)&v22,
v11,
v18,
a3,
a4,
a5,
v20,
v21,
a8,
a9,
v9,
0LL);
}
else
{
doUpdateClients((__int64)v31);
v12 = reply(a1, 9LL, (unsigned int)v11, LODWORD(v32[0]));
v14 = v13;
slog(
"ACT",
&v23,
v10,
(unsigned int *)&v22 + 1,
(unsigned int *)&v22,
v11,
v12,
a3,
a4,
a5,
v15,
v16,
a8,
a9,
v9,
v32);
usleep(0x64u);
}
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int *a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
long double v9; // fst7
unsigned int v10; // er12
int v11; // ebx
double v12; // xmm0_8
unsigned int v13; // eax
unsigned int v14; // er13
double v15; // xmm4_8
double v16; // xmm5_8
double v18; // xmm0_8
unsigned int v19; // eax
double v20; // xmm4_8
double v21; // xmm5_8
__int64 v22; // [rsp+1Ch] [rbp-2DCh] BYREF
unsigned int v23; // [rsp+24h] [rbp-2D4h] BYREF
char v24[4]; // [rsp+28h] [rbp-2D0h] BYREF
__int16 v25[2]; // [rsp+2Ch] [rbp-2CCh] BYREF
__int128 v26; // [rsp+30h] [rbp-2C8h] BYREF
__int128 v27; // [rsp+40h] [rbp-2B8h]
__int128 v28; // [rsp+50h] [rbp-2A8h]
char v29[20]; // [rsp+60h] [rbp-298h] BYREF
int v30; // [rsp+74h] [rbp-284h]
char v31[208]; // [rsp+78h] [rbp-280h] BYREF
__int64 v32[54]; // [rsp+148h] [rbp-1B0h] BYREF

v9 = tick();
v10 = *a1;
v26 = 0LL;
v27 = 0LL;
v28 = 0LL;
proto_session_hdr_unmarshall(a1, &v26);
v23 = DWORD1(v28);
v22 = v27;
if ( (unsigned int)func2() )
fprintf(stderr, "len %d\n", HIDWORD(v28));
proto_session_body_unmarshall_bytes(a1, 0LL, 4LL, v24);
proto_session_body_unmarshall_bytes(a1, 4LL, 4LL, v25);
v11 = server_request_init(&maze, v29, v10, v23, (unsigned __int16)v25[0], (unsigned __int16)v25[1]);
v30 = teleport;
if ( v11 < 0 || (v11 = server_game_action(&maze, v29), v11 < 0) )
{
v18 = reply(a1, 9LL, (unsigned int)v11, 0xFFFFFFFFLL);
v14 = v19;
func3(
"ACT",
&v23,
v10,
(unsigned int *)&v22 + 1,
(unsigned int *)&v22,
v11,
v18,
a3,
a4,
a5,
v20,
v21,
a8,
a9,
v9,
0LL);
}
else
{
func5((__int64)v31);
v12 = reply(a1, 9LL, (unsigned int)v11, LODWORD(v32[0]));
v14 = v13;
func3(
"ACT",
&v23,
v10,
(unsigned int *)&v22 + 1,
(unsigned int *)&v22,
v11,
v12,
a3,
a4,
a5,
v15,
v16,
a8,
a9,
v9,
v32);
usleep(0x64u);
}
return v14;
}

original_code:
int action_handler( Proto_Session *s)
{
  long double clk = tick();
  Proto_Msg_Hdr h;
  int rc,id,team,action,fd,rpc;
  Pos current,next;
  GameRequest request;
  rc = 0;
  fd = s->fd;
  bzero(&h, sizeof(Proto_Msg_Hdr));
  proto_session_hdr_unmarshall(s, &h);
  action = h.gstate.v1.raw;
  id = h.pstate.v0.raw;
  team = h.pstate.v1.raw;
  if (proto_debug() ) fprintf(stderr,"len %d\n",h.blen);
  proto_session_body_unmarshall_bytes(s, 0, sizeof(Pos), (char*)&current);
  proto_session_body_unmarshall_bytes(s, sizeof(Pos), sizeof(Pos), (char*)&next);
  rc = server_request_init(&maze,&request,fd,action,next.x,next.y);
  request.test_mode = teleport;
  if (rc<0)
  {
    rpc = reply(s,PROTO_MT_REP_ACTION,rc,-1);
    slog("ACT",&action,fd,&team,&id,rc,clk,((void *)0));
    return rpc;
  }
  rc = server_game_action(&maze, &request);
  if (rc<0)
  {
    rpc = reply(s,PROTO_MT_REP_ACTION,rc,-1);
    slog("ACT",&action,fd,&team,&id,rc,clk,((void *)0));
    return rpc;
  }
  doUpdateClients(&request.update);
  rpc = reply(s,PROTO_MT_REP_ACTION,rc,request.update.timestamp);
  slog("ACT",&action,fd,&team,&id,rc,clk,&request.update.timestamp);
  usleep((size_t)100);
  return rpc;
}

canonical_original_code:
int action_handler(struct Proto_Session *s)
{
  long double clk = tick();
  struct Proto_Msg_Hdr h;
  int rc; int id; int team; int action; int fd; int rpc;
  struct Pos current; struct Pos next;
  struct GameRequest request;
  rc = 0;
  fd = s->fd;
  bzero(&h, sizeof(Proto_Msg_Hdr));
  proto_session_hdr_unmarshall(s, &h);
  action = h.gstate.v1.raw;
  id = h.pstate.v0.raw;
  team = h.pstate.v1.raw;
  if (proto_debug() ) fprintf(stderr,"len %d\n",h.blen);
  proto_session_body_unmarshall_bytes(s, 0, sizeof(Pos), (char *)&current);
  proto_session_body_unmarshall_bytes(s, sizeof(Pos), sizeof(Pos), (char *)&next);
  rc = server_request_init(&maze,&request,fd,action,next.x,next.y);
  request.test_mode = teleport;
  if (rc<0)
  {
    rpc = reply(s,PROTO_MT_REP_ACTION,rc,-1);
    slog("ACT",&action,fd,&team,&id,rc,clk,((void *)0));
    return rpc;
  }
  rc = server_game_action(&maze, &request);
  if (rc<0)
  {
    rpc = reply(s,PROTO_MT_REP_ACTION,rc,-1);
    slog("ACT",&action,fd,&team,&id,rc,clk,((void *)0));
    return rpc;
  }
  doUpdateClients(&request.update);
  rpc = reply(s,PROTO_MT_REP_ACTION,rc,request.update.timestamp);
  slog("ACT",&action,fd,&team,&id,rc,clk,&request.update.timestamp);
  usleep((unsigned long)100);
  return rpc;
}

variable_types: action int

variable_types: struct GameRequest { struct Pos { unsigned short x; unsigned short y; } pos; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; int id; int fd; enum Action_Types { ACTION_NOOP=0, ACTION_MOVE=1, ACTION_DROP_FLAG=2, ACTION_DROP_SHOVEL=3, ACTION_PICKUP_FLAG=4, ACTION_PICKUP_SHOVEL=5 } action; int test_mode; struct Update { struct PlayerStruct { struct CellStruct { struct Pos pos; enum Cell_Types { CELL_WALL=0, CELL_FLOOR=1, CELL_JAIL=2, CELL_HOME=3 } type; enum Cell_State_Types { CELLSTATE_EMPTY=0, CELLSTATE_OCCUPIED=1, CELLSTATE_HOLDING=2, CELLSTATE_OCCUPIED_HOLDING=3 } cell_state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } turf; enum Mutable_Types { CELLTYPE_IMMUTABLE=0, CELLTYPE_MUTABLE=1 } is_mutable; struct PlayerStruct *player; struct Object { struct CellStruct *cell; struct PlayerStruct *player; enum Object_Types { OBJECT_FLAG=0, OBJECT_SHOVEL=1 } type; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; enum Visible_Types { OBJECT_VISIBLE=0, OBJECT_INVISIBLE=1 } visiblity; struct Pos client_position; int client_player_id; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } client_player_team; int client_has_player; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } lock; unsigned int thread; } *object; union pthread_mutex_t lock; unsigned int thread; } *cell; struct Object *shovel; struct Object *flag; enum Player_State_Types { PLAYER_FREE=0, PLAYER_JAILED=1 } state; enum Team_Types { TEAM_RED=0, TEAM_BLUE=1 } team; unsigned short id; int fd; struct Pos client_position; union pthread_mutex_t lock; unsigned int thread; } player_a; struct PlayerStruct player_b; int compress_player_a; int compress_player_b; struct Pos broken_wall; int game_state_update; long long timestamp; struct Object objects[4]; } update; }

user_defined_types: struct GameRequest { struct Pos pos; enum Team_Types team; int id; int fd; enum Action_Types action; int test_mode; struct Update update; }


decompiled_code:
__int64 init_game()
{
int v0; // er12

teleport = 0;
v0 = maze_build_from_file(&maze, "./daGame.map");
if ( v0 < 0 )
fwrite("ERROR: Failed to build map\n", 1uLL, 0x1BuLL, stderr);
if ( (unsigned int)proto_debug() )
fwrite("Initializing Request Handlers\n", 1uLL, 0x1EuLL, stderr);
proto_server_set_req_handler(1LL, hello_handler);
proto_server_set_req_handler(2LL, goodbye_handler);
proto_server_set_req_handler(3LL, action_handler);
proto_server_set_req_handler(4LL, sync_handler);
proto_server_set_session_lost_handler(client_lost_handler);
return (unsigned int)v0;
}

canonical_decompiled_code:
__int64 func10()
{
int v0; // er12

teleport = 0;
v0 = maze_build_from_file(&maze, "./daGame.map");
if ( v0 < 0 )
fwrite("ERROR: Failed to build map\n", 1uLL, 0x1BuLL, stderr);
if ( (unsigned int)func2() )
fwrite("Initializing Request Handlers\n", 1uLL, 0x1EuLL, stderr);
proto_server_set_req_handler(1LL, hello_handler);
proto_server_set_req_handler(2LL, goodbye_handler);
proto_server_set_req_handler(3LL, action_handler);
proto_server_set_req_handler(4LL, sync_handler);
proto_server_set_session_lost_handler(client_lost_handler);
return (unsigned int)v0;
}

original_code:
int init_game(void){
 int rc;
  teleport = 0;
  rc = maze_build_from_file(&maze,"./daGame.map");
  if (rc <0) fprintf(stderr, "ERROR: Failed to build map\n");
  if (proto_debug()) fprintf(stderr, "Initializing Request Handlers\n");
  proto_server_set_req_handler( PROTO_MT_REQ_HELLO, &(hello_handler) );
  proto_server_set_req_handler( PROTO_MT_REQ_GOODBYE, &(goodbye_handler) );
  proto_server_set_req_handler( PROTO_MT_REQ_ACTION, &(action_handler) );
  proto_server_set_req_handler( PROTO_MT_REQ_SYNC, &(sync_handler) );
  proto_server_set_session_lost_handler( &(client_lost_handler) );
  return rc;
}

canonical_original_code:
int init_game(){
 int rc;
  teleport = 0;
  rc = maze_build_from_file(&maze,"./daGame.map");
  if (rc <0) fprintf(stderr, "ERROR: Failed to build map\n");
  if (proto_debug()) fprintf(stderr, "Initializing Request Handlers\n");
  proto_server_set_req_handler( PROTO_MT_REQ_HELLO, &(hello_handler) );
  proto_server_set_req_handler( PROTO_MT_REQ_GOODBYE, &(goodbye_handler) );
  proto_server_set_req_handler( PROTO_MT_REQ_ACTION, &(action_handler) );
  proto_server_set_req_handler( PROTO_MT_REQ_SYNC, &(sync_handler) );
  proto_server_set_session_lost_handler( &(client_lost_handler) );
  return rc;
}


docmd

decompiled_code:
__int64 __fastcall docmd(char *a1)
{
unsigned int v2; // er12
char v3; // al
__int64 result; // rax
bool v5; // zf
char *v6; // rsi
char *v7; // rsi

v2 = -1;
if ( !memcmp(a1, "quit", 4uLL) )
return v2;
if ( !memcmp(a1, "teleport", 4uLL) )
{
v5 = teleport == 0;
teleport = teleport == 0;
if ( v5 )
fwrite("Teleportation \x1B[34mENABLED\x1B[0m\n", 1uLL, 0x1FuLL, stdout);
else
fwrite("Teleportation \x1B[31mDISABLED\x1B[0m\n", 1uLL, 0x20uLL, stdout);
fflush(stdout);
result = 0LL;
}
else if ( !memcmp(a1, "textdump", 8uLL) )
{
v7 = strtok(a1 + 8, ": \n");
if ( !v7 )
{
v2 = 1;
fwrite("Please specify filename $textdump <filename>\n", 1uLL, 0x2DuLL, stderr);
return v2;
}
maze_text_dump(&maze, v7);
result = 1LL;
}
else
{
if ( !memcmp(a1, "asciidump", 9uLL) )
{
v6 = strtok(a1 + 9, ": \n");
v2 = 1;
if ( v6 )
maze_ascii_dump(&maze, v6);
else
fwrite("Please specify filename $asciidump <filename>\n", 1uLL, 0x2EuLL, stderr);
return v2;
}
v3 = *a1;
if ( v3 == 100 )
{
proto_debug_on();
return 1;
}
if ( v3 <= 100 )
{
if ( v3 == 68 )
{
proto_debug_off();
return 1;
}
if ( v3 <= 68 )
{
v2 = 1;
if ( v3 == 10 )
return v2;
if ( v3 == 32 )
return 1LL;
}
LABEL_9:
v2 = 1;
puts("Unkown Command");
return v2;
}
if ( v3 != 113 )
goto LABEL_9;
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
unsigned int v2; // er12
char v3; // al
__int64 result; // rax
bool v5; // zf
char *v6; // rsi
char *v7; // rsi

v2 = -1;
if ( !memcmp(a1, "quit", 4uLL) )
return v2;
if ( !memcmp(a1, "teleport", 4uLL) )
{
v5 = teleport == 0;
teleport = teleport == 0;
if ( v5 )
fwrite("Teleportation \x1B[34mENABLED\x1B[0m\n", 1uLL, 0x1FuLL, stdout);
else
fwrite("Teleportation \x1B[31mDISABLED\x1B[0m\n", 1uLL, 0x20uLL, stdout);
fflush(stdout);
result = 0LL;
}
else if ( !memcmp(a1, "textdump", 8uLL) )
{
v7 = strtok(a1 + 8, ": \n");
if ( !v7 )
{
v2 = 1;
fwrite("Please specify filename $textdump <filename>\n", 1uLL, 0x2DuLL, stderr);
return v2;
}
maze_text_dump(&maze, v7);
result = 1LL;
}
else
{
if ( !memcmp(a1, "asciidump", 9uLL) )
{
v6 = strtok(a1 + 9, ": \n");
v2 = 1;
if ( v6 )
maze_ascii_dump(&maze, v6);
else
fwrite("Please specify filename $asciidump <filename>\n", 1uLL, 0x2EuLL, stderr);
return v2;
}
v3 = *a1;
if ( v3 == 100 )
{
func0();
return 1;
}
if ( v3 <= 100 )
{
if ( v3 == 68 )
{
func1();
return 1;
}
if ( v3 <= 68 )
{
v2 = 1;
if ( v3 == 10 )
return v2;
if ( v3 == 32 )
return 1LL;
}
LABEL_9:
v2 = 1;
puts("Unkown Command");
return v2;
}
if ( v3 != 113 )
goto LABEL_9;
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int docmd(char* cmd)
{
  int rc = 1;
  if ((strncmp(cmd,"quit",sizeof("quit")-1))==0)
  {
    return -1;
  }
  else if ((strncmp(cmd,"teleport",sizeof("quit")-1))==0)
  {
    teleport = !teleport;
    if (teleport)
      fprintf(stdout,"Teleportation " "\033[34m" "ENABLED" "\033[0m" "\n");
    else
      fprintf(stdout,"Teleportation " "\033[31m" "DISABLED" "\033[0m" "\n");
    fflush(stdout);
    return 0;
  }
  else if((strncmp(cmd,"textdump",sizeof("textdump")-1))==0)
  {
    char* token;
    token = strtok(cmd+sizeof("textdump")-1,": \n\0");
    if (token == ((void *)0) )
    {
      fprintf(stderr,"Please specify filename $textdump <filename>\n");
      return rc;
    }
    maze_text_dump(&maze,token);
    return rc;
  }
  else if((strncmp(cmd,"asciidump",sizeof("asciidump")-1))==0)
  {
    char* token;
    token = strtok(cmd+sizeof("asciidump")-1,": \n\0");
    if (token == ((void *)0) )
    {
      fprintf(stderr,"Please specify filename $asciidump <filename>\n");
      return rc;
    }
    maze_ascii_dump(&maze,token);
    return rc;
  }
  switch (*cmd) {
  case 'd':
    proto_debug_on();
    break;
  case 'D':
    proto_debug_off();
    break;
  case 'q':
    rc=-1;
    break;
  case '\n':
  case ' ':
    rc=1;
    break;
  default:
    printf("Unkown Command\n");
  }
  return rc;
}

canonical_original_code:
int docmd(char *cmd)
{
  int rc = 1;
  if ((strncmp(cmd,"quit",sizeof("quit")-1))==0)
  {
    return -1;
  }
  else if ((strncmp(cmd,"teleport",sizeof("quit")-1))==0)
  {
    teleport = !teleport;
    if (teleport)
      fprintf(stdout,"Teleportation " "\033[34m" "ENABLED" "\033[0m" "\n");
    else
      fprintf(stdout,"Teleportation " "\033[31m" "DISABLED" "\033[0m" "\n");
    fflush(stdout);
    return 0;
  }
  else if((strncmp(cmd,"textdump",sizeof("textdump")-1))==0)
  {
    char *token;
    token = strtok(cmd+sizeof("textdump")-1,": \n\0");
    if (token == ((void *)0) )
    {
      fprintf(stderr,"Please specify filename $textdump <filename>\n");
      return rc;
    }
    maze_text_dump(&maze,token);
    return rc;
  }
  else if((strncmp(cmd,"asciidump",sizeof("asciidump")-1))==0)
  {
    char *token;
    token = strtok(cmd+sizeof("asciidump")-1,": \n\0");
    if (token == ((void *)0) )
    {
      fprintf(stderr,"Please specify filename $asciidump <filename>\n");
      return rc;
    }
    maze_ascii_dump(&maze,token);
    return rc;
  }
  switch (*cmd) {
  case 'd':
    proto_debug_on();
    break;
  case 'D':
    proto_debug_off();
    break;
  case 'q':
    rc=-1;
    break;
  case '\n':
  case ' ':
    rc=1;
    break;
  default:
    printf("Unkown Command\n");
  }
  return rc;
}

variable_types:
cmd
char *

variable_types:
token
char *