isBeginningOf

decompiled_code:
__int64 __fastcall isBeginningOf(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // cl
char v4; // dl

v2 = 0LL;
do
{
v4 = *(_BYTE *)(a2 + v2);
if ( !v4 )
return 1LL;
v3 = *(_BYTE *)(a1 + v2++);
}
while ( v3 == v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
__int64 v2; // rax
char v3; // cl
char v4; // dl

v2 = 0LL;
do
{
v4 = *(_BYTE *)(a2 + v2);
if ( !v4 )
return 1LL;
v3 = *(_BYTE *)(a1 + v2++);
}
while ( v3 == v4 );
return 0LL;
}

original_code:
static int isBeginningOf(char *s, char *scode) {
 while (*scode) {
  if (*s++ != *scode++)
   return 0;
 }
 return 1;
}

variable_types:
s
char *

variable_types:
scode
char *


repo: VjiaoBlack/terminvaders

decompiled_code:
__int64 get_circ()
{
unsigned int v0; // er8

if ( !dword_378 )
return (unsigned int)-2;
--dword_378;
v0 = circ[SHIDWORD(qword_370)];
HIDWORD(qword_370) = (HIDWORD(qword_370) + 1) % 20;
return v0;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // er8

if ( !dword_378 )
return (unsigned int)-2;
--dword_378;
v0 = circ[SHIDWORD(qword_370)];
HIDWORD(qword_370) = (HIDWORD(qword_370) + 1) % 20;
return v0;
}

original_code:
static int get_circ(void) {
 int out_code;
 if (circ.in_buf == 0)
  return -2;
 out_code = circ.buf[circ.next_out++];
 circ.next_out %= 20;
 --circ.in_buf;
 return out_code;
}

canonical_original_code:
static int get_circ() {
 int out_code;
 if (circ.in_buf == 0)
  return -2;
 out_code = circ.buf[circ.next_out++];
 circ.next_out %= 20;
 --circ.in_buf;
 return out_code;
}

return_type: int


decompiled_code:
int getkey_terminate()
{
tcsetattr(0, 0, &oldt);
return fcntl(0, 4, (unsigned int)oldf);
}

canonical_decompiled_code:
int func4()
{
tcsetattr(0, 0, &oldt);
return fcntl(0, 4, (unsigned int)oldf);
}

original_code:
void getkey_terminate(void) {
 tcsetattr(0, 0, &oldt);
 fcntl(0, 4, oldf);
}

canonical_original_code:
void getkey_terminate() {
 tcsetattr(0, 0, &oldt);
 fcntl(0, 4, oldf);
}

return_type: void


decompiled_code:
int __fastcall xt_par0(const char *a1)
{
return printf("%s", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("%s", a1);
}

original_code:
void xt_par0(char *control_sequence) {
 printf("%s",control_sequence);
}


decompiled_code:
int __fastcall xt_par1(const char *format)
{
return printf(format);
}

canonical_decompiled_code:
int __fastcall func1(const char *format)
{
return printf(format);
}

original_code:
void xt_par1(char *control_sequence, int parameter1) {
 printf(control_sequence, parameter1);
}


decompiled_code:
int __fastcall xt_par2(const char *format)
{
return printf(format);
}

canonical_decompiled_code:
int __fastcall func2(const char *format)
{
return printf(format);
}

original_code:
void xt_par2(char *control_sequence, int parameter1, int parameter2) {
 printf(control_sequence, parameter1, parameter2);
}


user_defined_types: struct sprite_t { char *graphic[7]; int width; int height; char *fg_color; char *bg_color; }


draw

original_code:
void draw(point_t* point, sprite_t* sprite) {
    int startx = point->x - sprite->width / 2,
        starty = point->y - sprite->height / 2,
        row, col;
    if (sprite->fg_color)
        xt_par0(sprite->fg_color);
    if (sprite->bg_color)
        xt_par0(sprite->bg_color);
    for (row = 0; row < sprite->height; row++) {
        xt_par2("\033[%d;%dH", (row + starty + 1), (startx + 1));
        for (col = 0; col < sprite->width; col++)
            putchar(sprite->graphic[row][col]);
    }
    if (sprite->fg_color)
        xt_par0("\033[0m");
    if (sprite->bg_color)
        xt_par0("\033[49m");
}

canonical_original_code:
void draw(struct point_t *point, struct sprite_t *sprite) {
    int startx = point->x - sprite->width / 2; int starty = point->y - sprite->height / 2; int row; int col;
    if (sprite->fg_color)
        xt_par0(sprite->fg_color);
    if (sprite->bg_color)
        xt_par0(sprite->bg_color);
    for (row = 0; row < sprite->height; row++) {
        xt_par2("\033[%d;%dH", (row + starty + 1), (startx + 1));
        for (col = 0; col < sprite->width; col++)
            putchar(sprite->graphic[row][col]);
    }
    if (sprite->fg_color)
        xt_par0("\033[0m");
    if (sprite->bg_color)
        xt_par0("\033[49m");
}

variable_types: struct point_t { double x; double y; } *

variable_types: struct sprite_t { char *graphic[7]; int width; int height; char *fg_color; char *bg_color; } *

variable_types: startx int

variable_types: starty int

variable_types: row int

variable_types: col int


collides

decompiled_code:
_BOOL8 __fastcall collides(double *a1, double *a2, int a3, int a4)
{
double v4; // xmm1_8
_BOOL8 result; // rax

if ( *a1 + (double)a3 < *a2 || *a2 < *a1 - (double)a3 || (v4 = a2[1], a1[1] + (double)a4 < v4) )
result = 0LL;
else
result = v4 >= a1[1] - (double)a4;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(double *a1, double *a2, int a3, int a4)
{
double v4; // xmm1_8
_BOOL8 result; // rax

if ( *a1 + (double)a3 < *a2 || *a2 < *a1 - (double)a3 || (v4 = a2[1], a1[1] + (double)a4 < v4) )
result = 0LL;
else
result = v4 >= a1[1] - (double)a4;
return result;
}

original_code:
int collides(point_t* point1, point_t* point2, int fuzzx, int fuzzy) {
    return (point1->x + fuzzx >= point2->x) && (point1->x - fuzzx <= point2->x) &&
           (point1->y + fuzzy >= point2->y) && (point1->y - fuzzy <= point2->y);
}

canonical_original_code:
int collides(struct point_t *point1, struct point_t *point2, int fuzzx, int fuzzy) {
    return (point1->x + fuzzx >= point2->x) && (point1->x - fuzzx <= point2->x) &&
           (point1->y + fuzzy >= point2->y) && (point1->y - fuzzy <= point2->y);
}

variable_types: fuzzx int

variable_types: fuzzy int


display

decompiled_code:
__int64 __fastcall display(unsigned int *a1)
{
unsigned int *v1; // rbp
__int64 result; // rax
unsigned int v3; // ebx
int v4; // eax
unsigned int v5; // ebx
int v6; // eax
unsigned int v7; // ebx
int v8; // eax
unsigned int v9; // ebx
int v10; // eax
unsigned int v11; // ebx
__int64 v12; // kr10_8
unsigned int v13; // ebx
__int64 v14; // kr18_8

v1 = a1;
xt_par0("\x1B[2J");
do
{
xt_par2("\x1B[%d;%dH", v1[1], *v1);
v3 = *v1;
v4 = get_cols();
if ( (int)(abs32(v3 - v4 / 2) + 2 * abs32(v1[1] - (int)get_rows() / 2)) > 60 )
{
putchar(35);
}
else
{
v5 = *v1;
v6 = get_cols();
if ( (int)(abs32(v5 - v6 / 2) + 2 * abs32(v1[1] - (int)get_rows() / 2)) <= 35 )
{
putchar(46);
}
else
{
v7 = *v1;
v8 = get_cols();
if ( (int)abs32(v7 - v8 / 2 - 2 * (v1[1] - (int)get_rows() / 2)) > 11 )
{
v9 = *v1;
v10 = get_cols();
if ( (int)abs32(v9 - v10 / 2 + 2 * (v1[1] - (int)get_rows() / 2)) > 11 )
{
v11 = *v1;
v12 = (int)(v11 - (int)get_cols() / 2);
if ( (int)((HIDWORD(v12) ^ v12) - HIDWORD(v12)) > 19 )
{
v13 = v1[1];
v14 = (int)(v13 - (int)get_rows() / 2);
if ( (int)((HIDWORD(v14) ^ v14) - HIDWORD(v14)) <= 19 )
putchar(95);
}
else
{
putchar(124);
}
}
else
{
putchar(47);
}
}
else
{
putchar(92);
}
}
}
v1 += 9;
result = xt_par0("\x1B[0m");
}
while ( v1 != a1 + 900 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
unsigned int *v1; // rbp
__int64 result; // rax
unsigned int v3; // ebx
int v4; // eax
unsigned int v5; // ebx
int v6; // eax
unsigned int v7; // ebx
int v8; // eax
unsigned int v9; // ebx
int v10; // eax
unsigned int v11; // ebx
__int64 v12; // kr10_8
unsigned int v13; // ebx
__int64 v14; // kr18_8

v1 = a1;
xt_par0("\x1B[2J");
do
{
xt_par2("\x1B[%d;%dH", v1[1], *v1);
v3 = *v1;
v4 = get_cols();
if ( (int)(abs32(v3 - v4 / 2) + 2 * abs32(v1[1] - (int)get_rows() / 2)) > 60 )
{
putchar(35);
}
else
{
v5 = *v1;
v6 = get_cols();
if ( (int)(abs32(v5 - v6 / 2) + 2 * abs32(v1[1] - (int)get_rows() / 2)) <= 35 )
{
putchar(46);
}
else
{
v7 = *v1;
v8 = get_cols();
if ( (int)abs32(v7 - v8 / 2 - 2 * (v1[1] - (int)get_rows() / 2)) > 11 )
{
v9 = *v1;
v10 = get_cols();
if ( (int)abs32(v9 - v10 / 2 + 2 * (v1[1] - (int)get_rows() / 2)) > 11 )
{
v11 = *v1;
v12 = (int)(v11 - (int)get_cols() / 2);
if ( (int)((HIDWORD(v12) ^ v12) - HIDWORD(v12)) > 19 )
{
v13 = v1[1];
v14 = (int)(v13 - (int)get_rows() / 2);
if ( (int)((HIDWORD(v14) ^ v14) - HIDWORD(v14)) <= 19 )
putchar(95);
}
else
{
putchar(124);
}
}
else
{
putchar(47);
}
}
else
{
putchar(92);
}
}
}
v1 += 9;
result = xt_par0("\x1B[0m");
}
while ( v1 != a1 + 900 );
return result;
}

original_code:
void display(star_t* stars) {
    int i;
    xt_par0("\033[2J");;
    for (i = 0; i < 100; ++i) {
        xt_par2("\033[%d;%dH", (stars[i].y), (stars[i].x));
        if (abs(stars[i].x - get_cols() / 2) + 2 * abs(stars[i].y - get_rows() / 2) > 60) {
            putchar('#');
        } else if (abs(stars[i].x - get_cols() / 2) + 2 * abs(stars[i].y - get_rows() / 2) > 35) {
            if (abs((stars[i].x - get_cols() / 2) - 2 * (stars[i].y - get_rows() / 2)) < 12) {
                putchar('\\');
            }
            else if (abs((stars[i].x - get_cols() / 2) + 2 * (stars[i].y - get_rows() / 2)) < 12) {
                putchar('/');
            }
            else if (abs(stars[i].x - get_cols() / 2) < 20) {
                putchar('|');
            }
            else if (abs(stars[i].y - get_rows() / 2 ) < 20) {
                putchar('_');
            }
        } else {
            putchar('.');
        }
        xt_par0("\033[0m");
    }
}

canonical_original_code:
void display(struct star_t *stars) {
    int i;
    xt_par0("\033[2J");;
    for (i = 0; i < 100; ++i) {
        xt_par2("\033[%d;%dH", (stars[i].y), (stars[i].x));
        if (abs(stars[i].x - get_cols() / 2) + 2 * abs(stars[i].y - get_rows() / 2) > 60) {
            putchar('#');
        } else if (abs(stars[i].x - get_cols() / 2) + 2 * abs(stars[i].y - get_rows() / 2) > 35) {
            if (abs((stars[i].x - get_cols() / 2) - 2 * (stars[i].y - get_rows() / 2)) < 12) {
                putchar('\\');
            }
            else if (abs((stars[i].x - get_cols() / 2) + 2 * (stars[i].y - get_rows() / 2)) < 12) {
                putchar('/');
            }
            else if (abs(stars[i].x - get_cols() / 2) < 20) {
                putchar('|');
            }
            else if (abs(stars[i].y - get_rows() / 2 ) < 20) {
                putchar('_');
            }
        } else {
            putchar('.');
        }
        xt_par0("\033[0m");
    }
}

variable_types: struct star_t { int x; int y; int xwait; int ywait; int xwaited; int ywaited; int roy; int rox; int d; } *

variable_types: i int


dispframe

decompiled_code:
__int64 dispframe()
{
unsigned int v0; // ebx
unsigned int v1; // eax
__int64 v2; // rdx
unsigned int i; // ebx
unsigned int v4; // eax
__int64 v5; // rsi
__int64 result; // rax

v0 = 1;
xt_par2("\x1B[%d;%dH", 1LL, 1LL);
while ( (int)get_cols() >= (int)v0 )
{
xt_par2("\x1B[%d;%dH", 1LL, v0);
putchar(45);
v1 = get_rows();
v2 = v0++;
xt_par2("\x1B[%d;%dH", v1, v2);
putchar(45);
}
for ( i = 2; ; ++i )
{
result = get_rows();
if ( (int)result < (int)i )
break;
xt_par2("\x1B[%d;%dH", i, 1LL);
putchar(124);
v4 = get_cols();
v5 = i;
xt_par2("\x1B[%d;%dH", v5, v4);
putchar(124);
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
unsigned int v0; // ebx
unsigned int v1; // eax
__int64 v2; // rdx
unsigned int i; // ebx
unsigned int v4; // eax
__int64 v5; // rsi
__int64 result; // rax

v0 = 1;
xt_par2("\x1B[%d;%dH", 1LL, 1LL);
while ( (int)get_cols() >= (int)v0 )
{
xt_par2("\x1B[%d;%dH", 1LL, v0);
putchar(45);
v1 = get_rows();
v2 = v0++;
xt_par2("\x1B[%d;%dH", v1, v2);
putchar(45);
}
for ( i = 2; ; ++i )
{
result = get_rows();
if ( (int)result < (int)i )
break;
xt_par2("\x1B[%d;%dH", i, 1LL);
putchar(124);
v4 = get_cols();
v5 = i;
xt_par2("\x1B[%d;%dH", v5, v4);
putchar(124);
}
return result;
}

original_code:
void dispframe(){
    int cursor_r = 1, cursor_c = 1;
    xt_par2("\033[%d;%dH", (1), (1));
    while (cursor_c <= get_cols()) {
        cursor_r = 1;
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        putchar('-');
        cursor_r = get_rows();
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        putchar('-');
        cursor_c++;
    }
    cursor_r = 2;
    while (cursor_r <= get_rows()) {
        cursor_c = 1;
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        putchar('|');
        cursor_c = get_cols();
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        putchar('|');
        cursor_r++;
    }
}

canonical_original_code:
void dispframe(){
    int cursor_r = 1; int cursor_c = 1;
    xt_par2("\033[%d;%dH", (1), (1));
    while (cursor_c <= get_cols()) {
        cursor_r = 1;
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        putchar('-');
        cursor_r = get_rows();
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        putchar('-');
        cursor_c++;
    }
    cursor_r = 2;
    while (cursor_r <= get_rows()) {
        cursor_c = 1;
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        putchar('|');
        cursor_c = get_cols();
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        putchar('|');
        cursor_r++;
    }
}


original_code:
int calculate_wait(int is_horiz, int x, int y) {
    double d = sqrt(x * x / 16 + y * y / 8) + 5;
    double r;
    if (is_horiz) {
        r = ((double)y / (double)x) + .1;
        r *= 2;
    } else {
        r = ((double)x / (double)y) + .1;
    }
    int fd = 2000 / (d * d);
    return (r * fd);
}

variable_types: x int

variable_types: y int

variable_types: d double

variable_types: r double

variable_types: fd int


init

original_code:
void init(star_t* stars) {
    int i;
    for (i = 0; i < 100; ++i) {
        int rox = 0;
        int roy = 0;
        while (abs(rox) - 2 < 0)
            rox = rand() % 400 - 200;
        while (abs(roy) - 1 < 0)
            roy = rand() % 200 - 100;
        int x = ( (rox * 50) / (250 + 50) ) + get_cols() / 2;
        int y = ( (roy * 50) / (250 + 50) ) + get_rows() / 2;
        int xwait = calculate_wait(1, rox, roy);
        int ywait = calculate_wait(0, rox, roy);
        int d = sqrt((x - get_cols() / 2) * (x - get_cols() / 2) + (y - get_rows() / 2) * (y - get_rows() / 2) * 4);
        stars[i] = (star_t) {x, y, xwait, ywait, 0, 0, rox, roy, d};
    }
}

canonical_original_code:
void init(struct star_t *stars) {
    int i;
    for (i = 0; i < 100; ++i) {
        int rox = 0;
        int roy = 0;
        while (abs(rox) - 2 < 0)
            rox = rand() % 400 - 200;
        while (abs(roy) - 1 < 0)
            roy = rand() % 200 - 100;
        int x = ( (rox * 50) / (250 + 50) ) + get_cols() / 2;
        int y = ( (roy * 50) / (250 + 50) ) + get_rows() / 2;
        int xwait = calculate_wait(1, rox, roy);
        int ywait = calculate_wait(0, rox, roy);
        int d = sqrt((x - get_cols() / 2) * (x - get_cols() / 2) + (y - get_rows() / 2) * (y - get_rows() / 2) * 4);
        stars[i] = (struct star_t) {x, y, xwait, ywait, 0, 0, rox, roy, d};
    }
}

variable_types: rox int

variable_types: roy int

variable_types: xwait int

variable_types: ywait int

variable_types: d int

user_defined_types: struct star_t { int x; int y; int xwait; int ywait; int xwaited; int ywaited; int roy; int rox; int d; }


update

original_code:
void update(star_t* stars) {
    int i;
    for (i = 0; i < 100; ++i) {
        stars[i].d = sqrt((stars[i].x - get_cols() / 2) * (stars[i].x - get_cols() / 2) + (stars[i].y - get_rows() / 2) * (stars[i].y - get_rows() / 2 ) * 4);
        if (stars[i].xwait - stars[i].xwaited <= 0) {
            stars[i].xwaited = 0;
            stars[i].xwait = calculate_wait(1, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
            stars[i].ywait = calculate_wait(0, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
            if (stars[i].ywait <= 3) {
                stars[i].ywait = calculate_wait(0, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
                if (stars[i].y > get_rows() / 2)
                    stars[i].y = stars[i].y + 1;
                else
                    stars[i].y = stars[i].y - 1;
            }
            else if (stars[i].x > get_cols() / 2)
                stars[i].x = stars[i].x + 1;
            else
                stars[i].x = stars[i].x - 1;
        } else {
            stars[i].xwaited++;
        }
        if (stars[i].ywait - stars[i].ywaited <= 0) {
            stars[i].ywaited = 0;
            stars[i].xwait = calculate_wait(1, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
            stars[i].ywait = calculate_wait(0, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
            if (stars[i].xwait <= 3) {
                stars[i].xwait = calculate_wait(1, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
                if (stars[i].x > get_cols() / 2)
                    stars[i].x = stars[i].x + 1;
                else
                    stars[i].x = stars[i].x - 1;
            }
            else if (stars[i].y > get_rows() / 2)
                stars[i].y = stars[i].y + 1;
            else
                stars[i].y = stars[i].y - 1;
        } else {
            stars[i].ywaited++;
        }
        if (stars[i].x >= get_cols() || stars[i].x <= 0 || stars[i].y >= get_rows() || stars[i].y <= 0){
            int rox = 0;
            int roy = 0;
            while (abs(rox) - 2 < 0)
                rox = rand() % 400 - 200;
            while (abs(roy) - 1 < 0)
                roy = rand() % 200 - 100;
            int x = ( (rox * 50) / (250 + 50) ) + get_cols() / 2;
            int y = ( (roy * 50) / (250 + 50) ) + get_rows() / 2;
            int xwait = calculate_wait(1, abs(rox), abs(roy));
            int ywait = calculate_wait(0, abs(rox), abs(roy));
            stars[i] = (star_t) {x, y, xwait, ywait, 0, 0, rox, roy, 250};
        }
    }
}

canonical_original_code:
void update(struct star_t *stars) {
    int i;
    for (i = 0; i < 100; ++i) {
        stars[i].d = sqrt((stars[i].x - get_cols() / 2) * (stars[i].x - get_cols() / 2) + (stars[i].y - get_rows() / 2) * (stars[i].y - get_rows() / 2 ) * 4);
        if (stars[i].xwait - stars[i].xwaited <= 0) {
            stars[i].xwaited = 0;
            stars[i].xwait = calculate_wait(1, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
            stars[i].ywait = calculate_wait(0, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
            if (stars[i].ywait <= 3) {
                stars[i].ywait = calculate_wait(0, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
                if (stars[i].y > get_rows() / 2)
                    stars[i].y = stars[i].y + 1;
                else
                    stars[i].y = stars[i].y - 1;
            }
            else if (stars[i].x > get_cols() / 2)
                stars[i].x = stars[i].x + 1;
            else
                stars[i].x = stars[i].x - 1;
        } else {
            stars[i].xwaited++;
        }
        if (stars[i].ywait - stars[i].ywaited <= 0) {
            stars[i].ywaited = 0;
            stars[i].xwait = calculate_wait(1, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
            stars[i].ywait = calculate_wait(0, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
            if (stars[i].xwait <= 3) {
                stars[i].xwait = calculate_wait(1, abs(stars[i].x - get_cols() / 2), abs(stars[i].y - get_rows() / 2));
                if (stars[i].x > get_cols() / 2)
                    stars[i].x = stars[i].x + 1;
                else
                    stars[i].x = stars[i].x - 1;
            }
            else if (stars[i].y > get_rows() / 2)
                stars[i].y = stars[i].y + 1;
            else
                stars[i].y = stars[i].y - 1;
        } else {
            stars[i].ywaited++;
        }
        if (stars[i].x >= get_cols() || stars[i].x <= 0 || stars[i].y >= get_rows() || stars[i].y <= 0){
            int rox = 0;
            int roy = 0;
            while (abs(rox) - 2 < 0)
                rox = rand() % 400 - 200;
            while (abs(roy) - 1 < 0)
                roy = rand() % 200 - 100;
            int x = ( (rox * 50) / (250 + 50) ) + get_cols() / 2;
            int y = ( (roy * 50) / (250 + 50) ) + get_rows() / 2;
            int xwait = calculate_wait(1, abs(rox), abs(roy));
            int ywait = calculate_wait(0, abs(rox), abs(roy));
            stars[i] = (struct star_t) {x, y, xwait, ywait, 0, 0, rox, roy, 250};
        }
    }
}


decompiled_code:
__int64 __fastcall handle_input(unsigned int a1)
{
int v2; // eax

while ( 1 )
{
v2 = getkey();
if ( v2 == -2 )
break;
if ( v2 == 113 )
a1 = 0;
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1)
{
int v2; // eax

while ( 1 )
{
v2 = getkey();
if ( v2 == -2 )
break;
if ( v2 == 113 )
a1 = 0;
}
return a1;
}

original_code:
int handle_input(int running) {
    int key;
    while ((key = getkey()) != -2) {
        switch (key) {
            case 'q':
                running = 0;
                break;
        }
    }
    return running;
}

variable_types: running int

variable_types: key int


original_code:
void serialize_status_data(client_t* clients, mgame_t* games, char* databuf) {
    int id, n_clients = 0, nc_connecting = 0, nc_idle = 0, nc_waiting = 0,
        nc_in_game = 0, n_games = 0, ng_waiting = 0, ng_playing = 0;
    for (id = 0; id < 64; id++) {
        if (clients[id].status != 0)
            n_clients++;
        switch (clients[id].status) {
            case 1:
                nc_connecting++; break;
            case 2:
                nc_idle++; break;
            case 3:
                nc_waiting++; break;
            case 4:
                nc_in_game++; break;
        }
    }
    for (id = 0; id < 32; id++) {
        if (games[id].status != 0)
            n_games++;
        switch (games[id].status) {
            case 1:
                ng_waiting++; break;
            case 2:
                ng_playing++; break;
        }
    }
    n_clients--;
    nc_connecting--;
    snprintf(databuf, 1024, "%d/%d (%d/%d/%d/%d)\n%d/%d (%d/%d)", n_clients,
             64, nc_connecting, nc_idle, nc_waiting, nc_in_game,
             n_games, 32, ng_waiting, ng_playing);
}

canonical_original_code:
void serialize_status_data(struct client_t *clients, struct mgame_t *games, char *databuf) {
    int id; int n_clients = 0; int nc_connecting = 0; int nc_idle = 0; int nc_waiting = 0; int nc_in_game = 0; int n_games = 0; int ng_waiting = 0; int ng_playing = 0;
    for (id = 0; id < 64; id++) {
        if (clients[id].status != 0)
            n_clients++;
        switch (clients[id].status) {
            case 1:
                nc_connecting++; break;
            case 2:
                nc_idle++; break;
            case 3:
                nc_waiting++; break;
            case 4:
                nc_in_game++; break;
        }
    }
    for (id = 0; id < 32; id++) {
        if (games[id].status != 0)
            n_games++;
        switch (games[id].status) {
            case 1:
                ng_waiting++; break;
            case 2:
                ng_playing++; break;
        }
    }
    n_clients--;
    nc_connecting--;
    snprintf(databuf, 1024, "%d/%d (%d/%d/%d/%d)\n%d/%d (%d/%d)", n_clients,
             64, nc_connecting, nc_idle, nc_waiting, nc_in_game,
             n_games, 32, ng_waiting, ng_playing);
}

variable_types: struct client_t { int id; int status; int sockfd; int game; char name[-1]; int request; struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } send_lock; } *

variable_types: struct mgame_t { int id; int status; int slots_total; int slots_filled; int players[4]; char name[-1]; int mode; struct game_t { int running; int multiplayer; int score; int over; int until_spawn; int spawn_timer; struct player_t { struct point_t { double x; double y; } point; int lives; int respawning; int invincible; int cooldown; int nospawn; int vertical_accel; int horiz_accel; int bullet_type; } *players; struct enemy_t { struct point_t point; int score; int cooldown; int max_cooldown; double velocity; double bullet_velocity; struct enemy_t *next; } *first_enemy; struct bullet_t { struct point_t point; double velocity; int fired_by_player; int type; struct bullet_t *next; } *first_bullet; struct explosion_t { struct point_t point; int step; int score; struct explosion_t *next; } *first_explosion; struct multidata_t { int mode; int players; int player; int sockfd; } multiplayer_data; } data; unsigned long thread; struct inptbuf_t { struct input_t { int player; int action; struct input_t *next; } *first; union pthread_mutex_t lock; } input_buffer; union pthread_mutex_t state_lock; } *

variable_types:
databuf
char *

variable_types: id int

user_defined_types: struct client_t { int id; int status; int sockfd; int game; char name[-1]; int request; struct sockaddr_in addr; unsigned long thread; union pthread_mutex_t send_lock; }

user_defined_types: struct mgame_t { int id; int status; int slots_total; int slots_filled; int players[4]; char name[-1]; int mode; struct game_t data; unsigned long thread; struct inptbuf_t input_buffer; union pthread_mutex_t state_lock; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

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

user_defined_types: struct game_t { int running; int multiplayer; int score; int over; int until_spawn; int spawn_timer; struct player_t *players; struct enemy_t *first_enemy; struct bullet_t *first_bullet; struct explosion_t *first_explosion; struct multidata_t multiplayer_data; }

user_defined_types: struct inptbuf_t { struct input_t *first; union pthread_mutex_t lock; }

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

user_defined_types: struct player_t { struct point_t point; int lives; int respawning; int invincible; int cooldown; int nospawn; int vertical_accel; int horiz_accel; int bullet_type; }


original_code:
void serialize_lobby_info(client_t* clients, mgame_t* games, char** buffer_ptr) {
    int id, status, pos, i, bufsize = (64 + 32) * (32 + 20);
    char* buffer = malloc(sizeof(char) * bufsize);
    *buffer_ptr = buffer;
    pos = 0;
    for (id = 0; id < 64; id++) {
        status = clients[id].status;
        if (status == 0 || status == 1)
            continue;
        pos += snprintf(buffer + pos, bufsize - pos, "1|%d|%d|%s\n", id, status, clients[id].name);
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
    for (id = 0; id < 32; id++) {
        pthread_mutex_lock(&games[id].state_lock);
        status = games[id].status;
        if (status == 0) {
            pthread_mutex_unlock(&games[id].state_lock);
            continue;
        }
        pos += snprintf(buffer + pos, bufsize - pos, "1|%d|%d|%d|%d|%d|%s\n", id, status, games[id].mode, games[id].slots_total, games[id].slots_filled, games[id].name);
        for (i = 0; i < games[id].slots_total; i++)
            pos += snprintf(buffer + pos, bufsize - pos, "%d|", games[id].players[i]);
        pthread_mutex_unlock(&games[id].state_lock);
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
}

canonical_original_code:
void serialize_lobby_info(struct client_t *clients, struct mgame_t *games, char **buffer_ptr) {
    int id; int status; int pos; int i; int bufsize = (64 + 32) * (32 + 20);
    char *buffer = malloc(sizeof(char) * bufsize);
    *buffer_ptr = buffer;
    pos = 0;
    for (id = 0; id < 64; id++) {
        status = clients[id].status;
        if (status == 0 || status == 1)
            continue;
        pos += snprintf(buffer + pos, bufsize - pos, "1|%d|%d|%s\n", id, status, clients[id].name);
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
    for (id = 0; id < 32; id++) {
        pthread_mutex_lock(&games[id].state_lock);
        status = games[id].status;
        if (status == 0) {
            pthread_mutex_unlock(&games[id].state_lock);
            continue;
        }
        pos += snprintf(buffer + pos, bufsize - pos, "1|%d|%d|%d|%d|%d|%s\n", id, status, games[id].mode, games[id].slots_total, games[id].slots_filled, games[id].name);
        for (i = 0; i < games[id].slots_total; i++)
            pos += snprintf(buffer + pos, bufsize - pos, "%d|", games[id].players[i]);
        pthread_mutex_unlock(&games[id].state_lock);
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
}

variable_types: status int

variable_types: pos int

variable_types: i int

variable_types: bufsize int

variable_types:
buffer
char *

user_defined_types: struct multidata_t { int mode; int players; int player; int sockfd; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }

user_defined_types: struct enemy_t { struct point_t point; int score; int cooldown; int max_cooldown; double velocity; double bullet_velocity; struct enemy_t *next; }

user_defined_types: struct bullet_t { struct point_t point; double velocity; int fired_by_player; int type; struct bullet_t *next; }

user_defined_types: struct explosion_t { struct point_t point; int step; int score; struct explosion_t *next; }

user_defined_types: struct input_t { int player; int action; struct input_t *next; }


decompiled_code:
int __fastcall serialize_game_setup(unsigned int a1, unsigned int a2, const char *a3, char **a4)
{
char *v6; // rax

v6 = (char *)malloc(0x30uLL);
*a4 = v6;
return snprintf(v6, 0x30uLL, "%d|%d|%s\n", a1, a2, a3);
}

canonical_decompiled_code:
int __fastcall func2(unsigned int a1, unsigned int a2, const char *a3, char **a4)
{
char *v6; // rax

v6 = (char *)malloc(0x30uLL);
*a4 = v6;
return snprintf(v6, 0x30uLL, "%d|%d|%s\n", a1, a2, a3);
}

original_code:
void serialize_game_setup(int type, int users, char* title, char** buffer_ptr) {
    int bufsize = 32 + 16;
    char* buffer = malloc(sizeof(char) * bufsize);
    *buffer_ptr = buffer;
    snprintf(buffer, bufsize, "%d|%d|%s\n", type, users, title);
}

canonical_original_code:
void serialize_game_setup(int type, int users, char *title, char **buffer_ptr) {
    int bufsize = 32 + 16;
    char *buffer = malloc(sizeof(char) * bufsize);
    *buffer_ptr = buffer;
    snprintf(buffer, bufsize, "%d|%d|%s\n", type, users, title);
}

variable_types: type int

variable_types: users int

variable_types:
title
char *


original_code:
void serialize_game_data(game_t* game, char** buffer_ptr) {
    int pos = 0, bufsize = 32768, slot;
    char* buffer = malloc(sizeof(char) * bufsize);
    player_t* player;
    enemy_t* enemy = game->first_enemy;
    bullet_t* bullet = game->first_bullet;
    explosion_t* explosion = game->first_explosion;
    *buffer_ptr = buffer;
    pos += snprintf(buffer + pos, bufsize - pos, "%d|%d|%d\n", game->running, game->score, game->over);
    for (slot = 0; slot < game->multiplayer_data.players; slot++) {
        player = &game->players[slot];
        pos += snprintf(buffer + pos, bufsize - pos, "%.2lf,%.2lf|%d|%d|%d\n", player->point.x, player->point.y, player->lives, player->respawning, player->invincible);
    }
    while (enemy) {
        pos += snprintf(buffer + pos, bufsize - pos, "1|%.2lf,%.2lf\n", enemy->point.x, enemy->point.y);
        enemy = enemy->next;
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
    while (bullet) {
        pos += snprintf(buffer + pos, bufsize - pos, "1|%.2lf,%.2lf|%d|%d\n", bullet->point.x, bullet->point.y, bullet->fired_by_player, bullet->type);
        bullet = bullet->next;
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
    while (explosion) {
        pos += snprintf(buffer + pos, bufsize - pos, "1|%.2lf,%.2lf|%d|%d\n", explosion->point.x, explosion->point.y, explosion->step, explosion->score);
        explosion = explosion->next;
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
}

canonical_original_code:
void serialize_game_data(struct game_t *game, char **buffer_ptr) {
    int pos = 0; int bufsize = 32768; int slot;
    char *buffer = malloc(sizeof(char) * bufsize);
    struct player_t *player;
    struct enemy_t *enemy = game->first_enemy;
    struct bullet_t *bullet = game->first_bullet;
    struct explosion_t *explosion = game->first_explosion;
    *buffer_ptr = buffer;
    pos += snprintf(buffer + pos, bufsize - pos, "%d|%d|%d\n", game->running, game->score, game->over);
    for (slot = 0; slot < game->multiplayer_data.players; slot++) {
        player = &game->players[slot];
        pos += snprintf(buffer + pos, bufsize - pos, "%.2lf,%.2lf|%d|%d|%d\n", player->point.x, player->point.y, player->lives, player->respawning, player->invincible);
    }
    while (enemy) {
        pos += snprintf(buffer + pos, bufsize - pos, "1|%.2lf,%.2lf\n", enemy->point.x, enemy->point.y);
        enemy = enemy->next;
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
    while (bullet) {
        pos += snprintf(buffer + pos, bufsize - pos, "1|%.2lf,%.2lf|%d|%d\n", bullet->point.x, bullet->point.y, bullet->fired_by_player, bullet->type);
        bullet = bullet->next;
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
    while (explosion) {
        pos += snprintf(buffer + pos, bufsize - pos, "1|%.2lf,%.2lf|%d|%d\n", explosion->point.x, explosion->point.y, explosion->step, explosion->score);
        explosion = explosion->next;
    }
    pos += snprintf(buffer + pos, bufsize - pos, "0|");
}

variable_types: struct game_t { int running; int multiplayer; int score; int over; int until_spawn; int spawn_timer; struct player_t { struct point_t { double x; double y; } point; int lives; int respawning; int invincible; int cooldown; int nospawn; int vertical_accel; int horiz_accel; int bullet_type; } *players; struct enemy_t { struct point_t point; int score; int cooldown; int max_cooldown; double velocity; double bullet_velocity; struct enemy_t *next; } *first_enemy; struct bullet_t { struct point_t point; double velocity; int fired_by_player; int type; struct bullet_t *next; } *first_bullet; struct explosion_t { struct point_t point; int step; int score; struct explosion_t *next; } *first_explosion; struct multidata_t { int mode; int players; int player; int sockfd; } multiplayer_data; } *

variable_types: slot int

variable_types: struct enemy_t { struct point_t { double x; double y; } point; int score; int cooldown; int max_cooldown; double velocity; double bullet_velocity; struct enemy_t *next; } *

variable_types: struct bullet_t { struct point_t { double x; double y; } point; double velocity; int fired_by_player; int type; struct bullet_t *next; } *

variable_types: struct explosion_t { struct point_t { double x; double y; } point; int step; int score; struct explosion_t *next; } *


original_code:
void unserialize_lobby_info(char* buffer, user_t* users, multiplayergame_t* games) {
    int pos = 0, offset, more, userid, status, gameid, mode, tslots, fslots, i;
    char name[32 + 1];
    for (userid = 0; userid < 64; userid++)
        users[userid].status = 0;
    for (gameid = 0; gameid < 32; gameid++)
        games[gameid].status = 0;
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        sscanf(buffer + pos, "%d|%d|%[^\n]\n%n", &userid, &status, name, &offset); pos += offset;;
        users[userid].status = status;
        strcpy(users[userid].username, name);
    }
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        sscanf(buffer + pos, "%d|%d|%d|%d|%d|%[^\n]\n%n", &gameid, &status, &mode, &tslots, &fslots, name, &offset); pos += offset;;
        games[gameid].status = status;
        games[gameid].mode = mode;
        games[gameid].slots_total = tslots;
        games[gameid].slots_filled = fslots;
        strcpy(games[gameid].name, name);
        for (i = 0; i < tslots; i++) {
            sscanf(buffer + pos, "%d|%n", &games[gameid].players[i], &offset); pos += offset;;
        }
    }
}

canonical_original_code:
void unserialize_lobby_info(char *buffer, struct user_t *users, struct multiplayergame_t *games) {
    int pos = 0; int offset; int more; int userid; int status; int gameid; int mode; int tslots; int fslots; int i;
    char name[-1];
    for (userid = 0; userid < 64; userid++)
        users[userid].status = 0;
    for (gameid = 0; gameid < 32; gameid++)
        games[gameid].status = 0;
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        sscanf(buffer + pos, "%d|%d|%[^\n]\n%n", &userid, &status, name, &offset); pos += offset;;
        users[userid].status = status;
        strcpy(users[userid].username, name);
    }
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        sscanf(buffer + pos, "%d|%d|%d|%d|%d|%[^\n]\n%n", &gameid, &status, &mode, &tslots, &fslots, name, &offset); pos += offset;;
        games[gameid].status = status;
        games[gameid].mode = mode;
        games[gameid].slots_total = tslots;
        games[gameid].slots_filled = fslots;
        strcpy(games[gameid].name, name);
        for (i = 0; i < tslots; i++) {
            sscanf(buffer + pos, "%d|%n", &games[gameid].players[i], &offset); pos += offset;;
        }
    }
}

variable_types: struct user_t { int id; int status; char username[-1]; } *

variable_types: struct multiplayergame_t { int id; int status; int slots_total; int slots_filled; int players[4]; char name[-1]; int mode; } *

variable_types: offset int

variable_types: more int

variable_types: userid int

variable_types: gameid int

variable_types: mode int

variable_types: tslots int

variable_types: fslots int

variable_types:
name
char [-1]


decompiled_code:
__int64 __fastcall unserialize_game_setup(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
return _isoc99_sscanf(a1, "%d|%d|%[^\n]\n", a3, a4, a2);
}

original_code:
void unserialize_game_setup(char* buffer, char* name, int* type, int* slots) {
    sscanf(buffer, "%d|%d|%[^\n]\n", type, slots, name);
}

canonical_original_code:
void unserialize_game_setup(char *buffer, char *name, int *type, int *slots) {
    sscanf(buffer, "%d|%d|%[^\n]\n", type, slots, name);
}

variable_types:
buffer
char *

variable_types:
name
char *

variable_types:
type
int *

variable_types:
slots
int *


original_code:
void unserialize_game_data(char* buffer, game_t* game) {
    int pos = 0, offset, slot, more;
    player_t* player;
    enemy_t *enemy;
    bullet_t *bullet;
    explosion_t *explosion;
    while (game->first_enemy) {
        enemy = game->first_enemy->next;
        free(game->first_enemy);
        game->first_enemy = enemy;
    }
    while (game->first_bullet) {
        bullet = game->first_bullet->next;
        free(game->first_bullet);
        game->first_bullet = bullet;
    }
    while (game->first_explosion) {
        explosion = game->first_explosion->next;
        free(game->first_explosion);
        game->first_explosion = explosion;
    }
    sscanf(buffer + pos, "%d|%d|%d\n%n", &game->running, &game->score, &game->over, &offset); pos += offset;;
    for (slot = 0; slot < game->multiplayer_data.players; slot++) {
        player = &game->players[slot];
        sscanf(buffer + pos, "%lf,%lf|%d|%d|%d\n%n", &player->point.x, &player->point.y, &player->lives, &player->respawning, &player->invincible, &offset); pos += offset;;
    }
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        enemy = malloc(sizeof(enemy_t));
        *enemy = (enemy_t) {{0}};
        sscanf(buffer + pos, "%lf,%lf\n%n", &enemy->point.x, &enemy->point.y, &offset); pos += offset;;
        enemy->next = game->first_enemy;
        game->first_enemy = enemy;
    }
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        bullet = malloc(sizeof(bullet_t));
        *bullet = (bullet_t) {{0}};
        sscanf(buffer + pos, "%lf,%lf|%d|%d\n%n", &bullet->point.x, &bullet->point.y, &bullet->fired_by_player, &bullet->type, &offset); pos += offset;;
        bullet->next = game->first_bullet;
        game->first_bullet = bullet;
    }
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        explosion = malloc(sizeof(explosion_t));
        *explosion = (explosion_t) {{0}};
        sscanf(buffer + pos, "%lf,%lf|%d|%d\n%n", &explosion->point.x, &explosion->point.y, &explosion->step, &explosion->score, &offset); pos += offset;;
        explosion->next = game->first_explosion;
        game->first_explosion = explosion;
    }
}

canonical_original_code:
void unserialize_game_data(char *buffer, struct game_t *game) {
    int pos = 0; int offset; int slot; int more;
    struct player_t *player;
    struct enemy_t *enemy;
    struct bullet_t *bullet;
    struct explosion_t *explosion;
    while (game->first_enemy) {
        enemy = game->first_enemy->next;
        free(game->first_enemy);
        game->first_enemy = enemy;
    }
    while (game->first_bullet) {
        bullet = game->first_bullet->next;
        free(game->first_bullet);
        game->first_bullet = bullet;
    }
    while (game->first_explosion) {
        explosion = game->first_explosion->next;
        free(game->first_explosion);
        game->first_explosion = explosion;
    }
    sscanf(buffer + pos, "%d|%d|%d\n%n", &game->running, &game->score, &game->over, &offset); pos += offset;;
    for (slot = 0; slot < game->multiplayer_data.players; slot++) {
        player = &game->players[slot];
        sscanf(buffer + pos, "%lf,%lf|%d|%d|%d\n%n", &player->point.x, &player->point.y, &player->lives, &player->respawning, &player->invincible, &offset); pos += offset;;
    }
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        enemy = malloc(sizeof(enemy_t));
        *enemy = (struct enemy_t) {{0}};
        sscanf(buffer + pos, "%lf,%lf\n%n", &enemy->point.x, &enemy->point.y, &offset); pos += offset;;
        enemy->next = game->first_enemy;
        game->first_enemy = enemy;
    }
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        bullet = malloc(sizeof(bullet_t));
        *bullet = (struct bullet_t) {{0}};
        sscanf(buffer + pos, "%lf,%lf|%d|%d\n%n", &bullet->point.x, &bullet->point.y, &bullet->fired_by_player, &bullet->type, &offset); pos += offset;;
        bullet->next = game->first_bullet;
        game->first_bullet = bullet;
    }
    while (1) {
        sscanf(buffer + pos, "%d|%n", &more, &offset); pos += offset;;
        if (!more)
            break;
        explosion = malloc(sizeof(explosion_t));
        *explosion = (struct explosion_t) {{0}};
        sscanf(buffer + pos, "%lf,%lf|%d|%d\n%n", &explosion->point.x, &explosion->point.y, &explosion->step, &explosion->score, &offset); pos += offset;;
        explosion->next = game->first_explosion;
        game->first_explosion = explosion;
    }
}

variable_types: struct game_t { int running; int multiplayer; int score; int over; int until_spawn; int spawn_timer; struct player_t { struct point_t { double x; double y; } point; int lives; int respawning; int invincible; int cooldown; int nospawn; int vertical_accel; int horiz_accel; int bullet_type; } *players; struct enemy_t { struct point_t point; int score; int cooldown; int max_cooldown; double velocity; double bullet_velocity; struct enemy_t *next; } *first_enemy; struct bullet_t { struct point_t point; double velocity; int fired_by_player; int type; struct bullet_t *next; } *first_bullet; struct explosion_t { struct point_t point; int step; int score; struct explosion_t *next; } *first_explosion; struct multidata_t { int mode; int players; int player; int sockfd; } multiplayer_data; } *

variable_types: pos int

variable_types: slot int

variable_types: struct enemy_t { struct point_t { double x; double y; } point; int score; int cooldown; int max_cooldown; double velocity; double bullet_velocity; struct enemy_t *next; } *


decompiled_code:
__int64 get_rows()
{
return (unsigned int)rows;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)rows;
}

original_code:
int get_rows(void) {
    return rows;
}

canonical_original_code:
int get_rows() {
    return rows;
}


decompiled_code:
__int64 get_cols()
{
return (unsigned int)cols;
}

canonical_decompiled_code:
__int64 func2()
{
return (unsigned int)cols;
}

original_code:
int get_cols(void) {
    return cols;
}

canonical_original_code:
int get_cols() {
    return cols;
}


decompiled_code:
int __fastcall draw_menu(int a1)
{
const char *v2; // rdi
int v3; // ebp
int v4; // ebx
__int64 v5; // rdx
unsigned int v6; // eax
__int64 v7; // rdx
int v8; // ebp
int v9; // eax
__int64 v10; // rsi
__int64 v11; // rsi
unsigned int v12; // eax
int v13; // eax
int v14; // kr00_4
__int64 v15; // rsi
__int64 v16; // rdx
int v17; // eax
int v18; // ecx
__int64 v19; // rsi
__int64 v20; // rdx
int v21; // eax
int v22; // ecx
__int64 v23; // rsi
__int64 v24; // rdx
int v25; // ecx
__int64 v26; // rsi
const char *v27; // rdi
unsigned int v28; // eax
unsigned int v29; // eax
__int64 v30; // rdx
__int64 v32; // rsi
__int64 v33; // rdx
int v34; // eax
int v35; // ecx
__int64 v36; // rsi
__int64 v37; // rdx
int v38; // ecx

v2 = "\x1B[%d;%dH";
v3 = 1;
v4 = 0;
xt_par2("\x1B[%d;%dH", 1LL, 1LL);
while ( (int)((__int64 (*)(void))get_cols)() >= v3 )
{
while ( 1 )
{
xt_par2("\x1B[%d;%dH", 1LL, (unsigned int)v3);
putchar(45);
v5 = (unsigned int)v3++;
v6 = get_rows("\x1B[%d;%dH", 1LL, v5);
xt_par2("\x1B[%d;%dH", v6, v7);
v2 = (_BYTE *)(&loc_29 + 4);
putchar(45);
if ( v4 == 3 )
break;
++v4;
if ( (int)((__int64 (*)(void))get_cols)() < v3 )
goto LABEL_5;
}
v2 = (const char *)stdout;
v4 = 1;
fflush(stdout);
}
LABEL_5:
v8 = 2;
while ( 1 )
{
v9 = get_rows(v2);
v10 = (unsigned int)v9;
if ( v9 <= v8 )
break;
while ( 1 )
{
xt_par2("\x1B[%d;%dH", (unsigned int)v8, 1LL);
putchar(124);
v11 = (unsigned int)v8++;
v12 = get_cols("\x1B[%d;%dH", v11);
xt_par2("\x1B[%d;%dH", v11, v12);
v2 = (_BYTE *)(&loc_7B + 1);
putchar(124);
if ( v4 == 3 )
break;
v13 = get_rows((_BYTE *)&loc_7B + 1);
++v4;
v10 = (unsigned int)v13;
if ( v13 <= v8 )
goto LABEL_9;
}
v2 = (const char *)stdout;
v4 = 1;
fflush(stdout);
}
LABEL_9:
v14 = get_cols(v2, v10);
v15 = (unsigned int)((int)v10 / 4);
xt_par2("\x1B[%d;%dH", v15, (unsigned int)(v14 / 2 - 7));
xt_par0("\x1B[33m");
xt_par0("\x1B[1m");
printf("{[ Settings ]}");
xt_par0("\x1B[0m");
get_cols("\x1B[%d;%dH", v15);
v17 = get_rows("\x1B[%d;%dH", v15, v16);
xt_par2("\x1B[%d;%dH", (unsigned int)(v17 / 2), (unsigned int)(v18 / 2 - 5));
if ( !a1 )
{
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
printf("Height: ");
xt_par0("\x1B[0m");
v19 = (unsigned int)rows;
printf("%d", (unsigned int)rows);
get_cols("\x1B[%d;%dH", v19);
v21 = 5 * get_rows("\x1B[%d;%dH", v19, v20);
xt_par2("\x1B[%d;%dH", (unsigned int)(v21 / 8), (unsigned int)(v22 / 2 - 4));
printf("Width: ");
LABEL_11:
v23 = (unsigned int)cols;
printf("%d", (unsigned int)cols);
get_cols("\x1B[%d;%dH", v23);
v26 = (unsigned int)((int)(3 * get_rows("\x1B[%d;%dH", v23, v24)) / 4);
xt_par2("\x1B[%d;%dH", v26, (unsigned int)(v25 / 2 - 2));
goto LABEL_12;
}
printf("Height: ");
v32 = (unsigned int)rows;
printf("%d", (unsigned int)rows);
get_cols("\x1B[%d;%dH", v32);
v34 = 5 * get_rows("\x1B[%d;%dH", v32, v33);
xt_par2("\x1B[%d;%dH", (unsigned int)(v34 / 8), (unsigned int)(v35 / 2 - 4));
if ( a1 == 1 )
{
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
printf("Width: ");
xt_par0("\x1B[0m");
goto LABEL_11;
}
printf("Width: ");
v36 = (unsigned int)cols;
printf("%d", (unsigned int)cols);
get_cols("\x1B[%d;%dH", v36);
v26 = (unsigned int)((int)(3 * get_rows("\x1B[%d;%dH", v36, v37)) / 4);
xt_par2("\x1B[%d;%dH", v26, (unsigned int)(v38 / 2 - 2));
if ( a1 == 2 )
{
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
printf("Back");
v27 = "\x1B[0m";
xt_par0("\x1B[0m");
goto LABEL_13;
}
LABEL_12:
v27 = "Back";
printf("Back");
LABEL_13:
v28 = get_cols(v27, v26);
v29 = get_rows("\x1B[%d;%dH", v26, v28);
xt_par2("\x1B[%d;%dH", v29, v30);
return fflush(stdout);
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
const char *v2; // rdi
int v3; // ebp
int v4; // ebx
__int64 v5; // rdx
unsigned int v6; // eax
__int64 v7; // rdx
int v8; // ebp
int v9; // eax
__int64 v10; // rsi
__int64 v11; // rsi
unsigned int v12; // eax
int v13; // eax
int v14; // kr00_4
__int64 v15; // rsi
__int64 v16; // rdx
int v17; // eax
int v18; // ecx
__int64 v19; // rsi
__int64 v20; // rdx
int v21; // eax
int v22; // ecx
__int64 v23; // rsi
__int64 v24; // rdx
int v25; // ecx
__int64 v26; // rsi
const char *v27; // rdi
unsigned int v28; // eax
unsigned int v29; // eax
__int64 v30; // rdx
__int64 v32; // rsi
__int64 v33; // rdx
int v34; // eax
int v35; // ecx
__int64 v36; // rsi
__int64 v37; // rdx
int v38; // ecx

v2 = "\x1B[%d;%dH";
v3 = 1;
v4 = 0;
xt_par2("\x1B[%d;%dH", 1LL, 1LL);
while ( (int)((__int64 (*)(void))get_cols)() >= v3 )
{
while ( 1 )
{
xt_par2("\x1B[%d;%dH", 1LL, (unsigned int)v3);
putchar(45);
v5 = (unsigned int)v3++;
v6 = func1("\x1B[%d;%dH", 1LL, v5);
xt_par2("\x1B[%d;%dH", v6, v7);
v2 = (_BYTE *)(&loc_29 + 4);
putchar(45);
if ( v4 == 3 )
break;
++v4;
if ( (int)((__int64 (*)(void))get_cols)() < v3 )
goto LABEL_5;
}
v2 = (const char *)stdout;
v4 = 1;
fflush(stdout);
}
LABEL_5:
v8 = 2;
while ( 1 )
{
v9 = func1(v2);
v10 = (unsigned int)v9;
if ( v9 <= v8 )
break;
while ( 1 )
{
xt_par2("\x1B[%d;%dH", (unsigned int)v8, 1LL);
putchar(124);
v11 = (unsigned int)v8++;
v12 = func2("\x1B[%d;%dH", v11);
xt_par2("\x1B[%d;%dH", v11, v12);
v2 = (_BYTE *)(&loc_7B + 1);
putchar(124);
if ( v4 == 3 )
break;
v13 = func1((_BYTE *)&loc_7B + 1);
++v4;
v10 = (unsigned int)v13;
if ( v13 <= v8 )
goto LABEL_9;
}
v2 = (const char *)stdout;
v4 = 1;
fflush(stdout);
}
LABEL_9:
v14 = func2(v2, v10);
v15 = (unsigned int)((int)v10 / 4);
xt_par2("\x1B[%d;%dH", v15, (unsigned int)(v14 / 2 - 7));
xt_par0("\x1B[33m");
xt_par0("\x1B[1m");
printf("{[ Settings ]}");
xt_par0("\x1B[0m");
func2("\x1B[%d;%dH", v15);
v17 = func1("\x1B[%d;%dH", v15, v16);
xt_par2("\x1B[%d;%dH", (unsigned int)(v17 / 2), (unsigned int)(v18 / 2 - 5));
if ( !a1 )
{
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
printf("Height: ");
xt_par0("\x1B[0m");
v19 = (unsigned int)rows;
printf("%d", (unsigned int)rows);
func2("\x1B[%d;%dH", v19);
v21 = 5 * func1("\x1B[%d;%dH", v19, v20);
xt_par2("\x1B[%d;%dH", (unsigned int)(v21 / 8), (unsigned int)(v22 / 2 - 4));
printf("Width: ");
LABEL_11:
v23 = (unsigned int)cols;
printf("%d", (unsigned int)cols);
func2("\x1B[%d;%dH", v23);
v26 = (unsigned int)((int)(3 * func1("\x1B[%d;%dH", v23, v24)) / 4);
xt_par2("\x1B[%d;%dH", v26, (unsigned int)(v25 / 2 - 2));
goto LABEL_12;
}
printf("Height: ");
v32 = (unsigned int)rows;
printf("%d", (unsigned int)rows);
func2("\x1B[%d;%dH", v32);
v34 = 5 * func1("\x1B[%d;%dH", v32, v33);
xt_par2("\x1B[%d;%dH", (unsigned int)(v34 / 8), (unsigned int)(v35 / 2 - 4));
if ( a1 == 1 )
{
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
printf("Width: ");
xt_par0("\x1B[0m");
goto LABEL_11;
}
printf("Width: ");
v36 = (unsigned int)cols;
printf("%d", (unsigned int)cols);
func2("\x1B[%d;%dH", v36);
v26 = (unsigned int)((int)(3 * func1("\x1B[%d;%dH", v36, v37)) / 4);
xt_par2("\x1B[%d;%dH", v26, (unsigned int)(v38 / 2 - 2));
if ( a1 == 2 )
{
xt_par0("\x1B[1m");
xt_par0("\x1B[7m");
printf("Back");
v27 = "\x1B[0m";
xt_par0("\x1B[0m");
goto LABEL_13;
}
LABEL_12:
v27 = "Back";
printf("Back");
LABEL_13:
v28 = func2(v27, v26);
v29 = func1("\x1B[%d;%dH", v26, v28);
xt_par2("\x1B[%d;%dH", v29, v30);
return fflush(stdout);
}

original_code:
static void draw_menu(int config) {
    int cursor_r = 1, cursor_c = 1;
    xt_par2("\033[%d;%dH", (1), (1));
    int test = 0;
    int lim = 3;
    while (cursor_c <= get_cols()) {
        cursor_r = 1;
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        printf("-");
        cursor_r = get_rows();
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        printf("-");
        cursor_c++;
        if (test == lim){
            fflush(stdout);
            test = 0;
        }
        test++;
    }
    cursor_r = 2;
    while (cursor_r < get_rows()) {
        cursor_c = 1;
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        printf("|");
        cursor_c = get_cols();
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        printf("|");
        cursor_r++;
        if (test == lim){
            fflush(stdout);
            test = 0;
        }
        test++;
    }
    xt_par2("\033[%d;%dH", (get_rows() / 4), (get_cols() / 2 - 7));
    xt_par0("\033[33m");
    xt_par0("\033[1m");
    printf("{[ Settings ]}");
    xt_par0("\033[0m");
    xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 - 5));
    if (config == 0) {
        xt_par0("\033[1m");
        xt_par0("\033[7m");
        printf("Height: ");
        xt_par0("\033[0m");
    }
    else
        printf("Height: ");
    printf("%d", rows);
    xt_par2("\033[%d;%dH", (5 * get_rows() / 8), (get_cols() / 2 - 4));
    if (config == 1) {
        xt_par0("\033[1m");
        xt_par0("\033[7m");
        printf("Width: ");
        xt_par0("\033[0m");
    }
    else
        printf("Width: ");
    printf("%d", cols);
    xt_par2("\033[%d;%dH", (3 * get_rows() / 4), (get_cols() / 2 - 2));
    if (config == 2) {
        xt_par0("\033[1m");
        xt_par0("\033[7m");
        printf("Back");
        xt_par0("\033[0m");
    }
    else
        printf("Back");
    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
    fflush(stdout);
}

canonical_original_code:
static void draw_menu(int config) {
    int cursor_r = 1; int cursor_c = 1;
    xt_par2("\033[%d;%dH", (1), (1));
    int test = 0;
    int lim = 3;
    while (cursor_c <= get_cols()) {
        cursor_r = 1;
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        printf("-");
        cursor_r = get_rows();
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        printf("-");
        cursor_c++;
        if (test == lim){
            fflush(stdout);
            test = 0;
        }
        test++;
    }
    cursor_r = 2;
    while (cursor_r < get_rows()) {
        cursor_c = 1;
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        printf("|");
        cursor_c = get_cols();
        xt_par2("\033[%d;%dH", (cursor_r), (cursor_c));
        printf("|");
        cursor_r++;
        if (test == lim){
            fflush(stdout);
            test = 0;
        }
        test++;
    }
    xt_par2("\033[%d;%dH", (get_rows() / 4), (get_cols() / 2 - 7));
    xt_par0("\033[33m");
    xt_par0("\033[1m");
    printf("{[ Settings ]}");
    xt_par0("\033[0m");
    xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 - 5));
    if (config == 0) {
        xt_par0("\033[1m");
        xt_par0("\033[7m");
        printf("Height: ");
        xt_par0("\033[0m");
    }
    else
        printf("Height: ");
    printf("%d", rows);
    xt_par2("\033[%d;%dH", (5 * get_rows() / 8), (get_cols() / 2 - 4));
    if (config == 1) {
        xt_par0("\033[1m");
        xt_par0("\033[7m");
        printf("Width: ");
        xt_par0("\033[0m");
    }
    else
        printf("Width: ");
    printf("%d", cols);
    xt_par2("\033[%d;%dH", (3 * get_rows() / 4), (get_cols() / 2 - 2));
    if (config == 2) {
        xt_par0("\033[1m");
        xt_par0("\033[7m");
        printf("Back");
        xt_par0("\033[0m");
    }
    else
        printf("Back");
    xt_par2("\033[%d;%dH", (get_rows()), (get_cols()));
    fflush(stdout);
}

variable_types: config int

variable_types: test int

variable_types: lim int


original_code:
static int read_int(int rows) {
    char key;
    int len= 0;
    int place = 0;
    int result = 0;
    char* data = malloc(sizeof(char) * 4);
    int pos = 0;
    int i;
    data[0] = data[1] = data[2] = data[3] = '\0';
    place = 0;
    while (1) {
        xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3));
        printf("%s   ", data);
        xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
        while ((key = getkey()) == -2);
        if (key >= '0' && key <= '9' && pos < 3){
            xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
            putchar(key);
            for (i = 1; i >= pos; i--) {
                data[i+1] = data[i];
            }
            data[pos] = key;
            pos++;
            len++;
            xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3));
            printf("%s   ", data);
            xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
        } else switch (key) {
            case -13:
                if (pos > 0)
                    pos--;
                xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                break;
            case -12:
                if (pos < 3 && pos < len)
                    pos++;
                xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                break;
            case 127:
                if (pos > 0) {
                    for (i = pos - 1; i <= 2; i++) {
                        data[i] = data[i+1];
                    }
                    pos--;
                    len--;
                    xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                    putchar(' ');
                    xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3));
                    printf("%s   ", data);
                    xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                }
                break;
            case -20:
                if (pos < 3) {
                    for (i = pos; i <= 2; i++) {
                        data[i] = data[i+1];
                    }
                }
                xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3));
                printf("%s   ", data);
                xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                break;
            case 10:
                for (i = 2; i >= 0; i--) {
                    if (data[i] != '\0')
                        result += pow(10, place++) * (data[i] - '0');
                }
                return result;
            default:
                break;
        }
    }
}

canonical_original_code:
static int read_int(int rows) {
    char key;
    int len = 0;
    int place = 0;
    int result = 0;
    char *data = malloc(sizeof(char) * 4);
    int pos = 0;
    int i;
    data[0] = data[1] = data[2] = data[3] = '\0';
    place = 0;
    while (1) {
        xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3));
        printf("%s   ", data);
        xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
        while ((key = getkey()) == -2);
        if (key >= '0' && key <= '9' && pos < 3){
            xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
            putchar(key);
            for (i = 1; i >= pos; i--) {
                data[i+1] = data[i];
            }
            data[pos] = key;
            pos++;
            len++;
            xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3));
            printf("%s   ", data);
            xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
        } else switch (key) {
            case -13:
                if (pos > 0)
                    pos--;
                xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                break;
            case -12:
                if (pos < 3 && pos < len)
                    pos++;
                xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                break;
            case 127:
                if (pos > 0) {
                    for (i = pos - 1; i <= 2; i++) {
                        data[i] = data[i+1];
                    }
                    pos--;
                    len--;
                    xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                    putchar(' ');
                    xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3));
                    printf("%s   ", data);
                    xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                }
                break;
            case -20:
                if (pos < 3) {
                    for (i = pos; i <= 2; i++) {
                        data[i] = data[i+1];
                    }
                }
                xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3));
                printf("%s   ", data);
                xt_par2("\033[%d;%dH", (rows), (get_cols() / 2 + 3 + pos));
                break;
            case 10:
                for (i = 2; i >= 0; i--) {
                    if (data[i] != '\0')
                        result += pow(10, place++) * (data[i] - '0');
                }
                return result;
            default:
                break;
        }
    }
}

variable_types: rows int

variable_types: key char

variable_types: len int

variable_types: place int

variable_types: result int

variable_types:
data
char *

variable_types: i int


configloop

decompiled_code:
int __fastcall configloop(__int64 a1, __int64 a2)
{
void *v2; // r12
int v3; // ebp
char v4; // bl
int result; // eax
__int64 v6; // rdx
int v7; // ecx
__int64 v8; // rsi
__int64 v9; // rdx
int v10; // eax
__int64 v11; // rdx
int v12; // ecx
char v13; // bl
char v14; // bl
__int64 v15; // rdx
int v16; // ecx
__int64 v17; // rsi
int v18; // eax
__int64 v19; // rdx
int v20; // ecx
char v21; // bl

dispframe();
v2 = malloc(0xE10uLL);
init(v2);
do
{
v3 = 2;
LABEL_3:
update(v2);
display(v2);
draw_menu(v3);
usleep(0x1046u);
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
LABEL_4:
v4 = getkey();
if ( v4 == -2 )
goto LABEL_3;
update(v2);
display(v2);
draw_menu(v3);
result = usleep(0x1046u);
if ( v4 == 113 )
return result;
if ( v4 <= 113 )
break;
if ( v4 == 115 )
{
LABEL_19:
v3 = (v3 + 1) % 3;
}
else if ( v4 == 119 )
{
LABEL_11:
if ( !v3 )
goto LABEL_28;
--v3;
}
}
if ( v4 == 10 )
break;
if ( v4 <= 10 )
{
if ( v4 == -11 )
goto LABEL_19;
if ( v4 == -10 )
goto LABEL_11;
}
}
if ( v3 != 1 )
break;
do
{
get_cols(4166LL, a2);
v17 = (unsigned int)((int)(5 * get_rows("\x1B[%d;%dH", a2, v15)) / 8);
xt_par2("\x1B[%d;%dH", v17, (unsigned int)(v16 / 2 + 3));
v18 = 5 * get_rows("\x1B[%d;%dH");
cols = read_int(v18 / 8, v17);
write_preferences();
get_cols("\x1B[%d;%dH", v17);
a2 = (unsigned int)((int)(5 * get_rows("\x1B[%d;%dH", v17, v19)) / 8);
xt_par2("\x1B[%d;%dH", a2, (unsigned int)(v20 / 2 - 4));
v21 = getkey();
if ( v21 == -2 )
goto LABEL_3;
update(v2);
display(v2);
draw_menu(1);
result = usleep(0x1046u);
if ( v21 == 113 )
return result;
if ( v21 > 113 )
{
if ( v21 == 115 )
goto LABEL_51;
if ( v21 == 119 )
--v3;
goto LABEL_4;
}
}
while ( v21 == 10 );
if ( v21 > 10 )
goto LABEL_4;
if ( v21 == -11 )
{
LABEL_51:
v3 = 2;
goto LABEL_4;
}
if ( v21 == -10 )
--v3;
}
if ( v3 == 2 )
return result;
}
while ( v3 );
do
{
get_cols(4166LL, a2);
v8 = (unsigned int)((int)get_rows("\x1B[%d;%dH", a2, v6) / 2);
xt_par2("\x1B[%d;%dH", v8, (unsigned int)(v7 / 2 + 3));
v10 = get_rows("\x1B[%d;%dH", v8, v9);
rows = read_int(v10 / 2, v8);
write_preferences();
get_cols("\x1B[%d;%dH", v8);
a2 = (unsigned int)((int)get_rows("\x1B[%d;%dH", v8, v11) / 2);
xt_par2("\x1B[%d;%dH", a2, (unsigned int)(v12 / 2 - 5));
v13 = getkey();
if ( v13 == -2 )
goto LABEL_3;
update(v2);
display(v2);
draw_menu(0);
result = usleep(0x1046u);
if ( v13 == 113 )
return result;
if ( v13 > 113 )
{
if ( v13 == 115 )
goto LABEL_52;
if ( v13 == 119 )
goto LABEL_28;
goto LABEL_4;
}
}
while ( v13 == 10 );
if ( v13 > 10 )
goto LABEL_4;
if ( v13 == -11 )
{
LABEL_52:
v3 = 1;
goto LABEL_4;
}
if ( v13 != -10 )
goto LABEL_4;
LABEL_28:
v14 = getkey();
}
while ( v14 == -2 );
update(v2);
display(v2);
draw_menu(2);
result = usleep(0x1046u);
if ( v14 == 113 )
return result;
if ( v14 > 113 )
{
v3 = 0;
if ( v14 != 115 )
v3 = (v14 != 119) + 1;
goto LABEL_4;
}
if ( v14 != 10 )
{
v3 = 2;
if ( v14 <= 10 )
{
v3 = 0;
if ( v14 != -11 )
v3 = (v14 != -10) + 1;
}
goto LABEL_4;
}
return result;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2)
{
void *v2; // r12
int v3; // ebp
char v4; // bl
int result; // eax
__int64 v6; // rdx
int v7; // ecx
__int64 v8; // rsi
__int64 v9; // rdx
int v10; // eax
__int64 v11; // rdx
int v12; // ecx
char v13; // bl
char v14; // bl
__int64 v15; // rdx
int v16; // ecx
__int64 v17; // rsi
int v18; // eax
__int64 v19; // rdx
int v20; // ecx
char v21; // bl

dispframe();
v2 = malloc(0xE10uLL);
init(v2);
do
{
v3 = 2;
LABEL_3:
update(v2);
display(v2);
func3(v3);
usleep(0x1046u);
do
{
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
LABEL_4:
v4 = getkey();
if ( v4 == -2 )
goto LABEL_3;
update(v2);
display(v2);
func3(v3);
result = usleep(0x1046u);
if ( v4 == 113 )
return result;
if ( v4 <= 113 )
break;
if ( v4 == 115 )
{
LABEL_19:
v3 = (v3 + 1) % 3;
}
else if ( v4 == 119 )
{
LABEL_11:
if ( !v3 )
goto LABEL_28;
--v3;
}
}
if ( v4 == 10 )
break;
if ( v4 <= 10 )
{
if ( v4 == -11 )
goto LABEL_19;
if ( v4 == -10 )
goto LABEL_11;
}
}
if ( v3 != 1 )
break;
do
{
func2(4166LL, a2);
v17 = (unsigned int)((int)(5 * func1("\x1B[%d;%dH", a2, v15)) / 8);
xt_par2("\x1B[%d;%dH", v17, (unsigned int)(v16 / 2 + 3));
v18 = 5 * func1("\x1B[%d;%dH");
cols = func4(v18 / 8, v17);
func0();
func2("\x1B[%d;%dH", v17);
a2 = (unsigned int)((int)(5 * func1("\x1B[%d;%dH", v17, v19)) / 8);
xt_par2("\x1B[%d;%dH", a2, (unsigned int)(v20 / 2 - 4));
v21 = getkey();
if ( v21 == -2 )
goto LABEL_3;
update(v2);
display(v2);
func3(1);
result = usleep(0x1046u);
if ( v21 == 113 )
return result;
if ( v21 > 113 )
{
if ( v21 == 115 )
goto LABEL_51;
if ( v21 == 119 )
--v3;
goto LABEL_4;
}
}
while ( v21 == 10 );
if ( v21 > 10 )
goto LABEL_4;
if ( v21 == -11 )
{
LABEL_51:
v3 = 2;
goto LABEL_4;
}
if ( v21 == -10 )
--v3;
}
if ( v3 == 2 )
return result;
}
while ( v3 );
do
{
func2(4166LL, a2);
v8 = (unsigned int)((int)func1("\x1B[%d;%dH", a2, v6) / 2);
xt_par2("\x1B[%d;%dH", v8, (unsigned int)(v7 / 2 + 3));
v10 = func1("\x1B[%d;%dH", v8, v9);
rows = func4(v10 / 2, v8);
func0();
func2("\x1B[%d;%dH", v8);
a2 = (unsigned int)((int)func1("\x1B[%d;%dH", v8, v11) / 2);
xt_par2("\x1B[%d;%dH", a2, (unsigned int)(v12 / 2 - 5));
v13 = getkey();
if ( v13 == -2 )
goto LABEL_3;
update(v2);
display(v2);
func3(0);
result = usleep(0x1046u);
if ( v13 == 113 )
return result;
if ( v13 > 113 )
{
if ( v13 == 115 )
goto LABEL_52;
if ( v13 == 119 )
goto LABEL_28;
goto LABEL_4;
}
}
while ( v13 == 10 );
if ( v13 > 10 )
goto LABEL_4;
if ( v13 == -11 )
{
LABEL_52:
v3 = 1;
goto LABEL_4;
}
if ( v13 != -10 )
goto LABEL_4;
LABEL_28:
v14 = getkey();
}
while ( v14 == -2 );
update(v2);
display(v2);
func3(2);
result = usleep(0x1046u);
if ( v14 == 113 )
return result;
if ( v14 > 113 )
{
v3 = 0;
if ( v14 != 115 )
v3 = (v14 != 119) + 1;
goto LABEL_4;
}
if ( v14 != 10 )
{
v3 = 2;
if ( v14 <= 10 )
{
v3 = 0;
if ( v14 != -11 )
v3 = (v14 != -10) + 1;
}
goto LABEL_4;
}
return result;
}

original_code:
void configloop(void) {
    char key = ' ';
    int config = 2;
    dispframe();
    star_t* stars = malloc(sizeof(star_t) * 100);
    init(stars);
    while (1) {
        update(stars);
        display(stars);
        draw_menu(config);
        usleep(1000000/240);
        while ((key = getkey()) != -2){
            update(stars);
            display(stars);
            draw_menu(config);
            usleep(1000000/240);
            switch (key) {
                case -10:
                case 'w':
                    config = !config ? 2 : config - 1;
                    break;
                case -11:
                case 's':
                    config = (config + 1) % 3;
                    break;
                case 'q':
                    return;
                case 10:
                    switch (config) {
                        case 0:
                            xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 + 3));
                            rows = read_int(get_rows() / 2);
                            write_preferences();
                            xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 - 5));
                            break;
                        case 1:
                            xt_par2("\033[%d;%dH", (5 * get_rows() / 8), (get_cols() / 2 + 3));
                            cols = read_int(5 * get_rows() / 8);
                            write_preferences();
                            xt_par2("\033[%d;%dH", (5 * get_rows() / 8), (get_cols() / 2 - 4));
                            break;
                        case 2:
                            return;
                    }
            }
        }
    }
}

canonical_original_code:
void configloop() {
    char key = ' ';
    int config = 2;
    dispframe();
    struct star_t *stars = malloc(sizeof(star_t) * 100);
    init(stars);
    while (1) {
        update(stars);
        display(stars);
        draw_menu(config);
        usleep(1000000/240);
        while ((key = getkey()) != -2){
            update(stars);
            display(stars);
            draw_menu(config);
            usleep(1000000/240);
            switch (key) {
                case -10:
                case 'w':
                    config = !config ? 2 : config - 1;
                    break;
                case -11:
                case 's':
                    config = (config + 1) % 3;
                    break;
                case 'q':
                    return;
                case 10:
                    switch (config) {
                        case 0:
                            xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 + 3));
                            rows = read_int(get_rows() / 2);
                            write_preferences();
                            xt_par2("\033[%d;%dH", (get_rows() / 2), (get_cols() / 2 - 5));
                            break;
                        case 1:
                            xt_par2("\033[%d;%dH", (5 * get_rows() / 8), (get_cols() / 2 + 3));
                            cols = read_int(5 * get_rows() / 8);
                            write_preferences();
                            xt_par2("\033[%d;%dH", (5 * get_rows() / 8), (get_cols() / 2 - 4));
                            break;
                        case 2:
                            return;
                    }
            }
        }
    }
}

variable_types: struct star_t { int x; int y; int xwait; int ywait; int xwaited; int ywaited; int roy; int rox; int d; } *


decompiled_code:
__int64 __fastcall make_connection(char *name)
{
int v1; // eax
unsigned int v2; // er12
struct hostent *v3; // rax
socklen_t v4; // edx
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
v2 = -1;
perror("error: cannot create socket");
}
else
{
v2 = v1;
v3 = gethostbyname(name);
if ( v3 )
{
v6[0] = 0LL;
v6[0].sa_family = 2;
memmove(&v6[0].sa_data[2], *(const void **)v3->h_addr_list, v3->h_length);
*(_WORD *)v6[0].sa_data = _bswap_16_constprop_0(v2, v6, 16LL);
if ( connect(v2, v6, v4) < 0 )
v2 = -1;
}
else
{
v2 = -1;
perror("error: cannot gethostbyname()");
}
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name)
{
int v1; // eax
unsigned int v2; // er12
struct hostent *v3; // rax
socklen_t v4; // edx
struct sockaddr v6[2]; // [rsp+0h] [rbp-28h] BYREF

v1 = socket(2, 1, 0);
if ( v1 < 0 )
{
v2 = -1;
perror("error: cannot create socket");
}
else
{
v2 = v1;
v3 = gethostbyname(name);
if ( v3 )
{
v6[0] = 0LL;
v6[0].sa_family = 2;
memmove(&v6[0].sa_data[2], *(const void **)v3->h_addr_list, v3->h_length);
*(_WORD *)v6[0].sa_data = func0(v2, v6, 16LL);
if ( connect(v2, v6, v4) < 0 )
v2 = -1;
}
else
{
v2 = -1;
perror("error: cannot gethostbyname()");
}
}
return v2;
}

original_code:
int make_connection(char* name) {
    int sockfd;
    struct sockaddr_in serv_addr;
    struct hostent *server;
    if ((sockfd = socket(2, SOCK_STREAM, 0)) < 0) {
        perror("error: cannot create socket");
        return -1;
    }
    if ((server = gethostbyname(name)) == ((void *)0)) {
        perror("error: cannot gethostbyname()");
        return -1;
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    bcopy((char *) server->h_addr_list[0], (char *) &serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons(6413);
    if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
        return -1;
    return sockfd;
}

canonical_original_code:
int make_connection(char *name) {
    int sockfd;
    struct sockaddr_in serv_addr;
    struct hostent *server;
    if ((sockfd = socket(2, SOCK_STREAM, 0)) < 0) {
        perror("error: cannot create socket");
        return -1;
    }
    if ((server = gethostbyname(name)) == ((void *)0)) {
        perror("error: cannot gethostbyname()");
        return -1;
    }
    bzero((char *) &serv_addr, sizeof(serv_addr));
    serv_addr.sin_family = 2;
    bcopy((char *) server->h_addr_list[0], (char *) &serv_addr.sin_addr.s_addr, server->h_length);
    serv_addr.sin_port = htons(6413);
    if (connect(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr)) < 0)
        return -1;
    return sockfd;
}

variable_types:
name
char *

variable_types: sockfd int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; }

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


transmit

decompiled_code:
__int64 __fastcall transmit(int fd, unsigned int a2, const char *a3)
{
int v4; // eax
int v5; // ebx
int v6; // ebp
size_t v7; // r14
char *v8; // r13
char *v9; // rbp
int v10; // eax
unsigned int v11; // er14

if ( a3 )
{
v4 = strlen(a3);
v5 = v4 + 9;
v6 = v4 + 1;
v7 = v4 + 9;
v8 = (char *)malloc(v7);
snprintf(v8, 9uLL, "%02d%06d", a2, (unsigned int)v6);
if ( v6 > 1 )
snprintf(v8 + 8, v6, "%s", a3);
if ( !v5 )
{
v11 = 0;
goto LABEL_9;
}
}
else
{
v5 = 9;
v7 = 9LL;
v8 = (char *)malloc(9uLL);
snprintf(v8, 9uLL, "%02d%06d", a2, 1LL);
}
v9 = v8;
while ( 1 )
{
v10 = write(fd, v9, v7);
v11 = v10;
if ( v10 < 0 )
break;
v9 += v10;
v5 -= v10;
if ( !v5 )
break;
v7 = v5;
}
LABEL_9:
free(v8);
return v11;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, unsigned int a2, const char *a3)
{
int v4; // eax
int v5; // ebx
int v6; // ebp
size_t v7; // r14
char *v8; // r13
char *v9; // rbp
int v10; // eax
unsigned int v11; // er14

if ( a3 )
{
v4 = strlen(a3);
v5 = v4 + 9;
v6 = v4 + 1;
v7 = v4 + 9;
v8 = (char *)malloc(v7);
snprintf(v8, 9uLL, "%02d%06d", a2, (unsigned int)v6);
if ( v6 > 1 )
snprintf(v8 + 8, v6, "%s", a3);
if ( !v5 )
{
v11 = 0;
goto LABEL_9;
}
}
else
{
v5 = 9;
v7 = 9LL;
v8 = (char *)malloc(9uLL);
snprintf(v8, 9uLL, "%02d%06d", a2, 1LL);
}
v9 = v8;
while ( 1 )
{
v10 = write(fd, v9, v7);
v11 = v10;
if ( v10 < 0 )
break;
v9 += v10;
v5 -= v10;
if ( !v5 )
break;
v7 = v5;
}
LABEL_9:
free(v8);
return v11;
}

original_code:
int transmit(int sockfd, int command, char* data) {
    int datalen = (data ? strlen(data) : 0) + 1, retval = 0, remainder;
    char *encoded = malloc(sizeof(char) * (8 + datalen)), *unsent;
    snprintf(encoded, 8 + 1, "%02d%06d", command, datalen);
    if (datalen > 1)
        snprintf(encoded + 8, datalen, "%s", data);
    remainder = 8 + datalen;
    unsent = encoded;
    while (remainder) {
        retval = write(sockfd, unsent, remainder);
        if (retval < 0)
            goto cleanup;
        remainder -= retval;
        unsent += retval;
    }
    cleanup:
    free(encoded);
    return retval;
}

canonical_original_code:
int transmit(int sockfd, int command, char *data) {
    int datalen = (data ? strlen(data) : 0) + 1; int retval = 0; int remainder;
    char *encoded = malloc(sizeof(char) * (8 + datalen)); char *unsent;
    snprintf(encoded, 8 + 1, "%02d%06d", command, datalen);
    if (datalen > 1)
        snprintf(encoded + 8, datalen, "%s", data);
    remainder = 8 + datalen;
    unsent = encoded;
    while (remainder) {
        retval = write(sockfd, unsent, remainder);
        if (retval < 0)
            goto cleanup;
        remainder -= retval;
        unsent += retval;
    }
    cleanup:
    free(encoded);
    return retval;
}

variable_types: command int

variable_types: datalen int

variable_types: retval int

variable_types: remainder int

variable_types:
encoded
char *

variable_types:
unsent
char *


receive

decompiled_code:
__int64 __fastcall receive(int fd, __int64 a2, char **a3)
{
int v4; // er12
int v5; // eax
int v6; // ebp
char *v7; // rax
size_t v8; // rdx
__int64 v9; // rsi
int v10; // eax
size_t v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+14h] [rbp-34h] BYREF
char v14[48]; // [rsp+18h] [rbp-30h] BYREF

v4 = 8;
while ( 1 )
{
v5 = read(fd, &v14[8LL - v4], v4);
if ( v5 <= 0 )
break;
v4 -= v5;
if ( !v4 )
{
if ( (int)_isoc99_sscanf(v14, "%02d%06d", a2, &v13) > 1 )
{
v6 = v13;
v12 = v13;
v7 = (char *)malloc(v13);
v8 = v12;
v9 = v6;
*a3 = v7;
if ( !v6 )
return (unsigned int)v4;
while ( 1 )
{
v10 = read(fd, &v7[v9 - v8], v8);
if ( v10 <= 0 )
break;
v6 -= v10;
if ( !v6 )
return (unsigned int)v4;
v7 = *a3;
v9 = v13;
v8 = v6;
}
}
break;
}
}
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int64 a2, char **a3)
{
int v4; // er12
int v5; // eax
int v6; // ebp
char *v7; // rax
size_t v8; // rdx
__int64 v9; // rsi
int v10; // eax
size_t v12; // [rsp+8h] [rbp-40h]
int v13; // [rsp+14h] [rbp-34h] BYREF
char v14[48]; // [rsp+18h] [rbp-30h] BYREF

v4 = 8;
while ( 1 )
{
v5 = read(fd, &v14[8LL - v4], v4);
if ( v5 <= 0 )
break;
v4 -= v5;
if ( !v4 )
{
if ( (int)_isoc99_sscanf(v14, "%02d%06d", a2, &v13) > 1 )
{
v6 = v13;
v12 = v13;
v7 = (char *)malloc(v13);
v8 = v12;
v9 = v6;
*a3 = v7;
if ( !v6 )
return (unsigned int)v4;
while ( 1 )
{
v10 = read(fd, &v7[v9 - v8], v8);
if ( v10 <= 0 )
break;
v6 -= v10;
if ( !v6 )
return (unsigned int)v4;
v7 = *a3;
v9 = v13;
v8 = v6;
}
}
break;
}
}
return (unsigned int)-1;
}

original_code:
int receive(int sockfd, int* command, char** data) {
    char header[8];
    int nread, datalen, remainder;
    remainder = 8;
    while (remainder) {
        nread = read(sockfd, header + 8 - remainder, remainder);
        if (nread < 1)
            return -1;
        remainder -= nread;
    }
    if (sscanf(header, "%02d%06d", command, &datalen) < 2)
        return -1;
    *data = malloc(sizeof(char) * datalen);
    remainder = datalen;
    while (remainder) {
        nread = read(sockfd, *data + datalen - remainder, remainder);
        if (nread < 1)
            return -1;
        remainder -= nread;
    }
    return 0;
}

canonical_original_code:
int receive(int sockfd, int *command, char **data) {
    char header[8];
    int nread; int datalen; int remainder;
    remainder = 8;
    while (remainder) {
        nread = read(sockfd, header + 8 - remainder, remainder);
        if (nread < 1)
            return -1;
        remainder -= nread;
    }
    if (sscanf(header, "%02d%06d", command, &datalen) < 2)
        return -1;
    *data = malloc(sizeof(char) * datalen);
    remainder = datalen;
    while (remainder) {
        nread = read(sockfd, *data + datalen - remainder, remainder);
        if (nread < 1)
            return -1;
        remainder -= nread;
    }
    return 0;
}

variable_types:
command
int *

variable_types:
data
char **

variable_types:
header
char [8]

variable_types: nread int


decompiled_code:
char *__fastcall setup_multiplayer(__int64 a1, int a2, int a3, int a4)
{
char *result; // rax
__int64 v5; // rbx
__int64 v6; // r12
char *v7; // rsi

*(_DWORD *)(a1 + 4) = 1;
*(_DWORD *)(a1 + 56) = 0;
*(_DWORD *)(a1 + 60) = a2;
*(_DWORD *)(a1 + 64) = a3;
*(_DWORD *)(a1 + 68) = a4;
result = (char *)realloc(*(void **)(a1 + 24), 48LL * a2);
*(_QWORD *)(a1 + 24) = result;
if ( a2 > 1 )
{
v5 = 48LL;
v6 = 48LL * (unsigned int)(a2 - 2) + 96;
while ( 1 )
{
v7 = &result[v5];
v5 += 48LL;
result = (char *)spawn_player(a1, v7, 3LL);
if ( v5 == v6 )
break;
result = *(char **)(a1 + 24);
}
}
return result;
}

original_code:
void setup_multiplayer(game_t* game, int players, int player, int sockfd) {
    int i;
    game->multiplayer = 1;
    game->multiplayer_data.mode = 0;
    game->multiplayer_data.players = players;
    game->multiplayer_data.player = player;
    game->multiplayer_data.sockfd = sockfd;
    game->players = realloc(game->players, sizeof(player_t) * players);
    for (i = 1; i < players; i++)
        spawn_player(game, &game->players[i], 3);
}

canonical_original_code:
void setup_multiplayer(struct game_t *game, int players, int player, int sockfd) {
    int i;
    game->multiplayer = 1;
    game->multiplayer_data.mode = 0;
    game->multiplayer_data.players = players;
    game->multiplayer_data.player = player;
    game->multiplayer_data.sockfd = sockfd;
    game->players = realloc(game->players, sizeof(player_t) * players);
    for (i = 1; i < players; i++)
        spawn_player(game, &game->players[i], 3);
}

variable_types: struct game_t { int running; int multiplayer; int score; int over; int until_spawn; int spawn_timer; struct player_t { struct point_t { double x; double y; } point; int lives; int respawning; int invincible; int cooldown; int nospawn; int vertical_accel; int horiz_accel; int bullet_type; } *players; struct enemy_t { struct point_t point; int score; int cooldown; int max_cooldown; double velocity; double bullet_velocity; struct enemy_t *next; } *first_enemy; struct bullet_t { struct point_t point; double velocity; int fired_by_player; int type; struct bullet_t *next; } *first_bullet; struct explosion_t { struct point_t point; int step; int score; struct explosion_t *next; } *first_explosion; struct multidata_t { int mode; int players; int player; int sockfd; } multiplayer_data; } *

variable_types: players int

variable_types: player int


decompiled_code:
__int64 __fastcall check_multiplayer_game_over(__int64 a1)
{
__int64 v1; // rax
int i; // edx
unsigned int v3; // er8
int v4; // ecx

v1 = 0LL;
for ( i = 0; ; ++i )
{
v4 = 1;
if ( *(_DWORD *)(a1 + 4) )
v4 = *(_DWORD *)(a1 + 60);
if ( i >= v4 )
break;
v3 = *(_DWORD *)(*(_QWORD *)(a1 + 24) + v1 + 32);
v1 += 48LL;
if ( !v3 )
return v3;
}
return 1;
}

original_code:
int check_multiplayer_game_over(game_t* game) {
    int slot;
    for (slot = 0; slot < (game->multiplayer ? game->multiplayer_data.players : 1); slot++) {
        if (!game->players[slot].nospawn)
            return 0;
    }
    return 1;
}

canonical_original_code:
int check_multiplayer_game_over(struct game_t *game) {
    int slot;
    for (slot = 0; slot < (game->multiplayer ? game->multiplayer_data.players : 1); slot++) {
        if (!game->players[slot].nospawn)
            return 0;
    }
    return 1;
}

variable_types: slot int


decompiled_code:
int *__fastcall load_server_data(_DWORD *a1)
{
unsigned int v1; // ebx
int *result; // rax
int v3; // [rsp+4h] [rbp-24h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v1 = a1[17];
while ( (int)receive(v1, &v3, &ptr) >= 0 )
{
if ( v3 == 15 )
{
unserialize_game_data(ptr, a1);
}
else if ( v3 == 17 || !v3 )
{
*a1 = 0;
}
free(ptr);
}
result = _errno_location();
if ( *result != 11 )
*a1 = 0;
return result;
}

canonical_decompiled_code:
int *__fastcall func2(_DWORD *a1)
{
unsigned int v1; // ebx
int *result; // rax
int v3; // [rsp+4h] [rbp-24h] BYREF
void *ptr; // [rsp+8h] [rbp-20h] BYREF

v1 = a1[17];
while ( (int)receive(v1, &v3, &ptr) >= 0 )
{
if ( v3 == 15 )
{
unserialize_game_data(ptr, a1);
}
else if ( v3 == 17 || !v3 )
{
*a1 = 0;
}
free(ptr);
}
result = _errno_location();
if ( *result != 11 )
*a1 = 0;
return result;
}

original_code:
void load_server_data(game_t* game) {
    char* buffer;
    int sockfd = game->multiplayer_data.sockfd, command;
    while (1) {
        if (receive(sockfd, &command, &buffer) < 0) {
            if ((*__errno_location ()) != 11 && (*__errno_location ()) != 11)
                game->running = 0;
            break;
        }
        switch (command) {
            case 15:
                unserialize_game_data(buffer, game);
                break;
            case 17:
            case 0:
                game->running = 0;
                break;
        }
        free(buffer);
    }
}

canonical_original_code:
void load_server_data(struct game_t *game) {
    char *buffer;
    int sockfd = game->multiplayer_data.sockfd; int command;
    while (1) {
        if (receive(sockfd, &command, &buffer) < 0) {
            if ((*__errno_location ()) != 11 && (*__errno_location ()) != 11)
                game->running = 0;
            break;
        }
        switch (command) {
            case 15:
                unserialize_game_data(buffer, game);
                break;
            case 17:
            case 0:
                game->running = 0;
                break;
        }
        free(buffer);
    }
}

variable_types:
buffer
char *

variable_types: sockfd int


decompiled_code:
__int64 __fastcall handle_input_multi(_DWORD *a1)
{
__int64 result; // rax
__int64 v2; // rcx
char s[16]; // [rsp+8h] [rbp-10h] BYREF

LABEL_1:
while ( 1 )
{
result = getkey();
if ( (_DWORD)result == -2 )
return result;
while ( (int)result <= 119 )
{
if ( (int)result > 96 )
{
switch ( (int)result )
{
case 'a':
goto LABEL_16;
case 'd':
goto LABEL_13;
case 'q':
transmit((unsigned int)a1[17], 13LL, 0LL);
*a1 = 0;
goto LABEL_1;
case 's':
goto LABEL_18;
case 'w':
goto LABEL_15;
default:
goto LABEL_1;
}
}
if ( (_DWORD)result == -11 )
{
LABEL_18:
v2 = 1LL;
}
else if ( (int)result < -10 )
{
if ( (_DWORD)result == -13 )
{
LABEL_16:
v2 = 2LL;
}
else
{
if ( (_DWORD)result != -12 )
goto LABEL_1;
LABEL_13:
v2 = 3LL;
}
}
else if ( (_DWORD)result == -10 )
{
LABEL_15:
v2 = 0LL;
}
else
{
if ( (_DWORD)result != 32 )
goto LABEL_1;
v2 = 4LL;
}
snprintf(s, 8uLL, "%d", v2);
transmit((unsigned int)a1[17], 16LL, s);
result = getkey();
if ( (_DWORD)result == -2 )
return result;
}
}
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
__int64 result; // rax
__int64 v2; // rcx
char s[16]; // [rsp+8h] [rbp-10h] BYREF

LABEL_1:
while ( 1 )
{
result = getkey();
if ( (_DWORD)result == -2 )
return result;
while ( (int)result <= 119 )
{
if ( (int)result > 96 )
{
switch ( (int)result )
{
case 'a':
goto LABEL_16;
case 'd':
goto LABEL_13;
case 'q':
transmit((unsigned int)a1[17], 13LL, 0LL);
*a1 = 0;
goto LABEL_1;
case 's':
goto LABEL_18;
case 'w':
goto LABEL_15;
default:
goto LABEL_1;
}
}
if ( (_DWORD)result == -11 )
{
LABEL_18:
v2 = 1LL;
}
else if ( (int)result < -10 )
{
if ( (_DWORD)result == -13 )
{
LABEL_16:
v2 = 2LL;
}
else
{
if ( (_DWORD)result != -12 )
goto LABEL_1;
LABEL_13:
v2 = 3LL;
}
}
else if ( (_DWORD)result == -10 )
{
LABEL_15:
v2 = 0LL;
}
else
{
if ( (_DWORD)result != 32 )
goto LABEL_1;
v2 = 4LL;
}
snprintf(s, 8uLL, "%d", v2);
transmit((unsigned int)a1[17], 16LL, s);
result = getkey();
if ( (_DWORD)result == -2 )
return result;
}
}
}

original_code:
void handle_input_multi(game_t* game) {
    int key;
    char tmpbuf[8];
    while ((key = getkey()) != -2) {
        switch (key) {
            case 'q':
                transmit(game->multiplayer_data.sockfd, 13, ((void *)0));
                game->running = 0;
                break;
            case -10:
            case 'w':
                snprintf(tmpbuf, 8, "%d", 0);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
            case -11:
            case 's':
                snprintf(tmpbuf, 8, "%d", 1);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
            case -13:
            case 'a':
                snprintf(tmpbuf, 8, "%d", 2);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
            case -12:
            case 'd':
                snprintf(tmpbuf, 8, "%d", 3);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
            case ' ':
                snprintf(tmpbuf, 8, "%d", 4);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
        }
    }
}

canonical_original_code:
void handle_input_multi(struct game_t *game) {
    int key;
    char tmpbuf[8];
    while ((key = getkey()) != -2) {
        switch (key) {
            case 'q':
                transmit(game->multiplayer_data.sockfd, 13, ((void *)0));
                game->running = 0;
                break;
            case -10:
            case 'w':
                snprintf(tmpbuf, 8, "%d", 0);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
            case -11:
            case 's':
                snprintf(tmpbuf, 8, "%d", 1);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
            case -13:
            case 'a':
                snprintf(tmpbuf, 8, "%d", 2);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
            case -12:
            case 'd':
                snprintf(tmpbuf, 8, "%d", 3);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
            case ' ':
                snprintf(tmpbuf, 8, "%d", 4);
                transmit(game->multiplayer_data.sockfd, 16, tmpbuf);
                break;
        }
    }
}

variable_types: key int

variable_types:
tmpbuf
char [8]


readDisk

repo: Vvnesaa/fsck

decompiled_code:
ssize_t __fastcall readDisk(__off64_t offset, size_t nbytes, void *buf)
{
__off64_t v4; // rax
ssize_t result; // rax

v4 = lseek64(device, (unsigned int)offset, 0);
if ( (unsigned int)offset != v4 )
{
printf("Seek to position %d failed at %lld, device:%d\n", (unsigned int)offset, v4, (unsigned int)device);
exit(-1);
}
result = read(device, buf, (unsigned int)nbytes);
if ( (_DWORD)nbytes != (_DWORD)result )
{
printf("Read disk error at %d length %d\n", (unsigned int)offset, (unsigned int)nbytes);
exit(-1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(__off64_t offset, size_t nbytes, void *buf)
{
__off64_t v4; // rax
ssize_t result; // rax

v4 = lseek64(device, (unsigned int)offset, 0);
if ( (unsigned int)offset != v4 )
{
printf("Seek to position %d failed at %lld, device:%d\n", (unsigned int)offset, v4, (unsigned int)device);
exit(-1);
}
result = read(device, buf, (unsigned int)nbytes);
if ( (_DWORD)nbytes != (_DWORD)result )
{
printf("Read disk error at %d length %d\n", (unsigned int)offset, (unsigned int)nbytes);
exit(-1);
}
return result;
}

original_code:
void readDisk(unsigned int startPoint, unsigned int readByteNum, void *buf) {
 int ret;
 int64_t lret;
 if ((lret = lseek64(device, startPoint, 0)) != startPoint) {
  printf("Seek to position %d failed at %lld, device:%d\n", startPoint, lret, device);
  exit(-1);
 }
 if ((ret = read(device, buf, readByteNum)) != readByteNum) {
  printf("Read disk error at %d length %d\n", startPoint, readByteNum);
  exit(-1);
 }
}

canonical_original_code:
void readDisk(unsigned int startPoint, unsigned int readByteNum, void *buf) {
 int ret;
 long lret;
 if ((lret = lseek64(device, startPoint, 0)) != startPoint) {
  printf("Seek to position %d failed at %lld, device:%d\n", startPoint, lret, device);
  exit(-1);
 }
 if ((ret = read(device, buf, readByteNum)) != readByteNum) {
  printf("Read disk error at %d length %d\n", startPoint, readByteNum);
  exit(-1);
 }
}

variable_types:
startPoint
unsigned int

variable_types:
readByteNum
unsigned int

variable_types:
buf
void *

variable_types: ret int

variable_types: lret long


writeDisk

decompiled_code:
ssize_t __fastcall writeDisk(__off64_t offset, size_t n, void *buf)
{
__off64_t v4; // rax
ssize_t result; // rax

v4 = lseek64(device, (unsigned int)offset, 0);
if ( (unsigned int)offset != v4 )
{
printf("Seek to position %d failed at %lld, device:%d\n", (unsigned int)offset, v4, (unsigned int)device);
exit(-1);
}
result = write(device, buf, (unsigned int)n);
if ( (_DWORD)n != (_DWORD)result )
{
printf("Write disk error at %d length %d\n", (unsigned int)offset, (unsigned int)n);
exit(-1);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(__off64_t offset, size_t n, void *buf)
{
__off64_t v4; // rax
ssize_t result; // rax

v4 = lseek64(device, (unsigned int)offset, 0);
if ( (unsigned int)offset != v4 )
{
printf("Seek to position %d failed at %lld, device:%d\n", (unsigned int)offset, v4, (unsigned int)device);
exit(-1);
}
result = write(device, buf, (unsigned int)n);
if ( (_DWORD)n != (_DWORD)result )
{
printf("Write disk error at %d length %d\n", (unsigned int)offset, (unsigned int)n);
exit(-1);
}
return result;
}

original_code:
void writeDisk(unsigned int startPoint, unsigned int writeByteNum, void *buf) {
 int ret;
        int64_t lret;
 if ((lret = lseek64(device, startPoint, 0)) != startPoint) {
  printf("Seek to position %d failed at %lld, device:%d\n", startPoint, lret, device);
                exit(-1);
 }
 if ((ret = write(device, buf, writeByteNum)) != writeByteNum) {
  printf("Write disk error at %d length %d\n", startPoint, writeByteNum);
                exit(-1);
 }
}

canonical_original_code:
void writeDisk(unsigned int startPoint, unsigned int writeByteNum, void *buf) {
 int ret;
        long lret;
 if ((lret = lseek64(device, startPoint, 0)) != startPoint) {
  printf("Seek to position %d failed at %lld, device:%d\n", startPoint, lret, device);
                exit(-1);
 }
 if ((ret = write(device, buf, writeByteNum)) != writeByteNum) {
  printf("Write disk error at %d length %d\n", startPoint, writeByteNum);
                exit(-1);
 }
}

variable_types:
writeByteNum
unsigned int


getIntFromBuf

decompiled_code:
__int64 __fastcall getIntFromBuf(__int64 a1, int a2)
{
return _uint32_identity(*(_DWORD *)(a1 + a2));
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
return func0(*(_DWORD *)(a1 + a2));
}

original_code:
int getIntFromBuf(unsigned char* buf, int start) {
 uint32_t x = *(uint32_t*)(buf + start);
 return (int) __uint32_identity (x);
}

canonical_original_code:
int getIntFromBuf(unsigned char *buf, int start) {
 unsigned int x = *(uint32_t*)(buf + start);
 return (int) __uint32_identity (x);
}

variable_types:
buf
unsigned char *

variable_types: start int

variable_types:
x
unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // er12
int v4; // eax
__int64 v5; // rbx

opterr = 0;
v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "f:p:i:");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'i':
diskFileName = (__int64)optarg;
break;
case 'p':
goto LABEL_7;
case 'f':
v3 = 1;
LABEL_7:
theParNum = atoi(optarg);
break;
}
}
if ( diskFileName )
{
printPartitionInfo(v3);
if ( v3 && pNum > 0 )
{
v5 = (unsigned int)((_DWORD)&par + 12);
do
{
if ( *(_BYTE *)v5 == 0x83 && (theParNum == v3 || !theParNum) )
{
init(v3, *(unsigned int *)(v5 + 4));
pass1();
pass2();
pass3();
pass4();
cleanup();
}
++v3;
v5 += 12LL;
}
while ( pNum >= (int)v3 );
}
}
else
{
puts("Argument error");
}
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int fsck = 0;
 int opt;
 opterr = 0;
 while ((opt = getopt(argc, argv, "f:p:i:")) != -1) {
  switch (opt) {
   case 'f':
    fsck = 1;
   case 'p':
    theParNum = atoi(optarg);
    break;
   case 'i':
    diskFileName = optarg;
    break;
   default:
    break;
  }
 }
 if (diskFileName == 0) {
  printf("Argument error\n");
  return 0;
 }
 printPartitionInfo(fsck);
 if (fsck) {
  int i;
  for (i = 1; i <= pNum; ++i)
   if (par[i].type == 0x83 && (theParNum == 0 || theParNum == i)) {
   init(i, par[i].start);
   pass1();
   pass2();
   pass3();
   pass4();
   cleanup();
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: fsck int

variable_types: opt int

variable_types: i int


checkDirInode

decompiled_code:
void __fastcall checkDirInode(unsigned int a1, unsigned int a2)
{
int *v2; // rcx
int v3; // eax
__int64 v4; // rbp
void *v5; // r14

v2 = (int *)(inodeLink + 4LL * (int)a1);
v3 = *v2 + 1;
*v2 = v3;
if ( v3 <= 1 )
{
v4 = inodeTable + ((__int64)(int)a1 << 7);
if ( (unsigned int)isDirectory(v4) )
{
v5 = malloc(*(unsigned int *)(v4 + 4));
getData(start, v4, blockSize, v5);
checkDir(v4, v5, a1, a2);
free(v5);
}
}
}

canonical_decompiled_code:
void __fastcall func0(unsigned int a1, unsigned int a2)
{
int *v2; // rcx
int v3; // eax
__int64 v4; // rbp
void *v5; // r14

v2 = (int *)(inodeLink + 4LL * (int)a1);
v3 = *v2 + 1;
*v2 = v3;
if ( v3 <= 1 )
{
v4 = inodeTable + ((__int64)(int)a1 << 7);
if ( (unsigned int)isDirectory(v4) )
{
v5 = malloc(*(unsigned int *)(v4 + 4));
getData(start, v4, blockSize, v5);
func1(v4, v5, a1, a2);
free(v5);
}
}
}

original_code:
void checkDirInode(int localId, int parent) {
 ++inodeLink[localId];
 if (inodeLink[localId] > 1) return;
 struct ext2_inode *inode;
 inode = inodeTable + localId;
 if (!isDirectory(inode)) return;
 unsigned char *buf = malloc(inode->i_size);
 getData(start, inode, blockSize, buf);
 checkDir(inode, buf, localId, parent);
 free(buf);
}

variable_types: localId int

variable_types: parent int

variable_types: struct ext2_inode { unsigned short i_mode; unsigned short i_uid; unsigned int i_size; unsigned int i_atime; unsigned int i_ctime; unsigned int i_mtime; unsigned int i_dtime; unsigned short i_gid; unsigned short i_links_count; unsigned int i_blocks; unsigned int i_flags; union { struct { unsigned int l_i_reserved1; } linux1; struct { unsigned int h_i_translator; } hurd1; struct { unsigned int m_i_reserved1; } masix1; } osd1; unsigned int i_block[-1]; unsigned int i_generation; unsigned int i_file_acl; unsigned int i_dir_acl; unsigned int i_faddr; union { struct { unsigned char l_i_frag; unsigned char l_i_fsize; unsigned short i_pad1; unsigned short l_i_uid_high; unsigned short l_i_gid_high; unsigned int l_i_reserved2; } linux2; struct { unsigned char h_i_frag; unsigned char h_i_fsize; unsigned short h_i_mode_high; unsigned short h_i_uid_high; unsigned short h_i_gid_high; unsigned int h_i_author; } hurd2; struct { unsigned char m_i_frag; unsigned char m_i_fsize; unsigned short m_pad1; unsigned int m_i_reserved2[2]; } masix2; } osd2; } *