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


repo: sameenjalal/Linux-File-System

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

return_type: void


decompiled_code:
__int64 __fastcall format_fs(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // ebx
void *v4; // r12
int v5; // eax
int v6; // er14
int i; // ebp
_DWORD *v8; // rbx
int v9; // eax
int v10; // eax
unsigned int v11; // ebx
int v12; // eax
int v13; // ebx
unsigned int v14; // ebx
__int64 v15; // rax
int v17[138]; // [rsp+0h] [rbp-228h] 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 = malloc(0x200uLL);
strcpy((char *)v4, "ssjfs");
*((_DWORD *)v4 + 6) = a2;
*((_DWORD *)v4 + 7) = 0;
*((_DWORD *)v4 + 8) = 8 * (a2 / 20);
v5 = a2 / 20 + 1;
*((_DWORD *)v4 + 9) = v5;
*((_DWORD *)v4 + 11) = v5;
*((_DWORD *)v4 + 10) = 0;
mylseek(v3, 0LL, 0LL);
mywrite((unsigned int)fs_disk, v4, 1LL);
v6 = *((_DWORD *)v4 + 8);
if ( v6 > 0 )
{
for ( i = 0; i < v6; ++i )
{
v8 = malloc(0x40uLL);
v8[2] = 0;
v8[3] = 0;
v9 = i + 1;
if ( v6 - 1 == i )
v9 = 0;
*v8 = v9;
v10 = v6 - 1;
if ( i )
v10 = i - 1;
v8[1] = v10;
write_inode(v8, (unsigned int)i);
free(v8);
v6 = *((_DWORD *)v4 + 8);
}
}
v11 = *((_DWORD *)v4 + 9);
while ( (signed int)v11 < *((_DWORD *)v4 + 6) )
{
mylseek((unsigned int)fs_disk, v11, 0LL);
memset(v17, 0, 0x200uLL);
v12 = v11 - 1;
if ( *((_DWORD *)v4 + 9) == v11 )
v12 = *((_DWORD *)v4 + 6) - 1;
v17[1] = v12;
v17[0] = ++v11;
mywrite((unsigned int)fs_disk, v17, 1LL);
}
v13 = *((_DWORD *)v4 + 9);
do
load_free_block((unsigned int)v13++);
while ( *((_DWORD *)v4 + 9) + 4 >= v13 );
mylseek((unsigned int)fs_disk, 0LL, 0LL);
mywrite((unsigned int)fs_disk, v4, 1LL);
v14 = get_new_inode();
if ( v14 )
{
fwrite("get_new_inode() didnt return 0 on the format call?", 1uLL, 0x32uLL, stderr);
v14 = -5;
}
else
{
v15 = get_inode(0LL);
*(_DWORD *)(v15 + 12) = 1;
write_inode(v15, 0LL);
free(v4);
close(fs_disk);
puts("Exiting formatfs");
}
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, int a2)
{
int v2; // eax
unsigned int v3; // ebx
void *v4; // r12
int v5; // eax
int v6; // er14
int i; // ebp
_DWORD *v8; // rbx
int v9; // eax
int v10; // eax
unsigned int v11; // ebx
int v12; // eax
int v13; // ebx
unsigned int v14; // ebx
__int64 v15; // rax
int v17[138]; // [rsp+0h] [rbp-228h] 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 = malloc(0x200uLL);
strcpy((char *)v4, "ssjfs");
*((_DWORD *)v4 + 6) = a2;
*((_DWORD *)v4 + 7) = 0;
*((_DWORD *)v4 + 8) = 8 * (a2 / 20);
v5 = a2 / 20 + 1;
*((_DWORD *)v4 + 9) = v5;
*((_DWORD *)v4 + 11) = v5;
*((_DWORD *)v4 + 10) = 0;
mylseek(v3, 0LL, 0LL);
mywrite((unsigned int)fs_disk, v4, 1LL);
v6 = *((_DWORD *)v4 + 8);
if ( v6 > 0 )
{
for ( i = 0; i < v6; ++i )
{
v8 = malloc(0x40uLL);
v8[2] = 0;
v8[3] = 0;
v9 = i + 1;
if ( v6 - 1 == i )
v9 = 0;
*v8 = v9;
v10 = v6 - 1;
if ( i )
v10 = i - 1;
v8[1] = v10;
write_inode(v8, (unsigned int)i);
free(v8);
v6 = *((_DWORD *)v4 + 8);
}
}
v11 = *((_DWORD *)v4 + 9);
while ( (signed int)v11 < *((_DWORD *)v4 + 6) )
{
mylseek((unsigned int)fs_disk, v11, 0LL);
memset(v17, 0, 0x200uLL);
v12 = v11 - 1;
if ( *((_DWORD *)v4 + 9) == v11 )
v12 = *((_DWORD *)v4 + 6) - 1;
v17[1] = v12;
v17[0] = ++v11;
mywrite((unsigned int)fs_disk, v17, 1LL);
}
v13 = *((_DWORD *)v4 + 9);
do
load_free_block((unsigned int)v13++);
while ( *((_DWORD *)v4 + 9) + 4 >= v13 );
mylseek((unsigned int)fs_disk, 0LL, 0LL);
mywrite((unsigned int)fs_disk, v4, 1LL);
v14 = get_new_inode();
if ( v14 )
{
fwrite("get_new_inode() didnt return 0 on the format call?", 1uLL, 0x32uLL, stderr);
v14 = -5;
}
else
{
v15 = get_inode(0LL);
*(_DWORD *)(v15 + 12) = 1;
write_inode(v15, 0LL);
free(v4);
close(fs_disk);
puts("Exiting formatfs");
}
return v14;
}

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 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 free_block { int next_free; int prev_free; char data[-1]; } *

variable_types:
buffer
char [512]

variable_types: dbn int

variable_types: i int

return_type: int


emalloc

repo: samgiles/C-Snippets

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 *

return_type: void *


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

v0 = (void **)memory_manager;
if ( *(_QWORD *)memory_manager )
return increase_store_areas();
*v0 = emalloc(0x20uLL);
v2 = (_QWORD **)memory_manager;
*(_QWORD *)(*(_QWORD *)memory_manager + 24LL) = memory_manager;
**v2 = 0LL;
v3 = memory_manager;
*(_QWORD *)(*(_QWORD *)memory_manager + 16LL) = 0LL;
v3[2] = 1;
return *(_QWORD **)v3;
}

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

v0 = (void **)memory_manager;
if ( *(_QWORD *)memory_manager )
return increase_store_areas();
*v0 = func7(0x20uLL);
v2 = (_QWORD **)memory_manager;
*(_QWORD *)(*(_QWORD *)memory_manager + 24LL) = memory_manager;
**v2 = 0LL;
v3 = memory_manager;
*(_QWORD *)(*(_QWORD *)memory_manager + 16LL) = 0LL;
v3[2] = 1;
return *(_QWORD **)v3;
}

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; // rax
__int64 v2; // rax

v1 = (_QWORD *)a1[3];
if ( v1 )
*v1 = a1[2];
else
MEMORY[0x10] = a1[2];
v2 = a1[2];
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);
}

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


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

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

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

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

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

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


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

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
mm_alloc();
mm_free();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
func13();
func11();
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 *[]


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

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

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 *


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

canonical_decompiled_code:
_BOOL8 __fastcall func4(__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 func7(__int64 ***a1, const char *a2, __int64 (__fastcall *a3)(_QWORD))
{
__int64 **v4; // rax

v4 = AL_NodeForKey(a1, a2);
return func6(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 *v12; // rax
double v13; // xmm0_8
char s[40]; // [rsp+10h] [rbp-68h] BYREF
time_t timer; // [rsp+38h] [rbp-40h] BYREF

time(&timer);
v12 = localtime(&timer);
sprintf(timestr, "%.2d:%.2d:%.2d", (unsigned int)v12->tm_hour, (unsigned int)v12->tm_min, (unsigned int)v12->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);
v13 = (double)(tick() - a15) * 1000.0;
if ( a5 != 0LL && a4 != 0LL )
{
if ( a2 && 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,
*a4,
*a5,
s,
v13,
*a16);
}
else if ( a2 )
{
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,
*a4,
*a5,
s,
v13);
}
else if ( a16 && a5 != 0LL && a4 != 0LL )
{
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,
*a4,
*a5,
s,
v13,
*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,
*a4,
*a5,
s,
v13);
}
}
else
{
fprintf(stdout, "%s\t\x1B[33m%s\x1B[0m\t\tfd:%05d\tteam:_\tid:___\trc:%s\t%.1fms\n", timestr, a1, a3, s, v13);
}
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 *v12; // rax
double v13; // xmm0_8
char s[40]; // [rsp+10h] [rbp-68h] BYREF
time_t timer; // [rsp+38h] [rbp-40h] BYREF

time(&timer);
v12 = localtime(&timer);
sprintf(timestr, "%.2d:%.2d:%.2d", (unsigned int)v12->tm_hour, (unsigned int)v12->tm_min, (unsigned int)v12->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);
v13 = (double)(tick() - a15) * 1000.0;
if ( a5 != 0LL && a4 != 0LL )
{
if ( a2 && 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,
*a4,
*a5,
s,
v13,
*a16);
}
else if ( a2 )
{
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,
*a4,
*a5,
s,
v13);
}
else if ( a16 && a5 != 0LL && a4 != 0LL )
{
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,
*a4,
*a5,
s,
v13,
*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,
*a4,
*a5,
s,
v13);
}
}
else
{
fprintf(stdout, "%s\t\x1B[33m%s\x1B[0m\t\tfd:%05d\tteam:_\tid:___\trc:%s\t%.1fms\n", timestr, a1, a3, s, v13);
}
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)
{
unsigned int *v9; // r14
unsigned int *v10; // r13
unsigned int *v11; // r12
__int64 v12; // rbp
__int64 v13; // rbp
__int64 v14; // rbp
double v15; // xmm0_8
unsigned int v16; // eax
unsigned int v17; // ebp
double v18; // xmm4_8
double v19; // xmm5_8
long double v21; // [rsp+0h] [rbp-88h]
unsigned int v22; // [rsp+14h] [rbp-74h] BYREF
unsigned int v23; // [rsp+18h] [rbp-70h] BYREF
unsigned int v24; // [rsp+1Ch] [rbp-6Ch] BYREF
unsigned int v25; // [rsp+20h] [rbp-68h] BYREF
int v26; // [rsp+24h] [rbp-64h] BYREF
int v27; // [rsp+28h] [rbp-60h] BYREF
int v28; // [rsp+2Ch] [rbp-5Ch] BYREF
__int64 v29[3]; // [rsp+30h] [rbp-58h] BYREF
__int64 v30; // [rsp+48h] [rbp-40h]
__int64 v31; // [rsp+50h] [rbp-38h]
__int64 v32; // [rsp+58h] [rbp-30h]

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

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)
{
unsigned int *v9; // r14
unsigned int *v10; // r13
unsigned int *v11; // r12
__int64 v12; // rbp
__int64 v13; // rbp
__int64 v14; // rbp
double v15; // xmm0_8
unsigned int v16; // eax
unsigned int v17; // ebp
double v18; // xmm4_8
double v19; // xmm5_8
long double v21; // [rsp+0h] [rbp-88h]
unsigned int v22; // [rsp+14h] [rbp-74h] BYREF
unsigned int v23; // [rsp+18h] [rbp-70h] BYREF
unsigned int v24; // [rsp+1Ch] [rbp-6Ch] BYREF
unsigned int v25; // [rsp+20h] [rbp-68h] BYREF
int v26; // [rsp+24h] [rbp-64h] BYREF
int v27; // [rsp+28h] [rbp-60h] BYREF
int v28; // [rsp+2Ch] [rbp-5Ch] BYREF
__int64 v29[3]; // [rsp+30h] [rbp-58h] BYREF
__int64 v30; // [rsp+48h] [rbp-40h]
__int64 v31; // [rsp+50h] [rbp-38h]
__int64 v32; // [rsp+58h] [rbp-30h]

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

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 i; // ebx
__int64 v3; // rax
int v5; // [rsp+Ch] [rbp-4Ch] BYREF
__int64 v6[2]; // [rsp+10h] [rbp-48h] BYREF
__int64 v7; // [rsp+20h] [rbp-38h]
__int64 v8; // [rsp+28h] [rbp-30h]
int v9; // [rsp+30h] [rbp-28h]
_QWORD v10[4]; // [rsp+34h] [rbp-24h]

v6[0] = 0LL;
v7 = 0LL;
v8 = 0LL;
*(_QWORD *)((char *)v10 + 4) = 0LL;
v6[1] = *(_QWORD *)(a1 + 208);
v9 = *(_DWORD *)(a1 + 204);
v10[0] = *(unsigned int *)(a1 + 192);
HIDWORD(v10[0]) = *(_DWORD *)(a1 + 196);
v1 = (_QWORD *)(a1 + 216);
for ( i = 0; i != 4; ++i )
{
if ( *v1 )
{
compress_object(v1, &v5);
if ( i == 2 )
{
LODWORD(v8) = v5;
}
else if ( i > 2 )
{
if ( i == 3 )
HIDWORD(v8) = v5;
}
else if ( i )
{
if ( i == 1 )
HIDWORD(v7) = v5;
}
else
{
LODWORD(v7) = v5;
}
}
v1 += 12;
}
v3 = proto_server_event_session();
HIDWORD(v6[0]) = 13;
proto_session_hdr_marshall(v3, v6);
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 i; // ebx
__int64 v3; // rax
int v5; // [rsp+Ch] [rbp-4Ch] BYREF
__int64 v6[2]; // [rsp+10h] [rbp-48h] BYREF
__int64 v7; // [rsp+20h] [rbp-38h]
__int64 v8; // [rsp+28h] [rbp-30h]
int v9; // [rsp+30h] [rbp-28h]
_QWORD v10[4]; // [rsp+34h] [rbp-24h]

v6[0] = 0LL;
v7 = 0LL;
v8 = 0LL;
*(_QWORD *)((char *)v10 + 4) = 0LL;
v6[1] = *(_QWORD *)(a1 + 208);
v9 = *(_DWORD *)(a1 + 204);
v10[0] = *(unsigned int *)(a1 + 192);
HIDWORD(v10[0]) = *(_DWORD *)(a1 + 196);
v1 = (_QWORD *)(a1 + 216);
for ( i = 0; i != 4; ++i )
{
if ( *v1 )
{
compress_object(v1, &v5);
if ( i == 2 )
{
LODWORD(v8) = v5;
}
else if ( i > 2 )
{
if ( i == 3 )
HIDWORD(v8) = v5;
}
else if ( i )
{
if ( i == 1 )
HIDWORD(v7) = v5;
}
else
{
LODWORD(v7) = v5;
}
}
v1 += 12;
}
v3 = proto_server_event_session();
HIDWORD(v6[0]) = 13;
proto_session_hdr_marshall(v3, v6);
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)
{
unsigned int v9; // ebp
double v10; // xmm4_8
double v11; // xmm5_8
double v12; // xmm4_8
double v13; // xmm5_8
long double v15; // [rsp+0h] [rbp-288h]
_QWORD v16[75]; // [rsp+10h] [rbp-278h] BYREF
unsigned int v17; // [rsp+268h] [rbp-20h] BYREF
unsigned int v18[7]; // [rsp+26Ch] [rbp-1Ch] BYREF

v15 = tick();
v9 = *a1;
if ( (int)server_fd_to_id_and_team(&maze, *a1, &v17, v18) < 0 )
{
slog("DIS", 0LL, v9, 0LL, 0LL, 0, a2, a3, a4, a5, v10, v11, a8, a9, v15, 0LL);
}
else
{
memset(v16, 0, sizeof(v16));
server_game_drop_player(&maze, v17, v18[0], v16);
if ( (unsigned int)proto_debug() )
proto_session_dump(a1);
doUpdateClients((__int64)v16);
slog("DRP", 0LL, v9, &v17, v18, 0, a2, a3, a4, a5, v12, v13, a8, a9, v15, &v16[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)
{
unsigned int v9; // ebp
double v10; // xmm4_8
double v11; // xmm5_8
double v12; // xmm4_8
double v13; // xmm5_8
long double v15; // [rsp+0h] [rbp-288h]
_QWORD v16[75]; // [rsp+10h] [rbp-278h] BYREF
unsigned int v17; // [rsp+268h] [rbp-20h] BYREF
unsigned int v18[7]; // [rsp+26Ch] [rbp-1Ch] BYREF

v15 = tick();
v9 = *a1;
if ( (int)server_fd_to_id_and_team(&maze, *a1, &v17, v18) < 0 )
{
func3("DIS", 0LL, v9, 0LL, 0LL, 0, a2, a3, a4, a5, v10, v11, a8, a9, v15, 0LL);
}
else
{
memset(v16, 0, sizeof(v16));
server_game_drop_player(&maze, v17, v18[0], v16);
if ( (unsigned int)func2() )
proto_session_dump(a1);
func5((__int64)v16);
func3("DRP", 0LL, v9, &v17, v18, 0, a2, a3, a4, a5, v12, v13, a8, a9, v15, &v16[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)
{
int v9; // eax
int v10; // ebp
double v11; // xmm0_8
unsigned int v12; // eax
unsigned int v13; // er12
double v14; // xmm4_8
double v15; // xmm5_8
double v17; // xmm0_8
unsigned int v18; // eax
double v19; // xmm4_8
double v20; // xmm5_8
long double v21; // [rsp+0h] [rbp-2B8h]
__int64 v22[2]; // [rsp+10h] [rbp-2A8h] BYREF
__int64 v23; // [rsp+20h] [rbp-298h]
__int64 v24; // [rsp+28h] [rbp-290h]
__int64 v25; // [rsp+30h] [rbp-288h]
__int64 v26; // [rsp+38h] [rbp-280h]
_QWORD v27[75]; // [rsp+40h] [rbp-278h] BYREF
__int64 v28[4]; // [rsp+298h] [rbp-20h] BYREF

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

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)
{
unsigned int v9; // er12
int v10; // ebp
int v11; // eax
unsigned int v12; // ebp
double v13; // xmm0_8
unsigned int v14; // eax
unsigned int v15; // ebx
double v16; // xmm4_8
double v17; // xmm5_8
double v19; // xmm0_8
unsigned int v20; // eax
double v21; // xmm4_8
double v22; // xmm5_8
double v23; // xmm0_8
unsigned int v24; // eax
double v25; // xmm4_8
double v26; // xmm5_8
long double v27; // [rsp+0h] [rbp-2E8h]
char v28[20]; // [rsp+10h] [rbp-2D8h] BYREF
int v29; // [rsp+24h] [rbp-2C4h]
char v30[208]; // [rsp+28h] [rbp-2C0h] BYREF
__int64 v31[50]; // [rsp+F8h] [rbp-1F0h] BYREF
__int16 v32[2]; // [rsp+28Ch] [rbp-5Ch] BYREF
char v33[4]; // [rsp+290h] [rbp-58h] BYREF
unsigned int v34; // [rsp+294h] [rbp-54h] BYREF
unsigned int v35; // [rsp+298h] [rbp-50h] BYREF
unsigned int v36; // [rsp+29Ch] [rbp-4Ch] BYREF
__int64 v37[2]; // [rsp+2A0h] [rbp-48h] BYREF
__int64 v38; // [rsp+2B0h] [rbp-38h]
__int64 v39; // [rsp+2B8h] [rbp-30h]
__int64 v40; // [rsp+2C0h] [rbp-28h]
__int64 v41; // [rsp+2C8h] [rbp-20h]

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

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)
{
unsigned int v9; // er12
int v10; // ebp
int v11; // eax
unsigned int v12; // ebp
double v13; // xmm0_8
unsigned int v14; // eax
unsigned int v15; // ebx
double v16; // xmm4_8
double v17; // xmm5_8
double v19; // xmm0_8
unsigned int v20; // eax
double v21; // xmm4_8
double v22; // xmm5_8
double v23; // xmm0_8
unsigned int v24; // eax
double v25; // xmm4_8
double v26; // xmm5_8
long double v27; // [rsp+0h] [rbp-2E8h]
char v28[20]; // [rsp+10h] [rbp-2D8h] BYREF
int v29; // [rsp+24h] [rbp-2C4h]
char v30[208]; // [rsp+28h] [rbp-2C0h] BYREF
__int64 v31[50]; // [rsp+F8h] [rbp-1F0h] BYREF
__int16 v32[2]; // [rsp+28Ch] [rbp-5Ch] BYREF
char v33[4]; // [rsp+290h] [rbp-58h] BYREF
unsigned int v34; // [rsp+294h] [rbp-54h] BYREF
unsigned int v35; // [rsp+298h] [rbp-50h] BYREF
unsigned int v36; // [rsp+29Ch] [rbp-4Ch] BYREF
__int64 v37[2]; // [rsp+2A0h] [rbp-48h] BYREF
__int64 v38; // [rsp+2B0h] [rbp-38h]
__int64 v39; // [rsp+2B8h] [rbp-30h]
__int64 v40; // [rsp+2C0h] [rbp-28h]
__int64 v41; // [rsp+2C8h] [rbp-20h]

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

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; // ebx

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; // ebx

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; // ebx
bool v3; // zf
char v4; // al
char *v6; // rsi
char *v7; // rsi

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

canonical_decompiled_code:
__int64 __fastcall func11(char *a1)
{
unsigned int v2; // ebx
bool v3; // zf
char v4; // al
char *v6; // rsi
char *v7; // rsi

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

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 *


prompt

decompiled_code:
char *__fastcall prompt(int a1)
{
int v1; // ebx
char *result; // rax
char *s; // [rsp+0h] [rbp-18h] BYREF
size_t n[2]; // [rsp+8h] [rbp-10h] BYREF

if ( a1 )
fprintf(stdout, "%sSERVER_SHELL$\n", MenuString);
fflush(stdout);
n[0] = 0LL;
s = (char *)malloc(1uLL);
v1 = getline(&s, n, stdin);
*strchr(s, 10) = 0;
result = 0LL;
if ( v1 > 0 )
result = s;
return result;
}

canonical_decompiled_code:
char *__fastcall func12(int a1)
{
int v1; // ebx
char *result; // rax
char *s; // [rsp+0h] [rbp-18h] BYREF
size_t n[2]; // [rsp+8h] [rbp-10h] BYREF

if ( a1 )
fprintf(stdout, "%sSERVER_SHELL$\n", MenuString);
fflush(stdout);
n[0] = 0LL;
s = (char *)malloc(1uLL);
v1 = getline(&s, n, stdin);
*strchr(s, 10) = 0;
result = 0LL;
if ( v1 > 0 )
result = s;
return result;
}

original_code:
char* prompt(int menu)
{
  if (menu) fprintf(stdout,"%sSERVER_SHELL$\n", MenuString);
  fflush(stdout);
  int bytes_read;
  size_t nbytes = 0;
  char *my_string = (char*) malloc(1);
  bytes_read = getline (&my_string, &nbytes, stdin);
  char* pch;
  pch = strchr(my_string,'\n');
  *pch = '\0';
  if(bytes_read>0)
 return my_string;
  else
 return 0;
}

canonical_original_code:
char *prompt(int menu)
{
  if (menu) fprintf(stdout,"%sSERVER_SHELL$\n", MenuString);
  fflush(stdout);
  int bytes_read;
  unsigned long nbytes = 0;
  char *my_string = (char*) malloc(1);
  bytes_read = getline (&my_string, &nbytes, stdin);
  char *pch;
  pch = strchr(my_string,'\n');
  *pch = '\0';
  if(bytes_read>0)
 return my_string;
  else
 return 0;
}

variable_types: menu int

variable_types:
nbytes
unsigned long

variable_types:
pch
char *

return_type: char *


shell

decompiled_code:
__int64 shell()
{
int v0; // er12
int v1; // ebp
char *v2; // rax
char *v3; // rbx

v0 = 1;
v1 = 1;
while ( 1 )
{
v2 = prompt(v0);
v3 = v2;
if ( v2 )
v1 = docmd(v2);
if ( v1 < 0 )
break;
v0 = v1 == 1;
if ( v3 )
free(v3);
}
if ( v3 )
free(v3);
fflush(stdout);
fwrite("terminating\n", 1uLL, 0xCuLL, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func13()
{
int v0; // er12
int v1; // ebp
char *v2; // rax
char *v3; // rbx

v0 = 1;
v1 = 1;
while ( 1 )
{
v2 = func12(v0);
v3 = v2;
if ( v2 )
v1 = func11(v2);
if ( v1 < 0 )
break;
v0 = v1 == 1;
if ( v3 )
free(v3);
}
if ( v3 )
free(v3);
fflush(stdout);
fwrite("terminating\n", 1uLL, 0xCuLL, stderr);
return 0LL;
}

original_code:
void * shell(void *arg)
{
  char* c;
  int rc=1;
  int menu=1;
  while (1)
  {
    if ((c=prompt(menu))!=0) rc=docmd(c);
    if (rc<0) break;
    if (rc==1) menu=1; else menu=0;
    if(c!=0) free(c);
  }
  if(c!=0) free(c);
  fflush(stdout);
  fprintf(stderr, "terminating\n");
  return ((void *)0);
}

canonical_original_code:
void *shell(void *arg)
{
  char *c;
  int rc = 1;
  int menu = 1;
  while (1)
  {
    if ((c=prompt(menu))!=0) rc=docmd(c);
    if (rc<0) break;
    if (rc==1) menu=1; else menu=0;
    if(c!=0) free(c);
  }
  if(c!=0) free(c);
  fflush(stdout);
  fprintf(stderr, "terminating\n");
  return ((void *)0);
}

variable_types:
arg
void *

variable_types:
c
char *


randint

decompiled_code:
int randint()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
return rand();
}

canonical_decompiled_code:
int func3()
{
unsigned int v0; // eax

v0 = time(0LL);
srand(v0);
return rand();
}

original_code:
extern int randint()
{
   srand (time(((void *)0)));
   return rand();
}


decompiled_code:
int __fastcall cell_dump(unsigned __int16 *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

fputc(10, stderr);
fprintf(stderr, "COLUMN - (x) - %d \n", *a1);
fprintf(stderr, "ROW - (y) - %d \n", a1[1]);
v1 = *((_DWORD *)a1 + 1);
if ( v1 == 2 )
{
fwrite("CELL TYPE: CELL_JAIL", 1uLL, 0x14uLL, stderr);
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
fwrite("CELL TYPE: CELL_HOME", 1uLL, 0x14uLL, stderr);
else
fwrite("CELL TYPE: UNKWOWN", 1uLL, 0x12uLL, stderr);
}
else if ( v1 )
{
fwrite("CELL TYPE: CELL_FLOOR", 1uLL, 0x15uLL, stderr);
}
else
{
fwrite("CELL TYPE: CELL_WALL", 1uLL, 0x14uLL, stderr);
}
fputc(10, stderr);
fprintf(stderr, "CELL TURF: %d", (unsigned int)(*((_DWORD *)a1 + 3) + 1));
fputc(10, stderr);
v2 = *((_DWORD *)a1 + 2);
if ( v2 == 2 )
{
fwrite("CELLSTATE: HOLDING", 1uLL, 0x12uLL, stderr);
}
else if ( v2 > 2 )
{
if ( v2 == 3 )
fwrite("CELLSTATE: OCCUPIED AND HOLDING", 1uLL, 0x1FuLL, stderr);
else
fwrite("CELLSTATE: UNKWOWN", 1uLL, 0x12uLL, stderr);
}
else if ( v2 )
{
fwrite("CELLSTATE: OCCUPIED\n", 1uLL, 0x14uLL, stderr);
}
else
{
fwrite("CELLSTATE: EMPTY", 1uLL, 0x10uLL, stderr);
}
return fputc(10, stderr);
}

canonical_decompiled_code:
int __fastcall func4(unsigned __int16 *a1)
{
unsigned int v1; // eax
unsigned int v2; // eax

fputc(10, stderr);
fprintf(stderr, "COLUMN - (x) - %d \n", *a1);
fprintf(stderr, "ROW - (y) - %d \n", a1[1]);
v1 = *((_DWORD *)a1 + 1);
if ( v1 == 2 )
{
fwrite("CELL TYPE: CELL_JAIL", 1uLL, 0x14uLL, stderr);
}
else if ( v1 > 2 )
{
if ( v1 == 3 )
fwrite("CELL TYPE: CELL_HOME", 1uLL, 0x14uLL, stderr);
else
fwrite("CELL TYPE: UNKWOWN", 1uLL, 0x12uLL, stderr);
}
else if ( v1 )
{
fwrite("CELL TYPE: CELL_FLOOR", 1uLL, 0x15uLL, stderr);
}
else
{
fwrite("CELL TYPE: CELL_WALL", 1uLL, 0x14uLL, stderr);
}
fputc(10, stderr);
fprintf(stderr, "CELL TURF: %d", (unsigned int)(*((_DWORD *)a1 + 3) + 1));
fputc(10, stderr);
v2 = *((_DWORD *)a1 + 2);
if ( v2 == 2 )
{
fwrite("CELLSTATE: HOLDING", 1uLL, 0x12uLL, stderr);
}
else if ( v2 > 2 )
{
if ( v2 == 3 )
fwrite("CELLSTATE: OCCUPIED AND HOLDING", 1uLL, 0x1FuLL, stderr);
else
fwrite("CELLSTATE: UNKWOWN", 1uLL, 0x12uLL, stderr);
}
else if ( v2 )
{
fwrite("CELLSTATE: OCCUPIED\n", 1uLL, 0x14uLL, stderr);
}
else
{
fwrite("CELLSTATE: EMPTY", 1uLL, 0x10uLL, stderr);
}
return fputc(10, stderr);
}

original_code:
extern void
cell_dump(Cell *cell)
{
  fprintf(stderr, "\n");
  fprintf(stderr, "COLUMN - (x) - %d \n",cell->pos.x);
  fprintf(stderr, "ROW    - (y) - %d \n",cell->pos.y);
  switch(cell->type)
  {
    case CELL_WALL:
      fprintf(stderr, "CELL TYPE: CELL_WALL");
      break;
    case CELL_FLOOR:
      fprintf(stderr, "CELL TYPE: CELL_FLOOR");
      break;
    case CELL_HOME:
      fprintf(stderr, "CELL TYPE: CELL_HOME");
      break;
    case CELL_JAIL:
      fprintf(stderr, "CELL TYPE: CELL_JAIL");
      break;
    default:
      fprintf(stderr, "CELL TYPE: UNKWOWN");
      break;
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "CELL TURF: %d",cell->turf+1);
  fprintf(stderr, "\n");
  switch(cell->cell_state)
  {
    case CELLSTATE_EMPTY:
      fprintf(stderr, "CELLSTATE: EMPTY");
      break;
    case CELLSTATE_HOLDING:
      fprintf(stderr, "CELLSTATE: HOLDING");
      break;
    case CELLSTATE_OCCUPIED:
      fprintf(stderr, "CELLSTATE: OCCUPIED\n");
      break;
    case CELLSTATE_OCCUPIED_HOLDING:
      fprintf(stderr, "CELLSTATE: OCCUPIED AND HOLDING");
      break;
    default:
      fprintf(stderr, "CELLSTATE: UNKWOWN");
      break;
  }
  fprintf(stderr, "\n");
}

canonical_original_code:
extern void cell_dump(struct CellStruct *cell)
{
  fprintf(stderr, "\n");
  fprintf(stderr, "COLUMN - (x) - %d \n",cell->pos.x);
  fprintf(stderr, "ROW    - (y) - %d \n",cell->pos.y);
  switch(cell->type)
  {
    case CELL_WALL:
      fprintf(stderr, "CELL TYPE: CELL_WALL");
      break;
    case CELL_FLOOR:
      fprintf(stderr, "CELL TYPE: CELL_FLOOR");
      break;
    case CELL_HOME:
      fprintf(stderr, "CELL TYPE: CELL_HOME");
      break;
    case CELL_JAIL:
      fprintf(stderr, "CELL TYPE: CELL_JAIL");
      break;
    default:
      fprintf(stderr, "CELL TYPE: UNKWOWN");
      break;
  }
  fprintf(stderr, "\n");
  fprintf(stderr, "CELL TURF: %d",cell->turf+1);
  fprintf(stderr, "\n");
  switch(cell->cell_state)
  {
    case CELLSTATE_EMPTY:
      fprintf(stderr, "CELLSTATE: EMPTY");
      break;
    case CELLSTATE_HOLDING:
      fprintf(stderr, "CELLSTATE: HOLDING");
      break;
    case CELLSTATE_OCCUPIED:
      fprintf(stderr, "CELLSTATE: OCCUPIED\n");
      break;
    case CELLSTATE_OCCUPIED_HOLDING:
      fprintf(stderr, "CELLSTATE: OCCUPIED AND HOLDING");
      break;
    default:
      fprintf(stderr, "CELLSTATE: UNKWOWN");
      break;
  }
  fprintf(stderr, "\n");
}

variable_types: 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 { 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; } *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; struct Object *object; union pthread_mutex_t lock; unsigned int thread; } *


decompiled_code:
int __fastcall proto_dump_mt(unsigned int a1)
{
int result; // eax

switch ( a1 )
{
case 0u:
result = fwrite("PROTO_MT_REQ_BASE_RESERVED_FIRST", 1uLL, 0x20uLL, stderr);
break;
case 1u:
result = fwrite("PROTO_MT_REQ_BASE_HELLO", 1uLL, 0x17uLL, stderr);
break;
case 2u:
result = fwrite("PROTO_MT_REQ_BASE_GOODBYE", 1uLL, 0x19uLL, stderr);
break;
case 3u:
result = fwrite("PROTO_MT_REQ_ACTION", 1uLL, 0x13uLL, stderr);
break;
case 4u:
result = fwrite("PROTO_MT_REQ_SYNC", 1uLL, 0x11uLL, stderr);
break;
case 5u:
result = fwrite("PROTO_MT_REQ_BASE_RESERVED_LAST", 1uLL, 0x1FuLL, stderr);
break;
case 6u:
result = fwrite("PROTO_MT_REP_BASE_RESERVED_FIRST", 1uLL, 0x20uLL, stderr);
break;
case 7u:
result = fwrite("PROTO_MT_REP_BASE_HELLO", 1uLL, 0x17uLL, stderr);
break;
case 8u:
result = fwrite("PROTO_MT_REP_BASE_GOODBYE", 1uLL, 0x19uLL, stderr);
break;
case 9u:
result = fwrite("PROTO_MT_REP_ACTION", 1uLL, 0x13uLL, stderr);
break;
case 0xAu:
result = fwrite("PROTO_MT_REP_SYNC", 1uLL, 0x11uLL, stderr);
break;
case 0xBu:
result = fwrite("PROTO_MT_REP_BASE_RESERVED_LAST", 1uLL, 0x1FuLL, stderr);
break;
case 0xCu:
case 0xEu:
result = fwrite("PROTO_MT_EVENT_BASE_RESERVED_LAST", 1uLL, 0x21uLL, stderr);
break;
case 0xDu:
result = fwrite("PROTO_MT_EVENT_BASE_UPDATE", 1uLL, 0x1AuLL, stderr);
break;
default:
result = fprintf(stderr, "UNKNOWN=%d", a1);
break;
}
return result;
}

canonical_decompiled_code:
int __fastcall func5(unsigned int a1)
{
int result; // eax

switch ( a1 )
{
case 0u:
result = fwrite("PROTO_MT_REQ_BASE_RESERVED_FIRST", 1uLL, 0x20uLL, stderr);
break;
case 1u:
result = fwrite("PROTO_MT_REQ_BASE_HELLO", 1uLL, 0x17uLL, stderr);
break;
case 2u:
result = fwrite("PROTO_MT_REQ_BASE_GOODBYE", 1uLL, 0x19uLL, stderr);
break;
case 3u:
result = fwrite("PROTO_MT_REQ_ACTION", 1uLL, 0x13uLL, stderr);
break;
case 4u:
result = fwrite("PROTO_MT_REQ_SYNC", 1uLL, 0x11uLL, stderr);
break;
case 5u:
result = fwrite("PROTO_MT_REQ_BASE_RESERVED_LAST", 1uLL, 0x1FuLL, stderr);
break;
case 6u:
result = fwrite("PROTO_MT_REP_BASE_RESERVED_FIRST", 1uLL, 0x20uLL, stderr);
break;
case 7u:
result = fwrite("PROTO_MT_REP_BASE_HELLO", 1uLL, 0x17uLL, stderr);
break;
case 8u:
result = fwrite("PROTO_MT_REP_BASE_GOODBYE", 1uLL, 0x19uLL, stderr);
break;
case 9u:
result = fwrite("PROTO_MT_REP_ACTION", 1uLL, 0x13uLL, stderr);
break;
case 0xAu:
result = fwrite("PROTO_MT_REP_SYNC", 1uLL, 0x11uLL, stderr);
break;
case 0xBu:
result = fwrite("PROTO_MT_REP_BASE_RESERVED_LAST", 1uLL, 0x1FuLL, stderr);
break;
case 0xCu:
case 0xEu:
result = fwrite("PROTO_MT_EVENT_BASE_RESERVED_LAST", 1uLL, 0x21uLL, stderr);
break;
case 0xDu:
result = fwrite("PROTO_MT_EVENT_BASE_UPDATE", 1uLL, 0x1AuLL, stderr);
break;
default:
result = fprintf(stderr, "UNKNOWN=%d", a1);
break;
}
return result;
}

original_code:
extern void
proto_dump_mt(Proto_Msg_Types type)
{
  switch (type) {
  case PROTO_MT_REQ_BASE_RESERVED_FIRST:
    fprintf(stderr, "PROTO_MT_REQ_BASE_RESERVED_FIRST");
    break;
  case PROTO_MT_REQ_HELLO:
    fprintf(stderr, "PROTO_MT_REQ_BASE_HELLO");
    break;
  case PROTO_MT_REQ_ACTION:
    fprintf(stderr, "PROTO_MT_REQ_ACTION");
    break;
  case PROTO_MT_REQ_SYNC:
    fprintf(stderr, "PROTO_MT_REQ_SYNC");
    break;
  case PROTO_MT_REQ_GOODBYE:
    fprintf(stderr, "PROTO_MT_REQ_BASE_GOODBYE");
    break;
  case PROTO_MT_REQ_BASE_RESERVED_LAST:
    fprintf(stderr, "PROTO_MT_REQ_BASE_RESERVED_LAST");
    break;
  case PROTO_MT_REP_BASE_RESERVED_FIRST:
    fprintf(stderr, "PROTO_MT_REP_BASE_RESERVED_FIRST");
    break;
  case PROTO_MT_REP_HELLO:
    fprintf(stderr, "PROTO_MT_REP_BASE_HELLO");
    break;
  case PROTO_MT_REP_ACTION:
    fprintf(stderr, "PROTO_MT_REP_ACTION");
    break;
  case PROTO_MT_REP_SYNC:
    fprintf(stderr, "PROTO_MT_REP_SYNC");
    break;
  case PROTO_MT_REP_GOODBYE:
    fprintf(stderr, "PROTO_MT_REP_BASE_GOODBYE");
    break;
  case PROTO_MT_REP_BASE_RESERVED_LAST:
    fprintf(stderr, "PROTO_MT_REP_BASE_RESERVED_LAST");
    break;
  case PROTO_MT_EVENT_BASE_RESERVED_FIRST:
    fprintf(stderr, "PROTO_MT_EVENT_BASE_RESERVED_LAST");
    break;
  case PROTO_MT_EVENT_UPDATE:
    fprintf(stderr, "PROTO_MT_EVENT_BASE_UPDATE");
    break;
  case PROTO_MT_EVENT_BASE_RESERVED_LAST:
    fprintf(stderr, "PROTO_MT_EVENT_BASE_RESERVED_LAST");
    break;
  default:
    fprintf(stderr, "UNKNOWN=%d", type);
  }
}

canonical_original_code:
extern void proto_dump_mt(enum Proto_Msg_Types type)
{
  switch (type) {
  case PROTO_MT_REQ_BASE_RESERVED_FIRST:
    fprintf(stderr, "PROTO_MT_REQ_BASE_RESERVED_FIRST");
    break;
  case PROTO_MT_REQ_HELLO:
    fprintf(stderr, "PROTO_MT_REQ_BASE_HELLO");
    break;
  case PROTO_MT_REQ_ACTION:
    fprintf(stderr, "PROTO_MT_REQ_ACTION");
    break;
  case PROTO_MT_REQ_SYNC:
    fprintf(stderr, "PROTO_MT_REQ_SYNC");
    break;
  case PROTO_MT_REQ_GOODBYE:
    fprintf(stderr, "PROTO_MT_REQ_BASE_GOODBYE");
    break;
  case PROTO_MT_REQ_BASE_RESERVED_LAST:
    fprintf(stderr, "PROTO_MT_REQ_BASE_RESERVED_LAST");
    break;
  case PROTO_MT_REP_BASE_RESERVED_FIRST:
    fprintf(stderr, "PROTO_MT_REP_BASE_RESERVED_FIRST");
    break;
  case PROTO_MT_REP_HELLO:
    fprintf(stderr, "PROTO_MT_REP_BASE_HELLO");
    break;
  case PROTO_MT_REP_ACTION:
    fprintf(stderr, "PROTO_MT_REP_ACTION");
    break;
  case PROTO_MT_REP_SYNC:
    fprintf(stderr, "PROTO_MT_REP_SYNC");
    break;
  case PROTO_MT_REP_GOODBYE:
    fprintf(stderr, "PROTO_MT_REP_BASE_GOODBYE");
    break;
  case PROTO_MT_REP_BASE_RESERVED_LAST:
    fprintf(stderr, "PROTO_MT_REP_BASE_RESERVED_LAST");
    break;
  case PROTO_MT_EVENT_BASE_RESERVED_FIRST:
    fprintf(stderr, "PROTO_MT_EVENT_BASE_RESERVED_LAST");
    break;
  case PROTO_MT_EVENT_UPDATE:
    fprintf(stderr, "PROTO_MT_EVENT_BASE_UPDATE");
    break;
  case PROTO_MT_EVENT_BASE_RESERVED_LAST:
    fprintf(stderr, "PROTO_MT_EVENT_BASE_RESERVED_LAST");
    break;
  default:
    fprintf(stderr, "UNKNOWN=%d", type);
  }
}

variable_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 }


decompiled_code:
int __fastcall proto_dump_pstate(unsigned int *a1)
{
unsigned int v1; // ebp
unsigned int v2; // er12
unsigned int v3; // er13
unsigned int v4; // eax

v1 = _bswap_32(*a1);
v2 = _bswap_32(a1[1]);
v3 = _bswap_32(a1[2]);
v4 = _bswap_32(a1[3]);
return fprintf(stderr, "v0=x0%x v1=0x%x v2=0x%x v3=0x%x\n", v1, v2, v3, v4);
}

canonical_decompiled_code:
int __fastcall func6(unsigned int *a1)
{
unsigned int v1; // ebp
unsigned int v2; // er12
unsigned int v3; // er13
unsigned int v4; // eax

v1 = func2(*a1);
v2 = func2(a1[1]);
v3 = func2(a1[2]);
v4 = func2(a1[3]);
return fprintf(stderr, "v0=x0%x v1=0x%x v2=0x%x v3=0x%x\n", v1, v2, v3, v4);
}

original_code:
extern void
proto_dump_pstate(Proto_Player_State *ps)
{
  int v0, v1, v2, v3;
  v0 = ntohl(ps->v0.raw);
  v1 = ntohl(ps->v1.raw);
  v2 = ntohl(ps->v2.raw);
  v3 = ntohl(ps->v3.raw);
  fprintf(stderr, "v0=x0%x v1=0x%x v2=0x%x v3=0x%x\n",
   v0, v1, v2, v3);
}

canonical_original_code:
extern void proto_dump_pstate(struct Proto_Player_State *ps)
{
  int v0; int v1; int v2; int v3;
  v0 = ntohl(ps->v0.raw);
  v1 = ntohl(ps->v1.raw);
  v2 = ntohl(ps->v2.raw);
  v3 = ntohl(ps->v3.raw);
  fprintf(stderr, "v0=x0%x v1=0x%x v2=0x%x v3=0x%x\n",
   v0, v1, v2, v3);
}

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


decompiled_code:
int __fastcall proto_dump_gstate(unsigned int *a1)
{
unsigned int v1; // ebp
unsigned int v2; // er12
unsigned int v3; // eax

v1 = _bswap_32(*a1);
v2 = _bswap_32(a1[1]);
v3 = _bswap_32(a1[2]);
return fprintf(stderr, "v0=0x%x v1=0x%x v2=0x%x\n", v1, v2, v3);
}

canonical_decompiled_code:
int __fastcall func7(unsigned int *a1)
{
unsigned int v1; // ebp
unsigned int v2; // er12
unsigned int v3; // eax

v1 = func2(*a1);
v2 = func2(a1[1]);
v3 = func2(a1[2]);
return fprintf(stderr, "v0=0x%x v1=0x%x v2=0x%x\n", v1, v2, v3);
}

original_code:
extern void
proto_dump_gstate(Proto_Game_State *gs)
{
  int v0, v1, v2;
  v0 = ntohl(gs->v0.raw);
  v1 = ntohl(gs->v1.raw);
  v2 = ntohl(gs->v2.raw);
  fprintf(stderr, "v0=0x%x v1=0x%x v2=0x%x\n",
   v0, v1, v2);
}

canonical_original_code:
extern void proto_dump_gstate(struct Proto_Game_State *gs)
{
  int v0; int v1; int v2;
  v0 = ntohl(gs->v0.raw);
  v1 = ntohl(gs->v1.raw);
  v2 = ntohl(gs->v2.raw);
  fprintf(stderr, "v0=0x%x v1=0x%x v2=0x%x\n",
   v0, v1, v2);
}

variable_types: struct Proto_Game_State { union Proto_GV0 { int raw; } v0; union Proto_GV1 { int raw; } v1; union Proto_GV2 { int raw; } v2; } *


decompiled_code:
int __fastcall proto_dump_msghdr(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned __int64 v3; // rax
unsigned int v4; // eax

v1 = _bswap_32(*(_DWORD *)a1);
fprintf(stderr, "ver=%d type=", v1);
v2 = _bswap_32(*(_DWORD *)(a1 + 4));
proto_dump_mt(v2);
v3 = _fswab64(*(_QWORD *)(a1 + 8));
fprintf(stderr, " sver=%llx", v3);
fwrite(" pstate:", 1uLL, 8uLL, stderr);
proto_dump_pstate((unsigned int *)(a1 + 16));
fwrite(" gstate:", 1uLL, 8uLL, stderr);
proto_dump_gstate((unsigned int *)(a1 + 32));
v4 = _bswap_32(*(_DWORD *)(a1 + 44));
return fprintf(stderr, " blen=%d\n", v4);
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1)
{
unsigned int v1; // eax
unsigned int v2; // eax
unsigned __int64 v3; // rax
unsigned int v4; // eax

v1 = func2(*(_DWORD *)a1);
fprintf(stderr, "ver=%d type=", v1);
v2 = func2(*(_DWORD *)(a1 + 4));
func5(v2);
v3 = func1(*(_QWORD *)(a1 + 8));
fprintf(stderr, " sver=%llx", v3);
fwrite(" pstate:", 1uLL, 8uLL, stderr);
func6((unsigned int *)(a1 + 16));
fwrite(" gstate:", 1uLL, 8uLL, stderr);
func7((unsigned int *)(a1 + 32));
v4 = func2(*(_DWORD *)(a1 + 44));
return fprintf(stderr, " blen=%d\n", v4);
}

canonical_original_code:
extern void proto_dump_msghdr(struct Proto_Msg_Hdr *hdr)
{
  fprintf(stderr, "ver=%d type=", ntohl(hdr->version));
  proto_dump_mt(ntohl(hdr->type));
  fprintf(stderr, " sver=%llx", (__builtin_constant_p((__u64)((__u64)(__be64)(hdr->sver.raw))) ? ((__u64)( (((__u64)((__u64)(__be64)(hdr->sver.raw)) & (unsigned long long)0x00000000000000ffULL) << 56) | (((__u64)((__u64)(__be64)(hdr->sver.raw)) & (unsigned long long)0x000000000000ff00ULL) << 40) | (((__u64)((__u64)(__be64)(hdr->sver.raw)) & (unsigned long long)0x0000000000ff0000ULL) << 24) | (((__u64)((__u64)(__be64)(hdr->sver.raw)) & (unsigned long long)0x00000000ff000000ULL) << 8) | (((__u64)((__u64)(__be64)(hdr->sver.raw)) & (unsigned long long)0x000000ff00000000ULL) >> 8) | (((__u64)((__u64)(__be64)(hdr->sver.raw)) & (unsigned long long)0x0000ff0000000000ULL) >> 24) | (((__u64)((__u64)(__be64)(hdr->sver.raw)) & (unsigned long long)0x00ff000000000000ULL) >> 40) | (((__u64)((__u64)(__be64)(hdr->sver.raw)) & (unsigned long long)0xff00000000000000ULL) >> 56))) : __fswab64((__u64)(__be64)(hdr->sver.raw))));
  fprintf(stderr, " pstate:");
  proto_dump_pstate(&(hdr->pstate));
  fprintf(stderr, " gstate:");
  proto_dump_gstate(&(hdr->gstate));
  fprintf(stderr, " blen=%d\n", ntohl(hdr->blen));
}

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


decompiled_code:
__int64 proto_debug()
{
return PROTO_DEBUG;
}

canonical_decompiled_code:
__int64 func0()
{
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; }