AddIWADPath

decompiled_code:
void __fastcall AddIWADPath(__int64 a1, __int64 a2)
{
char *v2; // r12
const char *i; // r13
__int64 v4; // rax
char *v5; // rax
char *v6; // rbx
__int64 v7; // rax

v2 = (char *)M_StringDuplicate();
for ( i = v2; ; i = v6 + 1 )
{
v5 = strchr(i, 58);
v6 = v5;
if ( !v5 )
break;
*v5 = 0;
v4 = M_StringJoin(i, a2, 0LL);
AddIWADDir(v4);
}
v7 = M_StringJoin(i, a2, 0LL);
AddIWADDir(v7);
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, __int64 a2)
{
char *v2; // r12
const char *i; // r13
__int64 v4; // rax
char *v5; // rax
char *v6; // rbx
__int64 v7; // rax

v2 = (char *)M_StringDuplicate();
for ( i = v2; ; i = v6 + 1 )
{
v5 = strchr(i, 58);
v6 = v5;
if ( !v5 )
break;
*v5 = 0;
v4 = M_StringJoin(i, a2, 0LL);
func0(v4);
}
v7 = M_StringJoin(i, a2, 0LL);
func0(v7);
free(v2);
}

original_code:
static void AddIWADPath(const char *path, const char *suffix)
{
    char *p;
    char *dup_path = M_StringDuplicate(path);
    char *left = dup_path;
    while (1)
        if ((p = strchr(left, ':')))
        {
            *p = '\0';
            AddIWADDir(M_StringJoin(left, suffix, ((void *)0)));
            left = p + 1;
        }
        else
            break;
    AddIWADDir(M_StringJoin(left, suffix, ((void *)0)));
    free(dup_path);
}

canonical_original_code:
static void AddIWADPath(char *path, char *suffix)
{
    char *p;
    char *dup_path = M_StringDuplicate(path);
    char *left = dup_path;
    while (1)
        if ((p = strchr(left, ':')))
        {
            *p = '\0';
            AddIWADDir(M_StringJoin(left, suffix, ((void *)0)));
            left = p + 1;
        }
        else
            break;
    AddIWADDir(M_StringJoin(left, suffix, ((void *)0)));
    free(dup_path);
}

variable_types:
path
char *

variable_types:
suffix
char *

variable_types:
left
char *


AddXdgDirs

repo: bradharding/doomretro

decompiled_code:
void AddXdgDirs()
{
char *v0; // rdi
char *v1; // rbx
__int64 v2; // rax
char *v3; // rbx
char *v4; // rdi

v0 = getenv("XDG_DATA_HOME");
v1 = 0LL;
if ( !v0 )
{
v4 = getenv("HOME");
if ( !v4 )
v4 = "/";
v0 = (char *)M_StringJoin(v4, "/.local/share", 0LL);
v1 = v0;
}
v2 = M_StringJoin(v0, "/games/doom", 0LL);
AddIWADDir(v2);
free(v1);
v3 = getenv("XDG_DATA_DIRS");
if ( !v3 )
v3 = "/usr/local/share:/usr/share";
AddIWADPath((__int64)v3, (__int64)"/games/doom");
AddIWADPath((__int64)v3, (__int64)"/doom");
AddIWADPath((__int64)v3, (__int64)"/games/doom3bfg/base/wads");
}

canonical_decompiled_code:
void func4()
{
char *v0; // rdi
char *v1; // rbx
__int64 v2; // rax
char *v3; // rbx
char *v4; // rdi

v0 = getenv("XDG_DATA_HOME");
v1 = 0LL;
if ( !v0 )
{
v4 = getenv("HOME");
if ( !v4 )
v4 = "/";
v0 = (char *)M_StringJoin(v4, "/.local/share", 0LL);
v1 = v0;
}
v2 = M_StringJoin(v0, "/games/doom", 0LL);
func0(v2);
free(v1);
v3 = getenv("XDG_DATA_DIRS");
if ( !v3 )
v3 = "/usr/local/share:/usr/share";
func3((__int64)v3, (__int64)"/games/doom");
func3((__int64)v3, (__int64)"/doom");
func3((__int64)v3, (__int64)"/games/doom3bfg/base/wads");
}

original_code:
static void AddXdgDirs(void)
{
    char *env = getenv("XDG_DATA_HOME");
    char *tmp_env = ((void *)0);
    if (!env)
    {
        char *homedir = getenv("HOME");
        if (!homedir)
            homedir = "/";
        tmp_env = M_StringJoin(homedir, "/.local/share", ((void *)0));
        env = tmp_env;
    }
    AddIWADDir(M_StringJoin(env, "/games/doom", ((void *)0)));
    free(tmp_env);
    if (!(env = getenv("XDG_DATA_DIRS")))
        env = "/usr/local/share:/usr/share";
    AddIWADPath(env, "/games/doom");
    AddIWADPath(env, "/doom");
    AddIWADPath(env, "/games/doom3bfg/base/wads");
}

canonical_original_code:
static void AddXdgDirs()
{
    char *env = getenv("XDG_DATA_HOME");
    char *tmp_env = ((void *)0);
    if (!env)
    {
        char *homedir = getenv("HOME");
        if (!homedir)
            homedir = "/";
        tmp_env = M_StringJoin(homedir, "/.local/share", ((void *)0));
        env = tmp_env;
    }
    AddIWADDir(M_StringJoin(env, "/games/doom", ((void *)0)));
    free(tmp_env);
    if (!(env = getenv("XDG_DATA_DIRS")))
        env = "/usr/local/share:/usr/share";
    AddIWADPath(env, "/games/doom");
    AddIWADPath(env, "/doom");
    AddIWADPath(env, "/games/doom3bfg/base/wads");
}

variable_types:
env
char *

variable_types:
homedir
char *

return_type: void


AddSteamDirs

decompiled_code:
void AddSteamDirs()
{
char *v0; // rdi
void *v1; // rbx

v0 = getenv("HOME");
if ( !v0 )
v0 = "/";
v1 = (void *)M_StringJoin(v0, "/.steam/root/steamapps/common", 0LL);
AddIWADPath((__int64)v1, (__int64)"/Doom 2/base");
AddIWADPath((__int64)v1, (__int64)"/Ultimate Doom/base");
AddIWADPath((__int64)v1, (__int64)"/Final Doom/base");
AddIWADPath((__int64)v1, (__int64)"/DOOM 3 BFG Edition/base/wads");
free(v1);
}

canonical_decompiled_code:
void func5()
{
char *v0; // rdi
void *v1; // rbx

v0 = getenv("HOME");
if ( !v0 )
v0 = "/";
v1 = (void *)M_StringJoin(v0, "/.steam/root/steamapps/common", 0LL);
func3((__int64)v1, (__int64)"/Doom 2/base");
func3((__int64)v1, (__int64)"/Ultimate Doom/base");
func3((__int64)v1, (__int64)"/Final Doom/base");
func3((__int64)v1, (__int64)"/DOOM 3 BFG Edition/base/wads");
free(v1);
}

original_code:
static void AddSteamDirs(void)
{
    char *homedir = getenv("HOME");
    char *steampath;
    if (!homedir)
        homedir = "/";
    steampath = M_StringJoin(homedir, "/.steam/root/steamapps/common", ((void *)0));
    AddIWADPath(steampath, "/Doom 2/base");
    AddIWADPath(steampath, "/Ultimate Doom/base");
    AddIWADPath(steampath, "/Final Doom/base");
    AddIWADPath(steampath, "/DOOM 3 BFG Edition/base/wads");
    free(steampath);
}

canonical_original_code:
static void AddSteamDirs()
{
    char *homedir = getenv("HOME");
    char *steampath;
    if (!homedir)
        homedir = "/";
    steampath = M_StringJoin(homedir, "/.steam/root/steamapps/common", ((void *)0));
    AddIWADPath(steampath, "/Doom 2/base");
    AddIWADPath(steampath, "/Ultimate Doom/base");
    AddIWADPath(steampath, "/Final Doom/base");
    AddIWADPath(steampath, "/DOOM 3 BFG Edition/base/wads");
    free(steampath);
}

variable_types:
steampath
char *


BuildIWADDirList

decompiled_code:
void BuildIWADDirList()
{
char *v0; // rax

if ( !iwad_dirs_built_0 )
{
v0 = getenv("DOOMWADDIR");
if ( v0 )
AddIWADDir((__int64)v0);
AddDoomWADPath();
AddXdgDirs();
AddSteamDirs();
iwad_dirs_built_0 = 1;
}
}

canonical_decompiled_code:
void func6()
{
char *v0; // rax

if ( !iwad_dirs_built_0 )
{
v0 = getenv("DOOMWADDIR");
if ( v0 )
func0((__int64)v0);
func2();
func4();
func5();
iwad_dirs_built_0 = 1;
}
}

original_code:
static void BuildIWADDirList(void)
{
    char *doomwaddir;
    static _Bool iwad_dirs_built;
    if (iwad_dirs_built)
        return;
    if ((doomwaddir = getenv("DOOMWADDIR")))
        AddIWADDir(doomwaddir);
    AddDoomWADPath();
    AddXdgDirs();
    AddSteamDirs();
    iwad_dirs_built = 1;
}

canonical_original_code:
static void BuildIWADDirList()
{
    char *doomwaddir;
    static _Bool iwad_dirs_built;
    if (iwad_dirs_built)
        return;
    if ((doomwaddir = getenv("DOOMWADDIR")))
        AddIWADDir(doomwaddir);
    AddDoomWADPath();
    AddXdgDirs();
    AddSteamDirs();
    iwad_dirs_built = 1;
}

variable_types:
doomwaddir
char *


DirIsFile

decompiled_code:
_BOOL8 __fastcall DirIsFile(const char *a1, const char *a2)
{
char *v2; // rdx
bool v3; // al
const char *v4; // rax

v2 = strchr(a1, 47);
v3 = 0;
if ( v2 )
{
v4 = (const char *)leafname(a1);
v3 = strcasecmp(v4, a2) == 0;
}
return v3;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(const char *a1, const char *a2)
{
char *v2; // rdx
bool v3; // al
const char *v4; // rax

v2 = strchr(a1, 47);
v3 = 0;
if ( v2 )
{
v4 = (const char *)leafname(a1);
v3 = strcasecmp(v4, a2) == 0;
}
return v3;
}

original_code:
static _Bool DirIsFile(char *path, char *filename)
{
    return (strchr(path, '/') && !strcasecmp(leafname(path), filename));
}

variable_types:
filename
char *


CheckDirectoryHasIWAD

decompiled_code:
void *__fastcall CheckDirectoryHasIWAD(const char *a1, const char *a2)
{
void *v4; // rbx
bool v5; // al
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
void *v11; // rbp

v4 = (void *)((__int64 (*)(void))M_FileCaseExists)();
v5 = DirIsFile(a1, a2);
v6 = 0;
v7 = v4 == 0LL;
if ( !v4 || (v6 = 0, v7 = !v5) )
{
v8 = ".";
v9 = 2LL;
v10 = a1;
do
{
if ( !v9 )
break;
v6 = *v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
if ( (!v6 && !v7) == v6 )
v11 = (void *)M_StringDuplicate(a2, v10);
else
v11 = (void *)M_StringJoin(a1, "/", a2);
free(v4);
v4 = (void *)M_FileCaseExists(v11);
free(v11);
}
return v4;
}

canonical_decompiled_code:
void *__fastcall func8(const char *a1, const char *a2)
{
void *v4; // rbx
bool v5; // al
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
const char *v10; // rsi
void *v11; // rbp

v4 = (void *)((__int64 (*)(void))M_FileCaseExists)();
v5 = func7(a1, a2);
v6 = 0;
v7 = v4 == 0LL;
if ( !v4 || (v6 = 0, v7 = !v5) )
{
v8 = ".";
v9 = 2LL;
v10 = a1;
do
{
if ( !v9 )
break;
v6 = *v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
if ( (!v6 && !v7) == v6 )
v11 = (void *)M_StringDuplicate(a2, v10);
else
v11 = (void *)M_StringJoin(a1, "/", a2);
free(v4);
v4 = (void *)M_FileCaseExists(v11);
free(v11);
}
return v4;
}

original_code:
static char *CheckDirectoryHasIWAD(char *dir, char *iwadname)
{
    char *filename;
    char *probe = M_FileCaseExists(dir);
    if (DirIsFile(dir, iwadname) && probe)
        return probe;
    if (!strcmp(dir, "."))
        filename = M_StringDuplicate(iwadname);
    else
        filename = M_StringJoin(dir, "/", iwadname, ".wad", ((void *)0));
    free(probe);
    probe = M_FileCaseExists(filename);
    free(filename);
    return probe;
}

variable_types:
dir
char *

variable_types:
iwadname
char *

variable_types:
probe
char *

return_type: char *


SearchDirectoryForIWAD

decompiled_code:
void *__fastcall SearchDirectoryForIWAD(const char *a1)
{
__int64 v1; // rbx
void *result; // rax

v1 = 0LL;
while ( 1 )
{
result = CheckDirectoryHasIWAD(a1, (&iwads)[2 * v1]);
if ( result )
break;
if ( ++v1 == 8 )
return result;
}
gamemission = dword_1888[4 * v1];
return result;
}

canonical_decompiled_code:
void *__fastcall func9(const char *a1)
{
__int64 v1; // rbx
void *result; // rax

v1 = 0LL;
while ( 1 )
{
result = func8(a1, (&iwads)[2 * v1]);
if ( result )
break;
if ( ++v1 == 8 )
return result;
}
gamemission = dword_1888[4 * v1];
return result;
}

original_code:
static char *SearchDirectoryForIWAD(char *dir)
{
    for (size_t i = 0; i < (sizeof(iwads) / sizeof(*iwads)); i++)
    {
        char *filename = CheckDirectoryHasIWAD(dir, iwads[i].name);
        if (filename)
        {
            gamemission = iwads[i].mission;
            return filename;
        }
    }
    return ((void *)0);
}

canonical_original_code:
static char *SearchDirectoryForIWAD(char *dir)
{
    for (unsigned long i = 0; i < (sizeof(iwads) / sizeof(*iwads)); i++)
    {
        char *filename = CheckDirectoryHasIWAD(dir, iwads[i].name);
        if (filename)
        {
            gamemission = iwads[i].mission;
            return filename;
        }
    }
    return ((void *)0);
}

variable_types:
i
unsigned long


decompiled_code:
__int64 __fastcall D_IdentifyIWADByName(char *s)
{
char *v1; // r12
char *v2; // rax
__int64 v3; // rbp
const char *v4; // rdi
void *v5; // rbx
__int64 result; // rax

v1 = s;
v2 = strrchr(s, 92);
if ( v2 || (v2 = strrchr(s, 47)) != 0LL )
v1 = v2 + 1;
gamemission = 5;
v3 = 0LL;
v4 = "doom2";
while ( 1 )
{
v5 = (void *)M_StringJoin(v4, ".WAD", 0LL);
if ( (unsigned __int8)M_StringCompare(v1, v5) )
break;
free(v5);
++v3;
v4 = (&iwads)[2 * v3];
if ( !*v4 )
goto LABEL_10;
}
gamemission = dword_1888[4 * v3];
free(v5);
LABEL_10:
result = M_StringCompare(v1, "HACX.WAD");
if ( (_BYTE)result )
{
hacx = 1;
}
else
{
result = M_StringCompare(v1, "harmony.wad");
if ( (_BYTE)result || (result = M_StringCompare(v1, "harm1.wad"), (_BYTE)result) )
harmony = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s)
{
char *v1; // r12
char *v2; // rax
__int64 v3; // rbp
const char *v4; // rdi
void *v5; // rbx
__int64 result; // rax

v1 = s;
v2 = strrchr(s, 92);
if ( v2 || (v2 = strrchr(s, 47)) != 0LL )
v1 = v2 + 1;
gamemission = 5;
v3 = 0LL;
v4 = "doom2";
while ( 1 )
{
v5 = (void *)M_StringJoin(v4, ".WAD", 0LL);
if ( (unsigned __int8)M_StringCompare(v1, v5) )
break;
free(v5);
++v3;
v4 = (&iwads)[2 * v3];
if ( !*v4 )
goto LABEL_10;
}
gamemission = dword_1888[4 * v3];
free(v5);
LABEL_10:
result = M_StringCompare(v1, "HACX.WAD");
if ( (_BYTE)result )
{
hacx = 1;
}
else
{
result = M_StringCompare(v1, "harmony.wad");
if ( (_BYTE)result || (result = M_StringCompare(v1, "harm1.wad"), (_BYTE)result) )
harmony = 1;
}
return result;
}

original_code:
void D_IdentifyIWADByName(char *name)
{
    char *p = strrchr(name, '\\');
    if (!p)
        p = strrchr(name, '/');
    if (p)
        name = p + 1;
    gamemission = none;
    for (size_t i = 0; iwads[i].name[0]; i++)
    {
        char *iwad = M_StringJoin(iwads[i].name, ".WAD", ((void *)0));
        if (M_StringCompare(name, iwad))
        {
            gamemission = iwads[i].mission;
            free(iwad);
            break;
        }
        free(iwad);
    }
    if (M_StringCompare(name, "HACX.WAD"))
        hacx = 1;
    else if (M_StringCompare(name, "harmony.wad") || M_StringCompare(name, "harm1.wad"))
        harmony = 1;
}

canonical_original_code:
void D_IdentifyIWADByName(char *name)
{
    char *p = strrchr(name, '\\');
    if (!p)
        p = strrchr(name, '/');
    if (p)
        name = p + 1;
    gamemission = none;
    for (unsigned long i = 0; iwads[i].name[0]; i++)
    {
        char *iwad = M_StringJoin(iwads[i].name, ".WAD", ((void *)0));
        if (M_StringCompare(name, iwad))
        {
            gamemission = iwads[i].mission;
            free(iwad);
            break;
        }
        free(iwad);
    }
    if (M_StringCompare(name, "HACX.WAD"))
        hacx = 1;
    else if (M_StringCompare(name, "harmony.wad") || M_StringCompare(name, "harm1.wad"))
        harmony = 1;
}

variable_types:
name
char *

variable_types:
p
char *

variable_types:
iwad
char *


decompiled_code:
__int64 __fastcall D_FindWADByName(void *a1)
{
void *v1; // r12
void *v3; // rbp
__int64 v4; // rbx

v1 = a1;
if ( !(unsigned __int8)((__int64 (*)(void))M_FileExists)() )
{
v3 = (void *)M_StringJoin(a1, ".WAD", 0LL);
if ( (unsigned __int8)M_FileExists(v3) )
{
v1 = v3;
}
else
{
BuildIWADDirList();
if ( num_iwad_dirs <= 0 )
{
LABEL_12:
free(v3);
v1 = 0LL;
}
else
{
v4 = 0LL;
while ( 1 )
{
if ( (unsigned __int8)M_StringEndsWith(iwad_dirs[v4], a1) && (unsigned __int8)M_FileExists(iwad_dirs[v4]) )
return M_StringDuplicate(iwad_dirs[(int)v4], a1);
free(v3);
v3 = (void *)M_StringJoin(iwad_dirs[v4], "/", a1);
if ( (unsigned __int8)M_FileExists(v3) )
break;
if ( num_iwad_dirs <= (int)++v4 )
goto LABEL_12;
}
v1 = v3;
}
}
}
return (__int64)v1;
}

canonical_decompiled_code:
__int64 __fastcall func11(void *a1)
{
void *v1; // r12
void *v3; // rbp
__int64 v4; // rbx

v1 = a1;
if ( !(unsigned __int8)((__int64 (*)(void))M_FileExists)() )
{
v3 = (void *)M_StringJoin(a1, ".WAD", 0LL);
if ( (unsigned __int8)M_FileExists(v3) )
{
v1 = v3;
}
else
{
func6();
if ( num_iwad_dirs <= 0 )
{
LABEL_12:
free(v3);
v1 = 0LL;
}
else
{
v4 = 0LL;
while ( 1 )
{
if ( (unsigned __int8)M_StringEndsWith(iwad_dirs[v4], a1) && (unsigned __int8)M_FileExists(iwad_dirs[v4]) )
return M_StringDuplicate(iwad_dirs[(int)v4], a1);
free(v3);
v3 = (void *)M_StringJoin(iwad_dirs[v4], "/", a1);
if ( (unsigned __int8)M_FileExists(v3) )
break;
if ( num_iwad_dirs <= (int)++v4 )
goto LABEL_12;
}
v1 = v3;
}
}
}
return (__int64)v1;
}

original_code:
char *D_FindWADByName(char *filename)
{
    char *path;
    if (M_FileExists(filename))
        return filename;
    path = M_StringJoin(filename, ".WAD", ((void *)0));
    if (M_FileExists(path))
        return path;
    BuildIWADDirList();
    for (int i = 0; i < num_iwad_dirs; i++)
    {
        if (M_StringEndsWith(iwad_dirs[i], filename) && M_FileExists(iwad_dirs[i]))
            return M_StringDuplicate(iwad_dirs[i]);
        free(path);
        path = M_StringJoin(iwad_dirs[i], "/", filename, ((void *)0));
        if (M_FileExists(path))
            return path;
    }
    free(path);
    return ((void *)0);
}

variable_types: i int


decompiled_code:
void __fastcall D_InitWADfolder(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

BuildIWADDirList();
if ( num_iwad_dirs > 0 )
{
v2 = 0LL;
while ( !(unsigned __int8)M_FolderExists(iwad_dirs[v2]) )
{
if ( num_iwad_dirs <= (int)++v2 )
return;
}
wadfolder = M_StringDuplicate(iwad_dirs[(int)v2], a2);
}
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

func6();
if ( num_iwad_dirs > 0 )
{
v2 = 0LL;
while ( !(unsigned __int8)M_FolderExists(iwad_dirs[v2]) )
{
if ( num_iwad_dirs <= (int)++v2 )
return;
}
wadfolder = M_StringDuplicate(iwad_dirs[(int)v2], a2);
}
}

original_code:
void D_InitWADfolder(void)
{
    BuildIWADDirList();
    for (int i = 0; i < num_iwad_dirs; i++)
        if (M_FolderExists(iwad_dirs[i]))
        {
            wadfolder = M_StringDuplicate(iwad_dirs[i]);
            break;
        }
}

canonical_original_code:
void D_InitWADfolder()
{
    BuildIWADDirList();
    for (int i = 0; i < num_iwad_dirs; i++)
        if (M_FolderExists(iwad_dirs[i]))
        {
            wadfolder = M_StringDuplicate(iwad_dirs[i]);
            break;
        }
}


decompiled_code:
__int64 __fastcall D_TryFindWADByName(void *a1)
{
__int64 result; // rax

result = D_FindWADByName(a1);
if ( !result )
result = (__int64)a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func13(void *a1)
{
__int64 result; // rax

result = func11(a1);
if ( !result )
result = (__int64)a1;
return result;
}

original_code:
char *D_TryFindWADByName(char *filename)
{
    char *result = D_FindWADByName(filename);
    return (result ? result : filename);
}

variable_types:
result
char *


decompiled_code:
char *D_FindIWAD()
{
int v0; // eax
void *v1; // rbp
char *v2; // rbx
__int64 v4; // rbp

v0 = M_CheckParmWithArgs("-iwad", 1LL);
if ( v0 )
{
v1 = *(void **)(myargv + 8LL * v0 + 8);
v2 = (char *)D_FindWADByName(v1);
if ( !v2 )
I_Error("The IWAD file \"%s\" wasn't found!", (const char *)v1);
D_IdentifyIWADByName(v2);
}
else
{
BuildIWADDirList();
v4 = 0LL;
while ( num_iwad_dirs > (int)v4 )
{
v2 = (char *)SearchDirectoryForIWAD((const char *)iwad_dirs[v4++]);
if ( v2 )
return v2;
}
v2 = 0LL;
}
return v2;
}

canonical_decompiled_code:
char *func14()
{
int v0; // eax
void *v1; // rbp
char *v2; // rbx
__int64 v4; // rbp

v0 = M_CheckParmWithArgs("-iwad", 1LL);
if ( v0 )
{
v1 = *(void **)(myargv + 8LL * v0 + 8);
v2 = (char *)func11(v1);
if ( !v2 )
I_Error("The IWAD file \"%s\" wasn't found!", (const char *)v1);
func10(v2);
}
else
{
func6();
v4 = 0LL;
while ( num_iwad_dirs > (int)v4 )
{
v2 = (char *)func9((const char *)iwad_dirs[v4++]);
if ( v2 )
return v2;
}
v2 = 0LL;
}
return v2;
}

original_code:
char *D_FindIWAD(void)
{
    char *result = ((void *)0);
    int iwadparm = M_CheckParmWithArgs("-iwad", 1);
    if (iwadparm)
    {
        char *iwadfile = myargv[iwadparm + 1];
        if (!(result = D_FindWADByName(iwadfile)))
            I_Error("The IWAD file \"%s\" wasn't found!", iwadfile);
        D_IdentifyIWADByName(result);
    }
    else
    {
        BuildIWADDirList();
        for (int i = 0; !result && i < num_iwad_dirs; i++)
            result = SearchDirectoryForIWAD(iwad_dirs[i]);
    }
    return result;
}

canonical_original_code:
char *D_FindIWAD()
{
    char *result = ((void *)0);
    int iwadparm = M_CheckParmWithArgs("-iwad", 1);
    if (iwadparm)
    {
        char *iwadfile = myargv[iwadparm + 1];
        if (!(result = D_FindWADByName(iwadfile)))
            I_Error("The IWAD file \"%s\" wasn't found!", iwadfile);
        D_IdentifyIWADByName(result);
    }
    else
    {
        BuildIWADDirList();
        for (int i = 0; !result && i < num_iwad_dirs; i++)
            result = SearchDirectoryForIWAD(iwad_dirs[i]);
    }
    return result;
}

variable_types: iwadparm int

variable_types:
iwadfile
char *


decompiled_code:
__int64 __fastcall D_SetSaveGameFolder(char a1)
{
int v1; // eax
const char *v2; // rbp
__int64 result; // rax
void *v4; // r12
void *v5; // rbp
__int64 v6; // rax
void *v7; // rsi
const char *v8; // rsi
unsigned int v9; // eax

v1 = M_CheckParmsWithArgs("-save", "-savedir", &unk_169B, 1LL);
if ( v1 )
{
v2 = *(const char **)(myargv + 8LL * v1 + 8);
if ( v2[strlen(v2) - 1] != 47 )
savegamefolder = M_StringJoin(v2, "/", 0LL);
}
else
{
v4 = (void *)M_GetAppDataFolder();
M_MakeDirectory(v4);
v5 = (void *)M_StringJoin(v4, "/savegames/", 0LL);
M_MakeDirectory(v5);
if ( *pwadfile )
{
v6 = GetCorrectCase();
v7 = (void *)removeext(v6);
savegamefolder = M_StringJoin(v5, v7, "/");
free(v7);
}
else
{
v8 = SaveGameIWADName();
savegamefolder = M_StringJoin(v5, v8, "/");
}
free(v4);
free(v5);
}
result = M_MakeDirectory(savegamefolder);
if ( a1 )
{
v9 = M_CountSaveGames();
if ( v9 )
{
if ( v9 == 1 )
result = C_Output(&unk_16B7, savegamefolder);
else
result = C_Output(&unk_17F0, v9);
}
else
{
result = C_Output(&unk_17C8, savegamefolder);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(char a1)
{
int v1; // eax
const char *v2; // rbp
__int64 result; // rax
void *v4; // r12
void *v5; // rbp
__int64 v6; // rax
void *v7; // rsi
const char *v8; // rsi
unsigned int v9; // eax

v1 = M_CheckParmsWithArgs("-save", "-savedir", &unk_169B, 1LL);
if ( v1 )
{
v2 = *(const char **)(myargv + 8LL * v1 + 8);
if ( v2[strlen(v2) - 1] != 47 )
savegamefolder = M_StringJoin(v2, "/", 0LL);
}
else
{
v4 = (void *)M_GetAppDataFolder();
M_MakeDirectory(v4);
v5 = (void *)M_StringJoin(v4, "/savegames/", 0LL);
M_MakeDirectory(v5);
if ( *pwadfile )
{
v6 = GetCorrectCase();
v7 = (void *)removeext(v6);
savegamefolder = M_StringJoin(v5, v7, "/");
free(v7);
}
else
{
v8 = func1();
savegamefolder = M_StringJoin(v5, v8, "/");
}
free(v4);
free(v5);
}
result = M_MakeDirectory(savegamefolder);
if ( a1 )
{
v9 = M_CountSaveGames();
if ( v9 )
{
if ( v9 == 1 )
result = C_Output(&unk_16B7, savegamefolder);
else
result = C_Output(&unk_17F0, v9);
}
else
{
result = C_Output(&unk_17C8, savegamefolder);
}
}
return result;
}

original_code:
void D_SetSaveGameFolder(_Bool output)
{
    const int p = M_CheckParmsWithArgs("-save", "-savedir", "", 1);
    if (p)
    {
        if (myargv[p + 1][strlen(myargv[p + 1]) - 1] != '/')
            savegamefolder = M_StringJoin(myargv[p + 1], "/", ((void *)0));
    }
    else
    {
        char *appdatafolder = M_GetAppDataFolder();
        char *tempsavegamefolder;
        M_MakeDirectory(appdatafolder);
        tempsavegamefolder = M_StringJoin(appdatafolder,
            "/" "savegames" "/", ((void *)0));
        M_MakeDirectory(tempsavegamefolder);
        if (*pwadfile)
        {
            char *temp = removeext(GetCorrectCase(pwadfile));
            savegamefolder = M_StringJoin(tempsavegamefolder, temp, "/", ((void *)0));
            free(temp);
        }
        else
            savegamefolder = M_StringJoin(tempsavegamefolder, SaveGameIWADName(), "/", ((void *)0));
        free(appdatafolder);
        free(tempsavegamefolder);
    }
    M_MakeDirectory(savegamefolder);
    if (output)
    {
        const int numsavegames = M_CountSaveGames();
        if (!numsavegames)
            C_Output("All savegames will be placed in " "\x1A" "%s" "\x1B" ".", savegamefolder);
        else if (numsavegames == 1)
            C_Output("There is 1 savegame in " "\x1A" "%s" "\x1B" ".", savegamefolder);
        else
            C_Output("There are %i savegames in " "\x1A" "%s" "\x1B" ".", numsavegames, savegamefolder);
    }
}

canonical_original_code:
void D_SetSaveGameFolder(_Bool output)
{
    int p = M_CheckParmsWithArgs("-save", "-savedir", "", 1);
    if (p)
    {
        if (myargv[p + 1][strlen(myargv[p + 1]) - 1] != '/')
            savegamefolder = M_StringJoin(myargv[p + 1], "/", ((void *)0));
    }
    else
    {
        char *appdatafolder = M_GetAppDataFolder();
        char *tempsavegamefolder;
        M_MakeDirectory(appdatafolder);
        tempsavegamefolder = M_StringJoin(appdatafolder,
            "/" "savegames" "/", ((void *)0));
        M_MakeDirectory(tempsavegamefolder);
        if (*pwadfile)
        {
            char *temp = removeext(GetCorrectCase(pwadfile));
            savegamefolder = M_StringJoin(tempsavegamefolder, temp, "/", ((void *)0));
            free(temp);
        }
        else
            savegamefolder = M_StringJoin(tempsavegamefolder, SaveGameIWADName(), "/", ((void *)0));
        free(appdatafolder);
        free(tempsavegamefolder);
    }
    M_MakeDirectory(savegamefolder);
    if (output)
    {
        int numsavegames = M_CountSaveGames();
        if (!numsavegames)
            C_Output("All savegames will be placed in " "\x1A" "%s" "\x1B" ".", savegamefolder);
        else if (numsavegames == 1)
            C_Output("There is 1 savegame in " "\x1A" "%s" "\x1B" ".", savegamefolder);
        else
            C_Output("There are %i savegames in " "\x1A" "%s" "\x1B" ".", numsavegames, savegamefolder);
    }
}

variable_types: p int

variable_types:
appdatafolder
char *

variable_types:
tempsavegamefolder
char *

variable_types:
temp
char *

variable_types: numsavegames int


decompiled_code:
void D_SetAutoloadFolder()
{
int v0; // eax
const char *v1; // rsi
void *v2; // rbx
__int64 v3; // rax
void *v4; // rbx

v0 = M_CheckParmsWithArgs("-autoload", "-autoloaddir", &unk_169B, 1LL);
if ( v0 )
{
M_StringCopy(autoloadfolder, *(_QWORD *)(myargv + 8LL * v0 + 8), 8LL);
}
else
{
v2 = (void *)M_GetAppDataFolder();
M_MakeDirectory(v2);
autoloadfolder = M_StringJoin(v2, "/autoload/", 0LL);
free(v2);
}
M_MakeDirectory(autoloadfolder);
v1 = SaveGameIWADName();
autoloadiwadsubfolder = M_StringJoin(autoloadfolder, v1, "/");
M_MakeDirectory(autoloadiwadsubfolder);
if ( *pwadfile )
{
v3 = GetCorrectCase();
v4 = (void *)removeext(v3);
autoloadpwadsubfolder = M_StringJoin(autoloadfolder, v4, "/");
M_MakeDirectory(autoloadpwadsubfolder);
free(v4);
}
}

canonical_decompiled_code:
void func16()
{
int v0; // eax
const char *v1; // rsi
void *v2; // rbx
__int64 v3; // rax
void *v4; // rbx

v0 = M_CheckParmsWithArgs("-autoload", "-autoloaddir", &unk_169B, 1LL);
if ( v0 )
{
M_StringCopy(autoloadfolder, *(_QWORD *)(myargv + 8LL * v0 + 8), 8LL);
}
else
{
v2 = (void *)M_GetAppDataFolder();
M_MakeDirectory(v2);
autoloadfolder = M_StringJoin(v2, "/autoload/", 0LL);
free(v2);
}
M_MakeDirectory(autoloadfolder);
v1 = func1();
autoloadiwadsubfolder = M_StringJoin(autoloadfolder, v1, "/");
M_MakeDirectory(autoloadiwadsubfolder);
if ( *pwadfile )
{
v3 = GetCorrectCase();
v4 = (void *)removeext(v3);
autoloadpwadsubfolder = M_StringJoin(autoloadfolder, v4, "/");
M_MakeDirectory(autoloadpwadsubfolder);
free(v4);
}
}

original_code:
void D_SetAutoloadFolder(void)
{
    const int p = M_CheckParmsWithArgs("-autoload", "-autoloaddir", "", 1);
    if (p)
        M_StringCopy(autoloadfolder, myargv[p + 1], sizeof(autoloadfolder));
    else
    {
        char *appdatafolder = M_GetAppDataFolder();
        M_MakeDirectory(appdatafolder);
        autoloadfolder = M_StringJoin(appdatafolder,
            "/" "autoload" "/", ((void *)0));
        free(appdatafolder);
    }
    M_MakeDirectory(autoloadfolder);
    autoloadiwadsubfolder = M_StringJoin(autoloadfolder, SaveGameIWADName(), "/", ((void *)0));
    M_MakeDirectory(autoloadiwadsubfolder);
    if (*pwadfile)
    {
        char *temp = removeext(GetCorrectCase(pwadfile));
        autoloadpwadsubfolder = M_StringJoin(autoloadfolder, temp, "/", ((void *)0));
        M_MakeDirectory(autoloadpwadsubfolder);
        free(temp);
    }
}

canonical_original_code:
void D_SetAutoloadFolder()
{
    int p = M_CheckParmsWithArgs("-autoload", "-autoloaddir", "", 1);
    if (p)
        M_StringCopy(autoloadfolder, myargv[p + 1], sizeof(autoloadfolder));
    else
    {
        char *appdatafolder = M_GetAppDataFolder();
        M_MakeDirectory(appdatafolder);
        autoloadfolder = M_StringJoin(appdatafolder,
            "/" "autoload" "/", ((void *)0));
        free(appdatafolder);
    }
    M_MakeDirectory(autoloadfolder);
    autoloadiwadsubfolder = M_StringJoin(autoloadfolder, SaveGameIWADName(), "/", ((void *)0));
    M_MakeDirectory(autoloadiwadsubfolder);
    if (*pwadfile)
    {
        char *temp = removeext(GetCorrectCase(pwadfile));
        autoloadpwadsubfolder = M_StringJoin(autoloadfolder, temp, "/", ((void *)0));
        M_MakeDirectory(autoloadpwadsubfolder);
        free(temp);
    }
}


decompiled_code:
__int64 D_SetScreenshotsFolder()
{
int v0; // eax
char *v2; // rbx

v0 = M_CheckParmsWithArgs("-shot", "-shotdir", &unk_169B, 1LL);
if ( v0 )
{
M_StringCopy(&screenshotfolder, *(_QWORD *)(myargv + 8LL * v0 + 8), 260LL);
}
else
{
v2 = (char *)M_GetAppDataFolder();
M_snprintf(&screenshotfolder, 260LL, "%s/screenshots/", v2);
free(v2);
}
M_MakeDirectory(&screenshotfolder);
return C_Output(&unk_1810, &screenshotfolder);
}

canonical_decompiled_code:
__int64 func17()
{
int v0; // eax
char *v2; // rbx

v0 = M_CheckParmsWithArgs("-shot", "-shotdir", &unk_169B, 1LL);
if ( v0 )
{
M_StringCopy(&screenshotfolder, *(_QWORD *)(myargv + 8LL * v0 + 8), 260LL);
}
else
{
v2 = (char *)M_GetAppDataFolder();
M_snprintf(&screenshotfolder, 260LL, "%s/screenshots/", v2);
free(v2);
}
M_MakeDirectory(&screenshotfolder);
return C_Output(&unk_1810, &screenshotfolder);
}

original_code:
void D_SetScreenshotsFolder(void)
{
    const int p = M_CheckParmsWithArgs("-shot", "-shotdir", "", 1);
    if (p)
        M_StringCopy(screenshotfolder, myargv[p + 1], sizeof(screenshotfolder));
    else
    {
        char *appdatafolder = M_GetAppDataFolder();
        M_snprintf(screenshotfolder, sizeof(screenshotfolder),
            "%s" "/" "screenshots" "/", appdatafolder);
        free(appdatafolder);
    }
    M_MakeDirectory(screenshotfolder);
    C_Output("All screenshots taken will be placed in " "\x1A" "%s" "\x1B" ".", screenshotfolder);
}

canonical_original_code:
void D_SetScreenshotsFolder()
{
    int p = M_CheckParmsWithArgs("-shot", "-shotdir", "", 1);
    if (p)
        M_StringCopy(screenshotfolder, myargv[p + 1], sizeof(screenshotfolder));
    else
    {
        char *appdatafolder = M_GetAppDataFolder();
        M_snprintf(screenshotfolder, sizeof(screenshotfolder),
            "%s" "/" "screenshots" "/", appdatafolder);
        free(appdatafolder);
    }
    M_MakeDirectory(screenshotfolder);
    C_Output("All screenshots taken will be placed in " "\x1A" "%s" "\x1B" ".", screenshotfolder);
}


decompiled_code:
void D_IdentifyVersion()
{
if ( gamemission == 5 )
{
if ( (int)W_CheckNumForName("MAP01") >= 0 )
{
gamemission = 1;
goto LABEL_3;
}
if ( (int)W_CheckNumForName("E1M1") >= 0 )
{
gamemission = 0;
goto LABEL_8;
}
I_Error("Unknown or invalid IWAD file.");
}
if ( gamemission )
{
LABEL_3:
gamemode = 2;
return;
}
LABEL_8:
if ( (int)W_CheckNumForName("E4M1") < 0 )
gamemode = (int)W_CheckNumForName("E3M1") >= 0;
else
gamemode = 3;
}

canonical_decompiled_code:
void func18()
{
if ( gamemission == 5 )
{
if ( (int)W_CheckNumForName("MAP01") >= 0 )
{
gamemission = 1;
goto LABEL_3;
}
if ( (int)W_CheckNumForName("E1M1") >= 0 )
{
gamemission = 0;
goto LABEL_8;
}
I_Error("Unknown or invalid IWAD file.");
}
if ( gamemission )
{
LABEL_3:
gamemode = 2;
return;
}
LABEL_8:
if ( (int)W_CheckNumForName("E4M1") < 0 )
gamemode = (int)W_CheckNumForName("E3M1") >= 0;
else
gamemode = 3;
}

original_code:
void D_IdentifyVersion(void)
{
    if (gamemission == none)
    {
        if (W_CheckNumForName("MAP01") >= 0)
            gamemission = doom2;
        else if (W_CheckNumForName("E1M1") >= 0)
            gamemission = doom;
        else
            I_Error("Unknown or invalid IWAD file.");
    }
    if (gamemission == doom)
    {
        if (W_CheckNumForName("E4M1") >= 0)
            gamemode = retail;
        else if (W_CheckNumForName("E3M1") >= 0)
            gamemode = registered;
        else
            gamemode = shareware;
    }
    else
        gamemode = commercial;
}

canonical_original_code:
void D_IdentifyVersion()
{
    if (gamemission == none)
    {
        if (W_CheckNumForName("MAP01") >= 0)
            gamemission = doom2;
        else if (W_CheckNumForName("E1M1") >= 0)
            gamemission = doom;
        else
            I_Error("Unknown or invalid IWAD file.");
    }
    if (gamemission == doom)
    {
        if (W_CheckNumForName("E4M1") >= 0)
            gamemode = retail;
        else if (W_CheckNumForName("E3M1") >= 0)
            gamemode = registered;
        else
            gamemode = shareware;
    }
    else
        gamemode = commercial;
}


decompiled_code:
__int64 D_SetGameDescription()
{
char v0; // bl
const char *v1; // rsi
__int64 v3; // rax
__int64 v4; // rsi
size_t v5; // rax
const char *v6; // rsi

v0 = M_StringCompare(playername, "you");
if ( chex1 )
{
M_StringCopy(&gamedescription, s_CAPTION_CHEX, 255LL);
goto LABEL_27;
}
if ( chex2 )
{
M_StringCopy(&gamedescription, s_CAPTION_CHEX2, 255LL);
goto LABEL_27;
}
if ( hacx )
{
M_StringCopy(&gamedescription, s_CAPTION_HACX, 255LL);
goto LABEL_27;
}
if ( BTSXE1 )
{
M_StringCopy(&gamedescription, s_CAPTION_BTSXE1, 255LL);
goto LABEL_27;
}
if ( BTSXE2 )
{
M_StringCopy(&gamedescription, s_CAPTION_BTSXE2, 255LL);
goto LABEL_27;
}
if ( BTSXE3 )
{
M_StringCopy(&gamedescription, s_CAPTION_BTSXE3, 255LL);
goto LABEL_27;
}
if ( REKKRSL )
{
M_StringCopy(&gamedescription, s_CAPTION_REKKRSL, 255LL);
goto LABEL_27;
}
if ( REKKR )
{
M_StringCopy(&gamedescription, s_CAPTION_REKKR, 255LL);
goto LABEL_27;
}
if ( anomalyreport )
{
M_StringCopy(&gamedescription, s_CAPTION_ANOMALYREPORT, 255LL);
goto LABEL_27;
}
if ( arrival )
{
M_StringCopy(&gamedescription, s_CAPTION_ARRIVAL, 255LL);
goto LABEL_27;
}
if ( dbimpact )
{
M_StringCopy(&gamedescription, s_CAPTION_DBIMPACT, 255LL);
goto LABEL_27;
}
if ( deathless )
{
M_StringCopy(&gamedescription, s_CAPTION_DEATHLESS, 255LL);
goto LABEL_27;
}
if ( doomzero )
{
M_StringCopy(&gamedescription, s_CAPTION_DOOMZERO, 255LL);
goto LABEL_27;
}
if ( earthless )
{
M_StringCopy(&gamedescription, s_CAPTION_EARTHLESS, 255LL);
goto LABEL_27;
}
if ( ganymede )
{
M_StringCopy(&gamedescription, s_CAPTION_GANYMEDE, 255LL);
goto LABEL_27;
}
if ( harmony )
{
M_StringCopy(&gamedescription, s_CAPTION_HARMONY, 255LL);
goto LABEL_27;
}
if ( KDIKDIZD )
{
M_StringCopy(&gamedescription, s_CAPTION_KDIKDIZD, 255LL);
goto LABEL_27;
}
if ( neis )
{
M_StringCopy(&gamedescription, s_CAPTION_NEIS, 255LL);
goto LABEL_27;
}
if ( revolution )
{
M_StringCopy(&gamedescription, s_CAPTION_REVOLUTION, 255LL);
goto LABEL_27;
}
if ( syringe )
{
M_StringCopy(&gamedescription, s_CAPTION_SYRINGE, 255LL);
goto LABEL_27;
}
if ( !gamemission )
{
if ( !modifiedgame || !*pwadfile )
{
if ( FREEDOOM )
M_StringCopy(&gamedescription, s_CAPTION_FREEDOOM1, 255LL);
else
M_StringCopy(&gamedescription, s_CAPTION_DOOM, 255LL);
goto LABEL_27;
}
LABEL_50:
v3 = GetCorrectCase(pwadfile);
return M_StringCopy(&gamedescription, v3, 255LL);
}
if ( modifiedgame && *pwadfile )
{
if ( !(unsigned __int8)M_StringCompare(pwadfile, "nerve.wad") )
goto LABEL_50;
goto LABEL_59;
}
if ( FREEDOOM )
{
v4 = s_CAPTION_FREEDOOM2;
if ( FREEDM )
v4 = s_CAPTION_FREEDM;
M_StringCopy(&gamedescription, v4, 255LL);
goto LABEL_27;
}
if ( nerve )
{
LABEL_59:
M_StringCopy(&gamedescription, s_CAPTION_DOOM2, 255LL);
goto LABEL_27;
}
switch ( gamemission )
{
case 1:
M_snprintf(&gamedescription, 255LL, "%s: %s", s_CAPTION_DOOM2, s_CAPTION_HELLONEARTH);
break;
case 3:
M_StringCopy(&gamedescription, s_CAPTION_PLUTONIA, 255LL);
break;
case 2:
M_StringCopy(&gamedescription, s_CAPTION_TNT, 255LL);
break;
default:
goto LABEL_65;
}
LABEL_27:
if ( nerve )
{
if ( v0 )
v1 = "You";
else
v1 = (const char *)playername;
return C_Output(&unk_1840, v1);
}
LABEL_65:
v5 = strlen(&gamedescription);
ispunctuation((unsigned int)*(&gamedescription + v5 - 1));
if ( v0 )
v6 = "You";
else
v6 = (const char *)playername;
return C_Output(&unk_1768, v6);
}

canonical_decompiled_code:
__int64 func19()
{
char v0; // bl
const char *v1; // rsi
__int64 v3; // rax
__int64 v4; // rsi
size_t v5; // rax
const char *v6; // rsi

v0 = M_StringCompare(playername, "you");
if ( chex1 )
{
M_StringCopy(&gamedescription, s_CAPTION_CHEX, 255LL);
goto LABEL_27;
}
if ( chex2 )
{
M_StringCopy(&gamedescription, s_CAPTION_CHEX2, 255LL);
goto LABEL_27;
}
if ( hacx )
{
M_StringCopy(&gamedescription, s_CAPTION_HACX, 255LL);
goto LABEL_27;
}
if ( BTSXE1 )
{
M_StringCopy(&gamedescription, s_CAPTION_BTSXE1, 255LL);
goto LABEL_27;
}
if ( BTSXE2 )
{
M_StringCopy(&gamedescription, s_CAPTION_BTSXE2, 255LL);
goto LABEL_27;
}
if ( BTSXE3 )
{
M_StringCopy(&gamedescription, s_CAPTION_BTSXE3, 255LL);
goto LABEL_27;
}
if ( REKKRSL )
{
M_StringCopy(&gamedescription, s_CAPTION_REKKRSL, 255LL);
goto LABEL_27;
}
if ( REKKR )
{
M_StringCopy(&gamedescription, s_CAPTION_REKKR, 255LL);
goto LABEL_27;
}
if ( anomalyreport )
{
M_StringCopy(&gamedescription, s_CAPTION_ANOMALYREPORT, 255LL);
goto LABEL_27;
}
if ( arrival )
{
M_StringCopy(&gamedescription, s_CAPTION_ARRIVAL, 255LL);
goto LABEL_27;
}
if ( dbimpact )
{
M_StringCopy(&gamedescription, s_CAPTION_DBIMPACT, 255LL);
goto LABEL_27;
}
if ( deathless )
{
M_StringCopy(&gamedescription, s_CAPTION_DEATHLESS, 255LL);
goto LABEL_27;
}
if ( doomzero )
{
M_StringCopy(&gamedescription, s_CAPTION_DOOMZERO, 255LL);
goto LABEL_27;
}
if ( earthless )
{
M_StringCopy(&gamedescription, s_CAPTION_EARTHLESS, 255LL);
goto LABEL_27;
}
if ( ganymede )
{
M_StringCopy(&gamedescription, s_CAPTION_GANYMEDE, 255LL);
goto LABEL_27;
}
if ( harmony )
{
M_StringCopy(&gamedescription, s_CAPTION_HARMONY, 255LL);
goto LABEL_27;
}
if ( KDIKDIZD )
{
M_StringCopy(&gamedescription, s_CAPTION_KDIKDIZD, 255LL);
goto LABEL_27;
}
if ( neis )
{
M_StringCopy(&gamedescription, s_CAPTION_NEIS, 255LL);
goto LABEL_27;
}
if ( revolution )
{
M_StringCopy(&gamedescription, s_CAPTION_REVOLUTION, 255LL);
goto LABEL_27;
}
if ( syringe )
{
M_StringCopy(&gamedescription, s_CAPTION_SYRINGE, 255LL);
goto LABEL_27;
}
if ( !gamemission )
{
if ( !modifiedgame || !*pwadfile )
{
if ( FREEDOOM )
M_StringCopy(&gamedescription, s_CAPTION_FREEDOOM1, 255LL);
else
M_StringCopy(&gamedescription, s_CAPTION_DOOM, 255LL);
goto LABEL_27;
}
LABEL_50:
v3 = GetCorrectCase(pwadfile);
return M_StringCopy(&gamedescription, v3, 255LL);
}
if ( modifiedgame && *pwadfile )
{
if ( !(unsigned __int8)M_StringCompare(pwadfile, "nerve.wad") )
goto LABEL_50;
goto LABEL_59;
}
if ( FREEDOOM )
{
v4 = s_CAPTION_FREEDOOM2;
if ( FREEDM )
v4 = s_CAPTION_FREEDM;
M_StringCopy(&gamedescription, v4, 255LL);
goto LABEL_27;
}
if ( nerve )
{
LABEL_59:
M_StringCopy(&gamedescription, s_CAPTION_DOOM2, 255LL);
goto LABEL_27;
}
switch ( gamemission )
{
case 1:
M_snprintf(&gamedescription, 255LL, "%s: %s", s_CAPTION_DOOM2, s_CAPTION_HELLONEARTH);
break;
case 3:
M_StringCopy(&gamedescription, s_CAPTION_PLUTONIA, 255LL);
break;
case 2:
M_StringCopy(&gamedescription, s_CAPTION_TNT, 255LL);
break;
default:
goto LABEL_65;
}
LABEL_27:
if ( nerve )
{
if ( v0 )
v1 = "You";
else
v1 = (const char *)playername;
return C_Output(&unk_1840, v1);
}
LABEL_65:
v5 = strlen(&gamedescription);
ispunctuation((unsigned int)*(&gamedescription + v5 - 1));
if ( v0 )
v6 = "You";
else
v6 = (const char *)playername;
return C_Output(&unk_1768, v6);
}

original_code:
void D_SetGameDescription(void)
{
    _Bool defaultname = M_StringCompare(playername, "you");
    if (chex1)
        M_StringCopy(gamedescription, s_CAPTION_CHEX, sizeof(gamedescription));
    else if (chex2)
        M_StringCopy(gamedescription, s_CAPTION_CHEX2, sizeof(gamedescription));
    else if (hacx)
        M_StringCopy(gamedescription, s_CAPTION_HACX, sizeof(gamedescription));
    else if (BTSXE1)
        M_StringCopy(gamedescription, s_CAPTION_BTSXE1, sizeof(gamedescription));
    else if (BTSXE2)
        M_StringCopy(gamedescription, s_CAPTION_BTSXE2, sizeof(gamedescription));
    else if (BTSXE3)
        M_StringCopy(gamedescription, s_CAPTION_BTSXE3, sizeof(gamedescription));
    else if (REKKRSL)
        M_StringCopy(gamedescription, s_CAPTION_REKKRSL, sizeof(gamedescription));
    else if (REKKR)
        M_StringCopy(gamedescription, s_CAPTION_REKKR, sizeof(gamedescription));
    else if (anomalyreport)
        M_StringCopy(gamedescription, s_CAPTION_ANOMALYREPORT, sizeof(gamedescription));
    else if (arrival)
        M_StringCopy(gamedescription, s_CAPTION_ARRIVAL, sizeof(gamedescription));
    else if (dbimpact)
        M_StringCopy(gamedescription, s_CAPTION_DBIMPACT, sizeof(gamedescription));
    else if (deathless)
        M_StringCopy(gamedescription, s_CAPTION_DEATHLESS, sizeof(gamedescription));
    else if (doomzero)
        M_StringCopy(gamedescription, s_CAPTION_DOOMZERO, sizeof(gamedescription));
    else if (earthless)
        M_StringCopy(gamedescription, s_CAPTION_EARTHLESS, sizeof(gamedescription));
    else if (ganymede)
        M_StringCopy(gamedescription, s_CAPTION_GANYMEDE, sizeof(gamedescription));
    else if (harmony)
        M_StringCopy(gamedescription, s_CAPTION_HARMONY, sizeof(gamedescription));
    else if (KDIKDIZD)
        M_StringCopy(gamedescription, s_CAPTION_KDIKDIZD, sizeof(gamedescription));
    else if (neis)
        M_StringCopy(gamedescription, s_CAPTION_NEIS, sizeof(gamedescription));
    else if (revolution)
        M_StringCopy(gamedescription, s_CAPTION_REVOLUTION, sizeof(gamedescription));
    else if (syringe)
        M_StringCopy(gamedescription, s_CAPTION_SYRINGE, sizeof(gamedescription));
    else if (gamemission == doom)
    {
        if (modifiedgame && *pwadfile)
        {
            M_StringCopy(gamedescription, GetCorrectCase(pwadfile), sizeof(gamedescription));
            return;
        }
        else if (FREEDOOM)
            M_StringCopy(gamedescription, s_CAPTION_FREEDOOM1, sizeof(gamedescription));
        else
            M_StringCopy(gamedescription, s_CAPTION_DOOM, sizeof(gamedescription));
    }
    else
    {
        if (modifiedgame && *pwadfile)
        {
            if (M_StringCompare(pwadfile, "nerve.wad"))
                M_StringCopy(gamedescription, s_CAPTION_DOOM2, sizeof(gamedescription));
            else
            {
                M_StringCopy(gamedescription, GetCorrectCase(pwadfile), sizeof(gamedescription));
                return;
            }
        }
        else if (FREEDOOM)
            M_StringCopy(gamedescription, (FREEDM ? s_CAPTION_FREEDM : s_CAPTION_FREEDOOM2), sizeof(gamedescription));
        else if (nerve)
            M_StringCopy(gamedescription, s_CAPTION_DOOM2, sizeof(gamedescription));
        else if (gamemission == doom2)
            M_snprintf(gamedescription, sizeof(gamedescription), "%s: %s", s_CAPTION_DOOM2, s_CAPTION_HELLONEARTH);
        else if (gamemission == pack_plut)
            M_StringCopy(gamedescription, s_CAPTION_PLUTONIA, sizeof(gamedescription));
        else if (gamemission == pack_tnt)
            M_StringCopy(gamedescription, s_CAPTION_TNT, sizeof(gamedescription));
    }
    if (nerve)
        C_Output("%s %s playing " "\x1C" "%s: %s" "\x1D" " and " "\x1C" "%s: %s." "\x1D",
            (defaultname ? "You" : playername), (defaultname ? "are" : "is"),
            s_CAPTION_DOOM2, s_CAPTION_HELLONEARTH, s_CAPTION_DOOM2, s_CAPTION_NERVE);
    else
        C_Output("%s %s playing " "\x1C" "%s%s" "\x1D",
            (defaultname ? "You" : playername), (defaultname ? "are" : "is"),
            gamedescription, (ispunctuation(gamedescription[strlen(gamedescription) - 1]) ? "" : "."));
}

canonical_original_code:
void D_SetGameDescription()
{
    _Bool defaultname = M_StringCompare(playername, "you");
    if (chex1)
        M_StringCopy(gamedescription, s_CAPTION_CHEX, sizeof(gamedescription));
    else if (chex2)
        M_StringCopy(gamedescription, s_CAPTION_CHEX2, sizeof(gamedescription));
    else if (hacx)
        M_StringCopy(gamedescription, s_CAPTION_HACX, sizeof(gamedescription));
    else if (BTSXE1)
        M_StringCopy(gamedescription, s_CAPTION_BTSXE1, sizeof(gamedescription));
    else if (BTSXE2)
        M_StringCopy(gamedescription, s_CAPTION_BTSXE2, sizeof(gamedescription));
    else if (BTSXE3)
        M_StringCopy(gamedescription, s_CAPTION_BTSXE3, sizeof(gamedescription));
    else if (REKKRSL)
        M_StringCopy(gamedescription, s_CAPTION_REKKRSL, sizeof(gamedescription));
    else if (REKKR)
        M_StringCopy(gamedescription, s_CAPTION_REKKR, sizeof(gamedescription));
    else if (anomalyreport)
        M_StringCopy(gamedescription, s_CAPTION_ANOMALYREPORT, sizeof(gamedescription));
    else if (arrival)
        M_StringCopy(gamedescription, s_CAPTION_ARRIVAL, sizeof(gamedescription));
    else if (dbimpact)
        M_StringCopy(gamedescription, s_CAPTION_DBIMPACT, sizeof(gamedescription));
    else if (deathless)
        M_StringCopy(gamedescription, s_CAPTION_DEATHLESS, sizeof(gamedescription));
    else if (doomzero)
        M_StringCopy(gamedescription, s_CAPTION_DOOMZERO, sizeof(gamedescription));
    else if (earthless)
        M_StringCopy(gamedescription, s_CAPTION_EARTHLESS, sizeof(gamedescription));
    else if (ganymede)
        M_StringCopy(gamedescription, s_CAPTION_GANYMEDE, sizeof(gamedescription));
    else if (harmony)
        M_StringCopy(gamedescription, s_CAPTION_HARMONY, sizeof(gamedescription));
    else if (KDIKDIZD)
        M_StringCopy(gamedescription, s_CAPTION_KDIKDIZD, sizeof(gamedescription));
    else if (neis)
        M_StringCopy(gamedescription, s_CAPTION_NEIS, sizeof(gamedescription));
    else if (revolution)
        M_StringCopy(gamedescription, s_CAPTION_REVOLUTION, sizeof(gamedescription));
    else if (syringe)
        M_StringCopy(gamedescription, s_CAPTION_SYRINGE, sizeof(gamedescription));
    else if (gamemission == doom)
    {
        if (modifiedgame && *pwadfile)
        {
            M_StringCopy(gamedescription, GetCorrectCase(pwadfile), sizeof(gamedescription));
            return;
        }
        else if (FREEDOOM)
            M_StringCopy(gamedescription, s_CAPTION_FREEDOOM1, sizeof(gamedescription));
        else
            M_StringCopy(gamedescription, s_CAPTION_DOOM, sizeof(gamedescription));
    }
    else
    {
        if (modifiedgame && *pwadfile)
        {
            if (M_StringCompare(pwadfile, "nerve.wad"))
                M_StringCopy(gamedescription, s_CAPTION_DOOM2, sizeof(gamedescription));
            else
            {
                M_StringCopy(gamedescription, GetCorrectCase(pwadfile), sizeof(gamedescription));
                return;
            }
        }
        else if (FREEDOOM)
            M_StringCopy(gamedescription, (FREEDM ? s_CAPTION_FREEDM : s_CAPTION_FREEDOOM2), sizeof(gamedescription));
        else if (nerve)
            M_StringCopy(gamedescription, s_CAPTION_DOOM2, sizeof(gamedescription));
        else if (gamemission == doom2)
            M_snprintf(gamedescription, sizeof(gamedescription), "%s: %s", s_CAPTION_DOOM2, s_CAPTION_HELLONEARTH);
        else if (gamemission == pack_plut)
            M_StringCopy(gamedescription, s_CAPTION_PLUTONIA, sizeof(gamedescription));
        else if (gamemission == pack_tnt)
            M_StringCopy(gamedescription, s_CAPTION_TNT, sizeof(gamedescription));
    }
    if (nerve)
        C_Output("%s %s playing " "\x1C" "%s: %s" "\x1D" " and " "\x1C" "%s: %s." "\x1D",
            (defaultname ? "You" : playername), (defaultname ? "are" : "is"),
            s_CAPTION_DOOM2, s_CAPTION_HELLONEARTH, s_CAPTION_DOOM2, s_CAPTION_NERVE);
    else
        C_Output("%s %s playing " "\x1C" "%s%s" "\x1D",
            (defaultname ? "You" : playername), (defaultname ? "are" : "is"),
            gamedescription, (ispunctuation(gamedescription[strlen(gamedescription) - 1]) ? "" : "."));
}


ABS

decompiled_code:
__int64 __fastcall ABS(int a1)
{
return abs32(a1);
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
return abs32(a1);
}

original_code:
__attribute__((const)) static inline int ABS(int a)
{
    return (a < 0 ? -a : a);
}

variable_types: a int

return_type: int


FixedDiv

decompiled_code:
__int64 __fastcall FixedDiv(int a1, int a2)
{
int v2; // er12
__int64 result; // rax

v2 = ABS(a1);
if ( v2 >> 15 < (int)ABS(a2) )
result = ((__int64)a1 << 16) / a2;
else
result = ((a2 ^ a1) >> 31) ^ 0x7FFFFFFFu;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, int a2)
{
int v2; // er12
__int64 result; // rax

v2 = func0(a1);
if ( v2 >> 15 < (int)func0(a2) )
result = ((__int64)a1 << 16) / a2;
else
result = ((a2 ^ a1) >> 31) ^ 0x7FFFFFFFu;
return result;
}

original_code:
__attribute__((const)) static inline fixed_t FixedDiv(fixed_t a, fixed_t b)
{
    return (((int64_t)ABS(a) >> 15) >= ABS(b) ? (((int64_t)(a ^ b) >> 31) ^ (2147483647)) : (((int64_t)a << 16) / b));
}

canonical_original_code:
static inline int FixedDiv(int a, int b)
{
    return (((long)ABS(a) >> 15) >= ABS(b) ? (((long)(a ^ b) >> 31) ^ (2147483647)) : (((long)a << 16) / b));
}

variable_types: b int