decompiled_code:
int __fastcall Server_shutdown(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

*(_BYTE *)(a1 + 56) = 0;
if ( *(int *)(a1 + 152) > 0 )
{
v1 = 0LL;
do
Player_disconnect(*(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v1++), "Server shutting down!");
while ( *(_DWORD *)(a1 + 152) > (int)v1 );
}
result = close(*(_DWORD *)(a1 + 248));
if ( *(_QWORD *)(a1 + 232) )
result = Map_write(*(_QWORD *)(a1 + 224));
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1)
{
__int64 v1; // rbx
int result; // eax

*(_BYTE *)(a1 + 56) = 0;
if ( *(int *)(a1 + 152) > 0 )
{
v1 = 0LL;
do
Player_disconnect(*(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v1++), "Server shutting down!");
while ( *(_DWORD *)(a1 + 152) > (int)v1 );
}
result = close(*(_DWORD *)(a1 + 248));
if ( *(_QWORD *)(a1 + 232) )
result = Map_write(*(_QWORD *)(a1 + 224));
return result;
}

original_code:
void Server_shutdown(Server *server){
    server->is_running = 0;
    int i;
    for(i=0; i < server->num_players; i++){
 Player_disconnect(server->players[i], "Server shutting down!");
    }
    close(server->distributor_socket);
    if (server->filename != ((void *)0)){
 Map_write(server->map, server->filename);
    }
}

canonical_original_code:
void Server_shutdown(struct Server *server){
    server->is_running = 0;
    int i;
    for(i=0; i < server->num_players; i++){
 Player_disconnect(server->players[i], "Server shutting down!");
    }
    close(server->distributor_socket);
    if (server->filename != ((void *)0)){
 Map_write(server->map, server->filename);
    }
}


repo: SpenceSellers/microMC

decompiled_code:
__int64 __fastcall Server_change_block(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v5; // er12
unsigned int v6; // er13
unsigned int v7; // er14
__int64 result; // rax
__int64 v9; // rbx

v5 = a3;
v6 = a4;
v7 = a5;
logfmt(3LL, "Block is being changed: %d %d %d", a3, a4, a5);
result = Map_set_block(*(_QWORD *)(a1 + 224), a2, v5, v6, v7);
if ( *(int *)(a1 + 152) > 0 )
{
v9 = 0LL;
do
result = Player_send_block_change(*(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v9++), a2, v5, v6, v7);
while ( *(_DWORD *)(a1 + 152) > (int)v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v5; // er12
unsigned int v6; // er13
unsigned int v7; // er14
__int64 result; // rax
__int64 v9; // rbx

v5 = a3;
v6 = a4;
v7 = a5;
logfmt(3LL, "Block is being changed: %d %d %d", a3, a4, a5);
result = Map_set_block(*(_QWORD *)(a1 + 224), a2, v5, v6, v7);
if ( *(int *)(a1 + 152) > 0 )
{
v9 = 0LL;
do
result = Player_send_block_change(*(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v9++), a2, v5, v6, v7);
while ( *(_DWORD *)(a1 + 152) > (int)v9 );
}
return result;
}

original_code:
void Server_change_block(Server *server, Block b, int x, int y, int z){
    logfmt(3, "Block is being changed: %d %d %d", x, y, z);
    Map_set_block(server->map, b, x, y, z);
    int i;
    for (i=0; i < server->num_players; i++){
 Player_send_block_change(server->players[i], b, x, y, z);
    }
}

canonical_original_code:
void Server_change_block(struct Server *server, struct Block b, int x, int y, int z){
    logfmt(3, "Block is being changed: %d %d %d", x, y, z);
    Map_set_block(server->map, b, x, y, z);
    int i;
    for (i=0; i < server->num_players; i++){
 Player_send_block_change(server->players[i], b, x, y, z);
    }
}

variable_types: struct Server { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } state_lock; char is_running; long time; int last_entity_id; int spawnx; int spawny; int spawnz; unsigned long max_players; union pthread_rwlock_t players_lock; int num_players; struct Player { union pthread_rwlock_t lock; char *username; int entity_id; int socket; struct Inventory { unsigned long size; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } **slots; } *inventory; int held_slot_num; double x; double y; double z; float yaw; float pitch; double last_x; double last_y; double last_z; } **players; union pthread_rwlock_t map_lock; struct Map { unsigned long xchunks; unsigned long zchunks; struct Chunk { struct Block { unsigned char id; unsigned char metadata; } blocks[-1]; char biome_data[-1]; } **chunks; } *map; char *filename; unsigned long distributor_thread; int distributor_socket; } *

variable_types:
b
struct Block

variable_types: x int

variable_types: y int

variable_types: z int

variable_types: i int

return_type: void

user_defined_types: struct Server { union pthread_rwlock_t state_lock; char is_running; long time; int last_entity_id; int spawnx; int spawny; int spawnz; unsigned long max_players; union pthread_rwlock_t players_lock; int num_players; struct Player **players; union pthread_rwlock_t map_lock; struct Map *map; char *filename; unsigned long distributor_thread; int distributor_socket; }

user_defined_types: union pthread_rwlock_t { struct __pthread_rwlock_arch_t __data; char __size[56]; long __align; }

user_defined_types: struct Map { unsigned long xchunks; unsigned long zchunks; struct Chunk **chunks; }

user_defined_types: struct Player { union pthread_rwlock_t lock; char *username; int entity_id; int socket; struct Inventory *inventory; int held_slot_num; double x; double y; double z; float yaw; float pitch; double last_x; double last_y; double last_z; }

user_defined_types: struct Inventory { unsigned long size; struct Slot **slots; }

user_defined_types: struct Chunk { struct Block blocks[-1]; char biome_data[-1]; }


decompiled_code:
__int64 __fastcall Server_tell_all(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 152) > 0 )
{
v2 = 0LL;
do
result = Player_send_message(*(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v2++), a2);
while ( *(_DWORD *)(a1 + 152) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v2; // rbx
__int64 result; // rax

if ( *(int *)(a1 + 152) > 0 )
{
v2 = 0LL;
do
result = Player_send_message(*(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v2++), a2);
while ( *(_DWORD *)(a1 + 152) > (int)v2 );
}
return result;
}

original_code:
void Server_tell_all(Server *server, char *message){
    int i;
    for (i=0; i < server->num_players; i++){
 Player_send_message(server->players[i], message);
    }
}

canonical_original_code:
void Server_tell_all(struct Server *server, char *message){
    int i;
    for (i=0; i < server->num_players; i++){
 Player_send_message(server->players[i], message);
    }
}

variable_types:
message
char *

user_defined_types: struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; }

user_defined_types: struct Block { unsigned char id; unsigned char metadata; }

user_defined_types: struct Slot { short id; char count; short damage; short nbt_len; char *nbt; }


decompiled_code:
__int64 __fastcall Server_add_player(__int64 a1, __int64 a2)
{
int v3; // eax
int v4; // eax
__int64 v5; // rbx
__int64 v7; // rdi
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

logmsg(3LL, "Adding new player to the server.");
if ( Server_is_full(a1) )
return logmsg(1LL, "Attempted to add more players than is allowed!");
v3 = *(_DWORD *)(a1 + 72) + 1;
*(_DWORD *)(a1 + 72) = v3;
*(_DWORD *)(a2 + 64) = v3;
*(_QWORD *)(*(_QWORD *)(a1 + 160) + 8LL * *(int *)(a1 + 152)) = a2;
v4 = *(_DWORD *)(a1 + 152) + 1;
*(_DWORD *)(a1 + 152) = v4;
if ( v4 > 0 )
{
v5 = 0LL;
do
{
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v5);
if ( v7 != a2 )
Player_send_new_player(v7, a2);
++v5;
}
while ( *(_DWORD *)(a1 + 152) > (int)v5 );
}
v8[0] = 0;
strcat(v8, *(const char **)(a2 + 56));
strcat(v8, " has joined!");
return Server_tell_all(a1, (__int64)v8);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v3; // eax
int v4; // eax
__int64 v5; // rbx
__int64 v7; // rdi
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

logmsg(3LL, "Adding new player to the server.");
if ( func2(a1) )
return logmsg(1LL, "Attempted to add more players than is allowed!");
v3 = *(_DWORD *)(a1 + 72) + 1;
*(_DWORD *)(a1 + 72) = v3;
*(_DWORD *)(a2 + 64) = v3;
*(_QWORD *)(*(_QWORD *)(a1 + 160) + 8LL * *(int *)(a1 + 152)) = a2;
v4 = *(_DWORD *)(a1 + 152) + 1;
*(_DWORD *)(a1 + 152) = v4;
if ( v4 > 0 )
{
v5 = 0LL;
do
{
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v5);
if ( v7 != a2 )
Player_send_new_player(v7, a2);
++v5;
}
while ( *(_DWORD *)(a1 + 152) > (int)v5 );
}
v8[0] = 0;
strcat(v8, *(const char **)(a2 + 56));
strcat(v8, " has joined!");
return func8(a1, (__int64)v8);
}

original_code:
void Server_add_player(Server *server, Player *player){
    logmsg(3, "Adding new player to the server.");
    if (Server_is_full(server)) {
 logmsg(1, "Attempted to add more players than is allowed!");
 return;
    }
    player->entity_id = ++server->last_entity_id;
    server->players[server->num_players] = player;
    server->num_players++;
    int i;
    for (i=0; i < server->num_players; i++){
 if (server->players[i] == player) continue;
 Player_send_new_player(server->players[i], player);
    }
    char msgbuffer[256];
    msgbuffer[0] = 0;
    strcat(msgbuffer, player->username);
    strcat(msgbuffer, " has joined!");
    Server_tell_all(server, msgbuffer);
}

canonical_original_code:
void Server_add_player(struct Server *server, struct Player *player){
    logmsg(3, "Adding new player to the server.");
    if (Server_is_full(server)) {
 logmsg(1, "Attempted to add more players than is allowed!");
 return;
    }
    player->entity_id = ++server->last_entity_id;
    server->players[server->num_players] = player;
    server->num_players++;
    int i;
    for (i=0; i < server->num_players; i++){
 if (server->players[i] == player) continue;
 Player_send_new_player(server->players[i], player);
    }
    char msgbuffer[256];
    msgbuffer[0] = 0;
    strcat(msgbuffer, player->username);
    strcat(msgbuffer, " has joined!");
    Server_tell_all(server, msgbuffer);
}

variable_types:
player
struct Player *

variable_types:
msgbuffer
char [256]


decompiled_code:
__int64 __fastcall Server_remove_player(__int64 a1, __int64 a2)
{
int v2; // ecx
int v3; // eax
__int64 v4; // rdx
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

logfmt(2LL, "Removing Player: %s from server.", *(const char **)(a2 + 56));
v2 = get_index_of_player(a1, a2);
v3 = *(_DWORD *)(a1 + 152) - 1;
if ( v2 < v3 )
{
v4 = 8LL * v2 + 8;
do
{
*(_QWORD *)(*(_QWORD *)(a1 + 160) + v4 - 8) = *(_QWORD *)(*(_QWORD *)(a1 + 160) + v4);
++v2;
v3 = *(_DWORD *)(a1 + 152) - 1;
v4 += 8LL;
}
while ( v3 > v2 );
}
*(_DWORD *)(a1 + 152) = v3;
logmsg(3LL, "Done removing player.");
v6[0] = 0;
strcat(v6, *(const char **)(a2 + 56));
strcat(v6, " has quit.");
return Server_tell_all(a1, (__int64)v6);
}

original_code:
void Server_remove_player(Server *server, Player *player){
    logfmt(2, "Removing Player: %s from server.", player->username);
    int index = get_index_of_player(server, player);
    int i;
    for(i = index; i < server->num_players - 1; i++){
 server->players[i] = server->players[i+1];
    }
    server->num_players -= 1;
    logmsg(3, "Done removing player.");
    char msgbuffer[256];
    msgbuffer[0] = 0;
    strcat(msgbuffer, player->username);
    strcat(msgbuffer, " has quit.");
    Server_tell_all(server, msgbuffer);
}

canonical_original_code:
void Server_remove_player(struct Server *server, struct Player *player){
    logfmt(2, "Removing Player: %s from server.", player->username);
    int index = get_index_of_player(server, player);
    int i;
    for(i = index; i < server->num_players - 1; i++){
 server->players[i] = server->players[i+1];
    }
    server->num_players -= 1;
    logmsg(3, "Done removing player.");
    char msgbuffer[256];
    msgbuffer[0] = 0;
    strcat(msgbuffer, player->username);
    strcat(msgbuffer, " has quit.");
    Server_tell_all(server, msgbuffer);
}

variable_types: index int


decompiled_code:
__int64 __fastcall Slot_encoded_size(__int64 a1)
{
__int16 v1; // ax

v1 = *(_WORD *)(a1 + 6);
if ( v1 == -1 )
v1 = 0;
return v1 + 7LL;
}

original_code:
size_t Slot_encoded_size(Slot *slot){
    size_t nbtlen = slot->nbt_len == -1 ? 0 : slot->nbt_len;
    return 2 + 1 + 2 + 2 + nbtlen;
}

canonical_original_code:
unsigned long Slot_encoded_size(struct Slot *slot){
    unsigned long nbtlen = slot->nbt_len == -1 ? 0 : slot->nbt_len;
    return 2 + 1 + 2 + 2 + nbtlen;
}

variable_types: struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } *

variable_types:
nbtlen
unsigned long

return_type: unsigned long


decompiled_code:
void __fastcall Slot_free(void *ptr)
{
if ( *((_WORD *)ptr + 3) != 0xFFFF )
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( *((_WORD *)ptr + 3) != 0xFFFF )
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Slot_free(Slot *slot){
    if (slot->nbt_len != -1) free(slot->nbt);
    free(slot);
}

canonical_original_code:
void Slot_free(struct Slot *slot){
    if (slot->nbt_len != -1) free(slot->nbt);
    free(slot);
}


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

result = 1;
if ( *(_WORD *)a1 != 0xFFFF )
result = *(_BYTE *)(a1 + 2) <= 0;
return result;
}

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

result = 1;
if ( *(_WORD *)a1 != 0xFFFF )
result = *(_BYTE *)(a1 + 2) <= 0;
return result;
}

original_code:
char Slot_is_empty(Slot *slot){
    if (slot->id == -1) return 1;
    if (slot->count <= 0) return 1;
    return 0;
}

canonical_original_code:
char Slot_is_empty(struct Slot *slot){
    if (slot->id == -1) return 1;
    if (slot->count <= 0) return 1;
    return 0;
}

return_type: char


decompiled_code:
_BYTE *Slot_new_empty()
{
_BYTE *result; // rax

result = malloc(0x10uLL);
*(_WORD *)result = -1;
result[2] = 0;
*((_WORD *)result + 2) = 0;
*((_WORD *)result + 3) = -1;
*((_QWORD *)result + 1) = 0LL;
return result;
}

canonical_decompiled_code:
_BYTE *func3()
{
_BYTE *result; // rax

result = malloc(0x10uLL);
*(_WORD *)result = -1;
result[2] = 0;
*((_WORD *)result + 2) = 0;
*((_WORD *)result + 3) = -1;
*((_QWORD *)result + 1) = 0LL;
return result;
}

original_code:
Slot * Slot_new_empty(){
    Slot *slot = malloc(sizeof(Slot));
    slot->id = -1;
    slot->count = 0;
    slot->damage = 0;
    slot->nbt_len = -1;
    slot->nbt = ((void *)0);
    return slot;
}

canonical_original_code:
struct Slot *Slot_new_empty(){
    struct Slot *slot = malloc(sizeof(Slot));
    slot->id = -1;
    slot->count = 0;
    slot->damage = 0;
    slot->nbt_len = -1;
    slot->nbt = ((void *)0);
    return slot;
}

return_type: struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } *


decompiled_code:
char *__fastcall Slot_encode(const void **a1, __int64 *a2)
{
__int16 v3; // di
char *v4; // r12
__int64 v5; // rbp
__int64 v6; // rbp
__int64 v7; // rbp
__int64 v8; // rbp
__int16 v9; // ax
_BYTE *v11; // rbx
__int64 v12; // r14

logmsg(3LL, "Encoding slot.");
if ( a1 )
{
if ( Slot_is_empty((__int64)a1) )
{
v4 = (char *)malloc(2uLL);
*a2 = write_short((unsigned int)*(__int16 *)a1, v4);
}
else
{
v3 = *((_WORD *)a1 + 3);
if ( v3 == -1 )
v4 = (char *)malloc(7uLL);
else
v4 = (char *)malloc(v3 + 7);
v5 = write_short((unsigned int)*(__int16 *)a1, v4);
v6 = write_char((unsigned int)*((char *)a1 + 2), &v4[v5]) + v5;
v7 = write_short((unsigned int)*((__int16 *)a1 + 2), &v4[v6]) + v6;
v8 = write_short((unsigned int)*((__int16 *)a1 + 3), &v4[v7]) + v7;
v9 = *((_WORD *)a1 + 3);
if ( v9 != -1 )
{
v12 = v9;
memcpy(&v4[v8], a1[1], v9);
v8 += v12;
}
*a2 = v8;
}
}
else
{
v11 = Slot_new_empty();
v4 = (char *)Slot_encode(v11, a2);
Slot_free(v11);
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func4(const void **a1, __int64 *a2)
{
__int16 v3; // di
char *v4; // r12
__int64 v5; // rbp
__int64 v6; // rbp
__int64 v7; // rbp
__int64 v8; // rbp
__int16 v9; // ax
_BYTE *v11; // rbx
__int64 v12; // r14

logmsg(3LL, "Encoding slot.");
if ( a1 )
{
if ( func2((__int64)a1) )
{
v4 = (char *)malloc(2uLL);
*a2 = write_short((unsigned int)*(__int16 *)a1, v4);
}
else
{
v3 = *((_WORD *)a1 + 3);
if ( v3 == -1 )
v4 = (char *)malloc(7uLL);
else
v4 = (char *)malloc(v3 + 7);
v5 = write_short((unsigned int)*(__int16 *)a1, v4);
v6 = write_char((unsigned int)*((char *)a1 + 2), &v4[v5]) + v5;
v7 = write_short((unsigned int)*((__int16 *)a1 + 2), &v4[v6]) + v6;
v8 = write_short((unsigned int)*((__int16 *)a1 + 3), &v4[v7]) + v7;
v9 = *((_WORD *)a1 + 3);
if ( v9 != -1 )
{
v12 = v9;
memcpy(&v4[v8], a1[1], v9);
v8 += v12;
}
*a2 = v8;
}
}
else
{
v11 = func3();
v4 = (char *)func4(v11, a2);
func1(v11);
}
return v4;
}

original_code:
char * Slot_encode(Slot *slot, size_t *len){
    logmsg(3, "Encoding slot.");
    if (slot == ((void *)0)){
 Slot *emptyslot = Slot_new_empty();
        char *data = Slot_encode(emptyslot, len);
 Slot_free(emptyslot);
 return data;
    }
    char *data;
    size_t pos = 0;
    if (Slot_is_empty(slot)){
 data = malloc(sizeof(char) * 2);
 pos += write_short(slot->id, data + pos);
 *len = pos;
 return data;
    }
    if (slot->nbt_len == -1){
 data = malloc(sizeof(char) *
        (2 + 1 + 2 + 2));
    } else {
 data = malloc(sizeof(char) *
        (2 + 1 + 2 + 2 +
         slot->nbt_len));
    }
    pos += write_short(slot->id, data+pos);
    pos += write_char(slot->count, data+pos);
    pos += write_short(slot->damage, data+pos);
    pos += write_short(slot->nbt_len, data+pos);
    if (slot->nbt_len != -1){
 memcpy(data+pos, slot->nbt, slot->nbt_len);
 pos += slot->nbt_len;
    }
    *len = pos;
    return data;
}

canonical_original_code:
char *Slot_encode(struct Slot *slot, unsigned long *len){
    logmsg(3, "Encoding slot.");
    if (slot == ((void *)0)){
 struct Slot *emptyslot = Slot_new_empty();
        char *data = Slot_encode(emptyslot, len);
 Slot_free(emptyslot);
 return data;
    }
    char *data;
    unsigned long pos = 0;
    if (Slot_is_empty(slot)){
 data = malloc(sizeof(char) * 2);
 pos += write_short(slot->id, data + pos);
 *len = pos;
 return data;
    }
    if (slot->nbt_len == -1){
 data = malloc(sizeof(char) *
        (2 + 1 + 2 + 2));
    } else {
 data = malloc(sizeof(char) *
        (2 + 1 + 2 + 2 +
         slot->nbt_len));
    }
    pos += write_short(slot->id, data+pos);
    pos += write_char(slot->count, data+pos);
    pos += write_short(slot->damage, data+pos);
    pos += write_short(slot->nbt_len, data+pos);
    if (slot->nbt_len != -1){
 memcpy(data+pos, slot->nbt, slot->nbt_len);
 pos += slot->nbt_len;
    }
    *len = pos;
    return data;
}

variable_types:
len
unsigned long *

variable_types:
data
char *

variable_types:
pos
unsigned long

return_type: char *


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

result = 0LL;
if ( *(_WORD *)a1 == *(_WORD *)a2 && *(_WORD *)(a1 + 4) == *(_WORD *)(a2 + 4) )
result = *(char *)(a2 + 2) + *(char *)(a1 + 2) <= 64;
return result;
}

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

result = 0LL;
if ( *(_WORD *)a1 == *(_WORD *)a2 && *(_WORD *)(a1 + 4) == *(_WORD *)(a2 + 4) )
result = *(char *)(a2 + 2) + *(char *)(a1 + 2) <= 64;
return result;
}

original_code:
int Slot_can_add(Slot *slot, Slot *other){
    if (slot->id != other->id) return 0;
    if (slot->damage != other->damage) return 0;
    if (slot->count + other->count > 64) return 0;
    return 1;
}

canonical_original_code:
int Slot_can_add(struct Slot *slot, struct Slot *other){
    if (slot->id != other->id) return 0;
    if (slot->damage != other->damage) return 0;
    if (slot->count + other->count > 64) return 0;
    return 1;
}

variable_types:
other
struct Slot *

return_type: int


decompiled_code:
__int64 __fastcall Slot_add(__int64 a1, unsigned __int16 *a2)
{
__int64 result; // rax
char v3; // dl
char v4; // cl

if ( !a1 || !a2 )
return logmsg(1LL, "Slot_add should not be used with NULL slots!");
result = *a2;
if ( *(_WORD *)a1 == (_WORD)result )
{
result = a2[2];
if ( *(_WORD *)(a1 + 4) == (_WORD)result )
{
v3 = *(_BYTE *)(a1 + 2);
result = (unsigned int)(64 - v3);
v4 = *((_BYTE *)a2 + 2);
if ( v4 > (int)result )
{
*(_BYTE *)(a1 + 2) = 64;
*((_BYTE *)a2 + 2) -= 64 - v3;
}
else
{
*(_BYTE *)(a1 + 2) = v4 + v3;
*((_BYTE *)a2 + 2) = 0;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int16 *a2)
{
__int64 result; // rax
char v3; // dl
char v4; // cl

if ( !a1 || !a2 )
return logmsg(1LL, "Slot_add should not be used with NULL slots!");
result = *a2;
if ( *(_WORD *)a1 == (_WORD)result )
{
result = a2[2];
if ( *(_WORD *)(a1 + 4) == (_WORD)result )
{
v3 = *(_BYTE *)(a1 + 2);
result = (unsigned int)(64 - v3);
v4 = *((_BYTE *)a2 + 2);
if ( v4 > (int)result )
{
*(_BYTE *)(a1 + 2) = 64;
*((_BYTE *)a2 + 2) -= 64 - v3;
}
else
{
*(_BYTE *)(a1 + 2) = v4 + v3;
*((_BYTE *)a2 + 2) = 0;
}
}
}
return result;
}

original_code:
void Slot_add(Slot *slot, Slot *other){
    if (slot == ((void *)0) || other == ((void *)0)){
 logmsg(1, "Slot_add should not be used with NULL slots!");
 return;
    }
    if (slot->id != other->id) return;
    if (slot->damage != other->damage) return;
    int max_added = 64 - slot->count;
    if (other->count <= max_added){
 slot->count += other->count;
 other->count = 0;
    } else {
 slot->count += max_added;
 other->count -= max_added;
    }
}

canonical_original_code:
void Slot_add(struct Slot *slot, struct Slot *other){
    if (slot == ((void *)0) || other == ((void *)0)){
 logmsg(1, "Slot_add should not be used with NULL slots!");
 return;
    }
    if (slot->id != other->id) return;
    if (slot->damage != other->damage) return;
    int max_added = 64 - slot->count;
    if (other->count <= max_added){
 slot->count += other->count;
 other->count = 0;
    } else {
 slot->count += max_added;
 other->count -= max_added;
    }
}


decompiled_code:
__int64 __fastcall Inventory_get(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( *a1 > a2 )
return *(_QWORD *)(a1[1] + 8 * a2);
logmsg(1LL, "Tried to get inventory item of invalid index!");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( *a1 > a2 )
return *(_QWORD *)(a1[1] + 8 * a2);
logmsg(1LL, "Tried to get inventory item of invalid index!");
return 0LL;
}

original_code:
Slot *Inventory_get(Inventory *inv, size_t index){
    if (index >= inv->size || index < 0) {
 logmsg(1, "Tried to get inventory item of invalid index!");
 return ((void *)0);
    }
    return inv->slots[index];
}

canonical_original_code:
struct Slot *Inventory_get(struct Inventory *inv, unsigned long index){
    if (index >= inv->size || index < 0) {
 logmsg(1, "Tried to get inventory item of invalid index!");
 return ((void *)0);
    }
    return inv->slots[index];
}

variable_types: struct Inventory { unsigned long size; struct Slot **slots; } *

variable_types:
index
unsigned long


decompiled_code:
void __fastcall Inventory_free(void *ptr)
{
unsigned __int64 v1; // rbx
void *v2; // rax

if ( *(_QWORD *)ptr )
{
v1 = 0LL;
do
{
v2 = (void *)Inventory_get((unsigned __int64 *)ptr, v1);
if ( v2 )
Slot_free(v2);
++v1;
}
while ( *(_QWORD *)ptr > v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
unsigned __int64 v1; // rbx
void *v2; // rax

if ( *(_QWORD *)ptr )
{
v1 = 0LL;
do
{
v2 = (void *)func8((unsigned __int64 *)ptr, v1);
if ( v2 )
func1(v2);
++v1;
}
while ( *(_QWORD *)ptr > v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void Inventory_free(Inventory *inv){
    for (int i=0; i < inv->size; i++){
 Slot *s = Inventory_get(inv, i);
 if (s != ((void *)0)){
     Slot_free(s);
 }
    }
    free(inv->slots);
    free(inv);
}

canonical_original_code:
void Inventory_free(struct Inventory *inv){
    for (int i = 0; i < inv->size; i++){
 struct Slot *s = Inventory_get(inv, i);
 if (s != ((void *)0)){
     Slot_free(s);
 }
    }
    free(inv->slots);
    free(inv);
}

variable_types: struct Inventory { unsigned long size; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } **slots; } *


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

if ( *a1 - 1 < a3 )
return logmsg(1LL, "Tried to set invalid slot index!");
v4 = (void *)Inventory_get(a1, a3);
if ( v4 )
Slot_free(v4);
result = a1[1];
*(_QWORD *)(result + 8 * a3) = a2;
return result;
}

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

if ( *a1 - 1 < a3 )
return logmsg(1LL, "Tried to set invalid slot index!");
v4 = (void *)func8(a1, a3);
if ( v4 )
func1(v4);
result = a1[1];
*(_QWORD *)(result + 8 * a3) = a2;
return result;
}

original_code:
void Inventory_set(Inventory *inv, Slot *slot, size_t index){
    if (index > inv->size - 1){
 logmsg(1, "Tried to set invalid slot index!");
 return;
    }
    Slot *old = Inventory_get(inv, index);
    if (old != ((void *)0)) Slot_free(old);
    inv->slots[index] = slot;
}

canonical_original_code:
void Inventory_set(struct Inventory *inv, struct Slot *slot, unsigned long index){
    if (index > inv->size - 1){
 logmsg(1, "Tried to set invalid slot index!");
 return;
    }
    struct Slot *old = Inventory_get(inv, index);
    if (old != ((void *)0)) Slot_free(old);
    inv->slots[index] = slot;
}

variable_types:
slot
struct Slot *


decompiled_code:
__int64 __fastcall Inventory_player_add_item(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
__int64 v3; // rax
_BYTE *v5; // rax

v2 = 36LL;
while ( 1 )
{
if ( Slot_is_empty(*(_QWORD *)(a1[1] + 8 * v2)) )
{
v5 = Slot_copy(a2);
Inventory_set(a1, (__int64)v5, v2);
*(_BYTE *)(a2 + 2) = 0;
*(_WORD *)a2 = -1;
return 1LL;
}
v3 = Inventory_get(a1, v2);
Slot_add(v3, (unsigned __int16 *)a2);
if ( Slot_is_empty(a2) )
break;
if ( ++v2 == 45 )
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func11(unsigned __int64 *a1, __int64 a2)
{
unsigned __int64 v2; // rbx
__int64 v3; // rax
_BYTE *v5; // rax

v2 = 36LL;
while ( 1 )
{
if ( func2(*(_QWORD *)(a1[1] + 8 * v2)) )
{
v5 = Slot_copy(a2);
func10(a1, (__int64)v5, v2);
*(_BYTE *)(a2 + 2) = 0;
*(_WORD *)a2 = -1;
return 1LL;
}
v3 = func8(a1, v2);
func6(v3, (unsigned __int16 *)a2);
if ( func2(a2) )
break;
if ( ++v2 == 45 )
return 0LL;
}
return 1LL;
}

original_code:
int Inventory_player_add_item(Inventory *inv, Slot *slot){
    int i;
    for (i=36; i < 45; i++){
 if (Slot_is_empty(inv->slots[i])){
     Inventory_set(inv, Slot_copy(slot), i);
     slot->count = 0;
     slot->id = -1;
     return 1;
 }
        Slot_add(Inventory_get(inv, i), slot);
 if (Slot_is_empty(slot)) return 1;
    }
    return 0;
}

canonical_original_code:
int Inventory_player_add_item(struct Inventory *inv, struct Slot *slot){
    int i;
    for (i=36; i < 45; i++){
 if (Slot_is_empty(inv->slots[i])){
     Inventory_set(inv, Slot_copy(slot), i);
     slot->count = 0;
     slot->id = -1;
     return 1;
 }
        Slot_add(Inventory_get(inv, i), slot);
 if (Slot_is_empty(slot)) return 1;
    }
    return 0;
}


decompiled_code:
void __fastcall Player_free(void *ptr)
{
close(*((_DWORD *)ptr + 17));
free(*((void **)ptr + 7));
Inventory_free(*((_QWORD *)ptr + 9));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
close(*((_DWORD *)ptr + 17));
free(*((void **)ptr + 7));
Inventory_free(*((_QWORD *)ptr + 9));
free(ptr);
}

original_code:
void Player_free(Player *player){
    close(player->socket);
    free(player->username);
    Inventory_free(player->inventory);
    free(player);
}

canonical_original_code:
void Player_free(struct Player *player){
    close(player->socket);
    free(player->username);
    Inventory_free(player->inventory);
    free(player);
}

variable_types: struct Player { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } lock; char *username; int entity_id; int socket; struct Inventory { unsigned long size; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } **slots; } *inventory; int held_slot_num; double x; double y; double z; float yaw; float pitch; double last_x; double last_y; double last_z; } *


decompiled_code:
int __fastcall Player_disconnect(__int64 a1, const char *a2)
{
_QWORD *v2; // rbx
void *v3; // rsi
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(8uLL);
if ( a2 )
*v2 = strdup(a2);
else
*v2 = strdup("Bye!");
v3 = (void *)PacketFFDisconnect_encode(v2, n);
send(*(_DWORD *)(a1 + 68), v3, n[0], 0);
PacketFFDisconnect_free(v2);
free(v3);
return close(*(_DWORD *)(a1 + 68));
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, const char *a2)
{
_QWORD *v2; // rbx
void *v3; // rsi
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(8uLL);
if ( a2 )
*v2 = strdup(a2);
else
*v2 = strdup("Bye!");
v3 = (void *)PacketFFDisconnect_encode(v2, n);
send(*(_DWORD *)(a1 + 68), v3, n[0], 0);
PacketFFDisconnect_free(v2);
free(v3);
return close(*(_DWORD *)(a1 + 68));
}

original_code:
void Player_disconnect(Player *player, char * reason){
    PacketFFDisconnect *disconnect = malloc(sizeof(PacketFFDisconnect));
    if (reason != ((void *)0)){
 disconnect->reason = strdup(reason);
    } else {
 disconnect->reason = strdup("Bye!");
    }
    size_t len;
    char *packet = PacketFFDisconnect_encode(disconnect, &len);
    send(player->socket, packet, len, 0);
    PacketFFDisconnect_free(disconnect);
    free(packet);
    close(player->socket);
}

canonical_original_code:
void Player_disconnect(struct Player *player, char *reason){
    struct PacketFFDisconnect *disconnect = malloc(sizeof(PacketFFDisconnect));
    if (reason != ((void *)0)){
 disconnect->reason = strdup(reason);
    } else {
 disconnect->reason = strdup("Bye!");
    }
    unsigned long len;
    char *packet = PacketFFDisconnect_encode(disconnect, &len);
    send(player->socket, packet, len, 0);
    PacketFFDisconnect_free(disconnect);
    free(packet);
    close(player->socket);
}

variable_types:
reason
char *

variable_types: struct PacketFFDisconnect { char *reason; } *

variable_types:
len
unsigned long

variable_types:
packet
char *


decompiled_code:
void __fastcall Player_send_keep_alive(__int64 a1)
{
void *v1; // rbx
size_t n; // [rsp+0h] [rbp-28h] BYREF
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3[0] = 1;
v1 = (void *)Packet00KeepAlive_encode(v3, &n);
send(*(_DWORD *)(a1 + 68), v1, n, 0);
free(v1);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
void *v1; // rbx
size_t n; // [rsp+0h] [rbp-28h] BYREF
int v3[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v3[0] = 1;
v1 = (void *)Packet00KeepAlive_encode(v3, &n);
send(*(_DWORD *)(a1 + 68), v1, n, 0);
free(v1);
}

original_code:
void Player_send_keep_alive(Player *player){
    Packet00KeepAlive info;
    info.id = 1;
    size_t size;
    char *data = Packet00KeepAlive_encode(&info, &size);
    send(player->socket, data, size, 0);
    free(data);
}

canonical_original_code:
void Player_send_keep_alive(struct Player *player){
    struct Packet00KeepAlive info;
    info.id = 1;
    unsigned long size;
    char *data = Packet00KeepAlive_encode(&info, &size);
    send(player->socket, data, size, 0);
    free(data);
}

variable_types:
info
struct Packet00KeepAlive { int id; }

variable_types:
size
unsigned long


decompiled_code:
void __fastcall Player_send_block_change(__int64 a1, __int16 a2, int a3, char a4, int a5)
{
_BYTE *v8; // rbx
void *v9; // rsi
size_t n[8]; // [rsp+8h] [rbp-40h] BYREF

v8 = malloc(0x10uLL);
*(_DWORD *)v8 = a3;
v8[4] = a4;
*((_DWORD *)v8 + 2) = a5;
*((_WORD *)v8 + 6) = (unsigned __int8)a2;
v8[14] = HIBYTE(a2);
v9 = (void *)Packet35BlockChange_encode(v8, n);
send(*(_DWORD *)(a1 + 68), v9, n[0], 0);
Packet35BlockChange_free(v8);
free(v9);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int16 a2, int a3, char a4, int a5)
{
_BYTE *v8; // rbx
void *v9; // rsi
size_t n[8]; // [rsp+8h] [rbp-40h] BYREF

v8 = malloc(0x10uLL);
*(_DWORD *)v8 = a3;
v8[4] = a4;
*((_DWORD *)v8 + 2) = a5;
*((_WORD *)v8 + 6) = (unsigned __int8)a2;
v8[14] = HIBYTE(a2);
v9 = (void *)Packet35BlockChange_encode(v8, n);
send(*(_DWORD *)(a1 + 68), v9, n[0], 0);
Packet35BlockChange_free(v8);
free(v9);
}

original_code:
void Player_send_block_change(Player *player, Block b, int x, int y, int z){
    Packet35BlockChange *packet = malloc(sizeof(Packet35BlockChange));
    packet->x = x;
    packet->y = y;
    packet->z = z;
    packet->id = b.id;
    packet->metadata = b.metadata;
    size_t len;
    char *data = Packet35BlockChange_encode(packet, &len);
    send(player->socket, data, len, 0);
    Packet35BlockChange_free(packet);
    free(data);
}

canonical_original_code:
void Player_send_block_change(struct Player *player, struct Block b, int x, int y, int z){
    struct Packet35BlockChange *packet = malloc(sizeof(Packet35BlockChange));
    packet->x = x;
    packet->y = y;
    packet->z = z;
    packet->id = b.id;
    packet->metadata = b.metadata;
    unsigned long len;
    char *data = Packet35BlockChange_encode(packet, &len);
    send(player->socket, data, len, 0);
    Packet35BlockChange_free(packet);
    free(data);
}

variable_types: struct Block { unsigned char id; unsigned char metadata; }

variable_types: x int

variable_types: y int

variable_types: z int

variable_types: struct Packet35BlockChange { int x; char y; int z; short id; char metadata; } *


decompiled_code:
__int64 __fastcall Player_send_message(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
void *v3; // rsi
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(8uLL);
*v2 = fake_json_chat(a2);
v3 = (void *)Packet03ChatMessage_encode(v2, n);
send(*(_DWORD *)(a1 + 68), v3, n[0], 0);
free(v3);
return Packet03ChatMessage_free(v2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
void *v3; // rsi
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(8uLL);
*v2 = fake_json_chat(a2);
v3 = (void *)Packet03ChatMessage_encode(v2, n);
send(*(_DWORD *)(a1 + 68), v3, n[0], 0);
free(v3);
return Packet03ChatMessage_free(v2);
}

original_code:
void Player_send_message(Player *player, char *msg){
    Packet03ChatMessage *chatmsg = malloc(sizeof(Packet03ChatMessage));
    chatmsg->str = fake_json_chat(msg);
    size_t len;
    char * packet = Packet03ChatMessage_encode(chatmsg, &len);
    send(player->socket, packet, len, 0);
    free(packet);
    Packet03ChatMessage_free(chatmsg);
}

canonical_original_code:
void Player_send_message(struct Player *player, char *msg){
    struct Packet03ChatMessage *chatmsg = malloc(sizeof(Packet03ChatMessage));
    chatmsg->str = fake_json_chat(msg);
    unsigned long len;
    char *packet = Packet03ChatMessage_encode(chatmsg, &len);
    send(player->socket, packet, len, 0);
    free(packet);
    Packet03ChatMessage_free(chatmsg);
}

variable_types:
msg
char *

variable_types: struct Packet03ChatMessage { char *str; } *


decompiled_code:
void __fastcall Player_set_position(double *a1, double a2, double a3, double a4)
{
a1[11] = a2;
a1[12] = a3;
a1[13] = a4;
}

canonical_decompiled_code:
void __fastcall func5(double *a1, double a2, double a3, double a4)
{
a1[11] = a2;
a1[12] = a3;
a1[13] = a4;
}

original_code:
void Player_set_position(Player *player, double x, double y, double z){
    player->x = x;
    player->y = y;
    player->z = z;
}

canonical_original_code:
void Player_set_position(struct Player *player, double x, double y, double z){
    player->x = x;
    player->y = y;
    player->z = z;
}

variable_types: x double

variable_types: y double

variable_types: z double


decompiled_code:
void __fastcall Player_set_look(__int64 a1, float a2, float a3)
{
*(float *)(a1 + 112) = a2;
*(float *)(a1 + 116) = a3;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, float a2, float a3)
{
*(float *)(a1 + 112) = a2;
*(float *)(a1 + 116) = a3;
}

original_code:
void Player_set_look(Player *player, float yaw, float pitch){
    player->yaw = yaw;
    player->pitch = pitch;
}

canonical_original_code:
void Player_set_look(struct Player *player, float yaw, float pitch){
    player->yaw = yaw;
    player->pitch = pitch;
}

variable_types: struct Player { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } lock; char *username; int entity_id; int socket; struct Inventory { unsigned long size; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } **slots; } *inventory; int held_slot_num; double x; double y; double z; float yaw; float pitch; double last_x; double last_y; double last_z; } *

variable_types: yaw float

variable_types: pitch float


decompiled_code:
void __fastcall Player_send_slot(__int64 a1, __int64 a2, __int16 a3)
{
void *v3; // rbx
size_t n; // [rsp+8h] [rbp-30h] BYREF
char v5[2]; // [rsp+10h] [rbp-28h] BYREF
__int16 v6; // [rsp+12h] [rbp-26h]
__int64 v7; // [rsp+18h] [rbp-20h]

v5[0] = 0;
v6 = a3;
v7 = a2;
v3 = (void *)Packet67SetSlot_encode(v5, &n);
send(*(_DWORD *)(a1 + 68), v3, n, 0);
free(v3);
}

original_code:
void Player_send_slot(Player *player, Slot *slot, short slot_id){
    Packet67SetSlot sets = {.window_id = 0, .slot_id = slot_id, slot};
    size_t slotlen;
    char *dat = Packet67SetSlot_encode(&sets, &slotlen);
    send(player->socket, dat, slotlen, 0);
    free(dat);
}

canonical_original_code:
void Player_send_slot(struct Player *player, struct Slot *slot, short slot_id){
    struct Packet67SetSlot sets = {.window_id = 0, .slot_id = slot_id, slot};
    unsigned long slotlen;
    char *dat = Packet67SetSlot_encode(&sets, &slotlen);
    send(player->socket, dat, slotlen, 0);
    free(dat);
}

variable_types:
slot
struct Slot *

variable_types: struct Packet67SetSlot { char window_id; short slot_id; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } *slot; }

variable_types:
slotlen
unsigned long

variable_types:
dat
char *

user_defined_types: struct Packet67SetSlot { char window_id; short slot_id; struct Slot *slot; }


decompiled_code:
void __fastcall Player_send_new_player(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
void *v3; // rsi
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x28uLL);
*(_DWORD *)v2 = *(_DWORD *)(a2 + 64);
v2[1] = strdup(*(const char **)(a2 + 56));
*((_DWORD *)v2 + 4) = to_fixed_point(*(double *)(a2 + 88));
*((_DWORD *)v2 + 5) = to_fixed_point(*(double *)(a2 + 96));
*((_DWORD *)v2 + 6) = to_fixed_point(*(double *)(a2 + 104));
*((_BYTE *)v2 + 28) = 0;
*((_BYTE *)v2 + 29) = 0;
*((_WORD *)v2 + 15) = 0;
*((_BYTE *)v2 + 32) = 31;
v3 = (void *)Packet14SpawnNamedEntity_encode(v2, n);
send(*(_DWORD *)(a1 + 68), v3, n[0], 0);
Packet14SpawnNamedEntity_free(v2);
free(v3);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, __int64 a2)
{
_QWORD *v2; // rbx
void *v3; // rsi
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = malloc(0x28uLL);
*(_DWORD *)v2 = *(_DWORD *)(a2 + 64);
v2[1] = strdup(*(const char **)(a2 + 56));
*((_DWORD *)v2 + 4) = to_fixed_point(*(double *)(a2 + 88));
*((_DWORD *)v2 + 5) = to_fixed_point(*(double *)(a2 + 96));
*((_DWORD *)v2 + 6) = to_fixed_point(*(double *)(a2 + 104));
*((_BYTE *)v2 + 28) = 0;
*((_BYTE *)v2 + 29) = 0;
*((_WORD *)v2 + 15) = 0;
*((_BYTE *)v2 + 32) = 31;
v3 = (void *)Packet14SpawnNamedEntity_encode(v2, n);
send(*(_DWORD *)(a1 + 68), v3, n[0], 0);
Packet14SpawnNamedEntity_free(v2);
free(v3);
}

original_code:
void Player_send_new_player(Player *player, Player *newplayer){
    Packet14SpawnNamedEntity *pack = malloc(sizeof(Packet14SpawnNamedEntity));
    pack->id = newplayer->entity_id;
    pack->player_name = strdup(newplayer->username);
    pack->x_fixedp = to_fixed_point(newplayer->x);
    pack->y_fixedp = to_fixed_point(newplayer->y);
    pack->z_fixedp = to_fixed_point(newplayer->z);
    pack->yaw = 0;
    pack->pitch = 0;
    pack->held_item = 0;
    pack->metadata = 0x1F;
    size_t len;
    char *packet = Packet14SpawnNamedEntity_encode(pack, &len);
    send(player->socket, packet, len, 0);
    Packet14SpawnNamedEntity_free(pack);
    free(packet);
}

canonical_original_code:
void Player_send_new_player(struct Player *player, struct Player *newplayer){
    struct Packet14SpawnNamedEntity *pack = malloc(sizeof(Packet14SpawnNamedEntity));
    pack->id = newplayer->entity_id;
    pack->player_name = strdup(newplayer->username);
    pack->x_fixedp = to_fixed_point(newplayer->x);
    pack->y_fixedp = to_fixed_point(newplayer->y);
    pack->z_fixedp = to_fixed_point(newplayer->z);
    pack->yaw = 0;
    pack->pitch = 0;
    pack->held_item = 0;
    pack->metadata = 0x1F;
    unsigned long len;
    char *packet = Packet14SpawnNamedEntity_encode(pack, &len);
    send(player->socket, packet, len, 0);
    Packet14SpawnNamedEntity_free(pack);
    free(packet);
}

variable_types:
newplayer
struct Player *

variable_types: struct Packet14SpawnNamedEntity { int id; char *player_name; int x_fixedp; int y_fixedp; int z_fixedp; char yaw; char pitch; short held_item; char metadata; } *

variable_types:
len
unsigned long

variable_types:
packet
char *


decompiled_code:
void __fastcall Player_send_inventory_update(__int64 a1)
{
void *v1; // rbx
size_t n; // [rsp+8h] [rbp-30h] BYREF
char v3[8]; // [rsp+10h] [rbp-28h] BYREF
__int64 v4; // [rsp+18h] [rbp-20h]

v3[0] = 0;
v4 = *(_QWORD *)(a1 + 72);
v1 = (void *)Packet68SetWindowItems_encode(v3, &n);
send(*(_DWORD *)(a1 + 68), v1, n, 0);
free(v1);
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
void *v1; // rbx
size_t n; // [rsp+8h] [rbp-30h] BYREF
char v3[8]; // [rsp+10h] [rbp-28h] BYREF
__int64 v4; // [rsp+18h] [rbp-20h]

v3[0] = 0;
v4 = *(_QWORD *)(a1 + 72);
v1 = (void *)Packet68SetWindowItems_encode(v3, &n);
send(*(_DWORD *)(a1 + 68), v1, n, 0);
free(v1);
}

original_code:
void Player_send_inventory_update(Player *player){
    Packet68SetWindowItems setwi;
    setwi.window_id = 0;
    setwi.inv = player->inventory;
    size_t len;
    char *pack = Packet68SetWindowItems_encode(&setwi, &len);
    send(player->socket, pack, len, 0);
    free(pack);
}

canonical_original_code:
void Player_send_inventory_update(struct Player *player){
    struct Packet68SetWindowItems setwi;
    setwi.window_id = 0;
    setwi.inv = player->inventory;
    unsigned long len;
    char *pack = Packet68SetWindowItems_encode(&setwi, &len);
    send(player->socket, pack, len, 0);
    free(pack);
}

variable_types: struct Packet68SetWindowItems { char window_id; struct Inventory { unsigned long size; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } **slots; } *inv; }

variable_types:
pack
char *

user_defined_types: struct Packet68SetWindowItems { char window_id; struct Inventory *inv; }


decompiled_code:
void __fastcall Player_send_pos_and_look_update(__int64 a1)
{
double *v1; // rbx
double v2; // xmm0_8
void *v3; // rsi
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (double *)malloc(0x30uLL);
*v1 = *(double *)(a1 + 88);
v2 = *(double *)(a1 + 96);
v1[1] = v2 + 1.0;
v1[2] = v2;
v1[3] = *(double *)(a1 + 104);
*((_DWORD *)v1 + 8) = *(_DWORD *)(a1 + 112);
*((_DWORD *)v1 + 9) = *(_DWORD *)(a1 + 116);
*((_BYTE *)v1 + 40) = 1;
v3 = (void *)Packet0DPlayerPositionAndLook_encode(v1, n);
send(*(_DWORD *)(a1 + 68), v3, n[0], 0);
Packet0DPlayerPositionAndLook_free(v1);
free(v3);
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
double *v1; // rbx
double v2; // xmm0_8
void *v3; // rsi
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (double *)malloc(0x30uLL);
*v1 = *(double *)(a1 + 88);
v2 = *(double *)(a1 + 96);
v1[1] = v2 + 1.0;
v1[2] = v2;
v1[3] = *(double *)(a1 + 104);
*((_DWORD *)v1 + 8) = *(_DWORD *)(a1 + 112);
*((_DWORD *)v1 + 9) = *(_DWORD *)(a1 + 116);
*((_BYTE *)v1 + 40) = 1;
v3 = (void *)Packet0DPlayerPositionAndLook_encode(v1, n);
send(*(_DWORD *)(a1 + 68), v3, n[0], 0);
Packet0DPlayerPositionAndLook_free(v1);
free(v3);
}

original_code:
void Player_send_pos_and_look_update(Player *player){
    Packet0DPlayerPositionAndLook *pack =
 malloc(sizeof(Packet0DPlayerPositionAndLook));
    pack->x = player->x;
    pack->y_stance = player->y + 1;
    pack->stance_y = player->y;
    pack->z = player->z;
    pack->yaw = player->yaw;
    pack->pitch = player->pitch;
    pack->on_ground = 1;
    size_t len;
    char *data = Packet0DPlayerPositionAndLook_encode(pack, &len);
    send(player->socket, data, len, 0);
    Packet0DPlayerPositionAndLook_free(pack);
    free(data);
}

canonical_original_code:
void Player_send_pos_and_look_update(struct Player *player){
    struct Packet0DPlayerPositionAndLook *pack = malloc(sizeof(Packet0DPlayerPositionAndLook));
    pack->x = player->x;
    pack->y_stance = player->y + 1;
    pack->stance_y = player->y;
    pack->z = player->z;
    pack->yaw = player->yaw;
    pack->pitch = player->pitch;
    pack->on_ground = 1;
    unsigned long len;
    char *data = Packet0DPlayerPositionAndLook_encode(pack, &len);
    send(player->socket, data, len, 0);
    Packet0DPlayerPositionAndLook_free(pack);
    free(data);
}

variable_types: struct Packet0DPlayerPositionAndLook { double x; double y_stance; double stance_y; double z; float yaw; float pitch; char on_ground; } *

variable_types:
data
char *


decompiled_code:
void __fastcall Player_teleport(double *a1, double a2, double a3, double a4)
{
Player_set_position(a1, a2, a3, a4);
Player_send_pos_and_look_update((__int64)a1);
}

canonical_decompiled_code:
void __fastcall func11(double *a1, double a2, double a3, double a4)
{
func5(a1, a2, a3, a4);
func10((__int64)a1);
}

original_code:
void Player_teleport(Player *player, double x, double y, double z){
    Player_set_position(player, x, y, z);
    Player_send_pos_and_look_update(player);
}

canonical_original_code:
void Player_teleport(struct Player *player, double x, double y, double z){
    Player_set_position(player, x, y, z);
    Player_send_pos_and_look_update(player);
}

variable_types: x double

variable_types: y double


decompiled_code:
void __fastcall Player_set_slot(__int64 a1, __int64 a2, __int16 a3)
{
Inventory_set(*(_QWORD *)(a1 + 72), a2, a3);
Player_send_slot(a1, a2, a3);
}

canonical_decompiled_code:
void __fastcall func14(__int64 a1, __int64 a2, __int16 a3)
{
Inventory_set(*(_QWORD *)(a1 + 72), a2, a3);
func7(a1, a2, a3);
}

original_code:
void Player_set_slot(Player *player, Slot *slot, short slot_id){
    Inventory_set(player->inventory, slot, slot_id);
    Player_send_slot(player, slot, slot_id);
}

canonical_original_code:
void Player_set_slot(struct Player *player, struct Slot *slot, short slot_id){
    Inventory_set(player->inventory, slot, slot_id);
    Player_send_slot(player, slot, slot_id);
}

variable_types: struct Player { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } lock; char *username; int entity_id; int socket; struct Inventory { unsigned long size; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } **slots; } *inventory; int held_slot_num; double x; double y; double z; float yaw; float pitch; double last_x; double last_y; double last_z; } *


decompiled_code:
__int64 __fastcall Player_get_held_slot(__int64 a1)
{
return Inventory_get(*(_QWORD *)(a1 + 72), *(_DWORD *)(a1 + 80) + 36);
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
return Inventory_get(*(_QWORD *)(a1 + 72), *(_DWORD *)(a1 + 80) + 36);
}

original_code:
Slot *Player_get_held_slot(Player *player){
    return Inventory_get(player->inventory, 36 + player->held_slot_num);
}

canonical_original_code:
struct Slot *Player_get_held_slot(struct Player *player){
    return Inventory_get(player->inventory, 36 + player->held_slot_num);
}

variable_types: struct Player { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } lock; char *username; int entity_id; int socket; struct Inventory { unsigned long size; struct Slot **slots; } *inventory; int held_slot_num; double x; double y; double z; float yaw; float pitch; double last_x; double last_y; double last_z; } *


decompiled_code:
__int64 __fastcall Player_place_block(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v5; // ebp
unsigned int v6; // er12
unsigned int v7; // er13
unsigned __int8 *v8; // rbx
__int64 result; // rax

v5 = a3;
v6 = a4;
v7 = a5;
logfmt(3LL, "Player is placing a block at %d %d %d", a3, a4, a5);
v8 = (unsigned __int8 *)Player_get_held_slot(a1);
result = Slot_is_empty(v8);
if ( !(_BYTE)result )
{
result = Server_change_block(a2, *v8, v5, v6, v7);
--v8[2];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v5; // ebp
unsigned int v6; // er12
unsigned int v7; // er13
unsigned __int8 *v8; // rbx
__int64 result; // rax

v5 = a3;
v6 = a4;
v7 = a5;
logfmt(3LL, "Player is placing a block at %d %d %d", a3, a4, a5);
v8 = (unsigned __int8 *)func15(a1);
result = Slot_is_empty(v8);
if ( !(_BYTE)result )
{
result = Server_change_block(a2, *v8, v5, v6, v7);
--v8[2];
}
return result;
}

original_code:
void Player_place_block(Player *player, Server *s, int x, int y, int z){
    logfmt(3, "Player is placing a block at %d %d %d", x, y, z);
    Block block;
    Slot *slot = Player_get_held_slot(player);
    if (Slot_is_empty(slot)) return;
    block.id = slot->id;
    block.metadata = slot->damage;
    Server_change_block(s, block, x, y, z);
    slot->count--;
}

canonical_original_code:
void Player_place_block(struct Player *player, struct Server *s, int x, int y, int z){
    logfmt(3, "Player is placing a block at %d %d %d", x, y, z);
    struct Block block;
    struct Slot *slot = Player_get_held_slot(player);
    if (Slot_is_empty(slot)) return;
    block.id = slot->id;
    block.metadata = slot->damage;
    Server_change_block(s, block, x, y, z);
    slot->count--;
}

variable_types: struct Server { union pthread_rwlock_t state_lock; char is_running; long time; int last_entity_id; int spawnx; int spawny; int spawnz; unsigned long max_players; union pthread_rwlock_t players_lock; int num_players; struct Player **players; union pthread_rwlock_t map_lock; struct Map { unsigned long xchunks; unsigned long zchunks; struct Chunk { struct Block { unsigned char id; unsigned char metadata; } blocks[-1]; char biome_data[-1]; } **chunks; } *map; char *filename; unsigned long distributor_thread; int distributor_socket; } *

variable_types: x int

variable_types: y int

variable_types: z int

variable_types: struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } *


decompiled_code:
void __fastcall Player_give_slot(__int64 a1, _WORD *a2)
{
if ( *a2 )
{
logmsg(3LL, "Giving a player an item.");
Inventory_player_add_item(*(_QWORD *)(a1 + 72), a2);
Player_send_inventory_update(a1);
}
else
{
logmsg(1LL, "Tried to give the player a air block!");
}
}

canonical_decompiled_code:
void __fastcall func17(__int64 a1, _WORD *a2)
{
if ( *a2 )
{
logmsg(3LL, "Giving a player an item.");
Inventory_player_add_item(*(_QWORD *)(a1 + 72), a2);
func9(a1);
}
else
{
logmsg(1LL, "Tried to give the player a air block!");
}
}

original_code:
void Player_give_slot(Player *player, Slot *slot){
    if (slot->id == 0) {
 logmsg(1, "Tried to give the player a air block!");
 return;
    }
    logmsg(3, "Giving a player an item.");
    Inventory_player_add_item(player->inventory, slot);
    Player_send_inventory_update(player);
}

canonical_original_code:
void Player_give_slot(struct Player *player, struct Slot *slot){
    if (slot->id == 0) {
 logmsg(1, "Tried to give the player a air block!");
 return;
    }
    logmsg(3, "Giving a player an item.");
    Inventory_player_add_item(player->inventory, slot);
    Player_send_inventory_update(player);
}

variable_types:
slot
struct Slot *


decompiled_code:
void __fastcall Player_break_block(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int16 v8; // ax
_WORD *v9; // rbx

logmsg(3LL, "Player has broken block!");
v8 = Map_get_block(*(_QWORD *)(a2 + 224), a3, a4, a5);
v9 = (_WORD *)Slot_new_basic((unsigned __int8)v8, 1LL, HIBYTE(v8));
Server_change_block(a2, 0LL, a3, a4, a5);
Player_give_slot(a1, v9);
free(v9);
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1, __int64 a2, unsigned int a3, unsigned int a4, unsigned int a5)
{
__int16 v8; // ax
_WORD *v9; // rbx

logmsg(3LL, "Player has broken block!");
v8 = Map_get_block(*(_QWORD *)(a2 + 224), a3, a4, a5);
v9 = (_WORD *)Slot_new_basic((unsigned __int8)v8, 1LL, HIBYTE(v8));
Server_change_block(a2, 0LL, a3, a4, a5);
func17(a1, v9);
free(v9);
}

original_code:
void Player_break_block(Player *player, Server *s, int x, int y, int z){
    logmsg(3, "Player has broken block!");
    Block air = {.id = 0, .metadata = 0};
    Block b = Map_get_block(s->map, x, y, z);
    Slot *new_item = Slot_new_basic(b.id, 1, b.metadata);
    Server_change_block(s, air, x, y, z);
    Player_give_slot(player, new_item);
    free(new_item);
}

canonical_original_code:
void Player_break_block(struct Player *player, struct Server *s, int x, int y, int z){
    logmsg(3, "Player has broken block!");
    struct Block air = {.id = 0, .metadata = 0};
    struct Block b = Map_get_block(s->map, x, y, z);
    struct Slot *new_item = Slot_new_basic(b.id, 1, b.metadata);
    Server_change_block(s, air, x, y, z);
    Player_give_slot(player, new_item);
    free(new_item);
}

variable_types: struct Block { unsigned char id; unsigned char metadata; }


decompiled_code:
__int64 __fastcall command_kick_me(__int64 a1)
{
return Player_disconnect(a1, "Get outa here!");
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return Player_disconnect(a1, "Get outa here!");
}

original_code:
void command_kick_me(Player *p, Server *s, char *cmd){
    Player_disconnect(p, "Get outa here!");
}

canonical_original_code:
void command_kick_me(struct Player *p, struct Server *s, char *cmd){
    Player_disconnect(p, "Get outa here!");
}

variable_types:
cmd
char *


decompiled_code:
__int64 __fastcall command_give_stuff(pthread_rwlock_t *rwlock)
{
__int64 v1; // rbp

v1 = Slot_new_basic(5LL, 64LL, 0LL);
pthread_rwlock_wrlock(rwlock);
Player_give_slot(rwlock, v1);
pthread_rwlock_unlock(rwlock);
return Slot_free(v1);
}

canonical_decompiled_code:
__int64 __fastcall func1(pthread_rwlock_t *rwlock)
{
__int64 v1; // rbp

v1 = Slot_new_basic(5LL, 64LL, 0LL);
pthread_rwlock_wrlock(rwlock);
Player_give_slot(rwlock, v1);
pthread_rwlock_unlock(rwlock);
return Slot_free(v1);
}

original_code:
void command_give_stuff(Player *p, Server *s, char *cmd){
    Slot *slot = Slot_new_basic(5, 64, 0);
    pthread_rwlock_wrlock(&p->lock);
    Player_give_slot(p, slot);
    pthread_rwlock_unlock(&p->lock);
    Slot_free(slot);
}

canonical_original_code:
void command_give_stuff(struct Player *p, struct Server *s, char *cmd){
    struct Slot *slot = Slot_new_basic(5, 64, 0);
    pthread_rwlock_wrlock(&p->lock);
    Player_give_slot(p, slot);
    pthread_rwlock_unlock(&p->lock);
    Slot_free(slot);
}


decompiled_code:
int __fastcall command_spawn(pthread_rwlock_t *rwlock, int *a2)
{
pthread_rwlock_wrlock(rwlock);
Player_teleport(rwlock, (double)a2[19], (double)a2[20], (double)a2[21]);
return pthread_rwlock_unlock(rwlock);
}

canonical_decompiled_code:
int __fastcall func2(pthread_rwlock_t *rwlock, int *a2)
{
pthread_rwlock_wrlock(rwlock);
Player_teleport(rwlock, (double)a2[19], (double)a2[20], (double)a2[21]);
return pthread_rwlock_unlock(rwlock);
}

original_code:
void command_spawn(Player *p, Server *s, char *cmd){
    pthread_rwlock_wrlock(&p->lock);
    Player_teleport(p, s->spawnx, s->spawny, s->spawnz);
    pthread_rwlock_unlock(&p->lock);
}

canonical_original_code:
void command_spawn(struct Player *p, struct Server *s, char *cmd){
    pthread_rwlock_wrlock(&p->lock);
    Player_teleport(p, s->spawnx, s->spawny, s->spawnz);
    pthread_rwlock_unlock(&p->lock);
}


decompiled_code:
void __fastcall command_item(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
void *v4; // rbp
__int16 v5; // [rsp+4h] [rbp-24h] BYREF
char v6; // [rsp+8h] [rbp-20h] BYREF
__int16 v7; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = _isoc99_sscanf(a3, "%d %d %d", &v7, &v6, &v5);
switch ( v3 )
{
case 1:
v4 = (void *)Slot_new_basic((unsigned int)v7, 64LL, 0LL);
goto LABEL_5;
case 2:
v4 = (void *)Slot_new_basic((unsigned int)v7, (unsigned int)v6, 0LL);
goto LABEL_5;
case 3:
v4 = (void *)Slot_new_basic((unsigned int)v7, (unsigned int)v6, (unsigned int)v5);
LABEL_5:
Player_give_slot(a1, v4);
free(v4);
return;
}
Player_send_message(a1, "Invalid number of arguments!");
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // eax
void *v4; // rbp
__int16 v5; // [rsp+4h] [rbp-24h] BYREF
char v6; // [rsp+8h] [rbp-20h] BYREF
__int16 v7; // [rsp+Ch] [rbp-1Ch] BYREF

v3 = _isoc99_sscanf(a3, "%d %d %d", &v7, &v6, &v5);
switch ( v3 )
{
case 1:
v4 = (void *)Slot_new_basic((unsigned int)v7, 64LL, 0LL);
goto LABEL_5;
case 2:
v4 = (void *)Slot_new_basic((unsigned int)v7, (unsigned int)v6, 0LL);
goto LABEL_5;
case 3:
v4 = (void *)Slot_new_basic((unsigned int)v7, (unsigned int)v6, (unsigned int)v5);
LABEL_5:
Player_give_slot(a1, v4);
free(v4);
return;
}
Player_send_message(a1, "Invalid number of arguments!");
}

original_code:
void command_item(Player *p, Server *s, char *cmd){
    int id;
    int count;
    int metadata;
    int read = sscanf(cmd, "%d %d %d", &id, &count, &metadata);
    Slot *slot;
    if (read == 1){
 slot = Slot_new_basic(id, 64, 0);
    } else if (read == 2){
 slot = Slot_new_basic(id, count, 0);
    } else if (read == 3){
 slot = Slot_new_basic(id, count, metadata);
    } else {
 Player_send_message(p, "Invalid number of arguments!");
 return;
    }
    Player_give_slot(p, slot);
    free(slot);
}

canonical_original_code:
void command_item(struct Player *p, struct Server *s, char *cmd){
    int id;
    int count;
    int metadata;
    int read = sscanf(cmd, "%d %d %d", &id, &count, &metadata);
    struct Slot *slot;
    if (read == 1){
 slot = Slot_new_basic(id, 64, 0);
    } else if (read == 2){
 slot = Slot_new_basic(id, count, 0);
    } else if (read == 3){
 slot = Slot_new_basic(id, count, metadata);
    } else {
 Player_send_message(p, "Invalid number of arguments!");
 return;
    }
    Player_give_slot(p, slot);
    free(slot);
}

variable_types: id int

variable_types: count int

variable_types: metadata int

variable_types: read int


decompiled_code:
void __fastcall handle_command(pthread_rwlock_t *rwlock, int *a2, char *a3)
{
char *v3; // rax
char *save_ptr; // [rsp+8h] [rbp-20h] BYREF

v3 = strtok_r(a3, " ", &save_ptr);
if ( !strcmp(v3, "/kickme") )
{
command_kick_me((__int64)rwlock);
}
else if ( !strcmp(v3, "/givestuff") )
{
command_give_stuff(rwlock);
}
else if ( !strcmp(v3, "/spawn") )
{
command_spawn(rwlock, a2);
}
else if ( !strcmp(v3, "/i") )
{
command_item((__int64)rwlock, (__int64)a2, (__int64)save_ptr);
}
else
{
Player_send_message(rwlock, "Unrecognized command!");
}
}

canonical_decompiled_code:
void __fastcall func4(pthread_rwlock_t *rwlock, int *a2, char *a3)
{
char *v3; // rax
char *save_ptr; // [rsp+8h] [rbp-20h] BYREF

v3 = strtok_r(a3, " ", &save_ptr);
if ( !strcmp(v3, "/kickme") )
{
func0((__int64)rwlock);
}
else if ( !strcmp(v3, "/givestuff") )
{
func1(rwlock);
}
else if ( !strcmp(v3, "/spawn") )
{
func2(rwlock, a2);
}
else if ( !strcmp(v3, "/i") )
{
func3((__int64)rwlock, (__int64)a2, (__int64)save_ptr);
}
else
{
Player_send_message(rwlock, "Unrecognized command!");
}
}

original_code:
void handle_command(Player *p, Server *s, char *cmd){
    char *first;
    char *remainder;
    first = strtok_r(cmd, " ", &remainder);
    if (strcmp(first, "/kickme") == 0) command_kick_me(p, s, remainder);
    else if (strcmp(first, "/givestuff") == 0) command_give_stuff(p, s, remainder);
    else if (strcmp(first, "/spawn") == 0) command_spawn(p, s, remainder);
    else if (strcmp(first, "/i") == 0) command_item(p, s, remainder);
    else Player_send_message(p, "Unrecognized command!");
}

canonical_original_code:
void handle_command(struct Player *p, struct Server *s, char *cmd){
    char *first;
    char *remainder;
    first = strtok_r(cmd, " ", &remainder);
    if (strcmp(first, "/kickme") == 0) command_kick_me(p, s, remainder);
    else if (strcmp(first, "/givestuff") == 0) command_give_stuff(p, s, remainder);
    else if (strcmp(first, "/spawn") == 0) command_spawn(p, s, remainder);
    else if (strcmp(first, "/i") == 0) command_item(p, s, remainder);
    else Player_send_message(p, "Unrecognized command!");
}

variable_types:
first
char *

variable_types:
remainder
char *


decompiled_code:
_BYTE *Chunk_new_empty()
{
_BYTE *v0; // rax
_BYTE *v1; // rbx
_BYTE *v2; // rdx
_BYTE *v3; // rax

logmsg(3LL, "Making new empty chunk.");
v0 = malloc(0x20100uLL);
v1 = v0;
v2 = v0 + 0x20000;
do
{
*v0 = 0;
v0[1] = 0;
v0 += 2;
}
while ( v0 != v2 );
v3 = v1 + 0x20000;
do
*v3++ = 1;
while ( v3 != v1 + 131328 );
logmsg(3LL, "Finishing making chunk.");
return v1;
}

canonical_decompiled_code:
_BYTE *func0()
{
_BYTE *v0; // rax
_BYTE *v1; // rbx
_BYTE *v2; // rdx
_BYTE *v3; // rax

logmsg(3LL, "Making new empty chunk.");
v0 = malloc(0x20100uLL);
v1 = v0;
v2 = v0 + 0x20000;
do
{
*v0 = 0;
v0[1] = 0;
v0 += 2;
}
while ( v0 != v2 );
v3 = v1 + 0x20000;
do
*v3++ = 1;
while ( v3 != v1 + 131328 );
logmsg(3LL, "Finishing making chunk.");
return v1;
}

original_code:
Chunk * Chunk_new_empty(){
    logmsg(3, "Making new empty chunk.");
    Chunk *chunk = malloc(sizeof(Chunk));
    Block airblock;
    airblock.id = 0;
    airblock.metadata = 0;
    int i;
    for (i=0; i < 16*16*256; i++){
 chunk->blocks[i] = airblock;
    }
    for(i=0; i < 16*16; i++){
 chunk->biome_data[i] = 1;
    }
    logmsg(3, "Finishing making chunk.");
    return chunk;
}

canonical_original_code:
struct Chunk *Chunk_new_empty(){
    logmsg(3, "Making new empty chunk.");
    struct Chunk *chunk = malloc(sizeof(Chunk));
    struct Block airblock;
    airblock.id = 0;
    airblock.metadata = 0;
    int i;
    for (i=0; i < 16*16*256; i++){
 chunk->blocks[i] = airblock;
    }
    for(i=0; i < 16*16; i++){
 chunk->biome_data[i] = 1;
    }
    logmsg(3, "Finishing making chunk.");
    return chunk;
}

variable_types: struct Chunk { struct Block { unsigned char id; unsigned char metadata; } blocks[-1]; char biome_data[-1]; } *

variable_types: i int


decompiled_code:
void __fastcall Chunk_set_block(__int64 a1, int a2, int a3, int a4, __int16 a5)
{
*(_WORD *)(a1 + 2LL * (a2 + 16 * (a4 + 16 * a3))) = a5;
}

original_code:
void Chunk_set_block(Chunk *chunk, int x, int y, int z, Block block){
    size_t blockpos = y * 256 + z * 16 + x;
    chunk->blocks[blockpos] = block;
}

canonical_original_code:
void Chunk_set_block(struct Chunk *chunk, int x, int y, int z, struct Block block){
    unsigned long blockpos = y * 256 + z * 16 + x;
    chunk->blocks[blockpos] = block;
}

variable_types:
block
struct Block

variable_types:
blockpos
unsigned long


decompiled_code:
__int64 __fastcall Chunk_get_block(__int64 a1, int a2, int a3, int a4)
{
return *(unsigned __int16 *)(a1 + 2LL * (a2 + 16 * (a4 + 16 * a3)));
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int a2, int a3, int a4)
{
return *(unsigned __int16 *)(a1 + 2LL * (a2 + 16 * (a4 + 16 * a3)));
}

original_code:
Block Chunk_get_block(Chunk *chunk, int x, int y, int z){
    size_t blockpos = y * 256 + z * 16 + x;
    return chunk->blocks[blockpos];
}

canonical_original_code:
struct Block Chunk_get_block(struct Chunk *chunk, int x, int y, int z){
    unsigned long blockpos = y * 256 + z * 16 + x;
    return chunk->blocks[blockpos];
}

variable_types: struct Chunk { struct Block blocks[-1]; char biome_data[-1]; } *

variable_types: x int

return_type: struct Block { unsigned char id; unsigned char metadata; }


decompiled_code:
void __fastcall Chunk_set_below(__int64 a1, __int16 a2, int a3)
{
int i; // er15
int v5; // ebx
int j; // ebp

for ( i = 0; i != 16; ++i )
{
for ( j = 0; j != 16; ++j )
{
v5 = 0;
if ( a3 > 0 )
{
do
Chunk_set_block(a1, i, v5++, j, a2);
while ( a3 != v5 );
}
}
}
}

original_code:
void Chunk_set_below(Chunk *chunk, Block b, int y){
    int x;
    int z;
    int level;
    for (x=0; x < 16; x++){
 for (z=0; z<16; z++){
     for (level=0; level<y; level++){
  Chunk_set_block(chunk, x, level, z, b);
     }
 }
    }
}

canonical_original_code:
void Chunk_set_below(struct Chunk *chunk, struct Block b, int y){
    int x;
    int z;
    int level;
    for (x=0; x < 16; x++){
 for (z=0; z<16; z++){
     for (level=0; level<y; level++){
  Chunk_set_block(chunk, x, level, z, b);
     }
 }
    }
}

variable_types:
b
struct Block

variable_types: y int

variable_types: z int

variable_types: level int


decompiled_code:
_BOOL8 __fastcall Map_validate_chunk_coords(_QWORD *a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 - 1LL >= (unsigned __int64)a2 && a1[1] - 1LL >= (unsigned __int64)a3 )
result = a3 >= 0 && a2 >= 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(_QWORD *a1, __int64 a2, __int64 a3)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 - 1LL >= (unsigned __int64)a2 && a1[1] - 1LL >= (unsigned __int64)a3 )
result = a3 >= 0 && a2 >= 0;
return result;
}

original_code:
char Map_validate_chunk_coords(Map *map, ssize_t x, ssize_t z){
    if (x > map->xchunks-1 || z > map->zchunks-1 || x < 0 || z < 0){
        return 0;
    }
    return 1;
}

canonical_original_code:
char Map_validate_chunk_coords(struct Map *map, long x, long z){
    if (x > map->xchunks-1 || z > map->zchunks-1 || x < 0 || z < 0){
        return 0;
    }
    return 1;
}

variable_types: struct Map { unsigned long xchunks; unsigned long zchunks; struct Chunk { struct Block { unsigned char id; unsigned char metadata; } blocks[-1]; char biome_data[-1]; } **chunks; } *

variable_types: x long

variable_types: z long


decompiled_code:
__int64 __fastcall Map_get_chunk(_QWORD *a1, __int64 a2, __int64 a3)
{
if ( Map_validate_chunk_coords(a1, a2, a3) )
return *(_QWORD *)(a1[2] + 8 * (a3 + *a1 * a2));
logmsg(3LL, "Tried to get invalid chunk!");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3)
{
if ( func4(a1, a2, a3) )
return *(_QWORD *)(a1[2] + 8 * (a3 + *a1 * a2));
logmsg(3LL, "Tried to get invalid chunk!");
return 0LL;
}

original_code:
Chunk * Map_get_chunk(Map *map, ssize_t x, ssize_t z){
    if (!Map_validate_chunk_coords(map, x, z)){
 logmsg(3, "Tried to get invalid chunk!");
 return ((void *)0);
    }
    return map->chunks[(x * map->xchunks) + z];
}

canonical_original_code:
struct Chunk *Map_get_chunk(struct Map *map, long x, long z){
    if (!Map_validate_chunk_coords(map, x, z)){
 logmsg(3, "Tried to get invalid chunk!");
 return ((void *)0);
    }
    return map->chunks[(x * map->xchunks) + z];
}

variable_types: struct Map { unsigned long xchunks; unsigned long zchunks; struct Chunk **chunks; } *

return_type: struct Chunk { struct Block { unsigned char id; unsigned char metadata; } blocks[-1]; char biome_data[-1]; } *


decompiled_code:
__int64 __fastcall Map_set_chunk(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

if ( !Map_validate_chunk_coords(a1, a3, a4) )
return logmsg(1LL, "Tried to set an invalid chunk position!");
result = a1[2];
*(_QWORD *)(result + 8 * (a4 + *a1 * a3)) = a2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 result; // rax

if ( !func4(a1, a3, a4) )
return logmsg(1LL, "Tried to set an invalid chunk position!");
result = a1[2];
*(_QWORD *)(result + 8 * (a4 + *a1 * a3)) = a2;
return result;
}

original_code:
void Map_set_chunk(Map *map, Chunk *chunk, ssize_t x, ssize_t z){
    if (!Map_validate_chunk_coords(map, x, z)){
 logmsg(1, "Tried to set an invalid chunk position!");
 return;
    }
    map->chunks[(x * map->xchunks) + z] = chunk;
}

canonical_original_code:
void Map_set_chunk(struct Map *map, struct Chunk *chunk, long x, long z){
    if (!Map_validate_chunk_coords(map, x, z)){
 logmsg(1, "Tried to set an invalid chunk position!");
 return;
    }
    map->chunks[(x * map->xchunks) + z] = chunk;
}

variable_types:
chunk
struct Chunk *


decompiled_code:
void __fastcall Map_set_block(_QWORD *a1, __int16 a2, int a3, int a4, int a5)
{
__int64 v8; // rax

v8 = Map_get_chunk(a1, a3 / 16, a5 / 16);
if ( v8 )
Chunk_set_block(v8, a3 % 16, a4, a5 % 16, a2);
else
logmsg(1LL, "Tried to set block that is outside of map!");
}

canonical_decompiled_code:
void __fastcall func7(_QWORD *a1, __int16 a2, int a3, int a4, int a5)
{
__int64 v8; // rax

v8 = func5(a1, a3 / 16, a5 / 16);
if ( v8 )
func1(v8, a3 % 16, a4, a5 % 16, a2);
else
logmsg(1LL, "Tried to set block that is outside of map!");
}

original_code:
void Map_set_block(Map *map, Block block, int x, int y, int z){
    ssize_t chunkx = x / 16;
    ssize_t chunkz = z / 16;
    Chunk *chunk = Map_get_chunk(map, chunkx, chunkz);
    if (chunk == ((void *)0)){
 logmsg(1, "Tried to set block that is outside of map!");
 return;
    }
    Chunk_set_block(chunk, x%16, y, z%16, block);
}

canonical_original_code:
void Map_set_block(struct Map *map, struct Block block, int x, int y, int z){
    long chunkx = x / 16;
    long chunkz = z / 16;
    struct Chunk *chunk = Map_get_chunk(map, chunkx, chunkz);
    if (chunk == ((void *)0)){
 logmsg(1, "Tried to set block that is outside of map!");
 return;
    }
    Chunk_set_block(chunk, x%16, y, z%16, block);
}

variable_types: chunkx long

variable_types: chunkz long


decompiled_code:
__int64 __fastcall Map_get_block(_QWORD *a1, int a2, int a3, int a4)
{
int v7; // esi
__int64 v8; // rax

v7 = a2 + 15;
if ( a2 >= 0 )
v7 = a2;
v8 = Map_get_chunk(a1, v7 >> 4, a4 / 16);
if ( v8 )
return Chunk_get_block(v8, a2 % 16, a3, a4 % 16);
logmsg(1LL, "Tried to get block that is outside of map!");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1, int a2, int a3, int a4)
{
int v7; // esi
__int64 v8; // rax

v7 = a2 + 15;
if ( a2 >= 0 )
v7 = a2;
v8 = func5(a1, v7 >> 4, a4 / 16);
if ( v8 )
return func2(v8, a2 % 16, a3, a4 % 16);
logmsg(1LL, "Tried to get block that is outside of map!");
return 0LL;
}

original_code:
Block Map_get_block(Map *map, int x, int y, int z){
    ssize_t chunkx = x / 16;
    ssize_t chunkz = z / 16;
    Chunk *chunk = Map_get_chunk(map, chunkx, chunkz);
    if (chunk == ((void *)0)){
 logmsg(1, "Tried to get block that is outside of map!");
 return (Block) {.id = 0, .metadata = 0};
    }
    return Chunk_get_block(chunk, x%16, y, z%16);
}

canonical_original_code:
struct Block Map_get_block(struct Map *map, int x, int y, int z){
    long chunkx = x / 16;
    long chunkz = z / 16;
    struct Chunk *chunk = Map_get_chunk(map, chunkx, chunkz);
    if (chunk == ((void *)0)){
 logmsg(1, "Tried to get block that is outside of map!");
 return (struct Block) {.id = 0, .metadata = 0};
    }
    return Chunk_get_block(chunk, x%16, y, z%16);
}

variable_types: struct Map { unsigned long xchunks; unsigned long zchunks; struct Chunk { struct Block blocks[-1]; char biome_data[-1]; } **chunks; } *

variable_types: struct Chunk { struct Block { unsigned char id; unsigned char metadata; } blocks[-1]; char biome_data[-1]; } *


decompiled_code:
__int64 __fastcall Map_set_below(_QWORD *a1, __int16 a2, int a3)
{
__int64 result; // rax
__int64 v5; // rbp
__int64 v6; // r15
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbx
int v10; // [rsp+4h] [rbp-44h]
__int64 v11; // [rsp+8h] [rbp-40h]

result = a1[1];
v10 = result;
if ( (int)*a1 > 0 )
{
v11 = (unsigned int)*a1 - 1;
v5 = 0LL;
v6 = (unsigned int)(result - 1);
while ( 1 )
{
v9 = 0LL;
if ( v10 > 0 )
{
do
{
v7 = Map_get_chunk(a1, v5, v9);
Chunk_set_below(v7, a2, a3);
v8 = v9++;
}
while ( v6 != v8 );
}
result = v5 + 1;
if ( v5 == v11 )
break;
++v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1, __int16 a2, int a3)
{
__int64 result; // rax
__int64 v5; // rbp
__int64 v6; // r15
__int64 v7; // rax
__int64 v8; // rax
__int64 v9; // rbx
int v10; // [rsp+4h] [rbp-44h]
__int64 v11; // [rsp+8h] [rbp-40h]

result = a1[1];
v10 = result;
if ( (int)*a1 > 0 )
{
v11 = (unsigned int)*a1 - 1;
v5 = 0LL;
v6 = (unsigned int)(result - 1);
while ( 1 )
{
v9 = 0LL;
if ( v10 > 0 )
{
do
{
v7 = func5(a1, v5, v9);
func3(v7, a2, a3);
v8 = v9++;
}
while ( v6 != v8 );
}
result = v5 + 1;
if ( v5 == v11 )
break;
++v5;
}
}
return result;
}

original_code:
void Map_set_below(Map *map, Block b, int level){
    int x = map->xchunks;
    int z = map->zchunks;
    int i;
    int j;
    for (i=0; i < x; i++){
 for (j=0; j < z; j++){
     Chunk_set_below(Map_get_chunk(map, i, j), b, level);
 }
    }
}

canonical_original_code:
void Map_set_below(struct Map *map, struct Block b, int level){
    int x = map->xchunks;
    int z = map->zchunks;
    int i;
    int j;
    for (i=0; i < x; i++){
 for (j=0; j < z; j++){
     Chunk_set_below(Map_get_chunk(map, i, j), b, level);
 }
    }
}

variable_types: i int

variable_types: j int


decompiled_code:
void __fastcall apply_face(char a1, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
switch ( a1 )
{
case 0:
--*a3;
break;
case 1:
++*a3;
break;
case 2:
--*a4;
break;
case 3:
++*a4;
break;
case 4:
--*a2;
break;
case 5:
++*a2;
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func11(char a1, _DWORD *a2, _DWORD *a3, _DWORD *a4)
{
switch ( a1 )
{
case 0:
--*a3;
break;
case 1:
++*a3;
break;
case 2:
--*a4;
break;
case 3:
++*a4;
break;
case 4:
--*a2;
break;
case 5:
++*a2;
break;
default:
return;
}
}

original_code:
void apply_face(char face, int *x, int *y, int *z){
    switch (face){
    case 0:
 *y -= 1;
 break;
    case 1:
 *y += 1;
 break;
    case 2:
 *z -= 1;
 break;
    case 3:
 *z += 1;
 break;
    case 4:
 *x -= 1;
 break;
    case 5:
 *x += 1;
 break;
    }
}

variable_types: face char

variable_types:
x
int *

variable_types:
y
int *

variable_types:
z
int *


decompiled_code:
int __fastcall handle_player_digging(__int64 a1, __int64 a2, __int64 a3)
{
int result; // eax

result = logfmt(3LL, "%s just broke a block.\n", *(const char **)(a2 + 56));
if ( *(_BYTE *)a1 == 2 )
{
pthread_rwlock_wrlock((pthread_rwlock_t *)(a3 + 168));
pthread_rwlock_wrlock((pthread_rwlock_t *)(a3 + 96));
pthread_rwlock_wrlock((pthread_rwlock_t *)a2);
Player_break_block(a2, a3, *(unsigned int *)(a1 + 4), (unsigned int)*(char *)(a1 + 8), *(unsigned int *)(a1 + 12));
pthread_rwlock_unlock((pthread_rwlock_t *)a2);
pthread_rwlock_unlock((pthread_rwlock_t *)(a3 + 168));
result = pthread_rwlock_unlock((pthread_rwlock_t *)(a3 + 96));
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
int result; // eax

result = logfmt(3LL, "%s just broke a block.\n", *(const char **)(a2 + 56));
if ( *(_BYTE *)a1 == 2 )
{
pthread_rwlock_wrlock((pthread_rwlock_t *)(a3 + 168));
pthread_rwlock_wrlock((pthread_rwlock_t *)(a3 + 96));
pthread_rwlock_wrlock((pthread_rwlock_t *)a2);
Player_break_block(a2, a3, *(unsigned int *)(a1 + 4), (unsigned int)*(char *)(a1 + 8), *(unsigned int *)(a1 + 12));
pthread_rwlock_unlock((pthread_rwlock_t *)a2);
pthread_rwlock_unlock((pthread_rwlock_t *)(a3 + 168));
result = pthread_rwlock_unlock((pthread_rwlock_t *)(a3 + 96));
}
return result;
}

original_code:
void handle_player_digging(Packet0EPlayerDigging *packet, Player *p, Server *s){
    logfmt(3, "%s just broke a block.\n", p->username);
    if (packet->action == 2){
 pthread_rwlock_wrlock(&s->map_lock);
 pthread_rwlock_wrlock(&s->players_lock);
 pthread_rwlock_wrlock(&p->lock);
 Player_break_block(p, s, packet->x, packet->y, packet->z);
 pthread_rwlock_unlock(&p->lock);
 pthread_rwlock_unlock(&s->map_lock);
 pthread_rwlock_unlock(&s->players_lock);
    } else {
    }
}

canonical_original_code:
void handle_player_digging(struct Packet0EPlayerDigging *packet, struct Player *p, struct Server *s){
    logfmt(3, "%s just broke a block.\n", p->username);
    if (packet->action == 2){
 pthread_rwlock_wrlock(&s->map_lock);
 pthread_rwlock_wrlock(&s->players_lock);
 pthread_rwlock_wrlock(&p->lock);
 Player_break_block(p, s, packet->x, packet->y, packet->z);
 pthread_rwlock_unlock(&p->lock);
 pthread_rwlock_unlock(&s->map_lock);
 pthread_rwlock_unlock(&s->players_lock);
    } else {
    }
}

variable_types: struct Packet0EPlayerDigging { char action; int x; char y; int z; char face; } *

variable_types: struct Player { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } lock; char *username; int entity_id; int socket; struct Inventory { unsigned long size; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } **slots; } *inventory; int held_slot_num; double x; double y; double z; float yaw; float pitch; double last_x; double last_y; double last_z; } *

variable_types: struct Server { union pthread_rwlock_t state_lock; char is_running; long time; int last_entity_id; int spawnx; int spawny; int spawnz; unsigned long max_players; union pthread_rwlock_t players_lock; int num_players; struct Player **players; union pthread_rwlock_t map_lock; struct Map { unsigned long xchunks; unsigned long zchunks; struct Chunk { struct Block { unsigned char id; unsigned char metadata; } blocks[-1]; char biome_data[-1]; } **chunks; } *map; char *filename; unsigned long distributor_thread; int distributor_socket; } *


decompiled_code:
void __fastcall send_all_chunks(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 i; // r12
void *v4; // r15
unsigned __int64 j; // rbx
__int64 v6; // rdi
size_t n[8]; // [rsp+8h] [rbp-40h] BYREF

logmsg(2LL, "Sending all chunks to a player!");
for ( i = 0LL; *a2 > i; ++i )
{
for ( j = 0LL; a2[1] > j; ++j )
{
v6 = Map_get_chunk(a2, i, j);
if ( v6 )
{
v4 = (void *)Packet33ChunkData_construct(v6, (unsigned int)i, (unsigned int)j, n);
send(*(_DWORD *)(a1 + 68), v4, n[0], 0);
free(v4);
}
}
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned __int64 *a2)
{
unsigned __int64 i; // r12
void *v4; // r15
unsigned __int64 j; // rbx
__int64 v6; // rdi
size_t n[8]; // [rsp+8h] [rbp-40h] BYREF

logmsg(2LL, "Sending all chunks to a player!");
for ( i = 0LL; *a2 > i; ++i )
{
for ( j = 0LL; a2[1] > j; ++j )
{
v6 = Map_get_chunk(a2, i, j);
if ( v6 )
{
v4 = (void *)Packet33ChunkData_construct(v6, (unsigned int)i, (unsigned int)j, n);
send(*(_DWORD *)(a1 + 68), v4, n[0], 0);
free(v4);
}
}
}
}

original_code:
void send_all_chunks(Player *p, Map *map){
    logmsg(2, "Sending all chunks to a player!");
    int i;
    int j;
    for (i=0; i < map->xchunks; i++){
        for (j=0; j < map->zchunks; j++){
     Chunk *c = Map_get_chunk(map, i, j);
     if (c == ((void *)0)) continue;
     size_t len;
     char *data = Packet33ChunkData_construct(c, i, j, &len);
     send(p->socket, data, len, 0);
     free(data);
 }
    }
}

canonical_original_code:
void send_all_chunks(struct Player *p, struct Map *map){
    logmsg(2, "Sending all chunks to a player!");
    int i;
    int j;
    for (i=0; i < map->xchunks; i++){
        for (j=0; j < map->zchunks; j++){
     struct Chunk *c = Map_get_chunk(map, i, j);
     if (c == ((void *)0)) continue;
     unsigned long len;
     char *data = Packet33ChunkData_construct(c, i, j, &len);
     send(p->socket, data, len, 0);
     free(data);
 }
    }
}

variable_types: struct Map { unsigned long xchunks; unsigned long zchunks; struct Chunk { struct Block { unsigned char id; unsigned char metadata; } blocks[-1]; char biome_data[-1]; } **chunks; } *

variable_types:
len
unsigned long

variable_types:
data
char *


decompiled_code:
int __fastcall send_all_players(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

pthread_rwlock_rdlock((pthread_rwlock_t *)(a2 + 96));
if ( *(int *)(a2 + 152) > 0 )
{
v2 = 0LL;
do
{
if ( *(_QWORD *)(*(_QWORD *)(a2 + 160) + 8 * v2) != a1 )
Player_send_new_player(a1);
++v2;
}
while ( *(_DWORD *)(a2 + 152) > (int)v2 );
}
return pthread_rwlock_unlock((pthread_rwlock_t *)(a2 + 96));
}

canonical_decompiled_code:
int __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

pthread_rwlock_rdlock((pthread_rwlock_t *)(a2 + 96));
if ( *(int *)(a2 + 152) > 0 )
{
v2 = 0LL;
do
{
if ( *(_QWORD *)(*(_QWORD *)(a2 + 160) + 8 * v2) != a1 )
Player_send_new_player(a1);
++v2;
}
while ( *(_DWORD *)(a2 + 152) > (int)v2 );
}
return pthread_rwlock_unlock((pthread_rwlock_t *)(a2 + 96));
}

original_code:
void send_all_players(Player *player, Server *server){
    pthread_rwlock_rdlock(&server->players_lock);
    int i;
    for (i=0; i < server->num_players; i++){
 if (player == server->players[i]) continue;
 Player_send_new_player(player, server->players[i]);
    }
    pthread_rwlock_unlock(&server->players_lock);
}

canonical_original_code:
void send_all_players(struct Player *player, struct Server *server){
    pthread_rwlock_rdlock(&server->players_lock);
    int i;
    for (i=0; i < server->num_players; i++){
 if (player == server->players[i]) continue;
 Player_send_new_player(player, server->players[i]);
    }
    pthread_rwlock_unlock(&server->players_lock);
}


decompiled_code:
int __fastcall handle_player_chat(const char **a1, __int64 a2, __int64 a3)
{
const char *v4; // r12
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v4 = *a1;
if ( **a1 == 47 )
return handle_command(a2, a3, *a1);
v6[0] = 0;
*(_WORD *)&v6[strlen(v6)] = 91;
strcat(v6, *(const char **)(a2 + 56));
strcat(v6, "] ");
strcat(v6, v4);
pthread_rwlock_rdlock((pthread_rwlock_t *)(a3 + 96));
Server_tell_all(a3, v6);
return pthread_rwlock_unlock((pthread_rwlock_t *)(a3 + 96));
}

canonical_decompiled_code:
int __fastcall func3(const char **a1, __int64 a2, __int64 a3)
{
const char *v4; // r12
char v6[280]; // [rsp+0h] [rbp-118h] BYREF

v4 = *a1;
if ( **a1 == 47 )
return handle_command(a2, a3, *a1);
v6[0] = 0;
*(_WORD *)&v6[strlen(v6)] = 91;
strcat(v6, *(const char **)(a2 + 56));
strcat(v6, "] ");
strcat(v6, v4);
pthread_rwlock_rdlock((pthread_rwlock_t *)(a3 + 96));
Server_tell_all(a3, v6);
return pthread_rwlock_unlock((pthread_rwlock_t *)(a3 + 96));
}

original_code:
void handle_player_chat(Packet03ChatMessage *packet, Player *p, Server *s){
    if (packet->str[0] == '/'){
 handle_command(p, s, packet->str);
 return;
    }
    char buffer[256];
    buffer[0] = 0;
    char *begin_name = "[";
    char *end_name = "] ";
    strcat(buffer, begin_name);
    strcat(buffer, p->username);
    strcat(buffer, end_name);
    strcat(buffer, packet->str);
    pthread_rwlock_rdlock(&s->players_lock);
    Server_tell_all(s, buffer);
    pthread_rwlock_unlock(&s->players_lock);
}

canonical_original_code:
void handle_player_chat(struct Packet03ChatMessage *packet, struct Player *p, struct Server *s){
    if (packet->str[0] == '/'){
 handle_command(p, s, packet->str);
 return;
    }
    char buffer[256];
    buffer[0] = 0;
    char *begin_name = "[";
    char *end_name = "] ";
    strcat(buffer, begin_name);
    strcat(buffer, p->username);
    strcat(buffer, end_name);
    strcat(buffer, packet->str);
    pthread_rwlock_rdlock(&s->players_lock);
    Server_tell_all(s, buffer);
    pthread_rwlock_unlock(&s->players_lock);
}

variable_types: struct Packet03ChatMessage { char *str; } *

variable_types:
buffer
char [256]


decompiled_code:
int __fastcall handle_player_position(double *a1, pthread_rwlock_t *a2)
{
pthread_rwlock_wrlock(a2);
Player_set_position(a2, *a1, a1[1], a1[3]);
return pthread_rwlock_unlock(a2);
}

canonical_decompiled_code:
int __fastcall func4(double *a1, pthread_rwlock_t *a2)
{
pthread_rwlock_wrlock(a2);
Player_set_position(a2, *a1, a1[1], a1[3]);
return pthread_rwlock_unlock(a2);
}

original_code:
void handle_player_position(Packet0BPlayerPosition *packet, Player *p, Server *s){
    pthread_rwlock_wrlock(&p->lock);
    Player_set_position(p, packet->x, packet->y, packet->z);
    pthread_rwlock_unlock(&p->lock);
}

canonical_original_code:
void handle_player_position(struct Packet0BPlayerPosition *packet, struct Player *p, struct Server *s){
    pthread_rwlock_wrlock(&p->lock);
    Player_set_position(p, packet->x, packet->y, packet->z);
    pthread_rwlock_unlock(&p->lock);
}

variable_types: struct Packet0BPlayerPosition { double x; double y; double stance; double z; char on_ground; } *


decompiled_code:
void handle_player_look()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void handle_player_look(Packet0CPlayerLook *packet, Player *p, Server *s){
}

canonical_original_code:
void handle_player_look(struct Packet0CPlayerLook *packet, struct Player *p, struct Server *s){
}

variable_types: struct Packet0CPlayerLook { float yaw; float pitch; } *


decompiled_code:
int __fastcall handle_block_placement(__int64 a1, __int64 a2, pthread_rwlock_t *a3)
{
unsigned int v5; // [rsp+4h] [rbp-24h] BYREF
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

logfmt(3LL, "Player: %s is placing block!", *(const char **)(a2 + 56));
v7[0] = *(_DWORD *)a1;
v6 = *(unsigned __int8 *)(a1 + 4);
v5 = *(_DWORD *)(a1 + 8);
apply_face((unsigned int)*(char *)(a1 + 12), v7, &v6, &v5);
pthread_rwlock_wrlock((pthread_rwlock_t *)a2);
pthread_rwlock_wrlock(a3 + 3);
Player_place_block(a2, a3, v7[0], v6, v5);
pthread_rwlock_unlock(a3 + 3);
return pthread_rwlock_unlock((pthread_rwlock_t *)a2);
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2, pthread_rwlock_t *a3)
{
unsigned int v5; // [rsp+4h] [rbp-24h] BYREF
unsigned int v6; // [rsp+8h] [rbp-20h] BYREF
unsigned int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

logfmt(3LL, "Player: %s is placing block!", *(const char **)(a2 + 56));
v7[0] = *(_DWORD *)a1;
v6 = *(unsigned __int8 *)(a1 + 4);
v5 = *(_DWORD *)(a1 + 8);
apply_face((unsigned int)*(char *)(a1 + 12), v7, &v6, &v5);
pthread_rwlock_wrlock((pthread_rwlock_t *)a2);
pthread_rwlock_wrlock(a3 + 3);
Player_place_block(a2, a3, v7[0], v6, v5);
pthread_rwlock_unlock(a3 + 3);
return pthread_rwlock_unlock((pthread_rwlock_t *)a2);
}

original_code:
void handle_block_placement(Packet0FPlayerBlockPlacement *packet,
       Player *p, Server *s){
    logfmt(3, "Player: %s is placing block!", p->username);
    int x = packet->x;
    int y = packet->y;
    int z = packet->z;
    apply_face(packet->direction, &x, &y, &z);
    pthread_rwlock_wrlock(&p->lock);
    pthread_rwlock_wrlock(&s->map_lock);
    Player_place_block(p, s, x,y,z);
    pthread_rwlock_unlock(&s->map_lock);
    pthread_rwlock_unlock(&p->lock);
}

canonical_original_code:
void handle_block_placement(struct Packet0FPlayerBlockPlacement *packet, struct Player *p, struct Server *s){
    logfmt(3, "Player: %s is placing block!", p->username);
    int x = packet->x;
    int y = packet->y;
    int z = packet->z;
    apply_face(packet->direction, &x, &y, &z);
    pthread_rwlock_wrlock(&p->lock);
    pthread_rwlock_wrlock(&s->map_lock);
    Player_place_block(p, s, x,y,z);
    pthread_rwlock_unlock(&s->map_lock);
    pthread_rwlock_unlock(&p->lock);
}

variable_types: struct Packet0FPlayerBlockPlacement { int x; unsigned char y; int z; char direction; struct Slot { short id; char count; short damage; short nbt_len; char *nbt; } *held_item; char c_posx; char c_posy; char c_posz; } *

variable_types: struct Player { union pthread_rwlock_t { struct __pthread_rwlock_arch_t { unsigned int __readers; unsigned int __writers; unsigned int __wrphase_futex; unsigned int __writers_futex; unsigned int __pad3; unsigned int __pad4; int __cur_writer; int __shared; char __rwelision; unsigned char __pad1[7]; unsigned long __pad2; unsigned int __flags; } __data; char __size[56]; long __align; } lock; char *username; int entity_id; int socket; struct Inventory { unsigned long size; struct Slot **slots; } *inventory; int held_slot_num; double x; double y; double z; float yaw; float pitch; double last_x; double last_y; double last_z; } *

variable_types: x int

variable_types: y int

variable_types: z int

user_defined_types: struct Packet0FPlayerBlockPlacement { int x; unsigned char y; int z; char direction; struct Slot *held_item; char c_posx; char c_posy; char c_posz; }


decompiled_code:
int __fastcall handle_item_change(__int16 *a1, pthread_rwlock_t *a2)
{
logfmt(3LL, "Player: is changing slot.", a2[1].__align);
pthread_rwlock_wrlock(a2);
a2[1].__writer = *a1;
return pthread_rwlock_unlock(a2);
}

canonical_decompiled_code:
int __fastcall func7(__int16 *a1, pthread_rwlock_t *a2)
{
logfmt(3LL, "Player: is changing slot.", a2[1].__align);
pthread_rwlock_wrlock(a2);
a2[1].__writer = *a1;
return pthread_rwlock_unlock(a2);
}

original_code:
void handle_item_change(Packet10HeldItemChange *packet, Player *p, Server *s){
    logfmt(3, "Player:  is changing slot.", p->username);
    pthread_rwlock_wrlock(&p->lock);
    p->held_slot_num = packet->slot_id;
    pthread_rwlock_unlock(&p->lock);
}

canonical_original_code:
void handle_item_change(struct Packet10HeldItemChange *packet, struct Player *p, struct Server *s){
    logfmt(3, "Player:  is changing slot.", p->username);
    pthread_rwlock_wrlock(&p->lock);
    p->held_slot_num = packet->slot_id;
    pthread_rwlock_unlock(&p->lock);
}

variable_types: struct Packet10HeldItemChange { short slot_id; } *


logmsg

decompiled_code:
int __fastcall logmsg(int a1, const char *a2)
{
const char *v2; // rbp
int result; // eax

if ( a1 <= 3 )
{
if ( a1 == 2 )
{
v2 = "[INFO]";
}
else
{
v2 = "[DEBUG]";
if ( a1 != 3 )
{
if ( a1 )
{
if ( a1 == 1 )
v2 = "[WARN]";
}
else
{
v2 = "[Error]";
}
}
}
pthread_mutex_lock(&log_mutex);
printf("%s %s \n", v2, a2);
result = pthread_mutex_unlock(&log_mutex);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(int a1, const char *a2)
{
const char *v2; // rbp
int result; // eax

if ( a1 <= 3 )
{
if ( a1 == 2 )
{
v2 = "[INFO]";
}
else
{
v2 = "[DEBUG]";
if ( a1 != 3 )
{
if ( a1 )
{
if ( a1 == 1 )
v2 = "[WARN]";
}
else
{
v2 = "[Error]";
}
}
}
pthread_mutex_lock(&log_mutex);
printf("%s %s \n", v2, a2);
result = pthread_mutex_unlock(&log_mutex);
}
return result;
}

original_code:
void logmsg(int level, const char *message){
    if (level <= 3){
 char *level_string;
 switch (level){
 case 0:
     level_string = "[Error]";
     break;
 case 1:
     level_string = "[WARN]";
     break;
 case 2:
     level_string = "[INFO]";
     break;
 case 3:
     level_string = "[DEBUG]";
     break;
 }
 pthread_mutex_lock(&log_mutex);
 printf("%s %s \n", level_string, message);
 pthread_mutex_unlock(&log_mutex);
    }
}

canonical_original_code:
void logmsg(int level, char *message){
    if (level <= 3){
 char *level_string;
 switch (level){
 case 0:
     level_string = "[Error]";
     break;
 case 1:
     level_string = "[WARN]";
     break;
 case 2:
     level_string = "[INFO]";
     break;
 case 3:
     level_string = "[DEBUG]";
     break;
 }
 pthread_mutex_lock(&log_mutex);
 printf("%s %s \n", level_string, message);
 pthread_mutex_unlock(&log_mutex);
    }
}

variable_types: level int

variable_types:
message
char *


logfmt

decompiled_code:
int logfmt(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
return logmsg(a1, s);
}

canonical_decompiled_code:
int func1(int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-2D0h] BYREF
char s[512]; // [rsp+20h] [rbp-2B8h] BYREF

va_start(arg, a2);
vsnprintf(s, 0x200uLL, a2, arg);
return func0(a1, s);
}

original_code:
void logfmt(int level, const char *fmt, ...){
    char buffer[512];
    va_list args;
    __builtin_va_start(args,fmt);
    vsnprintf(buffer, 512, fmt, args);
    __builtin_va_end(args);
    logmsg(level, buffer);
}

canonical_original_code:
void logfmt(int level, char *fmt, ...){
    char buffer[512];
    __builtin_va_list args;
    __builtin_va_start(args,fmt);
    vsnprintf(buffer, 512, fmt, args);
    __builtin_va_end(args);
    logmsg(level, buffer);
}

variable_types:
fmt
char *

variable_types:
buffer
char [512]


decompiled_code:
int logging_init()
{
return pthread_mutex_init(&log_mutex, 0LL);
}

canonical_decompiled_code:
int func2()
{
return pthread_mutex_init(&log_mutex, 0LL);
}

original_code:
void logging_init(){
    pthread_mutex_init(&log_mutex, ((void *)0));
}


decompiled_code:
void __noreturn catch_sigint()
{
logmsg(1LL, "Shutting down due to quit signal!");
pthread_rwlock_wrlock((pthread_rwlock_t *)(sigint_server + 96));
Server_shutdown(sigint_server);
pthread_rwlock_unlock((pthread_rwlock_t *)(sigint_server + 96));
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
logmsg(1LL, "Shutting down due to quit signal!");
pthread_rwlock_wrlock((pthread_rwlock_t *)(sigint_server + 96));
Server_shutdown(sigint_server);
pthread_rwlock_unlock((pthread_rwlock_t *)(sigint_server + 96));
exit(0);
}

original_code:
static void catch_sigint(int signal){
    logmsg(1, "Shutting down due to quit signal!");
    pthread_rwlock_wrlock(&sigint_server->players_lock);
    Server_shutdown(sigint_server);
    pthread_rwlock_unlock(&sigint_server->players_lock);
    exit(0);
}

variable_types: signal int