decompiled_code:
__int64 __fastcall char_to_set(char a1)
{
const __int32_t **v1; // rax
unsigned int v2; // ecx
__int64 result; // rax

v1 = __ctype_tolower_loc();
v2 = (*v1)[a1] - 97;
result = (unsigned int)(1 << (LOBYTE((*v1)[a1]) - 97));
if ( v2 >= 0x1A )
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(char a1)
{
const __int32_t **v1; // rax
unsigned int v2; // ecx
__int64 result; // rax

v1 = __ctype_tolower_loc();
v2 = (*v1)[a1] - 97;
result = (unsigned int)(1 << (LOBYTE((*v1)[a1]) - 97));
if ( v2 >= 0x1A )
result = 0LL;
return result;
}

original_code:
unsigned int char_to_set(char c) {
    unsigned int x = tolower(c);
    if (('a' <= x) && (x <= 'z'))
        return 1u << (x - 'a');
    else
        return 0;
}

variable_types: c char

variable_types:
x
unsigned int


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
int v5; // ebx
int v6; // eax
int v7; // eax

v3 = 0;
v4 = 0;
v5 = 0;
LABEL_2:
while ( 1 )
{
v6 = getchar();
if ( v6 == -1 )
break;
while ( 1 )
{
v7 = char_to_set((unsigned int)(char)v6, argv);
v5 |= v7;
if ( v7 || !v5 )
break;
if ( v4 == v5 )
{
v5 = 0;
v3 = 1;
goto LABEL_2;
}
v4 = v5;
v5 = 0;
v6 = getchar();
if ( v6 == -1 )
goto LABEL_7;
}
}
LABEL_7:
if ( v3 == 1 )
puts("true");
else
puts("false");
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // ebp
int v5; // ebx
int v6; // eax
int v7; // eax

v3 = 0;
v4 = 0;
v5 = 0;
LABEL_2:
while ( 1 )
{
v6 = getchar();
if ( v6 == -1 )
break;
while ( 1 )
{
v7 = func7((unsigned int)(char)v6, argv);
v5 |= v7;
if ( v7 || !v5 )
break;
if ( v4 == v5 )
{
v5 = 0;
v3 = 1;
goto LABEL_2;
}
v4 = v5;
v5 = 0;
v6 = getchar();
if ( v6 == -1 )
goto LABEL_7;
}
}
LABEL_7:
if ( v3 == 1 )
puts("true");
else
puts("false");
return 0;
}

original_code:
int main() {
    int c = 0;
    int flag = FALSE;
    unsigned int prev_letters = 0;
    unsigned int curr_letters = 0;
    while ((-1) != (c = getchar())) {
        unsigned int c_set = char_to_set(c);
        curr_letters = curr_letters | c_set;
        if (0 == c_set && 0 != curr_letters) {
            if (curr_letters == prev_letters) {
                flag = TRUE;
            }
            prev_letters = curr_letters;
            curr_letters = 0;
        }
    }
    flag == TRUE ? printf("true\n") : printf("false\n");
    return 0;
}

variable_types: c int

variable_types: flag int

return_type: int


repo: wader/gtktetris

decompiled_code:
__int64 get_config_dir_file()
{
int v0; // er13
char *v1; // rbp
__int64 result; // rax
char *v3; // rdi
__int64 v4; // [rsp+8h] [rbp-20h]

v0 = 0;
v1 = getenv("XDG_CONFIG_HOME");
if ( !v1 )
{
v3 = getenv("HOME");
if ( !v3 )
v3 = (char *)g_get_home_dir();
v0 = 1;
v1 = (char *)g_strconcat(v3, "/.config", 0LL);
}
result = g_strconcat(v1, "/", "games");
if ( v0 )
{
v4 = result;
free(v1);
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 func0()
{
int v0; // er13
char *v1; // rbp
__int64 result; // rax
char *v3; // rdi
__int64 v4; // [rsp+8h] [rbp-20h]

v0 = 0;
v1 = getenv("XDG_CONFIG_HOME");
if ( !v1 )
{
v3 = getenv("HOME");
if ( !v3 )
v3 = (char *)g_get_home_dir();
v0 = 1;
v1 = (char *)g_strconcat(v3, "/.config", 0LL);
}
result = g_strconcat(v1, "/", "games");
if ( v0 )
{
v4 = result;
free(v1);
result = v4;
}
return result;
}

original_code:
char * get_config_dir_file (const char * file)
{
    char * config_home = ((void *)0);
    char * res = ((void *)0);
    int freestr = 0;
    const char * HOME = ((void *)0);
    config_home = getenv ("XDG_CONFIG_HOME");
    if (!config_home) {
        HOME = getenv ("HOME");
        if (!HOME) {
            HOME = g_get_home_dir ();
        }
        config_home = g_strconcat (HOME, "/.config", ((void *)0));
        freestr = 1;
    }
    if (file) {
        res = g_strconcat (config_home, "/", "games",
                           "/", file, ((void *)0));
    } else {
        res = g_strconcat (config_home, "/", "games", ((void *)0));
    }
    if (freestr) {
        free (config_home);
    }
    return (res);
}

canonical_original_code:
char *get_config_dir_file(char *file)
{
    char *config_home = ((void *)0);
    char *res = ((void *)0);
    int freestr = 0;
    char *HOME = ((void *)0);
    config_home = getenv ("XDG_CONFIG_HOME");
    if (!config_home) {
        HOME = getenv ("HOME");
        if (!HOME) {
            HOME = g_get_home_dir ();
        }
        config_home = g_strconcat (HOME, "/.config", ((void *)0));
        freestr = 1;
    }
    if (file) {
        res = g_strconcat (config_home, "/", "games",
                           "/", file, ((void *)0));
    } else {
        res = g_strconcat (config_home, "/", "games", ((void *)0));
    }
    if (freestr) {
        free (config_home);
    }
    return (res);
}

variable_types:
file
char *

variable_types:
res
char *

variable_types: freestr int

variable_types:
HOME
char *

return_type: char *


decompiled_code:
__int64 ensure_config_dir_exists()
{
__int64 v0; // rax
const char *v1; // rbp
_BYTE *v2; // rbx
char i; // al
const char *v5; // rax

v0 = get_config_dir_file("dummy.file");
if ( !v0 )
ensure_config_dir_exists_cold();
v1 = (const char *)v0;
v2 = (_BYTE *)(v0 + 1);
for ( i = *(_BYTE *)(v0 + 1); i; ++v2 )
{
while ( i != 47 )
{
i = *++v2;
if ( !i )
return g_free(v1);
}
*v2 = 0;
if ( access(v1, 0) && mkdir(v1, 0x1FDu) == -1 )
{
v5 = (const char *)g_get_prgname();
fprintf(stderr, "%s: Unable to create %s\n", v5, v1);
}
*v2 = 47;
i = v2[1];
}
return g_free(v1);
}

canonical_decompiled_code:
__int64 func1()
{
__int64 v0; // rax
const char *v1; // rbp
_BYTE *v2; // rbx
char i; // al
const char *v5; // rax

v0 = func0("dummy.file");
if ( !v0 )
func4();
v1 = (const char *)v0;
v2 = (_BYTE *)(v0 + 1);
for ( i = *(_BYTE *)(v0 + 1); i; ++v2 )
{
while ( i != 47 )
{
i = *++v2;
if ( !i )
return g_free(v1);
}
*v2 = 0;
if ( access(v1, 0) && mkdir(v1, 0x1FDu) == -1 )
{
v5 = (const char *)g_get_prgname();
fprintf(stderr, "%s: Unable to create %s\n", v5, v1);
}
*v2 = 47;
i = v2[1];
}
return g_free(v1);
}

variable_types:
str
char *

variable_types:
p
char *

return_type: void


decompiled_code:
__int64 gtktetris_activate()
{
ensure_config_dir_exists();
options_defaults();
options_read();
return create_main_window();
}

canonical_decompiled_code:
__int64 func2()
{
func1();
options_defaults();
options_read();
return create_main_window();
}

original_code:
static void gtktetris_activate (void)
{
    ensure_config_dir_exists ();
    options_defaults ();
    options_read ();
    create_main_window ();
}

canonical_original_code:
static void gtktetris_activate()
{
    ensure_config_dir_exists ();
    options_defaults ();
    options_read ();
    create_main_window ();
}


decompiled_code:
__int64 gtktetris_exit()
{
free_tetris_blocks();
return gtk_main_quit();
}

canonical_decompiled_code:
__int64 func3()
{
free_tetris_blocks();
return gtk_main_quit();
}

original_code:
void gtktetris_exit (void)
{
    free_tetris_blocks ();
    gtk_main_quit();
}

canonical_original_code:
void gtktetris_exit()
{
    free_tetris_blocks ();
    gtk_main_quit();
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = argc;
v4 = argv;
gtk_init(v5, &v4, envp);
gtktetris_activate();
gtk_main();
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v4; // [rsp+0h] [rbp-18h] BYREF
int v5[3]; // [rsp+Ch] [rbp-Ch] BYREF

v5[0] = argc;
v4 = argv;
gtk_init(v5, &v4, envp);
func2();
gtk_main();
return 0;
}

original_code:
int main (int argc, char *argv[])
{
    int status = 0;
    gtk_init (&argc,&argv);
    gtktetris_activate ();
    gtk_main ();
    return status;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int status = 0;
    gtk_init (&argc,&argv);
    gtktetris_activate ();
    gtk_main ();
    return status;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: status int


original_code:
int addto_highscore (char *name, long score, int level, int lines)
{
    int place = 0;
    int temp, namelen;
    int added = (0);
    for (temp=10 -1; temp > -1; temp--)
    {
        if (score > highscore[temp].score || (highscore[temp].score == 0 && strlen(highscore[temp].name) == 0))
        {
            place = temp;
            added = (!(0));
        }
    }
    if (added)
    {
        for(temp=10 -1; temp > place; temp--) {
            memcpy (&highscore[temp], &highscore[temp-1], sizeof(highscore[0]));
        }
        namelen = strlen (name);
        if (namelen > 9) {
            namelen = 9;
        }
        memset (&highscore[place].name, 0, sizeof(highscore[0].name));
        memcpy (&highscore[place].name, name,namelen);
        highscore[place].score = score;
        highscore[place].level = level;
        highscore[place].lines = lines;
    }
    return (place+1);
}

canonical_original_code:
int addto_highscore(char *name, long score, int level, int lines)
{
    int place = 0;
    int temp; int namelen;
    int added = (0);
    for (temp=10 -1; temp > -1; temp--)
    {
        if (score > highscore[temp].score || (highscore[temp].score == 0 && strlen(highscore[temp].name) == 0))
        {
            place = temp;
            added = (!(0));
        }
    }
    if (added)
    {
        for(temp=10 -1; temp > place; temp--) {
            memcpy (&highscore[temp], &highscore[temp-1], sizeof(highscore[0]));
        }
        namelen = strlen (name);
        if (namelen > 9) {
            namelen = 9;
        }
        memset (&highscore[place].name, 0, sizeof(highscore[0].name));
        memcpy (&highscore[place].name, name,namelen);
        highscore[place].score = score;
        highscore[place].level = level;
        highscore[place].lines = lines;
    }
    return (place+1);
}

variable_types:
name
char *

variable_types: score long

variable_types: level int

variable_types: lines int

variable_types: place int

variable_types: temp int

variable_types: namelen int

variable_types: added int


decompiled_code:
__int64 get_hiscore()
{
return highscore[2];
}

canonical_decompiled_code:
__int64 func4()
{
return highscore[2];
}

original_code:
long get_hiscore(void)
{
    return (highscore[0].score);
}

canonical_original_code:
long get_hiscore()
{
    return (highscore[0].score);
}

return_type: long


decompiled_code:
__int64 __fastcall draw_block(int a1, int a2, int a3, int a4, int a5, unsigned int a6)
{
unsigned int v8; // ebp
unsigned __int64 v9; // rbx
unsigned __int64 v10; // r15
int v11; // esi
__int64 result; // rax

v8 = a3 + 1;
if ( a5 )
v8 = 0;
v9 = 32 * (a4 + 4LL * a3);
v10 = v9 + 16;
do
{
v11 = block_data[v9 / 4 + 4];
v9 += 4LL;
result = set_block((unsigned int)(a1 + block_data[v9 / 4 - 1]), (unsigned int)(a2 + v11), v8, a6);
}
while ( v9 != v10 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2, int a3, int a4, int a5, unsigned int a6)
{
unsigned int v8; // ebp
unsigned __int64 v9; // rbx
unsigned __int64 v10; // r15
int v11; // esi
__int64 result; // rax

v8 = a3 + 1;
if ( a5 )
v8 = 0;
v9 = 32 * (a4 + 4LL * a3);
v10 = v9 + 16;
do
{
v11 = block_data[v9 / 4 + 4];
v9 += 4LL;
result = set_block((unsigned int)(a1 + block_data[v9 / 4 - 1]), (unsigned int)(a2 + v11), v8, a6);
}
while ( v9 != v10 );
return result;
}

original_code:
void draw_block(int x,int y,int block,int frame,int clear,int next)
{
    int temp;
    for (temp=0;temp < 4;temp++)
        set_block (x+block_data[block][frame][0][temp],
                   y+block_data[block][frame][1][temp],
                   (clear ? 0 : block+1),
                   next);
}

canonical_original_code:
void draw_block(int x, int y, int block, int frame, int clear, int next)
{
    int temp;
    for (temp=0;temp < 4;temp++)
        set_block (x+block_data[block][frame][0][temp],
                   y+block_data[block][frame][1][temp],
                   (clear ? 0 : block+1),
                   next);
}

variable_types: x int

variable_types: y int

variable_types: block int

variable_types: frame int

variable_types: clear int

variable_types: next int


decompiled_code:
unsigned __int64 to_virtual()
{
int v0; // er9
int v1; // er8
int v2; // edi
unsigned __int64 result; // rax
unsigned __int64 v4; // rsi
int v5; // edx
int v6; // ecx

v0 = current_y;
v1 = current_x;
v2 = current_block + 1;
result = 32 * (current_frame + 4LL * current_block);
v4 = result + 16;
do
{
v5 = block_data[result / 4 + 4];
v6 = block_data[result / 4];
result += 4LL;
*((_DWORD *)&virtual + 10 * v0 + 10 * v5 + v1 + v6) = v2;
}
while ( result != v4 );
return result;
}

canonical_decompiled_code:
unsigned __int64 func1()
{
int v0; // er9
int v1; // er8
int v2; // edi
unsigned __int64 result; // rax
unsigned __int64 v4; // rsi
int v5; // edx
int v6; // ecx

v0 = current_y;
v1 = current_x;
v2 = current_block + 1;
result = 32 * (current_frame + 4LL * current_block);
v4 = result + 16;
do
{
v5 = block_data[result / 4 + 4];
v6 = block_data[result / 4];
result += 4LL;
*((_DWORD *)&virtual + 10 * v0 + 10 * v5 + v1 + v6) = v2;
}
while ( result != v4 );
return result;
}

original_code:
void to_virtual()
{
    int temp;
    for (temp=0;temp < 4;temp++)
        virtual[current_y+block_data[current_block][current_frame][1][temp]]
            [current_x+block_data[current_block][current_frame][0][temp]] = current_block+1;
}


decompiled_code:
__int64 from_virtual()
{
__int64 v0; // r12
unsigned int i; // ebp
__int64 j; // rbx
__int64 v3; // rdx
__int64 v4; // rdi
__int64 result; // rax

v0 = 0LL;
for ( i = 0; i != 18; ++i )
{
for ( j = 0LL; j != 10; ++j )
{
v3 = *(unsigned int *)((char *)&virtual + 4 * j + v0);
v4 = (unsigned int)j;
result = set_block(v4, i, v3, 0LL);
}
v0 += 40LL;
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // r12
unsigned int i; // ebp
__int64 j; // rbx
__int64 v3; // rdx
__int64 v4; // rdi
__int64 result; // rax

v0 = 0LL;
for ( i = 0; i != 18; ++i )
{
for ( j = 0LL; j != 10; ++j )
{
v3 = *(unsigned int *)((char *)&virtual + 4 * j + v0);
v4 = (unsigned int)j;
result = set_block(v4, i, v3, 0LL);
}
v0 += 40LL;
}
return result;
}

original_code:
void from_virtual()
{
    int temp_x,temp_y;
    for (temp_y=0;temp_y < 18;temp_y++)
        for (temp_x=0;temp_x < 10;temp_x++)
            set_block(temp_x,temp_y,virtual[temp_y][temp_x],(0));
}

canonical_original_code:
void from_virtual()
{
    int temp_x; int temp_y;
    for (temp_y=0;temp_y < 18;temp_y++)
        for (temp_x=0;temp_x < 10;temp_x++)
            set_block(temp_x,temp_y,virtual[temp_y][temp_x],(0));
}


decompiled_code:
__int64 __fastcall valid_position(int a1, int a2, int a3, int a4)
{
unsigned __int64 v6; // rax
unsigned __int64 v7; // r10
unsigned int v8; // esi

v6 = 32 * (a4 + 4LL * a3);
v7 = v6 + 16;
while ( 1 )
{
v8 = a2 + block_data[v6 / 4 + 4];
if ( (unsigned int)(a1 + block_data[v6 / 4]) > 9
|| *((_DWORD *)&virtual + 10 * (int)v8 + a1 + block_data[v6 / 4]) != 0
|| v8 > 0x11 )
{
break;
}
v6 += 4LL;
if ( v7 == v6 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2, int a3, int a4)
{
unsigned __int64 v6; // rax
unsigned __int64 v7; // r10
unsigned int v8; // esi

v6 = 32 * (a4 + 4LL * a3);
v7 = v6 + 16;
while ( 1 )
{
v8 = a2 + block_data[v6 / 4 + 4];
if ( (unsigned int)(a1 + block_data[v6 / 4]) > 9
|| *((_DWORD *)&virtual + 10 * (int)v8 + a1 + block_data[v6 / 4]) != 0
|| v8 > 0x11 )
{
break;
}
v6 += 4LL;
if ( v7 == v6 )
return 1LL;
}
return 0LL;
}

original_code:
int valid_position(int x,int y,int block,int frame)
{
    int temp;
    for (temp=0;temp < 4;temp++) {
        if (virtual[y+block_data[block][frame][1][temp]][x+block_data[block][frame][0][temp]] != 0 ||
            x+block_data[block][frame][0][temp] < 0 ||
            x+block_data[block][frame][0][temp] > 10 -1 ||
            y+block_data[block][frame][1][temp] < 0 ||
            y+block_data[block][frame][1][temp] > 18 -1)
        {
            return (0);
        }
    }
    return (!(0));
}

canonical_original_code:
int valid_position(int x, int y, int block, int frame)
{
    int temp;
    for (temp=0;temp < 4;temp++) {
        if (virtual[y+block_data[block][frame][1][temp]][x+block_data[block][frame][0][temp]] != 0 ||
            x+block_data[block][frame][0][temp] < 0 ||
            x+block_data[block][frame][0][temp] > 10 -1 ||
            y+block_data[block][frame][1][temp] < 0 ||
            y+block_data[block][frame][1][temp] > 18 -1)
        {
            return (0);
        }
    }
    return (!(0));
}


decompiled_code:
__int64 __fastcall move_block(int a1, int a2, int a3)
{
int v3; // ecx
int v4; // er12
int v5; // er14
int v6; // er13
__int64 result; // rax
int v8; // er11

v3 = current_frame;
v4 = current_block;
if ( a3 )
{
current_frame = (block_frames[current_block] + current_frame + a3) % block_frames[current_block];
v3 = current_frame;
}
v5 = current_y;
v6 = current_x;
result = valid_position(current_x + a1, current_y + a2, current_block, v3);
if ( (_DWORD)result )
{
draw_block(v6, v5, v4, v8, 1, 0);
current_x += a1;
current_y += a2;
result = draw_block(current_x, current_y, current_block, current_frame, 0, 0);
}
else
{
current_frame = v8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, int a3)
{
int v3; // ecx
int v4; // er12
int v5; // er14
int v6; // er13
__int64 result; // rax
int v8; // er11

v3 = current_frame;
v4 = current_block;
if ( a3 )
{
current_frame = (block_frames[current_block] + current_frame + a3) % block_frames[current_block];
v3 = current_frame;
}
v5 = current_y;
v6 = current_x;
result = func3(current_x + a1, current_y + a2, current_block, v3);
if ( (_DWORD)result )
{
func0(v6, v5, v4, v8, 1, 0);
current_x += a1;
current_y += a2;
result = func0(current_x, current_y, current_block, current_frame, 0, 0);
}
else
{
current_frame = v8;
}
return result;
}

original_code:
void move_block(int x,int y,int f)
{
    int last_frame = current_frame;
    int last_block = current_block;
    if (f != 0)
        current_frame = (block_frames[current_block]+(current_frame+f))%block_frames[current_block];
    if (valid_position(current_x+x,current_y+y,current_block,current_frame))
    {
        draw_block(current_x,current_y,last_block,last_frame,(!(0)),(0));
        current_x += x;
        current_y += y;
        draw_block(current_x,current_y,current_block,current_frame,(0),(0));
    }
    else
    {
        current_block = last_block;
        current_frame = last_frame;
    }
}

canonical_original_code:
void move_block(int x, int y, int f)
{
    int last_frame = current_frame;
    int last_block = current_block;
    if (f != 0)
        current_frame = (block_frames[current_block]+(current_frame+f))%block_frames[current_block];
    if (valid_position(current_x+x,current_y+y,current_block,current_frame))
    {
        draw_block(current_x,current_y,last_block,last_frame,(!(0)),(0));
        current_x += x;
        current_y += y;
        draw_block(current_x,current_y,current_block,current_frame,(0),(0));
    }
    else
    {
        current_block = last_block;
        current_frame = last_frame;
    }
}

variable_types: f int


original_code:
int check_lines()
{
    int temp_x,temp_y,temp,line,lines=0;
    for (temp_y=0;temp_y < 18;temp_y++)
    {
        line = (!(0));
        for (temp_x=0;temp_x < 10;temp_x++)
            if (virtual[temp_y][temp_x] == 0)
                line = (0);
        if (line)
        {
            lines++;
            for (temp=temp_y;temp > 0;temp--) {
                memcpy(virtual[temp],virtual[temp-1],sizeof(virtual[0]));
            }
            memset(virtual[0],0,sizeof(virtual[0]));
            usleep(50000);
            from_virtual();
        }
    }
    return lines;
}

canonical_original_code:
int check_lines()
{
    int temp_x; int temp_y; int temp; int line; int lines = 0;
    for (temp_y=0;temp_y < 18;temp_y++)
    {
        line = (!(0));
        for (temp_x=0;temp_x < 10;temp_x++)
            if (virtual[temp_y][temp_x] == 0)
                line = (0);
        if (line)
        {
            lines++;
            for (temp=temp_y;temp > 0;temp--) {
                memcpy(virtual[temp],virtual[temp-1],sizeof(virtual[0]));
            }
            memset(virtual[0],0,sizeof(virtual[0]));
            usleep(50000);
            from_virtual();
        }
    }
    return lines;
}

variable_types: line int


decompiled_code:
__int64 new_block()
{
int v0; // eax
int v1; // er12
int v2; // er11
int v3; // er11
__int64 result; // rax
float v5; // [rsp+0h] [rbp-Ch]
float v6; // [rsp+0h] [rbp-Ch]

current_block = next_block;
current_frame = next_frame;
v5 = (float)blocks;
next_block = (int)(float)((float)((float)(int)random() * 4.6566129e-10) * v5);
v6 = (float)block_frames[next_block];
v0 = random();
v1 = current_frame;
current_x = 4;
current_y = 0;
next_frame = (int)(float)((float)((float)v0 * 4.6566129e-10) * v6);
if ( !(unsigned int)valid_position(4, 0, current_block, current_frame) )
return game_over_init();
if ( (unsigned int)valid_position(4, -2, v2, v1) )
{
current_y = -2;
goto LABEL_4;
}
if ( !(unsigned int)valid_position(4, -1, v3, v1) )
{
LABEL_4:
result = (unsigned int)options[3];
if ( !(_DWORD)result )
return result;
LABEL_8:
draw_block(0, 0, v3, v1, 1, 1u);
return draw_block(0, 0, next_block, next_frame, 0, 1u);
}
current_y = -1;
result = (unsigned int)options[3];
if ( (_DWORD)result )
goto LABEL_8;
return result;
}

canonical_decompiled_code:
__int64 func6()
{
int v0; // eax
int v1; // er12
int v2; // er11
int v3; // er11
__int64 result; // rax
float v5; // [rsp+0h] [rbp-Ch]
float v6; // [rsp+0h] [rbp-Ch]

current_block = next_block;
current_frame = next_frame;
v5 = (float)blocks;
next_block = (int)(float)((float)((float)(int)random() * 4.6566129e-10) * v5);
v6 = (float)block_frames[next_block];
v0 = random();
v1 = current_frame;
current_x = 4;
current_y = 0;
next_frame = (int)(float)((float)((float)v0 * 4.6566129e-10) * v6);
if ( !(unsigned int)func3(4, 0, current_block, current_frame) )
return game_over_init();
if ( (unsigned int)func3(4, -2, v2, v1) )
{
current_y = -2;
goto LABEL_4;
}
if ( !(unsigned int)func3(4, -1, v3, v1) )
{
LABEL_4:
result = (unsigned int)options[3];
if ( !(_DWORD)result )
return result;
LABEL_8:
func0(0, 0, v3, v1, 1, 1u);
return func0(0, 0, next_block, next_frame, 0, 1u);
}
current_y = -1;
result = (unsigned int)options[3];
if ( (_DWORD)result )
goto LABEL_8;
return result;
}

original_code:
void new_block()
{
    current_block = next_block;
    current_frame = next_frame;
    next_block = ( (int) ((blocks) * ((float)random() / 2147483647)) );
    next_frame = ( (int) ((block_frames[next_block]) * ((float)random() / 2147483647)) );
    current_x = (int)(10/2)-1;
    current_y = 0;
    if (!valid_position(current_x,current_y,current_block,current_frame))
    {
        game_over_init();
        return;
    }
    if (valid_position(current_x,current_y-2,current_block,current_frame)) {
        current_y-=2;
    } else if (valid_position(current_x,current_y-1,current_block,current_frame)) {
        current_y-=1;
    }
    if (options.show_next_block)
    {
        draw_block(0,0,current_block,current_frame,(!(0)),(!(0)));
        draw_block(0,0,next_block,next_frame,(0),(!(0)));
    }
}


decompiled_code:
__int64 move_down()
{
__int64 v0; // rdi
__int64 v1; // rsi
int v2; // ebx
__int64 result; // rax
int v4; // eax
int v5; // eax

v0 = (unsigned int)current_x;
v1 = (unsigned int)(current_y + 1);
if ( (unsigned int)valid_position(current_x, v1, current_block, current_frame) )
{
move_block(0, 1, 0);
result = 1LL;
}
else
{
to_virtual();
v2 = check_lines();
if ( v2 > 0 )
{
from_virtual(v0, v1);
current_lines += v2;
v4 = current_level;
if ( current_lines / 10 > current_level )
{
current_level = current_lines / 10;
v4 = current_lines / 10;
}
if ( v4 > 19 )
{
current_level = 19;
v5 = 20;
}
else
{
v5 = v4 + 1;
}
current_score += lines_score[v2 - 1] * v5;
update_game_values();
}
new_block();
move_block(0, 0, 0);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rdi
__int64 v1; // rsi
int v2; // ebx
__int64 result; // rax
int v4; // eax
int v5; // eax

v0 = (unsigned int)current_x;
v1 = (unsigned int)(current_y + 1);
if ( (unsigned int)func3(current_x, v1, current_block, current_frame) )
{
func4(0, 1, 0);
result = 1LL;
}
else
{
func1();
v2 = func5();
if ( v2 > 0 )
{
func2(v0, v1);
current_lines += v2;
v4 = current_level;
if ( current_lines / 10 > current_level )
{
current_level = current_lines / 10;
v4 = current_lines / 10;
}
if ( v4 > 19 )
{
current_level = 19;
v5 = 20;
}
else
{
v5 = v4 + 1;
}
current_score += lines_score[v2 - 1] * v5;
update_game_values();
}
func6();
func4(0, 0, 0);
result = 0LL;
}
return result;
}

original_code:
int move_down()
{
    int lines;
    if (!valid_position(current_x,current_y+1,current_block,current_frame))
    {
        to_virtual();
        lines = check_lines();
        if (lines > 0)
        {
            from_virtual();
            current_lines += lines;
            if ((int)current_lines/10 > current_level)
                current_level = (int)current_lines/10;
            if (current_level > 19)
                current_level = 19;
            current_score += lines_score[lines-1]*(current_level+1);
            update_game_values();
        }
        new_block();
        move_block(0,0,0);
        return (0);
    }
    else
    {
        move_block(0,1,0);
        return (!(0));
    }
}


original_code:
void make_noise(int level,int height)
{
    int x,y;
    if (!level || !height) {
        return;
    }
    for (y=18 -height;y<18;y++)
    {
        for (x=0;x<10;x++)
            virtual[y][x] = ( (int) ((blocks) * ((float)random() / 2147483647)) )+1;
        for (x=0;x<10 -level;x++)
            virtual[y][( (int) ((10) * ((float)random() / 2147483647)) )] = 0;
    }
}

canonical_original_code:
void make_noise(int level, int height)
{
    int x; int y;
    if (!level || !height) {
        return;
    }
    for (y=18 -height;y<18;y++)
    {
        for (x=0;x<10;x++)
            virtual[y][x] = ( (int) ((blocks) * ((float)random() / 2147483647)) )+1;
        for (x=0;x<10 -level;x++)
            virtual[y][( (int) ((10) * ((float)random() / 2147483647)) )] = 0;
    }
}

variable_types: height int


decompiled_code:
__int64 game_init()
{
game_over = 0;
current_level = options[0];
memset(&virtual, 0, 0x2D0uLL);
game_pause = 0;
current_score = 0LL;
current_lines = 0;
new_block();
move_block(0, 0, 0);
return update_game_values();
}

canonical_decompiled_code:
__int64 func9()
{
game_over = 0;
current_level = options[0];
memset(&virtual, 0, 0x2D0uLL);
game_pause = 0;
current_score = 0LL;
current_lines = 0;
func6();
func4(0, 0, 0);
return update_game_values();
}

original_code:
void game_init()
{
    game_over = (0);
    game_pause = (0);
    current_score = 0;
    current_level = options.start_level;
    current_lines = 0;
    memset(virtual,0,sizeof(virtual));
    new_block();
    move_block(0,0,0);
    update_game_values();
}


decompiled_code:
__int64 free_tetris_blocks()
{
int *v0; // rbx
__int64 result; // rax

v0 = (int *)&tetris_block;
do
{
if ( *(_QWORD *)v0 )
{
result = cairo_surface_destroy(*(_QWORD *)v0);
*(_QWORD *)v0 = 0LL;
}
v0 += 2;
}
while ( v0 != &block_color_rgb );
return result;
}

canonical_decompiled_code:
__int64 func4()
{
int *v0; // rbx
__int64 result; // rax

v0 = (int *)&tetris_block;
do
{
if ( *(_QWORD *)v0 )
{
result = cairo_surface_destroy(*(_QWORD *)v0);
*(_QWORD *)v0 = 0LL;
}
v0 += 2;
}
while ( v0 != &block_color_rgb );
return result;
}

original_code:
void free_tetris_blocks (void)
{
    int i;
    for (i = 0; i < 8; i++)
    {
        if (tetris_block[i]) {
            cairo_surface_destroy (tetris_block[i]);
            tetris_block[i] = ((void *)0);
        }
    }
}

canonical_original_code:
void free_tetris_blocks()
{
    int i;
    for (i = 0; i < 8; i++)
    {
        if (tetris_block[i]) {
            cairo_surface_destroy (tetris_block[i]);
            tetris_block[i] = ((void *)0);
        }
    }
}

variable_types: i int


usage

repo: waitman/chucky

decompiled_code:
void __noreturn usage()
{
puts("\nusage: chucky [-hbuot]\n");
puts(
"This program reads /var/db/pkg/local.sqlite and compares install timestamp with\n"
"date in $FreeBSD header in the Makefile of the port. If there is no $FreeBSD\n"
"header then it is assumed to be a beta port. \n"
"\n"
" Command line switches: \n"
"\t\t-u\tshow ports with update status only \n"
"\t\t-o\tshow ports with current status only \n"
"\t\t-b\tshow ports with beta status only \n"
"\t\t-t\tshow timestamps (debug, etc)\n"
"\t\t-a\tcreate shar of files (useful with -b). output to stdout\n"
"\t\t-h\thelp \n"
"\n"
"NOTE: shar files are created with absolute path (ie /usr/ports/src/dir)\n"
"so executing them will restore to that path. Multiple shars are concatenated\n"
"by chucky stripping the 'exit' command from the output. (ie there is no 'exit'\n"
"in the shar output. the shar output is to stdout, if you want to save:\n"
"\n"
"# chucky -b -a > save.shar\n"
"\n"
"This will save all the ports marked 'beta' in the save.shar archive,\n"
"in the cwd \n"
"\n");
exit(0);
}

canonical_decompiled_code:
void __noreturn func8()
{
puts("\nusage: chucky [-hbuot]\n");
puts(
"This program reads /var/db/pkg/local.sqlite and compares install timestamp with\n"
"date in $FreeBSD header in the Makefile of the port. If there is no $FreeBSD\n"
"header then it is assumed to be a beta port. \n"
"\n"
" Command line switches: \n"
"\t\t-u\tshow ports with update status only \n"
"\t\t-o\tshow ports with current status only \n"
"\t\t-b\tshow ports with beta status only \n"
"\t\t-t\tshow timestamps (debug, etc)\n"
"\t\t-a\tcreate shar of files (useful with -b). output to stdout\n"
"\t\t-h\thelp \n"
"\n"
"NOTE: shar files are created with absolute path (ie /usr/ports/src/dir)\n"
"so executing them will restore to that path. Multiple shars are concatenated\n"
"by chucky stripping the 'exit' command from the output. (ie there is no 'exit'\n"
"in the shar output. the shar output is to stdout, if you want to save:\n"
"\n"
"# chucky -b -a > save.shar\n"
"\n"
"This will save all the ports marked 'beta' in the save.shar archive,\n"
"in the cwd \n"
"\n");
exit(0);
}

original_code:
void usage(void) {
 printf("\nusage: chucky [-hbuot]\n\n");
 printf("This program reads /var/db/pkg/local.sqlite and compares install timestamp with\ndate in $FreeBSD header in the Makefile of the port. If there is no $FreeBSD\nheader then it is assumed to be a beta port. \n\n Command line switches: \n\t\t-u\tshow ports with update status only \n\t\t-o\tshow ports with current status only \n\t\t-b\tshow ports with beta status only \n\t\t-t\tshow timestamps (debug, etc)\n\t\t-a\tcreate shar of files (useful with -b). output to stdout\n\t\t-h\thelp \n\nNOTE: shar files are created with absolute path (ie /usr/ports/src/dir)\nso executing them will restore to that path. Multiple shars are concatenated\nby chucky stripping the 'exit' command from the output. (ie there is no 'exit'\nin the shar output. the shar output is to stdout, if you want to save:\n\n# chucky -b -a > save.shar\n\nThis will save all the ports marked 'beta' in the save.shar archive,\nin the cwd \n\n\n");
 exit(0);
}

canonical_original_code:
void usage() {
 printf("\nusage: chucky [-hbuot]\n\n");
 printf("This program reads /var/db/pkg/local.sqlite and compares install timestamp with\ndate in $FreeBSD header in the Makefile of the port. If there is no $FreeBSD\nheader then it is assumed to be a beta port. \n\n Command line switches: \n\t\t-u\tshow ports with update status only \n\t\t-o\tshow ports with current status only \n\t\t-b\tshow ports with beta status only \n\t\t-t\tshow timestamps (debug, etc)\n\t\t-a\tcreate shar of files (useful with -b). output to stdout\n\t\t-h\thelp \n\nNOTE: shar files are created with absolute path (ie /usr/ports/src/dir)\nso executing them will restore to that path. Multiple shars are concatenated\nby chucky stripping the 'exit' command from the output. (ie there is no 'exit'\nin the shar output. the shar output is to stdout, if you want to save:\n\n# chucky -b -a > save.shar\n\nThis will save all the ports marked 'beta' in the save.shar archive,\nin the cwd \n\n\n");
 exit(0);
}


repo: wal-rus/song

decompiled_code:
__int64 callback_send_connect_terminate()
{
unsigned int v0; // eax
unsigned int v1; // eax
__int64 v2; // rax

puts("callback_send_connect_terminate");
v0 = vs_get_avatar();
vs_reset_owner(v0);
v1 = vs_get_avatar();
callback_send_node_destroy(0LL, v1);
v2 = vs_get_session();
verse_session_destroy(v2);
return vs_remove_connection();
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
unsigned int v1; // eax
__int64 v2; // rax

puts("callback_send_connect_terminate");
v0 = vs_get_avatar();
vs_reset_owner(v0);
v1 = vs_get_avatar();
callback_send_node_destroy(0LL, v1);
v2 = vs_get_session();
verse_session_destroy(v2);
return vs_remove_connection();
}

original_code:
static void callback_send_connect_terminate(void *user, char *address, char *bye)
{
 printf("callback_send_connect_terminate\n");
 vs_reset_owner(vs_get_avatar());
 callback_send_node_destroy(((void *)0), vs_get_avatar());
 verse_session_destroy(vs_get_session());
 vs_remove_connection();
}

variable_types:
user
void *

variable_types:
address
char *

variable_types:
bye
char *


decompiled_code:
__int64 __fastcall callback_send_connect(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v6; // r12
__int64 v7; // rax

printf("Connecting '%s'\n", a2);
v6 = (unsigned int)vs_node_create(0xFFFFFFFFLL, 0LL);
v7 = verse_send_connect_accept(v6, a4, 0LL);
return vs_add_new_connection(v7, a2, a3, (unsigned int)v6);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2, __int64 a3, __int64 a4)
{
__int64 v6; // r12
__int64 v7; // rax

printf("Connecting '%s'\n", a2);
v6 = (unsigned int)vs_node_create(0xFFFFFFFFLL, 0LL);
v7 = verse_send_connect_accept(v6, a4, 0LL);
return vs_add_new_connection(v7, a2, a3, (unsigned int)v6);
}

original_code:
static void callback_send_connect(void *user, const char *name, const char *pass, const char *address, const uint8 *host_id)
{
 VNodeID avatar;
 VSession *session;
 printf("Connecting '%s'\n", name);
 if(1)
 {
  avatar = vs_node_create(~0, V_NT_OBJECT);
  session = verse_send_connect_accept(avatar, address, ((void *)0));
  vs_add_new_connection(session, name, pass, avatar);
 }
 else
 {
  verse_send_connect_terminate(address, "I'm sorry but you are not welcome here.");
 }
}

canonical_original_code:
static void callback_send_connect(void *user, char *name, char *pass, char *address, unsigned char *host_id)
{
 unsigned int avatar;
 void **session;
 printf("Connecting '%s'\n", name);
 if(1)
 {
  avatar = vs_node_create(~0, V_NT_OBJECT);
  session = verse_send_connect_accept(avatar, address, ((void *)0));
  vs_add_new_connection(session, name, pass, avatar);
 }
 else
 {
  verse_send_connect_terminate(address, "I'm sorry but you are not welcome here.");
 }
}

variable_types:
name
char *

variable_types:
pass
char *

variable_types:
avatar
unsigned int

variable_types:
session
void **


decompiled_code:
char __fastcall callback_send_ping(__int64 a1, __int64 a2, _BYTE *a3)
{
bool v4; // zf
char result; // al

v4 = memcmp(a3, "DESCRIBE", 8uLL) == 0;
result = !v4;
if ( v4 && a3[8] == 32 )
result = vs_master_handle_describe(a2, a3 + 9);
return result;
}

canonical_decompiled_code:
char __fastcall func2(__int64 a1, __int64 a2, _BYTE *a3)
{
bool v4; // zf
char result; // al

v4 = memcmp(a3, "DESCRIBE", 8uLL) == 0;
result = !v4;
if ( v4 && a3[8] == 32 )
result = vs_master_handle_describe(a2, a3 + 9);
return result;
}

original_code:
static void callback_send_ping(void *user, const char *address, const char *message)
{
 if(strncmp(message, "DESCRIBE", 8) == 0 && message[8] == ' ')
  vs_master_handle_describe(address, message + 9);
}

canonical_original_code:
static void callback_send_ping(void *user, char *address, char *message)
{
 if(strncmp(message, "DESCRIBE", 8) == 0 && message[8] == ' ')
  vs_master_handle_describe(address, message + 9);
}

variable_types:
message
char *


decompiled_code:
void __fastcall cb_sigint_handler(int a1)
{
if ( a1 == 2 )
{
puts("Verse server terminating");
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
if ( a1 == 2 )
{
puts("Verse server terminating");
exit(0);
}
}

original_code:
static void cb_sigint_handler(int sig)
{
 if(sig == 2)
 {
  printf("Verse server terminating\n");
  exit(0);
 }
}

variable_types: sig int


decompiled_code:
int usage()
{
const char *v0; // rax

puts("Verse server usage:");
puts(" -h\t\t\tShow this usage information.");
puts(" -ms\t\t\tRegisters the server with a master server at the address");
puts(" \t\t\tgiven with the -ms:ip= option. Off by default.");
puts(" -ms:ip=IP[:PORT]\tSet master server to register with. Implies -ms.");
v0 = (const char *)vs_master_get_address();
printf(" \t\t\tThe default address is <%s>.\n", v0);
puts(" -ms:de=DESC\t\tSet description, sent to master server.");
puts(" -ms:ta=TAGS\t\tSet tags, sent to master server.");
puts(" -port=PORT\t\tSet port to use for incoming connections.");
return puts(" -version\t\tPrint version information and exit.");
}

canonical_decompiled_code:
int func4()
{
const char *v0; // rax

puts("Verse server usage:");
puts(" -h\t\t\tShow this usage information.");
puts(" -ms\t\t\tRegisters the server with a master server at the address");
puts(" \t\t\tgiven with the -ms:ip= option. Off by default.");
puts(" -ms:ip=IP[:PORT]\tSet master server to register with. Implies -ms.");
v0 = (const char *)vs_master_get_address();
printf(" \t\t\tThe default address is <%s>.\n", v0);
puts(" -ms:de=DESC\t\tSet description, sent to master server.");
puts(" -ms:ta=TAGS\t\tSet tags, sent to master server.");
puts(" -port=PORT\t\tSet port to use for incoming connections.");
return puts(" -version\t\tPrint version information and exit.");
}

original_code:
static void usage(void)
{
 printf("Verse server usage:\n");
 printf(" -h\t\t\tShow this usage information.\n");
 printf(" -ms\t\t\tRegisters the server with a master server at the address\n");
 printf(" \t\t\tgiven with the -ms:ip= option. Off by default.\n");
 printf(" -ms:ip=IP[:PORT]\tSet master server to register with. Implies -ms.\n");
 printf(" \t\t\tThe default address is <%s>.\n", vs_master_get_address());
 printf(" -ms:de=DESC\t\tSet description, sent to master server.\n");
 printf(" -ms:ta=TAGS\t\tSet tags, sent to master server.\n");
 printf(" -port=PORT\t\tSet port to use for incoming connections.\n");
 printf(" -version\t\tPrint version information and exit.\n");
}

canonical_original_code:
static void usage()
{
 printf("Verse server usage:\n");
 printf(" -h\t\t\tShow this usage information.\n");
 printf(" -ms\t\t\tRegisters the server with a master server at the address\n");
 printf(" \t\t\tgiven with the -ms:ip= option. Off by default.\n");
 printf(" -ms:ip=IP[:PORT]\tSet master server to register with. Implies -ms.\n");
 printf(" \t\t\tThe default address is <%s>.\n", vs_master_get_address());
 printf(" -ms:de=DESC\t\tSet description, sent to master server.\n");
 printf(" -ms:ta=TAGS\t\tSet tags, sent to master server.\n");
 printf(" -port=PORT\t\tSet port to use for incoming connections.\n");
 printf(" -version\t\tPrint version information and exit.\n");
}


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // rbp
unsigned int v5; // er12
bool v6; // al
bool v7; // cf
bool v8; // zf
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rsi
char v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
const char *v17; // rsi
const char *v18; // rdx
int v20; // [rsp+8h] [rbp-20h] BYREF
int v21[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_sysv_signal(2, cb_sigint_handler);
vs_master_set_address("master.uni-verse.org");
vs_master_set_enabled(0LL);
if ( (unsigned int)argc <= 1 )
{
v5 = 4950;
LABEL_22:
printf("Verse Server r%up%u%s by Eskil Steenberg <http://verse.blender.org/>\n", 6LL, 1LL, (const char *)&unk_640);
verse_set_port((unsigned __int16)v5);
printf(" Listening on port %d\n", v5);
v_n_get_current_time(&v20, v21);
srand(v21[0] ^ v20);
vs_load_host_id_constprop_0();
vs_init_node_storage();
vs_o_callback_init();
vs_g_callback_init();
vs_m_callback_init();
vs_b_callback_init();
vs_t_callback_init();
vs_c_callback_init();
vs_a_callback_init();
vs_h_callback_init();
init_callback_node_storage();
verse_callback_set(&verse_send_ping, callback_send_ping, 0LL);
verse_callback_set(&verse_send_connect, callback_send_connect, 0LL);
verse_callback_set(&verse_send_connect_terminate, callback_send_connect_terminate, 0LL);
while ( 1 )
{
vs_set_next_session();
verse_callback_update(1000000LL);
vs_master_update();
}
}
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
v5 = 4950;
while ( 1 )
{
while ( 1 )
{
v18 = *v3;
if ( **v3 == 45 && v18[1] == 104 && !v18[2] )
{
usage();
return 0;
}
if ( strcmp(*v3, "-ms") )
break;
vs_master_set_enabled(1LL);
LABEL_21:
if ( ++v3 == v4 )
goto LABEL_22;
}
v6 = memcmp(*v3, "-ms:ip=", 7uLL) != 0;
v7 = 0;
v8 = !v6;
if ( !v6 )
{
vs_master_set_address(v18 + 7);
vs_master_set_enabled(1LL);
goto LABEL_21;
}
v9 = "-ms:de=";
v10 = 7LL;
v11 = *v3;
do
{
if ( !v10 )
break;
v7 = *v11 < (unsigned int)*v9;
v8 = *v11++ == *v9++;
--v10;
}
while ( v8 );
v12 = (!v7 && !v8) - v7;
v13 = 0;
v14 = v12 == 0;
if ( !v12 )
{
vs_master_set_desc(v18 + 7, v11);
goto LABEL_15;
}
v15 = "-ms:ta=";
v16 = 7LL;
v17 = *v3;
do
{
if ( !v16 )
break;
v13 = *v17 < (unsigned int)*v15;
v14 = *v17++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
vs_master_set_tags(v18 + 7, v17);
goto LABEL_15;
}
if ( !memcmp(*v3, "-port=", 6uLL) )
{
v5 = strtoul(v18 + 6, 0LL, 0);
goto LABEL_15;
}
if ( !strcmp(*v3, "-version") )
break;
fprintf(stderr, "Ignoring unknown argument \"%s\", try -h for help\n", v18);
LABEL_15:
if ( ++v3 == v4 )
goto LABEL_22;
}
printf("r%up%u%s\n", 6LL, 1LL, (const char *)&unk_640);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char **v3; // rbx
const char **v4; // rbp
unsigned int v5; // er12
bool v6; // al
bool v7; // cf
bool v8; // zf
const char *v9; // rdi
__int64 v10; // rcx
const char *v11; // rsi
char v12; // al
bool v13; // cf
bool v14; // zf
const char *v15; // rdi
__int64 v16; // rcx
const char *v17; // rsi
const char *v18; // rdx
int v20; // [rsp+8h] [rbp-20h] BYREF
int v21[7]; // [rsp+Ch] [rbp-1Ch] BYREF

_sysv_signal(2, cb_sigint_handler);
vs_master_set_address("master.uni-verse.org");
vs_master_set_enabled(0LL);
if ( (unsigned int)argc <= 1 )
{
v5 = 4950;
LABEL_22:
printf("Verse Server r%up%u%s by Eskil Steenberg <http://verse.blender.org/>\n", 6LL, 1LL, (const char *)&unk_640);
verse_set_port((unsigned __int16)v5);
printf(" Listening on port %d\n", v5);
v_n_get_current_time(&v20, v21);
srand(v21[0] ^ v20);
func5();
vs_init_node_storage();
vs_o_callback_init();
vs_g_callback_init();
vs_m_callback_init();
vs_b_callback_init();
vs_t_callback_init();
vs_c_callback_init();
vs_a_callback_init();
vs_h_callback_init();
init_callback_node_storage();
verse_callback_set(&verse_send_ping, callback_send_ping, 0LL);
verse_callback_set(&verse_send_connect, callback_send_connect, 0LL);
verse_callback_set(&verse_send_connect_terminate, callback_send_connect_terminate, 0LL);
while ( 1 )
{
vs_set_next_session();
verse_callback_update(1000000LL);
vs_master_update();
}
}
v3 = argv + 1;
v4 = &argv[(unsigned int)(argc - 2) + 2];
v5 = 4950;
while ( 1 )
{
while ( 1 )
{
v18 = *v3;
if ( **v3 == 45 && v18[1] == 104 && !v18[2] )
{
func4();
return 0;
}
if ( strcmp(*v3, "-ms") )
break;
vs_master_set_enabled(1LL);
LABEL_21:
if ( ++v3 == v4 )
goto LABEL_22;
}
v6 = memcmp(*v3, "-ms:ip=", 7uLL) != 0;
v7 = 0;
v8 = !v6;
if ( !v6 )
{
vs_master_set_address(v18 + 7);
vs_master_set_enabled(1LL);
goto LABEL_21;
}
v9 = "-ms:de=";
v10 = 7LL;
v11 = *v3;
do
{
if ( !v10 )
break;
v7 = *v11 < (unsigned int)*v9;
v8 = *v11++ == *v9++;
--v10;
}
while ( v8 );
v12 = (!v7 && !v8) - v7;
v13 = 0;
v14 = v12 == 0;
if ( !v12 )
{
vs_master_set_desc(v18 + 7, v11);
goto LABEL_15;
}
v15 = "-ms:ta=";
v16 = 7LL;
v17 = *v3;
do
{
if ( !v16 )
break;
v13 = *v17 < (unsigned int)*v15;
v14 = *v17++ == *v15++;
--v16;
}
while ( v14 );
if ( (!v13 && !v14) == v13 )
{
vs_master_set_tags(v18 + 7, v17);
goto LABEL_15;
}
if ( !memcmp(*v3, "-port=", 6uLL) )
{
v5 = strtoul(v18 + 6, 0LL, 0);
goto LABEL_15;
}
if ( !strcmp(*v3, "-version") )
break;
fprintf(stderr, "Ignoring unknown argument \"%s\", try -h for help\n", v18);
LABEL_15:
if ( ++v3 == v4 )
goto LABEL_22;
}
printf("r%up%u%s\n", 6LL, 1LL, (const char *)&unk_640);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 uint32 i, seconds, fractions, port = 4950;
 signal(2, cb_sigint_handler);
 vs_master_set_address("master.uni-verse.org");
 vs_master_set_enabled(0);
 for(i = 1; i < (uint32) argc; i++)
 {
  if(strcmp(argv[i], "-h") == 0)
  {
   usage();
   return 0;
  }
  else if(strcmp(argv[i], "-ms") == 0)
   vs_master_set_enabled(1);
                else if(strncmp(argv[i], "-ms:ip=", 7) == 0)
  {
                        vs_master_set_address(argv[i] + 7);
   vs_master_set_enabled(1);
  }
                else if(strncmp(argv[i], "-ms:de=", 7) == 0)
                        vs_master_set_desc(argv[i] + 7);
                else if(strncmp(argv[i], "-ms:ta=", 7) == 0)
   vs_master_set_tags(argv[i] + 7);
  else if(strncmp(argv[i], "-port=", 6) == 0)
   port = strtoul(argv[i] + 6, ((void *)0), 0);
  else if(strcmp(argv[i], "-version") == 0)
  {
   printf("r%up%u%s\n", 6, 1, "");
   return 0;
  }
  else
   fprintf(stderr, "Ignoring unknown argument \"%s\", try -h for help\n", argv[i]);
 }
 printf("Verse Server r%up%u%s by Eskil Steenberg <http://verse.blender.org/>\n", 6, 1, "");
 verse_set_port(port);
 printf(" Listening on port %d\n", port);
 v_n_get_current_time(&seconds, &fractions);
 srand(seconds ^ fractions);
 vs_load_host_id("host_id.rsa");
 vs_init_node_storage();
 vs_o_callback_init();
 vs_g_callback_init();
 vs_m_callback_init();
 vs_b_callback_init();
 vs_t_callback_init();
 vs_c_callback_init();
 vs_a_callback_init();
 vs_h_callback_init();
 init_callback_node_storage();
 verse_callback_set(verse_send_ping, callback_send_ping, ((void *)0));
 verse_callback_set(verse_send_connect, callback_send_connect, ((void *)0));
 verse_callback_set(verse_send_connect_terminate, callback_send_connect_terminate, ((void *)0));
 while(1)
 {
  vs_set_next_session();
  verse_callback_update(1000000);
  vs_master_update();
 }
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 unsigned int i; unsigned int seconds; unsigned int fractions; unsigned int port = 4950;
 signal(2, cb_sigint_handler);
 vs_master_set_address("master.uni-verse.org");
 vs_master_set_enabled(0);
 for(i = 1; i < (unsigned int) argc; i++)
 {
  if(strcmp(argv[i], "-h") == 0)
  {
   usage();
   return 0;
  }
  else if(strcmp(argv[i], "-ms") == 0)
   vs_master_set_enabled(1);
                else if(strncmp(argv[i], "-ms:ip=", 7) == 0)
  {
                        vs_master_set_address(argv[i] + 7);
   vs_master_set_enabled(1);
  }
                else if(strncmp(argv[i], "-ms:de=", 7) == 0)
                        vs_master_set_desc(argv[i] + 7);
                else if(strncmp(argv[i], "-ms:ta=", 7) == 0)
   vs_master_set_tags(argv[i] + 7);
  else if(strncmp(argv[i], "-port=", 6) == 0)
   port = strtoul(argv[i] + 6, ((void *)0), 0);
  else if(strcmp(argv[i], "-version") == 0)
  {
   printf("r%up%u%s\n", 6, 1, "");
   return 0;
  }
  else
   fprintf(stderr, "Ignoring unknown argument \"%s\", try -h for help\n", argv[i]);
 }
 printf("Verse Server r%up%u%s by Eskil Steenberg <http://verse.blender.org/>\n", 6, 1, "");
 verse_set_port(port);
 printf(" Listening on port %d\n", port);
 v_n_get_current_time(&seconds, &fractions);
 srand(seconds ^ fractions);
 vs_load_host_id("host_id.rsa");
 vs_init_node_storage();
 vs_o_callback_init();
 vs_g_callback_init();
 vs_m_callback_init();
 vs_b_callback_init();
 vs_t_callback_init();
 vs_c_callback_init();
 vs_a_callback_init();
 vs_h_callback_init();
 init_callback_node_storage();
 verse_callback_set(verse_send_ping, callback_send_ping, ((void *)0));
 verse_callback_set(verse_send_connect, callback_send_connect, ((void *)0));
 verse_callback_set(verse_send_connect_terminate, callback_send_connect_terminate, ((void *)0));
 while(1)
 {
  vs_set_next_session();
  verse_callback_update(1000000);
  vs_master_update();
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types:
i
unsigned int

variable_types:
seconds
unsigned int

variable_types:
fractions
unsigned int

variable_types:
port
unsigned int


decompiled_code:
void vs_init_connection_storage()
{
VSConnectionStorage = 0LL;
dword_4E8 = 0;
ptr = 0LL;
qword_4F8 = 0LL;
}

canonical_decompiled_code:
void func0()
{
VSConnectionStorage = 0LL;
dword_4E8 = 0;
ptr = 0LL;
qword_4F8 = 0LL;
}

original_code:
void vs_init_connection_storage(void)
{
 VSConnectionStorage.connection = ((void *)0);
 VSConnectionStorage.connection_length = 0;
 VSConnectionStorage.list = ((void *)0);
 VSConnectionStorage.list_length = 0;
 VSConnectionStorage.current_session = 0;
}

canonical_original_code:
void vs_init_connection_storage()
{
 VSConnectionStorage.connection = ((void *)0);
 VSConnectionStorage.connection_length = 0;
 VSConnectionStorage.list = ((void *)0);
 VSConnectionStorage.list_length = 0;
 VSConnectionStorage.current_session = 0;
}


decompiled_code:
__int64 __fastcall vs_add_new_connection(__int64 a1, __int64 a2, __int64 a3, int a4)
{
char *v6; // rdi
__int64 v8; // rbx
char *v9; // rbx
__int64 result; // rax

v6 = (char *)VSConnectionStorage;
v8 = (unsigned int)dword_4E8;
if ( (dword_4E8 & 0x3F) == 0 )
{
VSConnectionStorage = realloc(VSConnectionStorage, 272LL * (unsigned int)(dword_4E8 + 64));
v6 = (char *)VSConnectionStorage;
}
v9 = &v6[272 * v8];
*(_QWORD *)v9 = a1;
*((_DWORD *)v9 + 2) = a4;
v_strlcpy(v9 + 12, a2, 128LL);
result = v_strlcpy(v9 + 140, a3, 128LL);
++dword_4E8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, int a4)
{
char *v6; // rdi
__int64 v8; // rbx
char *v9; // rbx
__int64 result; // rax

v6 = (char *)VSConnectionStorage;
v8 = (unsigned int)dword_4E8;
if ( (dword_4E8 & 0x3F) == 0 )
{
VSConnectionStorage = realloc(VSConnectionStorage, 272LL * (unsigned int)(dword_4E8 + 64));
v6 = (char *)VSConnectionStorage;
}
v9 = &v6[272 * v8];
*(_QWORD *)v9 = a1;
*((_DWORD *)v9 + 2) = a4;
v_strlcpy(v9 + 12, a2, 128LL);
result = v_strlcpy(v9 + 140, a3, 128LL);
++dword_4E8;
return result;
}

original_code:
void vs_add_new_connection(VSession session, const char *name, const char *pass, VNodeID node_id)
{
 VSConnection *conn;
 if(VSConnectionStorage.connection_length % 64 == 0)
  VSConnectionStorage.connection = realloc(VSConnectionStorage.connection, (sizeof *VSConnectionStorage.connection) * (VSConnectionStorage.connection_length + 64));
 conn = &VSConnectionStorage.connection[VSConnectionStorage.connection_length];
 conn->session = session;
 conn->node_id = node_id;
 v_strlcpy(conn->name, name, sizeof conn->name);
 v_strlcpy(conn->pass, pass, sizeof conn->pass);
 VSConnectionStorage.connection_length++;
}

canonical_original_code:
void vs_add_new_connection(void *session, char *name, char *pass, unsigned int node_id)
{
 struct VSConnection *conn;
 if(VSConnectionStorage.connection_length % 64 == 0)
  VSConnectionStorage.connection = realloc(VSConnectionStorage.connection, (sizeof *VSConnectionStorage.connection) * (VSConnectionStorage.connection_length + 64));
 conn = &VSConnectionStorage.connection[VSConnectionStorage.connection_length];
 conn->session = session;
 conn->node_id = node_id;
 v_strlcpy(conn->name, name, sizeof conn->name);
 v_strlcpy(conn->pass, pass, sizeof conn->pass);
 VSConnectionStorage.connection_length++;
}

variable_types:
session
void *

variable_types: struct VSConnection { void *session; unsigned int node_id; char name[128]; char pass[128]; } *


decompiled_code:
__int64 vs_get_avatar()
{
return *((unsigned int *)VSConnectionStorage + 68 * HIDWORD(qword_4F8) + 2);
}

canonical_decompiled_code:
__int64 func2()
{
return *((unsigned int *)VSConnectionStorage + 68 * HIDWORD(qword_4F8) + 2);
}

original_code:
uint32 vs_get_avatar(void)
{
 return VSConnectionStorage.connection[VSConnectionStorage.current_session].node_id;
}

canonical_original_code:
unsigned int vs_get_avatar()
{
 return VSConnectionStorage.connection[VSConnectionStorage.current_session].node_id;
}

return_type: unsigned int


decompiled_code:
__int64 vs_get_session()
{
return *((_QWORD *)VSConnectionStorage + 34 * HIDWORD(qword_4F8));
}

canonical_decompiled_code:
__int64 func3()
{
return *((_QWORD *)VSConnectionStorage + 34 * HIDWORD(qword_4F8));
}

original_code:
VSession vs_get_session(void)
{
 return VSConnectionStorage.connection[VSConnectionStorage.current_session].session;
}

canonical_original_code:
void *vs_get_session()
{
 return VSConnectionStorage.connection[VSConnectionStorage.current_session].session;
}

return_type: void *


decompiled_code:
char *vs_get_user_name()
{
return (char *)VSConnectionStorage + 272 * HIDWORD(qword_4F8) + 12;
}

canonical_decompiled_code:
char *func4()
{
return (char *)VSConnectionStorage + 272 * HIDWORD(qword_4F8) + 12;
}

original_code:
const char * vs_get_user_name(void)
{
 return VSConnectionStorage.connection[VSConnectionStorage.current_session].name;
}

canonical_original_code:
char *vs_get_user_name()
{
 return VSConnectionStorage.connection[VSConnectionStorage.current_session].name;
}


decompiled_code:
char *vs_get_user_pass()
{
return (char *)VSConnectionStorage + 272 * HIDWORD(qword_4F8) + 140;
}

canonical_decompiled_code:
char *func5()
{
return (char *)VSConnectionStorage + 272 * HIDWORD(qword_4F8) + 140;
}

original_code:
const char * vs_get_user_pass(void)
{
 return VSConnectionStorage.connection[VSConnectionStorage.current_session].pass;
}

canonical_original_code:
char *vs_get_user_pass()
{
 return VSConnectionStorage.connection[VSConnectionStorage.current_session].pass;
}


decompiled_code:
__int64 vs_remove_connection()
{
char *v0; // rbp
unsigned int v1; // er12
char *v2; // rbx
__int64 v3; // rcx
__int64 *v4; // rax
char *v5; // rdi
char *v6; // r11
__int64 v7; // r8
int v8; // edx
__int64 v9; // r10
_QWORD *v10; // rax
__int64 v11; // rdx
__int64 result; // rax
char *v13; // rbp

v0 = (char *)VSConnectionStorage;
v1 = HIDWORD(qword_4F8);
v2 = (char *)VSConnectionStorage + 272 * HIDWORD(qword_4F8);
v3 = *(_QWORD *)v2;
if ( (_DWORD)qword_4F8 )
{
v4 = (__int64 *)ptr;
v5 = (char *)ptr + 8;
v6 = (char *)ptr + 8 * (unsigned int)(qword_4F8 - 1) + 8;
while ( 1 )
{
v7 = *v4;
v8 = *(_DWORD *)(*v4 + 8);
if ( v8 )
{
v9 = (unsigned int)(v8 - 1);
v10 = *(_QWORD **)v7;
while ( *v10 != v3 )
{
if ( ++v10 == (_QWORD *)(*(_QWORD *)v7 + 8 * v9 + 8) )
goto LABEL_8;
}
v11 = *(_QWORD *)(*(_QWORD *)v7 + 8 * v9);
*(_DWORD *)(v7 + 8) = v9;
*v10 = v11;
}
LABEL_8:
v4 = (__int64 *)v5;
if ( v6 == v5 )
break;
v5 += 8;
}
}
result = (unsigned int)(dword_4E8 - 1);
dword_4E8 = result;
if ( v1 >= (unsigned int)result )
{
HIDWORD(qword_4F8) = 0;
}
else
{
v13 = &v0[272 * result];
*(_QWORD *)v2 = *(_QWORD *)v13;
result = *((unsigned int *)v13 + 2);
*((_DWORD *)v2 + 2) = result;
}
return result;
}

canonical_decompiled_code:
__int64 func6()
{
char *v0; // rbp
unsigned int v1; // er12
char *v2; // rbx
__int64 v3; // rcx
__int64 *v4; // rax
char *v5; // rdi
char *v6; // r11
__int64 v7; // r8
int v8; // edx
__int64 v9; // r10
_QWORD *v10; // rax
__int64 v11; // rdx
__int64 result; // rax
char *v13; // rbp

v0 = (char *)VSConnectionStorage;
v1 = HIDWORD(qword_4F8);
v2 = (char *)VSConnectionStorage + 272 * HIDWORD(qword_4F8);
v3 = *(_QWORD *)v2;
if ( (_DWORD)qword_4F8 )
{
v4 = (__int64 *)ptr;
v5 = (char *)ptr + 8;
v6 = (char *)ptr + 8 * (unsigned int)(qword_4F8 - 1) + 8;
while ( 1 )
{
v7 = *v4;
v8 = *(_DWORD *)(*v4 + 8);
if ( v8 )
{
v9 = (unsigned int)(v8 - 1);
v10 = *(_QWORD **)v7;
while ( *v10 != v3 )
{
if ( ++v10 == (_QWORD *)(*(_QWORD *)v7 + 8 * v9 + 8) )
goto LABEL_8;
}
v11 = *(_QWORD *)(*(_QWORD *)v7 + 8 * v9);
*(_DWORD *)(v7 + 8) = v9;
*v10 = v11;
}
LABEL_8:
v4 = (__int64 *)v5;
if ( v6 == v5 )
break;
v5 += 8;
}
}
result = (unsigned int)(dword_4E8 - 1);
dword_4E8 = result;
if ( v1 >= (unsigned int)result )
{
HIDWORD(qword_4F8) = 0;
}
else
{
v13 = &v0[272 * result];
*(_QWORD *)v2 = *(_QWORD *)v13;
result = *((unsigned int *)v13 + 2);
*((_DWORD *)v2 + 2) = result;
}
return result;
}

original_code:
void vs_remove_connection(void)
{
 unsigned int i, j;
 VSession *session;
 VSSubscriptionList *list;
 session = VSConnectionStorage.connection[VSConnectionStorage.current_session].session;
 for(i = 0; i < VSConnectionStorage.list_length; i++)
 {
  list = VSConnectionStorage.list[i];
  for(j = 0; j < list->session_count && list->session[j] != session; j++);
  if(j < list->session_count)
   list->session[j] = list->session[--list->session_count];
 }
 j = --VSConnectionStorage.connection_length;
 if(VSConnectionStorage.current_session < j)
 {
  VSConnectionStorage.connection[VSConnectionStorage.current_session].session = VSConnectionStorage.connection[j].session;
  VSConnectionStorage.connection[VSConnectionStorage.current_session].node_id = VSConnectionStorage.connection[j].node_id;
 }
 else
  VSConnectionStorage.current_session = 0;
}

canonical_original_code:
void vs_remove_connection()
{
 unsigned int i; unsigned int j;
 void **session;
 struct VSSubscriptionList *list;
 session = VSConnectionStorage.connection[VSConnectionStorage.current_session].session;
 for(i = 0; i < VSConnectionStorage.list_length; i++)
 {
  list = VSConnectionStorage.list[i];
  for(j = 0; j < list->session_count && list->session[j] != session; j++);
  if(j < list->session_count)
   list->session[j] = list->session[--list->session_count];
 }
 j = --VSConnectionStorage.connection_length;
 if(VSConnectionStorage.current_session < j)
 {
  VSConnectionStorage.connection[VSConnectionStorage.current_session].session = VSConnectionStorage.connection[j].session;
  VSConnectionStorage.connection[VSConnectionStorage.current_session].node_id = VSConnectionStorage.connection[j].node_id;
 }
 else
  VSConnectionStorage.current_session = 0;
}

variable_types:
j
unsigned int

variable_types: struct VSSubscriptionList { void **session; unsigned int session_count; } *


decompiled_code:
__int64 vs_set_next_session()
{
__int64 result; // rax

result = (unsigned int)(HIDWORD(qword_4F8) + 1);
if ( (unsigned int)result >= dword_4E8 )
result = 0LL;
HIDWORD(qword_4F8) = result;
if ( dword_4E8 )
result = verse_session_set(*((_QWORD *)VSConnectionStorage + 34 * (unsigned int)result));
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 result; // rax

result = (unsigned int)(HIDWORD(qword_4F8) + 1);
if ( (unsigned int)result >= dword_4E8 )
result = 0LL;
HIDWORD(qword_4F8) = result;
if ( dword_4E8 )
result = verse_session_set(*((_QWORD *)VSConnectionStorage + 34 * (unsigned int)result));
return result;
}

original_code:
void vs_set_next_session(void)
{
 if(++VSConnectionStorage.current_session >= VSConnectionStorage.connection_length)
  VSConnectionStorage.current_session = 0;
 if(VSConnectionStorage.connection_length != 0)
  verse_session_set(VSConnectionStorage.connection[VSConnectionStorage.current_session].session);
}

canonical_original_code:
void vs_set_next_session()
{
 if(++VSConnectionStorage.current_session >= VSConnectionStorage.connection_length)
  VSConnectionStorage.current_session = 0;
 if(VSConnectionStorage.connection_length != 0)
  verse_session_set(VSConnectionStorage.connection[VSConnectionStorage.current_session].session);
}


decompiled_code:
_DWORD *vs_create_subscription_list()
{
_DWORD *v0; // rax
int v1; // ebx
_QWORD *v2; // rdi
_DWORD *v3; // r12
_DWORD *result; // rax

v0 = malloc(0x10uLL);
v1 = qword_4F8;
v2 = ptr;
v3 = v0;
if ( (qword_4F8 & 0x3F) == 0 )
{
ptr = realloc(ptr, 8LL * (unsigned int)(qword_4F8 + 64));
v2 = ptr;
}
v2[v1] = v3;
result = v3;
*(_QWORD *)v3 = 0LL;
v3[2] = 0;
LODWORD(qword_4F8) = v1 + 1;
return result;
}

canonical_decompiled_code:
_DWORD *func8()
{
_DWORD *v0; // rax
int v1; // ebx
_QWORD *v2; // rdi
_DWORD *v3; // r12
_DWORD *result; // rax

v0 = malloc(0x10uLL);
v1 = qword_4F8;
v2 = ptr;
v3 = v0;
if ( (qword_4F8 & 0x3F) == 0 )
{
ptr = realloc(ptr, 8LL * (unsigned int)(qword_4F8 + 64));
v2 = ptr;
}
v2[v1] = v3;
result = v3;
*(_QWORD *)v3 = 0LL;
v3[2] = 0;
LODWORD(qword_4F8) = v1 + 1;
return result;
}

original_code:
VSSubscriptionList *vs_create_subscription_list(void)
{
 VSSubscriptionList *list;
 list = malloc(sizeof *list);
 if(VSConnectionStorage.list_length % 64 == 0)
  VSConnectionStorage.list = realloc(VSConnectionStorage.list, (sizeof *VSConnectionStorage.list) * (VSConnectionStorage.list_length + 64));
 VSConnectionStorage.list[VSConnectionStorage.list_length] = list;
 list->session = ((void *)0);
 list->session_count = 0;
 VSConnectionStorage.list_length++;
 return list;
}

canonical_original_code:
struct VSSubscriptionList *vs_create_subscription_list()
{
 struct VSSubscriptionList *list;
 list = malloc(sizeof *list);
 if(VSConnectionStorage.list_length % 64 == 0)
  VSConnectionStorage.list = realloc(VSConnectionStorage.list, (sizeof *VSConnectionStorage.list) * (VSConnectionStorage.list_length + 64));
 VSConnectionStorage.list[VSConnectionStorage.list_length] = list;
 list->session = ((void *)0);
 list->session_count = 0;
 VSConnectionStorage.list_length++;
 return list;
}

return_type: struct VSSubscriptionList { void **session; unsigned int session_count; } *


decompiled_code:
void __fastcall vs_destroy_subscription_list(void *ptr)
{
void *v2; // rdi
__int64 v3; // rdi
void **v4; // rax
void *v5; // rdx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
if ( (_DWORD)qword_4F8 )
{
v3 = (unsigned int)(qword_4F8 - 1);
v4 = (void **)::ptr;
while ( *v4 != ptr )
{
if ( ++v4 == (void **)((char *)::ptr + 8 * v3 + 8) )
goto LABEL_9;
}
v5 = (void *)*((_QWORD *)::ptr + v3);
LODWORD(qword_4F8) = qword_4F8 - 1;
*v4 = v5;
}
LABEL_9:
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func9(void *ptr)
{
void *v2; // rdi
__int64 v3; // rdi
void **v4; // rax
void *v5; // rdx

if ( ptr )
{
v2 = *(void **)ptr;
if ( v2 )
free(v2);
if ( (_DWORD)qword_4F8 )
{
v3 = (unsigned int)(qword_4F8 - 1);
v4 = (void **)::ptr;
while ( *v4 != ptr )
{
if ( ++v4 == (void **)((char *)::ptr + 8 * v3 + 8) )
goto LABEL_9;
}
v5 = (void *)*((_QWORD *)::ptr + v3);
LODWORD(qword_4F8) = qword_4F8 - 1;
*v4 = v5;
}
LABEL_9:
free(ptr);
}
}

original_code:
void vs_destroy_subscription_list(VSSubscriptionList *list)
{
 unsigned int i;
 if(list == ((void *)0))
  return;
 if(list->session != ((void *)0))
  free(list->session);
 for(i = 0; i < VSConnectionStorage.list_length && VSConnectionStorage.list[i] != list; i++)
  ;
 if(i < VSConnectionStorage.list_length)
  VSConnectionStorage.list[i] = VSConnectionStorage.list[--VSConnectionStorage.list_length];
 free(list);
}

canonical_original_code:
void vs_destroy_subscription_list(struct VSSubscriptionList *list)
{
 unsigned int i;
 if(list == ((void *)0))
  return;
 if(list->session != ((void *)0))
  free(list->session);
 for(i = 0; i < VSConnectionStorage.list_length && VSConnectionStorage.list[i] != list; i++)
  ;
 if(i < VSConnectionStorage.list_length)
  VSConnectionStorage.list[i] = VSConnectionStorage.list[--VSConnectionStorage.list_length];
 free(list);
}

user_defined_types: struct VSSubscriptionList { void **session; unsigned int session_count; }


decompiled_code:
__int64 __fastcall vs_add_new_subscriptor(__int64 a1)
{
unsigned int v1; // esi
_QWORD *v3; // rdi
__int64 v4; // rdx
_QWORD *v5; // rax
__int64 result; // rax
__int64 v7; // rax
int v8; // esi
_QWORD *v9; // rax
__int64 v10; // rdx

v1 = *(_DWORD *)(a1 + 8);
v3 = *(_QWORD **)a1;
if ( (v1 & 0x3F) != 0 )
{
v4 = *((_QWORD *)VSConnectionStorage + 34 * HIDWORD(qword_4F8));
}
else
{
v9 = realloc(v3, 8LL * (v1 + 64));
v10 = HIDWORD(qword_4F8);
v1 = *(_DWORD *)(a1 + 8);
*(_QWORD *)a1 = v9;
v3 = v9;
v4 = *((_QWORD *)VSConnectionStorage + 34 * v10);
if ( !v1 )
{
v8 = 1;
goto LABEL_8;
}
}
v5 = v3;
do
{
if ( *v5 == v4 )
return 0LL;
++v5;
}
while ( v5 != &v3[v1] );
v7 = v1;
v8 = v1 + 1;
v3 += v7;
LABEL_8:
*v3 = v4;
result = 1LL;
*(_DWORD *)(a1 + 8) = v8;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
unsigned int v1; // esi
_QWORD *v3; // rdi
__int64 v4; // rdx
_QWORD *v5; // rax
__int64 result; // rax
__int64 v7; // rax
int v8; // esi
_QWORD *v9; // rax
__int64 v10; // rdx

v1 = *(_DWORD *)(a1 + 8);
v3 = *(_QWORD **)a1;
if ( (v1 & 0x3F) != 0 )
{
v4 = *((_QWORD *)VSConnectionStorage + 34 * HIDWORD(qword_4F8));
}
else
{
v9 = realloc(v3, 8LL * (v1 + 64));
v10 = HIDWORD(qword_4F8);
v1 = *(_DWORD *)(a1 + 8);
*(_QWORD *)a1 = v9;
v3 = v9;
v4 = *((_QWORD *)VSConnectionStorage + 34 * v10);
if ( !v1 )
{
v8 = 1;
goto LABEL_8;
}
}
v5 = v3;
do
{
if ( *v5 == v4 )
return 0LL;
++v5;
}
while ( v5 != &v3[v1] );
v7 = v1;
v8 = v1 + 1;
v3 += v7;
LABEL_8:
*v3 = v4;
result = 1LL;
*(_DWORD *)(a1 + 8) = v8;
return result;
}

original_code:
int vs_add_new_subscriptor(VSSubscriptionList *list)
{
 unsigned int i;
 if(list->session_count % 64 == 0)
  list->session = realloc(list->session, (sizeof *list->session) * (list->session_count + 64));
 for(i = 0; i < list->session_count; i++)
  if(list->session[i] == VSConnectionStorage.connection[VSConnectionStorage.current_session].session)
   return 0;
 list->session[list->session_count] = VSConnectionStorage.connection[VSConnectionStorage.current_session].session;
 list->session_count++;
 return 1;
}

canonical_original_code:
int vs_add_new_subscriptor(struct VSSubscriptionList *list)
{
 unsigned int i;
 if(list->session_count % 64 == 0)
  list->session = realloc(list->session, (sizeof *list->session) * (list->session_count + 64));
 for(i = 0; i < list->session_count; i++)
  if(list->session[i] == VSConnectionStorage.connection[VSConnectionStorage.current_session].session)
   return 0;
 list->session[list->session_count] = VSConnectionStorage.connection[VSConnectionStorage.current_session].session;
 list->session_count++;
 return 1;
}


decompiled_code:
__int64 __fastcall vs_get_subscript_count(__int64 a1)
{
__int64 result; // rax

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 8);
return result;
}

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

result = 0LL;
if ( a1 )
result = *(unsigned int *)(a1 + 8);
return result;
}

original_code:
size_t vs_get_subscript_count(const VSSubscriptionList *list)
{
 return list != ((void *)0) ? list->session_count : 0;
}

canonical_original_code:
unsigned long vs_get_subscript_count(struct VSSubscriptionList *list)
{
 return list != ((void *)0) ? list->session_count : 0;
}

return_type: unsigned long


decompiled_code:
__int64 __fastcall vs_set_subscript_session(_QWORD *a1, unsigned int a2)
{
return verse_session_set(*(_QWORD *)(*a1 + 8LL * a2));
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1, unsigned int a2)
{
return verse_session_set(*(_QWORD *)(*a1 + 8LL * a2));
}

original_code:
void vs_set_subscript_session(VSSubscriptionList *list, unsigned int session)
{
 verse_session_set(list->session[session]);
}

canonical_original_code:
void vs_set_subscript_session(struct VSSubscriptionList *list, unsigned int session)
{
 verse_session_set(list->session[session]);
}

variable_types:
session
unsigned int


decompiled_code:
__int64 vs_reset_subscript_session()
{
return verse_session_set(*((_QWORD *)VSConnectionStorage + 34 * HIDWORD(qword_4F8)));
}

canonical_decompiled_code:
__int64 func13()
{
return verse_session_set(*((_QWORD *)VSConnectionStorage + 34 * HIDWORD(qword_4F8)));
}

original_code:
void vs_reset_subscript_session(void)
{
 verse_session_set(VSConnectionStorage.connection[VSConnectionStorage.current_session].session);
}

canonical_original_code:
void vs_reset_subscript_session()
{
 verse_session_set(VSConnectionStorage.connection[VSConnectionStorage.current_session].session);
}


decompiled_code:
_BOOL8 __fastcall desc_has_keyword(const char *a1, const char *a2)
{
_BOOL4 v2; // er12
char *v3; // rbx
size_t v4; // rax

v2 = 0;
if ( a1 )
{
if ( *a1 )
{
v3 = strstr(a1, a2);
if ( v3 )
{
v4 = strlen(a2);
v2 = v3[v4] == 0 || v3[v4] == 44;
}
}
}
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func0(const char *a1, const char *a2)
{
_BOOL4 v2; // er12
char *v3; // rbx
size_t v4; // rax

v2 = 0;
if ( a1 )
{
if ( *a1 )
{
v3 = strstr(a1, a2);
if ( v3 )
{
v4 = strlen(a2);
v2 = v3[v4] == 0 || v3[v4] == 44;
}
}
}
return v2;
}

original_code:
static int desc_has_keyword(const char *desc, const char *keyword)
{
 const char *ptr;
 if(desc == ((void *)0) || *desc == '\0')
  return 0;
 if((ptr = strstr(desc, keyword)) != ((void *)0))
 {
  size_t kl = strlen(keyword);
  return ptr[kl] == ',' || ptr[kl] == '\0';
 }
 return 0;
}

canonical_original_code:
static int desc_has_keyword(char *desc, char *keyword)
{
 char *ptr;
 if(desc == ((void *)0) || *desc == '\0')
  return 0;
 if((ptr = strstr(desc, keyword)) != ((void *)0))
 {
  unsigned long kl = strlen(keyword);
  return ptr[kl] == ',' || ptr[kl] == '\0';
 }
 return 0;
}

variable_types:
desc
char *

variable_types:
keyword
char *

variable_types:
ptr
char *

variable_types:
kl
unsigned long


decompiled_code:
char *__fastcall append_desc(char *a1, const char *a2, const char *a3)
{
return &a1[sprintf(a1, " %s=\"%s\"", a2, a3)];
}

canonical_decompiled_code:
char *__fastcall func1(char *a1, const char *a2, const char *a3)
{
return &a1[sprintf(a1, " %s=\"%s\"", a2, a3)];
}

original_code:
static char * append_desc(char *buf, const char *key, const char *value)
{
 return buf + sprintf(buf, " %s=\"%s\"", key, value);
}

canonical_original_code:
static char *append_desc(char *buf, char *key, char *value)
{
 return buf + sprintf(buf, " %s=\"%s\"", key, value);
}

variable_types:
buf
char *

variable_types:
key
char *

variable_types:
value
char *


decompiled_code:
void __fastcall vs_master_set_enabled(char a1)
{
server_info = a1;
}

canonical_decompiled_code:
void __fastcall func3(char a1)
{
server_info = a1;
}

original_code:
void vs_master_set_enabled(boolean enabled)
{
 server_info.enabled = enabled;
}

canonical_original_code:
void vs_master_set_enabled(unsigned char enabled)
{
 server_info.enabled = enabled;
}

variable_types:
enabled
unsigned char


decompiled_code:
__int64 vs_master_get_address()
{
return qword_328;
}

canonical_decompiled_code:
__int64 func4()
{
return qword_328;
}

original_code:
const char * vs_master_get_address(void)
{
 return server_info.master;
}

canonical_original_code:
char *vs_master_get_address()
{
 return server_info.master;
}


decompiled_code:
void __fastcall vs_master_set_address(__int64 a1)
{
qword_328 = a1;
}

canonical_decompiled_code:
void __fastcall func5(__int64 a1)
{
qword_328 = a1;
}

original_code:
void vs_master_set_address(const char *address)
{
 server_info.master = address;
}

canonical_original_code:
void vs_master_set_address(char *address)
{
 server_info.master = address;
}

variable_types:
address
char *


decompiled_code:
void __fastcall vs_master_set_tags(__int64 a1)
{
qword_370 = a1;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
qword_370 = a1;
}

original_code:
void vs_master_set_tags(const char *tags)
{
 server_info.tags = tags;
}

canonical_original_code:
void vs_master_set_tags(char *tags)
{
 server_info.tags = tags;
}

variable_types:
tags
char *


decompiled_code:
void vs_master_update()
{
if ( server_info && qword_328 )
{
if ( byte_321 )
{
if ( v_timer_elapsed(&unk_378) >= 60.0 )
{
verse_send_ping(qword_328, "MS:ANNOUNCE");
v_timer_start(&unk_378);
}
}
else
{
v_timer_start(&unk_378);
v_timer_advance(&unk_378, 60.0);
byte_321 = 1;
}
}
}

canonical_decompiled_code:
void func8()
{
if ( server_info && qword_328 )
{
if ( byte_321 )
{
if ( v_timer_elapsed(&unk_378) >= 60.0 )
{
verse_send_ping(qword_328, "MS:ANNOUNCE");
v_timer_start(&unk_378);
}
}
else
{
v_timer_start(&unk_378);
v_timer_advance(&unk_378, 60.0);
byte_321 = 1;
}
}
}

original_code:
void vs_master_update(void)
{
 if(!server_info.enabled || server_info.master == ((void *)0))
  return;
 if(!server_info.started)
 {
  v_timer_start(&server_info.timer);
  v_timer_advance(&server_info.timer, (60.0));
  server_info.started = 1;
  return;
 }
 if(v_timer_elapsed(&server_info.timer) < (60.0))
  return;
 verse_send_ping(server_info.master, "MS:ANNOUNCE");
 v_timer_start(&server_info.timer);
}

canonical_original_code:
void vs_master_update()
{
 if(!server_info.enabled || server_info.master == ((void *)0))
  return;
 if(!server_info.started)
 {
  v_timer_start(&server_info.timer);
  v_timer_advance(&server_info.timer, (60.0));
  server_info.started = 1;
  return;
 }
 if(v_timer_elapsed(&server_info.timer) < (60.0))
  return;
 verse_send_ping(server_info.master, "MS:ANNOUNCE");
 v_timer_start(&server_info.timer);
}


decompiled_code:
__int64 __fastcall vs_master_handle_describe(__int64 a1, const char *a2)
{
char *v2; // r13
const char *v3; // r14
__m128i v5; // [rsp+0h] [rbp-598h] BYREF
char v6[1360]; // [rsp+10h] [rbp-588h] BYREF
int v7; // [rsp+560h] [rbp-38h]

v2 = &v5.m128i_i8[11];
memset(v6, 0, sizeof(v6));
v5 = _mm_load_si128((const __m128i *)&LC5);
v7 = 0;
if ( desc_has_keyword(a2, "DE") && keyword_fits_constprop_0(11LL, "DE", byte_330) )
v2 = append_desc(&v5.m128i_i8[11], "DE", byte_330);
if ( desc_has_keyword(a2, "TA") )
{
v3 = (const char *)qword_370;
if ( qword_370 )
{
if ( keyword_fits_constprop_0(v2 - (char *)&v5, "TA", (const char *)qword_370) )
append_desc(v2, "TA", v3);
}
}
return verse_send_ping(a1, &v5);
}

original_code:
void vs_master_handle_describe(const char *address, const char *message)
{
 char desc[1380] = "DESCRIPTION", *put = desc + 11;
 if(desc_has_keyword(message, "DE") && server_info.desc != ((void *)0) && keyword_fits(put - desc, sizeof desc, "DE", server_info.desc))
  put = append_desc(put, "DE", server_info.desc);
 if(desc_has_keyword(message, "TA") && server_info.tags != ((void *)0) && keyword_fits(put - desc, sizeof desc, "TA", server_info.tags))
  put = append_desc(put, "TA", server_info.tags);
 verse_send_ping(address, desc);
}

canonical_original_code:
void vs_master_handle_describe(char *address, char *message)
{
 char desc[1380] = "DESCRIPTION"; char *put = desc + 11;
 if(desc_has_keyword(message, "DE") && server_info.desc != ((void *)0) && keyword_fits(put - desc, sizeof desc, "DE", server_info.desc))
  put = append_desc(put, "DE", server_info.desc);
 if(desc_has_keyword(message, "TA") && server_info.tags != ((void *)0) && keyword_fits(put - desc, sizeof desc, "TA", server_info.tags))
  put = append_desc(put, "TA", server_info.tags);
 verse_send_ping(address, desc);
}

variable_types:
message
char *

variable_types:
desc
char [1380]

variable_types:
put
char *


decompiled_code:
int __fastcall callback_send_m_fragment_destroy(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
__int64 v5; // rbp
int result; // eax
unsigned int v7; // er13
_DWORD *v8; // rbx
unsigned int v9; // ebx
int v10; // er14
__int64 v11; // rsi

v5 = vs_get_node(a2, 2LL);
result = printf("callback_send_m_fragment_destroy %p\n", (const void *)v5);
if ( v5 )
{
v7 = a3;
if ( *(_DWORD *)(v5 + 56) > (unsigned int)a3 )
{
v8 = (_DWORD *)(*(_QWORD *)(v5 + 48) + 1552LL * a3);
if ( *v8 <= 0xFu )
{
*v8 = 255;
v9 = 0;
v10 = vs_get_subscript_count(*(_QWORD *)(v5 + 40));
if ( v10 )
{
do
{
v11 = v9++;
vs_set_subscript_session(*(_QWORD *)(v5 + 40), v11);
verse_send_m_fragment_destroy(a2, v7);
}
while ( v10 != v9 );
}
result = vs_reset_subscript_session();
}
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
__int64 v5; // rbp
int result; // eax
unsigned int v7; // er13
_DWORD *v8; // rbx
unsigned int v9; // ebx
int v10; // er14
__int64 v11; // rsi

v5 = vs_get_node(a2, 2LL);
result = printf("callback_send_m_fragment_destroy %p\n", (const void *)v5);
if ( v5 )
{
v7 = a3;
if ( *(_DWORD *)(v5 + 56) > (unsigned int)a3 )
{
v8 = (_DWORD *)(*(_QWORD *)(v5 + 48) + 1552LL * a3);
if ( *v8 <= 0xFu )
{
*v8 = 255;
v9 = 0;
v10 = vs_get_subscript_count(*(_QWORD *)(v5 + 40));
if ( v10 )
{
do
{
v11 = v9++;
vs_set_subscript_session(*(_QWORD *)(v5 + 40), v11);
verse_send_m_fragment_destroy(a2, v7);
}
while ( v10 != v9 );
}
result = vs_reset_subscript_session();
}
}
}
return result;
}

original_code:
static void callback_send_m_fragment_destroy(void *user, VNodeID node_id, VNMFragmentID frag_id)
{
 unsigned int count, i;
 VSNodeMaterial *node;
 node = (VSNodeMaterial *)vs_get_node(node_id, V_NT_MATERIAL);
 printf("callback_send_m_fragment_destroy %p\n", node);
 if(node == ((void *)0))
  return;
 if(node->frag_count <= frag_id || node->frag[frag_id].type > VN_M_FT_OUTPUT)
  return;
 node->frag[frag_id].type = 255;
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_m_fragment_destroy(node_id, frag_id);
 }
 vs_reset_subscript_session();
}

canonical_original_code:
static void callback_send_m_fragment_destroy(void *user, unsigned int node_id, unsigned short frag_id)
{
 unsigned int count; unsigned int i;
 struct VSNodeMaterial *node;
 node = (struct VSNodeMaterial *)vs_get_node(node_id, V_NT_MATERIAL);
 printf("callback_send_m_fragment_destroy %p\n", node);
 if(node == ((void *)0))
  return;
 if(node->frag_count <= frag_id || node->frag[frag_id].type > VN_M_FT_OUTPUT)
  return;
 node->frag[frag_id].type = 255;
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_m_fragment_destroy(node_id, frag_id);
 }
 vs_reset_subscript_session();
}

variable_types:
user
void *

variable_types:
count
unsigned int

variable_types:
i
unsigned int

variable_types: struct VSNodeMaterial { struct VSNodeHead { unsigned int id; enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr } type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; } head; struct VSMatFrag { enum VNMFragmentType { VN_M_FT_COLOR=0, VN_M_FT_LIGHT=1, VN_M_FT_REFLECTION=2, VN_M_FT_TRANSPARENCY=3, VN_M_FT_VOLUME=4, VN_M_FT_VIEW=5, VN_M_FT_GEOMETRY=6, VN_M_FT_TEXTURE=7, VN_M_FT_NOISE=8, VN_M_FT_BLENDER=9, VN_M_FT_CLAMP=10, VN_M_FT_MATRIX=11, VN_M_FT_RAMP=12, VN_M_FT_ANIMATION=13, VN_M_FT_ALTERNATIVE=14, VN_M_FT_OUTPUT=15 } type; union VMatFrag { struct { double red; double green; double blue; } color; struct { unsigned char type; double normal_falloff; unsigned int brdf; char brdf_r[16]; char brdf_g[16]; char brdf_b[16]; } light; struct { double normal_falloff; } reflection; struct { double normal_falloff; double refraction_index; } transparency; struct { double diffusion; double col_r; double col_g; double col_b; } volume; struct { char layer_r[16]; char layer_g[16]; char layer_b[16]; } geometry; struct { unsigned int bitmap; char layer_r[16]; char layer_g[16]; char layer_b[16]; unsigned char filtered; unsigned short mapping; } texture; struct { unsigned char type; unsigned short mapping; } noise; struct { unsigned char type; unsigned short data_a; unsigned short data_b; unsigned short control; } blender; struct { unsigned char min; double red; double green; double blue; unsigned short data; } clamp; struct { double matrix[16]; unsigned short data; } matrix; struct { unsigned char type; unsigned char channel; unsigned short mapping; unsigned char point_count; struct VNMRampPoint { double pos; double red; double green; double blue; } ramp[48]; } ramp; struct { char label[16]; } animation; struct { unsigned short alt_a; unsigned short alt_b; } alternative; struct { char label[16]; unsigned short front; unsigned short back; } output; } frag; } *frag; unsigned int frag_count; } *

user_defined_types: struct VSNodeMaterial { struct VSNodeHead head; struct VSMatFrag *frag; unsigned int frag_count; }

user_defined_types: struct VSNodeHead { unsigned int id; enum VNodeType type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; }

user_defined_types: struct VSMatFrag { enum VNMFragmentType type; union VMatFrag frag; }

user_defined_types: union VMatFrag { struct { double red; double green; double blue; } color; struct { unsigned char type; double normal_falloff; unsigned int brdf; char brdf_r[16]; char brdf_g[16]; char brdf_b[16]; } light; struct { double normal_falloff; } reflection; struct { double normal_falloff; double refraction_index; } transparency; struct { double diffusion; double col_r; double col_g; double col_b; } volume; struct { char layer_r[16]; char layer_g[16]; char layer_b[16]; } geometry; struct { unsigned int bitmap; char layer_r[16]; char layer_g[16]; char layer_b[16]; unsigned char filtered; unsigned short mapping; } texture; struct { unsigned char type; unsigned short mapping; } noise; struct { unsigned char type; unsigned short data_a; unsigned short data_b; unsigned short control; } blender; struct { unsigned char min; double red; double green; double blue; unsigned short data; } clamp; struct { double matrix[16]; unsigned short data; } matrix; struct { unsigned char type; unsigned char channel; unsigned short mapping; unsigned char point_count; struct VNMRampPoint ramp[48]; } ramp; struct { char label[16]; } animation; struct { unsigned short alt_a; unsigned short alt_b; } alternative; struct { char label[16]; unsigned short front; unsigned short back; } output; }


decompiled_code:
__int64 __fastcall callback_send_m_fragment_create(__int64 a1, unsigned int a2, unsigned __int16 a3, unsigned __int8 a4, const void *a5)
{
unsigned __int16 v7; // bp
unsigned __int16 v8; // bx
__int64 result; // rax
unsigned int v10; // ecx
__int64 v11; // r14
unsigned int v12; // edx
char *v13; // rdi
__int64 v14; // rax
__int64 v15; // rbp
char *v16; // rdi
int v17; // er15
__int64 v18; // rdi
__int64 v19; // rsi
unsigned int v20; // ebp
char *v21; // rax
int v22; // edx
unsigned int i; // esi
__int64 v24; // rcx

v7 = a3;
v8 = a3;
result = vs_get_node(a2, 2LL);
if ( !result )
return result;
v10 = *(_DWORD *)(result + 56);
v11 = result;
v12 = v7;
v13 = *(char **)(result + 48);
v14 = v10 + 32;
if ( (unsigned int)v14 < v7 || v7 == 0xFFFF )
{
v8 = 0;
v15 = 0LL;
if ( v10 )
{
do
{
v15 = 1552LL * v8;
if ( *(_DWORD *)&v13[v15] > 0xFu )
{
v12 = v8;
goto LABEL_10;
}
++v8;
}
while ( v10 > v8 );
v15 = 1552LL * v8;
}
}
else
{
v15 = 1552LL * v7;
LABEL_10:
if ( v10 > v12 )
goto LABEL_11;
}
v21 = (char *)realloc(v13, 1552 * v14);
*(_QWORD *)(v11 + 48) = v21;
v13 = v21;
v22 = *(_DWORD *)(v11 + 56);
for ( i = v22 + 32; (unsigned __int16)v22 < i; *(_DWORD *)&v21[1552 * v24] = 255 )
v24 = (unsigned __int16)v22++;
*(_DWORD *)(v11 + 56) = i;
LABEL_11:
v16 = &v13[v15];
*(_DWORD *)v16 = a4;
v17 = 0;
qmemcpy(v16 + 8, a5, 0x608uLL);
v18 = *(_QWORD *)(v11 + 40);
v19 = 0LL;
v20 = vs_get_subscript_count(v18);
if ( v20 )
{
do
{
++v17;
vs_set_subscript_session(*(_QWORD *)(v11 + 40), v19);
v18 = a2;
verse_send_m_fragment_create(a2, v8, a4, a5);
v19 = (unsigned __int16)v17;
}
while ( (unsigned __int16)v17 < v20 );
}
return vs_reset_subscript_session(v18, v19);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2, unsigned __int16 a3, unsigned __int8 a4, const void *a5)
{
unsigned __int16 v7; // bp
unsigned __int16 v8; // bx
__int64 result; // rax
unsigned int v10; // ecx
__int64 v11; // r14
unsigned int v12; // edx
char *v13; // rdi
__int64 v14; // rax
__int64 v15; // rbp
char *v16; // rdi
int v17; // er15
__int64 v18; // rdi
__int64 v19; // rsi
unsigned int v20; // ebp
char *v21; // rax
int v22; // edx
unsigned int i; // esi
__int64 v24; // rcx

v7 = a3;
v8 = a3;
result = vs_get_node(a2, 2LL);
if ( !result )
return result;
v10 = *(_DWORD *)(result + 56);
v11 = result;
v12 = v7;
v13 = *(char **)(result + 48);
v14 = v10 + 32;
if ( (unsigned int)v14 < v7 || v7 == 0xFFFF )
{
v8 = 0;
v15 = 0LL;
if ( v10 )
{
do
{
v15 = 1552LL * v8;
if ( *(_DWORD *)&v13[v15] > 0xFu )
{
v12 = v8;
goto LABEL_10;
}
++v8;
}
while ( v10 > v8 );
v15 = 1552LL * v8;
}
}
else
{
v15 = 1552LL * v7;
LABEL_10:
if ( v10 > v12 )
goto LABEL_11;
}
v21 = (char *)realloc(v13, 1552 * v14);
*(_QWORD *)(v11 + 48) = v21;
v13 = v21;
v22 = *(_DWORD *)(v11 + 56);
for ( i = v22 + 32; (unsigned __int16)v22 < i; *(_DWORD *)&v21[1552 * v24] = 255 )
v24 = (unsigned __int16)v22++;
*(_DWORD *)(v11 + 56) = i;
LABEL_11:
v16 = &v13[v15];
*(_DWORD *)v16 = a4;
v17 = 0;
qmemcpy(v16 + 8, a5, 0x608uLL);
v18 = *(_QWORD *)(v11 + 40);
v19 = 0LL;
v20 = vs_get_subscript_count(v18);
if ( v20 )
{
do
{
++v17;
vs_set_subscript_session(*(_QWORD *)(v11 + 40), v19);
v18 = a2;
verse_send_m_fragment_create(a2, v8, a4, a5);
v19 = (unsigned __int16)v17;
}
while ( (unsigned __int16)v17 < v20 );
}
return vs_reset_subscript_session(v18, v19);
}

original_code:
static void callback_send_m_fragment_create(void *user, VNodeID node_id, VNMFragmentID frag_id, uint8 type, VMatFrag *fragment)
{
 unsigned int count;
 uint16 i;
 VSNodeMaterial *node;
 node = (VSNodeMaterial *)vs_get_node(node_id, V_NT_MATERIAL);
 if(node == ((void *)0))
  return;
 if(node->frag_count + 32 < frag_id)
  frag_id = (uint16)-1;
 if(frag_id == (uint16) ~0u)
  for(frag_id = 0; frag_id < node->frag_count && node->frag[frag_id].type < VN_M_FT_OUTPUT + 1; frag_id++)
   ;
 if(frag_id >= node->frag_count)
 {
  node->frag = realloc(node->frag, (sizeof *node->frag) * (node->frag_count + 32));
  for(i = node->frag_count; i < (node->frag_count + 32); i++)
   node->frag[i].type = 255;
  node->frag_count += 32;
 }
 node->frag[frag_id].type = type;
 node->frag[frag_id].frag = *fragment;
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_m_fragment_create(node_id, frag_id, type, fragment);
 }
 vs_reset_subscript_session();
}

canonical_original_code:
static void callback_send_m_fragment_create(void *user, unsigned int node_id, unsigned short frag_id, unsigned char type, union VMatFrag *fragment)
{
 unsigned int count;
 unsigned short i;
 struct VSNodeMaterial *node;
 node = (struct VSNodeMaterial *)vs_get_node(node_id, V_NT_MATERIAL);
 if(node == ((void *)0))
  return;
 if(node->frag_count + 32 < frag_id)
  frag_id = (uint16)-1;
 if(frag_id == (unsigned short) ~0u)
  for(frag_id = 0; frag_id < node->frag_count && node->frag[frag_id].type < VN_M_FT_OUTPUT + 1; frag_id++)
   ;
 if(frag_id >= node->frag_count)
 {
  node->frag = realloc(node->frag, (sizeof *node->frag) * (node->frag_count + 32));
  for(i = node->frag_count; i < (node->frag_count + 32); i++)
   node->frag[i].type = 255;
  node->frag_count += 32;
 }
 node->frag[frag_id].type = type;
 node->frag[frag_id].frag = *fragment;
 count = vs_get_subscript_count(node->head.subscribers);
 for(i = 0; i < count; i++)
 {
  vs_set_subscript_session(node->head.subscribers, i);
  verse_send_m_fragment_create(node_id, frag_id, type, fragment);
 }
 vs_reset_subscript_session();
}

variable_types:
type
unsigned char

variable_types: union VMatFrag { struct { double red; double green; double blue; } color; struct { unsigned char type; double normal_falloff; unsigned int brdf; char brdf_r[16]; char brdf_g[16]; char brdf_b[16]; } light; struct { double normal_falloff; } reflection; struct { double normal_falloff; double refraction_index; } transparency; struct { double diffusion; double col_r; double col_g; double col_b; } volume; struct { char layer_r[16]; char layer_g[16]; char layer_b[16]; } geometry; struct { unsigned int bitmap; char layer_r[16]; char layer_g[16]; char layer_b[16]; unsigned char filtered; unsigned short mapping; } texture; struct { unsigned char type; unsigned short mapping; } noise; struct { unsigned char type; unsigned short data_a; unsigned short data_b; unsigned short control; } blender; struct { unsigned char min; double red; double green; double blue; unsigned short data; } clamp; struct { double matrix[16]; unsigned short data; } matrix; struct { unsigned char type; unsigned char channel; unsigned short mapping; unsigned char point_count; struct VNMRampPoint { double pos; double red; double green; double blue; } ramp[48]; } ramp; struct { char label[16]; } animation; struct { unsigned short alt_a; unsigned short alt_b; } alternative; struct { char label[16]; unsigned short front; unsigned short back; } output; } *

variable_types:
i
unsigned short

user_defined_types: enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr }

user_defined_types: enum VNMFragmentType { VN_M_FT_COLOR=0, VN_M_FT_LIGHT=1, VN_M_FT_REFLECTION=2, VN_M_FT_TRANSPARENCY=3, VN_M_FT_VOLUME=4, VN_M_FT_VIEW=5, VN_M_FT_GEOMETRY=6, VN_M_FT_TEXTURE=7, VN_M_FT_NOISE=8, VN_M_FT_BLENDER=9, VN_M_FT_CLAMP=10, VN_M_FT_MATRIX=11, VN_M_FT_RAMP=12, VN_M_FT_ANIMATION=13, VN_M_FT_ALTERNATIVE=14, VN_M_FT_OUTPUT=15 }


decompiled_code:
unsigned int *__fastcall vs_m_create_node(unsigned int a1)
{
unsigned int *v1; // r12
unsigned int *result; // rax
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = (unsigned int *)malloc(0x40uLL);
vs_add_new_node(v1, 2LL);
sprintf(v3, "Material_Node_%u", *v1);
create_node_head(v1, v3, a1);
result = v1;
*((_QWORD *)v1 + 6) = 0LL;
v1[14] = 0;
return result;
}

canonical_decompiled_code:
unsigned int *__fastcall func2(unsigned int a1)
{
unsigned int *v1; // r12
unsigned int *result; // rax
char v3[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = (unsigned int *)malloc(0x40uLL);
vs_add_new_node(v1, 2LL);
sprintf(v3, "Material_Node_%u", *v1);
create_node_head(v1, v3, a1);
result = v1;
*((_QWORD *)v1 + 6) = 0LL;
v1[14] = 0;
return result;
}

original_code:
VSNodeMaterial * vs_m_create_node(unsigned int owner)
{
 VSNodeMaterial *node;
 char name[48];
 node = malloc(sizeof *node);
 vs_add_new_node(&node->head, V_NT_MATERIAL);
 sprintf(name, "Material_Node_%u", node->head.id);
 create_node_head(&node->head, name, owner);
 node->frag = ((void *)0);
 node->frag_count = 0;
 return node;
}

canonical_original_code:
struct VSNodeMaterial *vs_m_create_node(unsigned int owner)
{
 struct VSNodeMaterial *node;
 char name[48];
 node = malloc(sizeof *node);
 vs_add_new_node(&node->head, V_NT_MATERIAL);
 sprintf(name, "Material_Node_%u", node->head.id);
 create_node_head(&node->head, name, owner);
 node->frag = ((void *)0);
 node->frag_count = 0;
 return node;
}

variable_types:
owner
unsigned int

variable_types:
name
char [48]

return_type: struct VSNodeMaterial { struct VSNodeHead { unsigned int id; enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr } type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; } head; struct VSMatFrag { enum VNMFragmentType { VN_M_FT_COLOR=0, VN_M_FT_LIGHT=1, VN_M_FT_REFLECTION=2, VN_M_FT_TRANSPARENCY=3, VN_M_FT_VOLUME=4, VN_M_FT_VIEW=5, VN_M_FT_GEOMETRY=6, VN_M_FT_TEXTURE=7, VN_M_FT_NOISE=8, VN_M_FT_BLENDER=9, VN_M_FT_CLAMP=10, VN_M_FT_MATRIX=11, VN_M_FT_RAMP=12, VN_M_FT_ANIMATION=13, VN_M_FT_ALTERNATIVE=14, VN_M_FT_OUTPUT=15 } type; union VMatFrag { struct { double red; double green; double blue; } color; struct { unsigned char type; double normal_falloff; unsigned int brdf; char brdf_r[16]; char brdf_g[16]; char brdf_b[16]; } light; struct { double normal_falloff; } reflection; struct { double normal_falloff; double refraction_index; } transparency; struct { double diffusion; double col_r; double col_g; double col_b; } volume; struct { char layer_r[16]; char layer_g[16]; char layer_b[16]; } geometry; struct { unsigned int bitmap; char layer_r[16]; char layer_g[16]; char layer_b[16]; unsigned char filtered; unsigned short mapping; } texture; struct { unsigned char type; unsigned short mapping; } noise; struct { unsigned char type; unsigned short data_a; unsigned short data_b; unsigned short control; } blender; struct { unsigned char min; double red; double green; double blue; unsigned short data; } clamp; struct { double matrix[16]; unsigned short data; } matrix; struct { unsigned char type; unsigned char channel; unsigned short mapping; unsigned char point_count; struct VNMRampPoint { double pos; double red; double green; double blue; } ramp[48]; } ramp; struct { char label[16]; } animation; struct { unsigned short alt_a; unsigned short alt_b; } alternative; struct { char label[16]; unsigned short front; unsigned short back; } output; } frag; } *frag; unsigned int frag_count; } *


decompiled_code:
void __fastcall vs_m_destroy_node(void *ptr)
{
destroy_node_head();
free(*((void **)ptr + 6));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
destroy_node_head();
free(*((void **)ptr + 6));
free(ptr);
}

original_code:
void vs_m_destroy_node(VSNodeMaterial *node)
{
 destroy_node_head(&node->head);
 free(node->frag);
 free(node);
}

canonical_original_code:
void vs_m_destroy_node(struct VSNodeMaterial *node)
{
 destroy_node_head(&node->head);
 free(node->frag);
 free(node);
}

user_defined_types: struct VNMRampPoint { double pos; double red; double green; double blue; }


decompiled_code:
__int64 __fastcall vs_m_subscribe(unsigned int *a1)
{
__int64 result; // rax
int v2; // ebx
unsigned int *v3; // rcx
__int64 v4; // rdx
__int64 v5; // rsi

result = a1[14];
if ( (_DWORD)result )
{
v2 = 0;
do
{
while ( 1 )
{
v3 = (unsigned int *)(*((_QWORD *)a1 + 6) + 1552LL * (unsigned __int16)v2);
v4 = *v3;
if ( (unsigned int)v4 <= 0xF )
break;
result = (unsigned __int16)++v2;
if ( (unsigned __int16)v2 >= a1[14] )
return result;
}
v5 = (unsigned __int16)v2++;
verse_send_m_fragment_create(*a1, v5, v4, v3 + 2);
result = (unsigned __int16)v2;
}
while ( (unsigned __int16)v2 < a1[14] );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int *a1)
{
__int64 result; // rax
int v2; // ebx
unsigned int *v3; // rcx
__int64 v4; // rdx
__int64 v5; // rsi

result = a1[14];
if ( (_DWORD)result )
{
v2 = 0;
do
{
while ( 1 )
{
v3 = (unsigned int *)(*((_QWORD *)a1 + 6) + 1552LL * (unsigned __int16)v2);
v4 = *v3;
if ( (unsigned int)v4 <= 0xF )
break;
result = (unsigned __int16)++v2;
if ( (unsigned __int16)v2 >= a1[14] )
return result;
}
v5 = (unsigned __int16)v2++;
verse_send_m_fragment_create(*a1, v5, v4, v3 + 2);
result = (unsigned __int16)v2;
}
while ( (unsigned __int16)v2 < a1[14] );
}
return result;
}

original_code:
void vs_m_subscribe(VSNodeMaterial *node)
{
 uint16 i;
 for(i = 0; i < node->frag_count; i++)
  if(node->frag[i].type <= VN_M_FT_OUTPUT)
   verse_send_m_fragment_create(node->head.id, (uint16)i, (uint8)node->frag[i].type, &node->frag[i].frag);
}

canonical_original_code:
void vs_m_subscribe(struct VSNodeMaterial *node)
{
 unsigned short i;
 for(i = 0; i < node->frag_count; i++)
  if(node->frag[i].type <= VN_M_FT_OUTPUT)
   verse_send_m_fragment_create(node->head.id, (unsigned short)i, (unsigned char)node->frag[i].type, &node->frag[i].frag);
}


decompiled_code:
void vs_m_unsubscribe()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void vs_m_unsubscribe(VSNodeMaterial *node)
{
}

canonical_original_code:
void vs_m_unsubscribe(struct VSNodeMaterial *node)
{
}


decompiled_code:
__int64 vs_m_callback_init()
{
verse_callback_set(&verse_send_m_fragment_create, callback_send_m_fragment_create, 0LL);
return verse_callback_set(&verse_send_m_fragment_destroy, callback_send_m_fragment_destroy, 0LL);
}

canonical_decompiled_code:
__int64 func6()
{
verse_callback_set(&verse_send_m_fragment_create, callback_send_m_fragment_create, 0LL);
return verse_callback_set(&verse_send_m_fragment_destroy, callback_send_m_fragment_destroy, 0LL);
}

original_code:
void vs_m_callback_init(void)
{
 verse_callback_set(verse_send_m_fragment_create, callback_send_m_fragment_create, ((void *)0));
 verse_callback_set(verse_send_m_fragment_destroy, callback_send_m_fragment_destroy, ((void *)0));
}

canonical_original_code:
void vs_m_callback_init()
{
 verse_callback_set(verse_send_m_fragment_create, callback_send_m_fragment_create, ((void *)0));
 verse_callback_set(verse_send_m_fragment_destroy, callback_send_m_fragment_destroy, ((void *)0));
}


decompiled_code:
__int64 __fastcall callback_send_t_buffer_unsubscribe(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v5; // rdx

result = vs_get_node(a2, 4LL);
if ( result && (unsigned int)a3 < *(_DWORD *)(result + 568) )
{
v5 = *(_QWORD *)(result + 560) + 48LL * a3;
if ( *(_BYTE *)v5 )
result = vs_remove_subscriptor(*(_QWORD *)(v5 + 40));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, unsigned int a2, unsigned __int16 a3)
{
__int64 result; // rax
__int64 v5; // rdx

result = vs_get_node(a2, 4LL);
if ( result && (unsigned int)a3 < *(_DWORD *)(result + 568) )
{
v5 = *(_QWORD *)(result + 560) + 48LL * a3;
if ( *(_BYTE *)v5 )
result = vs_remove_subscriptor(*(_QWORD *)(v5 + 40));
}
return result;
}

original_code:
static void callback_send_t_buffer_unsubscribe(void *user, VNodeID node_id, VBufferID buffer_id)
{
 VSNodeText *node;
 node = (VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] == 0)
  return;
 vs_remove_subscriptor(node->buffer[buffer_id].subscribers);
}

canonical_original_code:
static void callback_send_t_buffer_unsubscribe(void *user, unsigned int node_id, unsigned short buffer_id)
{
 struct VSNodeText *node;
 node = (struct VSNodeText *)vs_get_node(node_id, V_NT_TEXT);
 if(node == ((void *)0))
  return;
 if(buffer_id >= node->buffer_count || node->buffer[buffer_id].name[0] == 0)
  return;
 vs_remove_subscriptor(node->buffer[buffer_id].subscribers);
}

variable_types: struct VSNodeText { struct VSNodeHead { unsigned int id; enum VNodeType { V_NT_OBJECT=0, V_NT_GEOMETRY=1, V_NT_MATERIAL=2, V_NT_BITMAP=3, V_NT_TEXT=4, V_NT_CURVE=5, V_NT_AUDIO=6, V_NT_NUM_TYPES=7, V_NT_SYSTEM=expr, V_NT_NUM_TYPES_NETPACK=expr } type; unsigned int owner; char *name; void *tag_groups; unsigned short group_count; void *subscribers; } head; char language[512]; struct VSTextBuffer { char name[16]; char *text; unsigned long length; unsigned long allocated; void *subscribers; } *buffer; unsigned int buffer_count; } *

user_defined_types: struct VSNodeText { struct VSNodeHead head; char language[512]; struct VSTextBuffer *buffer; unsigned int buffer_count; }