decompiled_code:
__int64 __fastcall Model_average_point(__int64 a1)
{
__int64 v1; // rsi
unsigned int v2; // ecx
signed int v3; // edx
int v4; // ebp
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rax
__int64 v9; // rdx
unsigned __int64 v10; // rax
__int64 v12; // [rsp+Ch] [rbp-24h]

if ( !a1 )
Model_average_point_cold();
v1 = 0LL;
v2 = 0;
v3 = 0;
v4 = 0;
v5 = a1;
do
{
v4 += 2;
v6 = Point3D_add(__PAIR64__(v2, v3), v1, *(_QWORD *)v5, *(unsigned int *)(v5 + 8));
v8 = Point3D_add(v6, v7, *(_QWORD *)(v5 + 12), *(unsigned int *)(v5 + 20));
v5 = *(_QWORD *)(v5 + 24);
v1 = v9;
v3 = v8;
v10 = HIDWORD(v8);
v2 = v10;
}
while ( v5 );
LODWORD(v12) = v3 / v4;
HIDWORD(v12) = (int)v10 / v4;
return v12;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 v1; // rsi
unsigned int v2; // ecx
signed int v3; // edx
int v4; // ebp
__int64 v5; // rbx
__int64 v6; // rax
__int64 v7; // rdx
unsigned __int64 v8; // rax
__int64 v9; // rdx
unsigned __int64 v10; // rax
__int64 v12; // [rsp+Ch] [rbp-24h]

if ( !a1 )
func9();
v1 = 0LL;
v2 = 0;
v3 = 0;
v4 = 0;
v5 = a1;
do
{
v4 += 2;
v6 = Point3D_add(__PAIR64__(v2, v3), v1, *(_QWORD *)v5, *(unsigned int *)(v5 + 8));
v8 = Point3D_add(v6, v7, *(_QWORD *)(v5 + 12), *(unsigned int *)(v5 + 20));
v5 = *(_QWORD *)(v5 + 24);
v1 = v9;
v3 = v8;
v10 = HIDWORD(v8);
v2 = v10;
}
while ( v5 );
LODWORD(v12) = v3 / v4;
HIDWORD(v12) = (int)v10 / v4;
return v12;
}

original_code:
Point3D Model_average_point(Model *model){
    Point3D sum = {0,0,0};
    int count = 0;
    Model *cur;
    for (cur=model; cur != ((void *)0); cur=cur->next){
 sum = Point3D_add(sum, cur->line.p1);
 sum = Point3D_add(sum, cur->line.p2);
 count += 2;
    }
    sum.x /= count;
    sum.y /= count;
    sum.z /= count;
    return sum;
}

canonical_original_code:
struct Point3D Model_average_point(struct Model *model){
    struct Point3D sum = {0,0,0};
    int count = 0;
    struct Model *cur;
    for (cur=model; cur != ((void *)0); cur=cur->next){
 sum = Point3D_add(sum, cur->line.p1);
 sum = Point3D_add(sum, cur->line.p2);
 count += 2;
    }
    sum.x /= count;
    sum.y /= count;
    sum.z /= count;
    return sum;
}

variable_types: struct Model { struct Line3D { struct Point3D p1; struct Point3D p2; } line; struct Model *next; } *

variable_types:
sum
struct Point3D { int x; int y; int z; }

variable_types: count int


repo: SpenceSellers/CRenderer

decompiled_code:
void __fastcall Model_centerize(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx
__int64 v3; // rax
unsigned int v4; // edx

v1 = Model_average_point(a1);
v3 = Point3D_subtract(0LL, 0LL, v1, v2);
Model_shift(a1, v3, v4);
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
__int64 v1; // rax
unsigned int v2; // edx
__int64 v3; // rax
unsigned int v4; // edx

v1 = func6(a1);
v3 = Point3D_subtract(0LL, 0LL, v1, v2);
func3(a1, v3, v4);
}

original_code:
void Model_centerize(Model *model){
    Point3D center = Model_average_point(model);
    Point3D origin = {0,0,0};
    Point3D delta = Point3D_subtract(origin, center);
    Model_shift(model, delta);
}

canonical_original_code:
void Model_centerize(struct Model *model){
    struct Point3D center = Model_average_point(model);
    struct Point3D origin = {0,0,0};
    struct Point3D delta = Point3D_subtract(origin, center);
    Model_shift(model, delta);
}

variable_types: struct Model { struct Line3D { struct Point3D { int x; int y; int z; } p1; struct Point3D p2; } line; struct Model *next; } *

variable_types:
center
struct Point3D { int x; int y; int z; }

variable_types:
origin
struct Point3D { int x; int y; int z; }

variable_types:
delta
struct Point3D { int x; int y; int z; }

return_type: void

user_defined_types: struct Model { struct Line3D line; struct Model *next; }

user_defined_types: struct Line3D { struct Point3D p1; struct Point3D p2; }


original_code:
Model * Model_extrude(Model *model, Point3D delta, int bothsides){
    Model *new_lines = ((void *)0);
    Model *cur;
    for (cur = model; cur != ((void *)0); cur = cur->next){
 Line3D shifted;
 shifted.p1 = Point3D_add(cur->line.p1, delta);
 shifted.p2 = Point3D_add(cur->line.p2, delta);
 Line3D l;
 l.p1 = cur->line.p1;
 l.p2 = shifted.p1;
 new_lines = Model_add(new_lines, shifted);
 new_lines = Model_add(new_lines, l);
 if (bothsides){
     l.p1 = cur->line.p2;
     l.p2 = shifted.p2;
     new_lines = Model_add(new_lines, l);
 }
    }
    model = Model_combine(new_lines, model);
    return model;
}

canonical_original_code:
struct Model *Model_extrude(struct Model *model, struct Point3D delta, int bothsides){
    struct Model *new_lines = ((void *)0);
    struct Model *cur;
    for (cur = model; cur != ((void *)0); cur = cur->next){
 struct Line3D shifted;
 shifted.p1 = Point3D_add(cur->line.p1, delta);
 shifted.p2 = Point3D_add(cur->line.p2, delta);
 struct Line3D l;
 l.p1 = cur->line.p1;
 l.p2 = shifted.p1;
 new_lines = Model_add(new_lines, shifted);
 new_lines = Model_add(new_lines, l);
 if (bothsides){
     l.p1 = cur->line.p2;
     l.p2 = shifted.p2;
     new_lines = Model_add(new_lines, l);
 }
    }
    model = Model_combine(new_lines, model);
    return model;
}

variable_types:
model
struct Model *

variable_types:
delta
struct Point3D

variable_types: bothsides int

return_type: struct Model { struct Line3D { struct Point3D { int x; int y; int z; } p1; struct Point3D p2; } line; struct Model *next; } *


decompiled_code:
void Scene_new()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
Scene * Scene_new(){
    Scene *scene = malloc(sizeof(Scene));
    scene->objects = ((void *)0);
    scene->time = 0;
}

canonical_original_code:
struct Scene *Scene_new(){
    struct Scene *scene = malloc(sizeof(Scene));
    scene->objects = ((void *)0);
    scene->time = 0;
}

variable_types: struct Scene { struct SceneList { struct Object { struct Point3D { int x; int y; int z; } pos; struct Model { struct Line3D { struct Point3D p1; struct Point3D p2; } line; struct Model *next; } *model; unsigned int color; struct RotationVector { double rotX; double rotY; double rotZ; } rotation; void (*ai)(struct Object *, struct Scene *); void *ai_data; void (*ai_data_free)(struct Object *); } *obj; struct SceneList *next; } *objects; int time; } *

user_defined_types: struct Scene { struct SceneList *objects; int time; }

user_defined_types: struct SceneList { struct Object *obj; struct SceneList *next; }

user_defined_types: struct Object { struct Point3D pos; struct Model *model; unsigned int color; struct RotationVector rotation; void (*ai)(struct Object *, struct Scene *); void *ai_data; void (*ai_data_free)(struct Object *); }


repo: SpenceSellers/microMC

decompiled_code:
size_t __fastcall encoded_MCString_len(const char *a1)
{
return 2 * strlen(a1) + 2;
}

canonical_decompiled_code:
size_t __fastcall func2(const char *a1)
{
return 2 * strlen(a1) + 2;
}

original_code:
size_t encoded_MCString_len(char *string){
    size_t slen = strlen(string);
    return 2 + (slen * 2);
}

canonical_original_code:
unsigned long encoded_MCString_len(char *string){
    unsigned long slen = strlen(string);
    return 2 + (slen * 2);
}

variable_types:
string
char *

variable_types:
slen
unsigned long

return_type: unsigned long


decompiled_code:
__int64 __fastcall write_int(unsigned int a1, _DWORD *a2)
{
*a2 = _bswap_32(a1);
return 4LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, _DWORD *a2)
{
*a2 = func1(a1);
return 4LL;
}

original_code:
size_t write_int(int i, char *place){
    int bige_int = htonl(i);
    *(int*) place = bige_int;
    return 4;
}

canonical_original_code:
unsigned long write_int(int i, char *place){
    int bige_int = htonl(i);
    *(int *) place = bige_int;
    return 4;
}

variable_types: i int

variable_types:
place
char *


decompiled_code:
__int64 __fastcall write_short(__int16 a1, __int16 *a2)
{
*a2 = _bswap_16(a1);
return 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int16 a1, __int16 *a2)
{
*a2 = func0(a1);
return 2LL;
}

original_code:
size_t write_short(short s, char *place){
    short flipped = htons(s);
    *(short*) place = flipped;
    return 2;
}

canonical_original_code:
unsigned long write_short(short s, char *place){
    short flipped = htons(s);
    *(short *) place = flipped;
    return 2;
}

variable_types: s short

variable_types: flipped short


decompiled_code:
__int64 __fastcall write_char(char a1, _BYTE *a2)
{
*a2 = a1;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char a1, _BYTE *a2)
{
*a2 = a1;
return 1LL;
}

original_code:
size_t write_char(char c, char *place){
    *place = c;
    return 1;
}

canonical_original_code:
unsigned long write_char(char c, char *place){
    *place = c;
    return 1;
}

variable_types: c char


decompiled_code:
__int64 __fastcall write_compressed(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v5 = a4;
if ( (unsigned int)compress(a3, &v5, a1, a2) == -4 )
logmsg(0LL, "Not enough memory given to compress data!");
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v5; // [rsp+8h] [rbp-10h] BYREF

v5 = a4;
if ( (unsigned int)compress(a3, &v5, a1, a2) == -4 )
logmsg(0LL, "Not enough memory given to compress data!");
return v5;
}

original_code:
size_t write_compressed(char *data, size_t len, char *place, size_t maxlen){
    size_t written = maxlen;
    int e = compress((unsigned char *) place, &written,(Bytef *) data, len);
    if (e == (-4)){
 logmsg(0, "Not enough memory given to compress data!");
    }
    return written;
}

canonical_original_code:
unsigned long write_compressed(char *data, unsigned long len, char *place, unsigned long maxlen){
    unsigned long written = maxlen;
    int e = compress((unsigned char *) place, &written,(Bytef *) data, len);
    if (e == (-4)){
 logmsg(0, "Not enough memory given to compress data!");
    }
    return written;
}

variable_types:
data
char *

variable_types:
len
unsigned long

variable_types:
maxlen
unsigned long

variable_types:
written
unsigned long

variable_types: e int


decompiled_code:
__int64 __fastcall read_int(unsigned int *a1, _QWORD *a2)
{
if ( a2 )
*a2 += 4LL;
return _bswap_32(*a1);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1, _QWORD *a2)
{
if ( a2 )
*a2 += 4LL;
return func1(*a1);
}

original_code:
int read_int(char *place, size_t *read){
    if (read) *read += 4;
    return ntohl(*( (int*) place));
}

canonical_original_code:
int read_int(char *place, unsigned long *read){
    if (read) *read += 4;
    return ntohl(*( (int *) place));
}

variable_types:
read
unsigned long *

return_type: int


decompiled_code:
__int16 __fastcall read_short(__int16 *a1, _QWORD *a2)
{
if ( a2 )
*a2 += 2LL;
return _bswap_16(*a1);
}

canonical_decompiled_code:
__int16 __fastcall func8(__int16 *a1, _QWORD *a2)
{
if ( a2 )
*a2 += 2LL;
return func0(*a1);
}

original_code:
short read_short(char *place, size_t *read){
    if (read) *read += 2;
    return ntohs(*( (short*) place));
}

canonical_original_code:
short read_short(char *place, unsigned long *read){
    if (read) *read += 2;
    return ntohs(*( (short *) place));
}

return_type: short


decompiled_code:
__int64 __fastcall read_char(unsigned __int8 *a1, _QWORD *a2)
{
if ( a2 )
++*a2;
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1, _QWORD *a2)
{
if ( a2 )
++*a2;
return *a1;
}

original_code:
char read_char(char *place, size_t *read){
    if (read) *read += 1;
    return *place;
}

canonical_original_code:
char read_char(char *place, unsigned long *read){
    if (read) *read += 1;
    return *place;
}

return_type: char


decompiled_code:
float __fastcall swap_float_endian(__m128i a1)
{
__int16 v1; // ax
float v3; // [rsp+0h] [rbp-4h]

v1 = _mm_cvtsi128_si32(a1);
BYTE2(v3) = HIBYTE(v1);
LOBYTE(v3) = (unsigned int)_mm_cvtsi128_si32(a1) >> 24;
HIBYTE(v3) = v1;
BYTE1(v3) = (unsigned int)(_mm_cvtsi128_si32(a1) << 8) >> 24;
return v3;
}

canonical_decompiled_code:
float __fastcall func10(__m128i a1)
{
__int16 v1; // ax
float v3; // [rsp+0h] [rbp-4h]

v1 = _mm_cvtsi128_si32(a1);
BYTE2(v3) = HIBYTE(v1);
LOBYTE(v3) = (unsigned int)_mm_cvtsi128_si32(a1) >> 24;
HIBYTE(v3) = v1;
BYTE1(v3) = (unsigned int)(_mm_cvtsi128_si32(a1) << 8) >> 24;
return v3;
}

original_code:
float swap_float_endian(float f){
    float result;
    char *fchars = (char*) &f;
    char *rchars = (char*) &result;
    rchars[0] = fchars[3];
    rchars[1] = fchars[2];
    rchars[2] = fchars[1];
    rchars[3] = fchars[0];
    return result;
}

variable_types: f float

variable_types: result float

variable_types:
fchars
char *

variable_types:
rchars
char *

return_type: float


decompiled_code:
__int64 __fastcall write_float(float *a1, __m128i a2)
{
float v2; // xmm0_4
__int64 result; // rax

v2 = swap_float_endian(a2);
result = 4LL;
*a1 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(float *a1, __m128i a2)
{
float v2; // xmm0_4
__int64 result; // rax

v2 = func10(a2);
result = 4LL;
*a1 = v2;
return result;
}

original_code:
size_t write_float(float f, char *place){
    float flipped = swap_float_endian(f);
    *(float*) place = flipped;
    return 4;
}

canonical_original_code:
unsigned long write_float(float f, char *place){
    float flipped = swap_float_endian(f);
    *(float *) place = flipped;
    return 4;
}

variable_types: flipped float


decompiled_code:
float __fastcall read_float(unsigned int *a1, _QWORD *a2)
{
__m128i v2; // xmm0

v2 = (__m128i)*a1;
if ( a2 )
*a2 += 4LL;
return swap_float_endian(v2);
}

canonical_decompiled_code:
float __fastcall func12(unsigned int *a1, _QWORD *a2)
{
__m128i v2; // xmm0

v2 = (__m128i)*a1;
if ( a2 )
*a2 += 4LL;
return func10(v2);
}

original_code:
float read_float(char *place, size_t *read){
    float f = *(float*) place;
    if (read) *read += 4;
    return swap_float_endian(f);
}

canonical_original_code:
float read_float(char *place, unsigned long *read){
    float f = *(float*) place;
    if (read) *read += 4;
    return swap_float_endian(f);
}


original_code:
double swap_double_endian(double f){
    double result;
    char *fchars = (char*) &f;
    char *rchars = (char*) &result;
    rchars[0] = fchars[7];
    rchars[1] = fchars[6];
    rchars[2] = fchars[5];
    rchars[3] = fchars[4];
    rchars[4] = fchars[3];
    rchars[5] = fchars[2];
    rchars[6] = fchars[1];
    rchars[7] = fchars[0];
    return result;
}

variable_types: f double

variable_types: result double

return_type: double


decompiled_code:
__int64 __fastcall write_double(double *a1, __m128i a2)
{
double v2; // xmm0_8
__int64 result; // rax

v2 = swap_double_endian(a2);
result = 8LL;
*a1 = v2;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(double *a1, __m128i a2)
{
double v2; // xmm0_8
__int64 result; // rax

v2 = func13(a2);
result = 8LL;
*a1 = v2;
return result;
}

original_code:
size_t write_double(double d, char *place){
    double flipped = swap_double_endian(d);
    *(double*) place = flipped;
    return 8;
}

canonical_original_code:
unsigned long write_double(double d, char *place){
    double flipped = swap_double_endian(d);
    *(double *) place = flipped;
    return 8;
}

variable_types: d double

variable_types:
place
char *

variable_types: flipped double


decompiled_code:
double __fastcall read_double(unsigned __int64 *a1, _QWORD *a2)
{
__m128i v2; // xmm0

v2 = (__m128i)*a1;
if ( a2 )
*a2 += 8LL;
return swap_double_endian(v2);
}

canonical_decompiled_code:
double __fastcall func15(unsigned __int64 *a1, _QWORD *a2)
{
__m128i v2; // xmm0

v2 = (__m128i)*a1;
if ( a2 )
*a2 += 8LL;
return func13(v2);
}

original_code:
double read_double(char *place, size_t *read){
    double d = *(double*) place;
    if (read) *read += 8;
    return swap_double_endian(d);
}

canonical_original_code:
double read_double(char *place, unsigned long *read){
    double d = *(double*) place;
    if (read) *read += 8;
    return swap_double_endian(d);
}


decompiled_code:
__int64 __fastcall pack_halfchars(int a1, int a2)
{
return a2 & (unsigned int)(16 * a1);
}

canonical_decompiled_code:
__int64 __fastcall func16(int a1, int a2)
{
return a2 & (unsigned int)(16 * a1);
}

original_code:
char pack_halfchars(char a, char b){
    return (a << 4) & b;
}

variable_types: a char

variable_types: b char


decompiled_code:
char *__fastcall fake_json_chat(void *src)
{
size_t v1; // rbx
char *v2; // r12

v1 = strlen((const char *)src);
v2 = (char *)malloc(v1 + 12);
*(_QWORD *)v2 = 0x3A2274786574227BLL;
v2[8] = 34;
memcpy(v2 + 9, src, v1);
strcpy(&v2[v1 + 9], "\"}");
return v2;
}

canonical_decompiled_code:
char *__fastcall func17(void *src)
{
size_t v1; // rbx
char *v2; // r12

v1 = strlen((const char *)src);
v2 = (char *)malloc(v1 + 12);
*(_QWORD *)v2 = 0x3A2274786574227BLL;
v2[8] = 34;
memcpy(v2 + 9, src, v1);
strcpy(&v2[v1 + 9], "\"}");
return v2;
}

original_code:
char * fake_json_chat(char *str){
    char *before = "{\"text\":\"";
    char *after = "\"}";
    char *fake_json = malloc(sizeof(char) * (strlen(before) + strlen(after) + strlen(str) + 1));
    fake_json[0] = 0;
    strcat(fake_json, before);
    strcat(fake_json, str);
    strcat(fake_json, after);
    return fake_json;
}

canonical_original_code:
char *fake_json_chat(char *str){
    char *before = "{\"text\":\"";
    char *after = "\"}";
    char *fake_json = malloc(sizeof(char) * (strlen(before) + strlen(after) + strlen(str) + 1));
    fake_json[0] = 0;
    strcat(fake_json, before);
    strcat(fake_json, str);
    strcat(fake_json, after);
    return fake_json;
}

variable_types:
str
char *

variable_types:
before
char *

variable_types:
after
char *

return_type: char *


decompiled_code:
__int64 __fastcall to_fixed_point(double a1)
{
return (unsigned int)(int)(a1 * 32.0);
}

canonical_decompiled_code:
__int64 __fastcall func18(double a1)
{
return (unsigned int)(int)(a1 * 32.0);
}

original_code:
int to_fixed_point(double d){
    return (int) (d*32);
}


decompiled_code:
double __fastcall from_fixed_point(int a1)
{
return (double)a1 * 0.03125;
}

canonical_decompiled_code:
double __fastcall func19(int a1)
{
return (double)a1 * 0.03125;
}

original_code:
double from_fixed_point(int i){
    return ((double) i)/32;
}

variable_types: i int


decompiled_code:
int __fastcall debug_list_players(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rsi
__int64 v4; // rax

printf("%d players logged in.\n", *(unsigned int *)(a1 + 152));
result = *(_DWORD *)(a1 + 152);
if ( result > 0 )
{
v2 = 0LL;
do
{
v3 = (unsigned int)v2;
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v2++);
result = printf(
"Index %d, Player: %s, eid: %d, socket %d \n",
v3,
*(const char **)(v4 + 56),
*(unsigned int *)(v4 + 64),
*(unsigned int *)(v4 + 68));
}
while ( *(_DWORD *)(a1 + 152) > (int)v2 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1)
{
int result; // eax
__int64 v2; // rbx
__int64 v3; // rsi
__int64 v4; // rax

printf("%d players logged in.\n", *(unsigned int *)(a1 + 152));
result = *(_DWORD *)(a1 + 152);
if ( result > 0 )
{
v2 = 0LL;
do
{
v3 = (unsigned int)v2;
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v2++);
result = printf(
"Index %d, Player: %s, eid: %d, socket %d \n",
v3,
*(const char **)(v4 + 56),
*(unsigned int *)(v4 + 64),
*(unsigned int *)(v4 + 68));
}
while ( *(_DWORD *)(a1 + 152) > (int)v2 );
}
return result;
}

original_code:
void debug_list_players(Server *server){
    int i;
    printf("%d players logged in.\n", server->num_players);
    for (i=0; i < server->num_players; i++){
 Player *p = server->players[i];
 printf("Index %d, Player: %s, eid: %d, socket %d \n",
        i, p->username, p->entity_id, p->socket);
    }
}

canonical_original_code:
void debug_list_players(struct Server *server){
    int i;
    printf("%d players logged in.\n", server->num_players);
    for (i=0; i < server->num_players; i++){
 struct Player *p = server->players[i];
 printf("Index %d, Player: %s, eid: %d, socket %d \n",
        i, p->username, p->entity_id, p->socket);
    }
}

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

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: 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: 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 Inventory { unsigned long size; struct Slot **slots; }

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


decompiled_code:
bool __fastcall Server_is_full(__int64 a1)
{
return (unsigned __int64)*(int *)(a1 + 152) >= *(_QWORD *)(a1 + 88);
}

canonical_decompiled_code:
bool __fastcall func1(__int64 a1)
{
return (unsigned __int64)*(int *)(a1 + 152) >= *(_QWORD *)(a1 + 88);
}

original_code:
char Server_is_full(Server *server){
    if (server->num_players >= server->max_players) return 1;
    else return 0;
}

canonical_original_code:
char Server_is_full(struct Server *server){
    if (server->num_players >= server->max_players) return 1;
    else return 0;
}

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 get_index_of_player(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 152);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
__int64 v2; // rdx
__int64 result; // rax

v2 = *(int *)(a1 + 152);
if ( (int)v2 <= 0 )
return 0xFFFFFFFFLL;
result = 0LL;
while ( *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * result) != a2 )
{
if ( ++result == v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)result;
}

original_code:
int get_index_of_player(Server *server, Player *player){
    int i;
    for (i=0; i < server->num_players; i++){
 if (server->players[i] == player){
     return i;
 }
    }
    return -1;
}

canonical_original_code:
int get_index_of_player(struct Server *server, struct Player *player){
    int i;
    for (i=0; i < server->num_players; i++){
 if (server->players[i] == player){
     return i;
 }
    }
    return -1;
}

variable_types:
player
struct Player *


decompiled_code:
__int64 __fastcall send_player_positions(__int64 a1)
{
int v1; // edx
__int64 v2; // r12
__int64 i; // rbx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 152);
if ( v1 > 0 )
{
v2 = 0LL;
do
{
for ( i = 0LL; v1 > (int)i; ++i )
{
result = *(_QWORD *)(a1 + 160);
if ( *(_QWORD *)(result + 8 * v2) != *(_QWORD *)(result + 8 * i) )
{
result = Player_send_player_position();
v1 = *(_DWORD *)(a1 + 152);
}
}
++v2;
}
while ( v1 > (int)v2 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // edx
__int64 v2; // r12
__int64 i; // rbx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 152);
if ( v1 > 0 )
{
v2 = 0LL;
do
{
for ( i = 0LL; v1 > (int)i; ++i )
{
result = *(_QWORD *)(a1 + 160);
if ( *(_QWORD *)(result + 8 * v2) != *(_QWORD *)(result + 8 * i) )
{
result = Player_send_player_position();
v1 = *(_DWORD *)(a1 + 152);
}
}
++v2;
}
while ( v1 > (int)v2 );
}
return result;
}

original_code:
void send_player_positions(Server *server){
    int i;
    int j;
    for (i=0; i < server->num_players; i++){
 for(j=0; j < server->num_players; j++){
     if (server->players[i] == server->players[j]) continue;
     Player_send_player_position(server->players[i], server->players[j]);
 }
    }
}

canonical_original_code:
void send_player_positions(struct Server *server){
    int i;
    int j;
    for (i=0; i < server->num_players; i++){
 for(j=0; j < server->num_players; j++){
     if (server->players[i] == server->players[j]) continue;
     Player_send_player_position(server->players[i], server->players[j]);
 }
    }
}

variable_types: j int


decompiled_code:
__int64 __fastcall Server_tick(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // rbx
__int64 v7; // rdi

v2 = *(_QWORD *)(a1 + 64) + 1LL;
*(_QWORD *)(a1 + 64) = v2;
if ( __ROR8__(0xCCCCCCCCCCCCCCCDLL * v2 + 0x1999999999999998LL, 2) <= 0xCCCCCCCCCCCCCCCuLL && *(int *)(a1 + 152) > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v3++);
Player_send_keep_alive(v4);
}
while ( *(_DWORD *)(a1 + 152) > (int)v3 );
}
send_player_positions(a1);
result = *(unsigned int *)(a1 + 152);
if ( (int)result > 0 )
{
v6 = 0LL;
do
{
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v6++);
result = Player_tick_lastlocation(v7);
}
while ( *(_DWORD *)(a1 + 152) > (int)v6 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v2; // rax
__int64 v3; // rbx
__int64 v4; // rdi
__int64 result; // rax
__int64 v6; // rbx
__int64 v7; // rdi

v2 = *(_QWORD *)(a1 + 64) + 1LL;
*(_QWORD *)(a1 + 64) = v2;
if ( __ROR8__(0xCCCCCCCCCCCCCCCDLL * v2 + 0x1999999999999998LL, 2) <= 0xCCCCCCCCCCCCCCCuLL && *(int *)(a1 + 152) > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v3++);
Player_send_keep_alive(v4);
}
while ( *(_DWORD *)(a1 + 152) > (int)v3 );
}
func3(a1);
result = *(unsigned int *)(a1 + 152);
if ( (int)result > 0 )
{
v6 = 0LL;
do
{
v7 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v6++);
result = Player_tick_lastlocation(v7);
}
while ( *(_DWORD *)(a1 + 152) > (int)v6 );
}
return result;
}

original_code:
void Server_tick(Server *server){
    server->time++;
    if (server->time % 20 == 0) {
 int i;
 for(i=0; i < server->num_players; i++){
     Player_send_keep_alive(server->players[i]);
 }
    }
    send_player_positions(server);
    int i;
    for(i=0; i < server->num_players; i++){
 Player_tick_lastlocation(server->players[i]);
    }
}

canonical_original_code:
void Server_tick(struct Server *server){
    server->time++;
    if (server->time % 20 == 0) {
 int i;
 for(i=0; i < server->num_players; i++){
     Player_send_keep_alive(server->players[i]);
 }
    }
    send_player_positions(server);
    int i;
    for(i=0; i < server->num_players; i++){
 Player_tick_lastlocation(server->players[i]);
    }
}


decompiled_code:
int __fastcall Server_shutdown(__int64 a1)
{
int v2; // eax
__int64 v3; // rbx
__int64 v4; // rdi
int result; // eax

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

canonical_decompiled_code:
int __fastcall func5(__int64 a1)
{
int v2; // eax
__int64 v3; // rbx
__int64 v4; // rdi
int result; // eax

v2 = *(_DWORD *)(a1 + 152);
*(_BYTE *)(a1 + 56) = 0;
if ( v2 > 0 )
{
v3 = 0LL;
do
{
v4 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v3++);
Player_disconnect(v4, "Server shutting down!");
}
while ( *(_DWORD *)(a1 + 152) > (int)v3 );
}
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);
    }
}


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

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

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned int a2, __int64 a3, __int64 a4, __int64 a5)
{
unsigned int v5; // er15
unsigned int v6; // er13
unsigned int v7; // er12
__int64 result; // rax
__int64 v10; // rbx
__int64 v11; // rdi

v5 = a5;
v6 = a4;
v7 = a3;
logfmt(3LL, "Block is being changed: %d %d %d", a3, a4, a5);
Map_set_block(*(_QWORD *)(a1 + 224), a2, v7, v6, v5);
result = *(unsigned int *)(a1 + 152);
if ( (int)result > 0 )
{
v10 = 0LL;
do
{
v11 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v10++);
result = Player_send_block_change(v11, a2, v7, v6, v5);
}
while ( *(_DWORD *)(a1 + 152) > (int)v10 );
}
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:
b
struct Block

variable_types: x int

variable_types: y int

variable_types: z int


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

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

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v4; // rbx
__int64 v5; // rdi

result = *(unsigned int *)(a1 + 152);
if ( (int)result > 0 )
{
v4 = 0LL;
do
{
v5 = *(_QWORD *)(*(_QWORD *)(a1 + 160) + 8 * v4++);
result = Player_send_message(v5, a2);
}
while ( *(_DWORD *)(a1 + 152) > (int)v4 );
}
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 *


decompiled_code:
__int64 __fastcall Server_add_player(__int64 a1, __int64 a2)
{
__int64 v3; // rcx
int v4; // eax
int v5; // edx
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rdi
const char *v9; // rsi
char v11[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 = *(int *)(a1 + 152);
v4 = *(_DWORD *)(a1 + 72) + 1;
v5 = *(_DWORD *)(a1 + 152);
*(_DWORD *)(a1 + 72) = v4;
++v5;
*(_DWORD *)(a2 + 64) = v4;
v6 = *(_QWORD *)(a1 + 160);
*(_QWORD *)(v6 + 8 * v3) = a2;
*(_DWORD *)(a1 + 152) = v5;
if ( v5 > 0 )
{
v7 = 0LL;
while ( 1 )
{
v8 = *(_QWORD *)(v6 + 8 * v7);
if ( v8 != a2 )
Player_send_new_player(v8, a2);
if ( *(_DWORD *)(a1 + 152) <= (int)++v7 )
break;
v6 = *(_QWORD *)(a1 + 160);
}
}
v9 = *(const char **)(a2 + 56);
v11[0] = 0;
strcpy(stpcpy(v11, v9), " has joined!");
return Server_tell_all(a1, (__int64)v11);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
__int64 v3; // rcx
int v4; // eax
int v5; // edx
__int64 v6; // rax
__int64 v7; // rbx
__int64 v8; // rdi
const char *v9; // rsi
char v11[280]; // [rsp+0h] [rbp-118h] BYREF

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

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:
msgbuffer
char [256]


decompiled_code:
__int64 __fastcall Server_remove_player(__int64 a1, __int64 a2)
{
int v2; // edx
int v3; // eax
int v4; // er12
const char *v5; // rsi
char v7[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);
v4 = v3 - 1;
if ( v2 < v3 - 1 )
memmove(
(void *)(8LL * v2 + *(_QWORD *)(a1 + 160)),
(const void *)(*(_QWORD *)(a1 + 160) + 8LL * v2 + 8),
8LL * (unsigned int)(v3 - 2 - v2) + 8);
*(_DWORD *)(a1 + 152) = v4;
logmsg(3LL, "Done removing player.");
v5 = *(const char **)(a2 + 56);
v7[0] = 0;
strcpy(stpcpy(v7, v5), " has quit.");
return Server_tell_all(a1, (__int64)v7);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2)
{
int v2; // edx
int v3; // eax
int v4; // er12
const char *v5; // rsi
char v7[280]; // [rsp+0h] [rbp-118h] BYREF

logfmt(2LL, "Removing Player: %s from server.", *(const char **)(a2 + 56));
v2 = func2(a1, a2);
v3 = *(_DWORD *)(a1 + 152);
v4 = v3 - 1;
if ( v2 < v3 - 1 )
memmove(
(void *)(8LL * v2 + *(_QWORD *)(a1 + 160)),
(const void *)(*(_QWORD *)(a1 + 160) + 8LL * v2 + 8),
8LL * (unsigned int)(v3 - 2 - v2) + 8);
*(_DWORD *)(a1 + 152) = v4;
logmsg(3LL, "Done removing player.");
v5 = *(const char **)(a2 + 56);
v7[0] = 0;
strcpy(stpcpy(v7, v5), " has quit.");
return func7(a1, (__int64)v7);
}

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)
{
__int64 result; // rax

result = *(__int16 *)(a1 + 6) + 7LL;
if ( *(_WORD *)(a1 + 6) == 0xFFFF )
result = 7LL;
return result;
}

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

result = *(__int16 *)(a1 + 6) + 7LL;
if ( *(_WORD *)(a1 + 6) == 0xFFFF )
result = 7LL;
return result;
}

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


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


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

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

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

result = malloc(0x10uLL);
*(_WORD *)result = -1;
result[2] = 0;
*((_DWORD *)result + 1) = -65536;
*((_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)
{
int v3; // edi
char *v4; // r12
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
__int16 v9; // ax
char *v10; // rdi
void *v12; // r12
_BYTE *v13; // rbp

logmsg(3LL, "Encoding slot.");
if ( !a1 )
{
v13 = Slot_new_empty();
v4 = (char *)Slot_encode(v13, a2);
Slot_free(v13);
return v4;
}
if ( !Slot_is_empty((__int64)a1) )
{
v3 = *((__int16 *)a1 + 3);
if ( *((_WORD *)a1 + 3) == 0xFFFF )
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 )
{
v10 = &v4[v8];
v8 += v9;
memcpy(v10, a1[1], v9);
}
*a2 = v8;
return v4;
}
v12 = malloc(2uLL);
*a2 = write_short((unsigned int)*(__int16 *)a1, v12);
return (char *)v12;
}

canonical_decompiled_code:
char *__fastcall func4(const void **a1, __int64 *a2)
{
int v3; // edi
char *v4; // r12
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbx
__int64 v8; // rbx
__int16 v9; // ax
char *v10; // rdi
void *v12; // r12
_BYTE *v13; // rbp

logmsg(3LL, "Encoding slot.");
if ( !a1 )
{
v13 = func3();
v4 = (char *)func4(v13, a2);
func1(v13);
return v4;
}
if ( !func2((__int64)a1) )
{
v3 = *((__int16 *)a1 + 3);
if ( *((_WORD *)a1 + 3) == 0xFFFF )
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 )
{
v10 = &v4[v8];
v8 += v9;
memcpy(v10, a1[1], v9);
}
*a2 = v8;
return v4;
}
v12 = malloc(2uLL);
*a2 = write_short((unsigned int)*(__int16 *)a1, v12);
return (char *)v12;
}

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


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 *


decompiled_code:
__int64 __fastcall Slot_add(__int64 a1, unsigned __int16 *a2)
{
__int64 result; // rax
int v3; // er8

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 = *((char *)a2 + 2);
result = (unsigned int)(64 - *(char *)(a1 + 2));
if ( v3 > (int)result )
{
*(_BYTE *)(a1 + 2) = 64;
*((_BYTE *)a2 + 2) -= result;
}
else
{
*(_BYTE *)(a1 + 2) += v3;
*((_BYTE *)a2 + 2) = 0;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, unsigned __int16 *a2)
{
__int64 result; // rax
int v3; // er8

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 = *((char *)a2 + 2);
result = (unsigned int)(64 - *(char *)(a1 + 2));
if ( v3 > (int)result )
{
*(_BYTE *)(a1 + 2) = 64;
*((_BYTE *)a2 + 2) -= result;
}
else
{
*(_BYTE *)(a1 + 2) += 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 v2; // rbx
void *v3; // rdi

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

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

if ( *(_QWORD *)ptr )
{
v2 = 0LL;
do
{
v3 = (void *)func8((unsigned __int64 *)ptr, v2);
if ( v3 )
func1(v3);
++v2;
}
while ( *(_QWORD *)ptr > v2 );
}
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; } *

variable_types: i int


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

if ( *a1 - 1 < a3 )
return logmsg(1LL, "Tried to set invalid slot index!");
v5 = (void *)Inventory_get(a1, a3);
if ( v5 )
Slot_free(v5);
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 *v5; // rdi
__int64 result; // rax

if ( *a1 - 1 < a3 )
return logmsg(1LL, "Tried to set invalid slot index!");
v5 = (void *)func8(a1, a3);
if ( v5 )
func1(v5);
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; // r12
__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; // r12
__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; // rbp
void *v3; // r12
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; // rbp
void *v3; // r12
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; // rbp
int v2; // [rsp+4h] [rbp-24h] BYREF
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

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

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
void *v1; // rbp
int v2; // [rsp+4h] [rbp-24h] BYREF
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

v2 = 1;
v1 = (void *)Packet00KeepAlive_encode(&v2, n);
send(*(_DWORD *)(a1 + 68), v1, n[0], 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; // rax
_BYTE *v9; // rbp
void *v10; // r12
size_t n[8]; // [rsp+8h] [rbp-40h] BYREF

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

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

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

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; // rbp
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; // rbp
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; // rbp
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]

v7 = a2;
v6 = a3;
v5[0] = 0;
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)
{
_DWORD *v3; // rax
const char *v4; // rdi
_DWORD *v5; // rbp
char *v6; // rax
double v7; // xmm0_8
int v8; // eax
double v9; // xmm0_8
int v10; // eax
double v11; // xmm0_8
int v12; // eax
void *v13; // r12
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = malloc(0x28uLL);
v4 = *(const char **)(a2 + 56);
v5 = v3;
*v3 = *(_DWORD *)(a2 + 64);
v6 = strdup(v4);
v7 = *(double *)(a2 + 88);
*((_QWORD *)v5 + 1) = v6;
v8 = to_fixed_point(v7);
v9 = *(double *)(a2 + 96);
v5[4] = v8;
v10 = to_fixed_point(v9);
v11 = *(double *)(a2 + 104);
v5[5] = v10;
v12 = to_fixed_point(v11);
*((_BYTE *)v5 + 32) = 31;
v5[6] = v12;
v5[7] = 0;
v13 = (void *)Packet14SpawnNamedEntity_encode(v5, n);
send(*(_DWORD *)(a1 + 68), v13, n[0], 0);
Packet14SpawnNamedEntity_free(v5);
free(v13);
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, __int64 a2)
{
_DWORD *v3; // rax
const char *v4; // rdi
_DWORD *v5; // rbp
char *v6; // rax
double v7; // xmm0_8
int v8; // eax
double v9; // xmm0_8
int v10; // eax
double v11; // xmm0_8
int v12; // eax
void *v13; // r12
size_t n[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = malloc(0x28uLL);
v4 = *(const char **)(a2 + 56);
v5 = v3;
*v3 = *(_DWORD *)(a2 + 64);
v6 = strdup(v4);
v7 = *(double *)(a2 + 88);
*((_QWORD *)v5 + 1) = v6;
v8 = to_fixed_point(v7);
v9 = *(double *)(a2 + 96);
v5[4] = v8;
v10 = to_fixed_point(v9);
v11 = *(double *)(a2 + 104);
v5[5] = v10;
v12 = to_fixed_point(v11);
*((_BYTE *)v5 + 32) = 31;
v5[6] = v12;
v5[7] = 0;
v13 = (void *)Packet14SpawnNamedEntity_encode(v5, n);
send(*(_DWORD *)(a1 + 68), v13, n[0], 0);
Packet14SpawnNamedEntity_free(v5);
free(v13);
}

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)
{
__int64 v1; // rax
void *v2; // rbp
size_t n; // [rsp+8h] [rbp-30h] BYREF
char v4[8]; // [rsp+10h] [rbp-28h] BYREF
__int64 v5; // [rsp+18h] [rbp-20h]

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

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

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

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; // rbp
double v2; // xmm0_8
__int64 v3; // rax
void *v4; // r12
size_t n[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

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

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(__int64 a1, double a2, double a3, double a4)
{
Player_set_position((double *)a1, a2, a3, a4);
Player_send_pos_and_look_update(a1);
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, double a2, double a3, double a4)
{
func5((double *)a1, a2, a3, a4);
func10(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; // er14
unsigned int v6; // er13
unsigned int v7; // er12
unsigned __int8 *v8; // rbx
__int64 result; // rax

v5 = a5;
v6 = a4;
v7 = a3;
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, v7, v6, v5);
--v8[2];
}
return result;
}

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

v5 = a5;
v6 = a4;
v7 = a3;
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, v7, v6, v5);
--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; // rbp

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

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

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

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; // r12
__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", &v5, &v6, &v7);
switch ( v3 )
{
case 1:
v4 = (void *)Slot_new_basic((unsigned int)v5, 64LL, 0LL);
goto LABEL_5;
case 2:
v4 = (void *)Slot_new_basic((unsigned int)v5, (unsigned int)v6, 0LL);
goto LABEL_5;
case 3:
v4 = (void *)Slot_new_basic((unsigned int)v5, (unsigned int)v6, (unsigned int)v7);
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; // r12
__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", &v5, &v6, &v7);
switch ( v3 )
{
case 1:
v4 = (void *)Slot_new_basic((unsigned int)v5, 64LL, 0LL);
goto LABEL_5;
case 2:
v4 = (void *)Slot_new_basic((unsigned int)v5, (unsigned int)v6, 0LL);
goto LABEL_5;
case 3:
v4 = (void *)Slot_new_basic((unsigned int)v5, (unsigned int)v6, (unsigned int)v7);
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 ( *v3 == 47 && v3[1] == 105 && !v3[2] )
{
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 ( *v3 == 47 && v3[1] == 105 && !v3[2] )
{
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 *


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; // esi
int j; // ecx
int v7; // eax

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

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)
{
__int64 v3; // r8
__int64 v4; // r9

if ( Map_validate_chunk_coords(a1, a2, a3) )
return *(_QWORD *)(a1[2] + 8 * (v4 + *a1 * v3));
logmsg(3LL, "Tried to get invalid chunk!");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // r8
__int64 v4; // r9

if ( func4(a1, a2, a3) )
return *(_QWORD *)(a1[2] + 8 * (v4 + *a1 * v3));
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 v4; // r8
__int64 v5; // r9
__int64 v6; // r10
__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 * (v5 + *a1 * v4)) = v6;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
__int64 v4; // r8
__int64 v5; // r9
__int64 v6; // r10
__int64 result; // rax

if ( !func4(a1, a3, a4) )
return logmsg(1LL, "Tried to set an invalid chunk position!");
result = a1[2];
*(_QWORD *)(result + 8 * (v5 + *a1 * v4)) = v6;
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)
{
int v9; // edx
int v10; // esi
int v11; // edx
__int64 v12; // rax

v9 = a5 + 15;
v10 = a3 + 15;
if ( a5 >= 0 )
v9 = a5;
v11 = v9 >> 4;
if ( a3 >= 0 )
v10 = a3;
v12 = Map_get_chunk(a1, v10 >> 4, v11);
if ( v12 )
Chunk_set_block(v12, 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)
{
int v9; // edx
int v10; // esi
int v11; // edx
__int64 v12; // rax

v9 = a5 + 15;
v10 = a3 + 15;
if ( a5 >= 0 )
v9 = a5;
v11 = v9 >> 4;
if ( a3 >= 0 )
v10 = a3;
v12 = func5(a1, v10 >> 4, v11);
if ( v12 )
func1(v12, 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