decompiled_code:
char *__fastcall FChecks_RulesetAdditionString(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v4; // rsi
__int64 v6[2]; // [rsp+0h] [rbp-28h] BYREF
char s[8]; // [rsp+10h] [rbp-18h] BYREF
__int64 v8; // [rsp+18h] [rbp-10h]

*(_QWORD *)s = 43LL;
v8 = 0LL;
v6[0] = 45LL;
v6[1] = 0LL;
features_0 = 0;
v4 = (const char *)FMod_Response_Text(a1, a2, a3, a4);
FChecks_RulesetFeatureAppend(strcmp(v4, "all models ok") != 0, (__int64)"m", (__int64)s, 16LL, (__int64)v6, 16LL);
FChecks_RulesetFeatureAppend(allow_scripts[16], (__int64)"s", (__int64)s, 16LL, (__int64)v6, 16LL);
FChecks_RulesetFeatureAppend(enemyforceskins[16], (__int64)"f", (__int64)s, 16LL, (__int64)v6, 16LL);
FChecks_RulesetFeatureAppend(cl_iDrive[16], (__int64)"i", (__int64)s, 16LL, (__int64)v6, 16LL);
if ( strlen(s) > 1 )
strlcat(&features_0, s, 32LL);
if ( strlen((const char *)v6) > 1 )
strlcat(&features_0, v6, 32LL);
return &features_0;
}

canonical_decompiled_code:
char *__fastcall func16(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
const char *v4; // rsi
__int64 v6[2]; // [rsp+0h] [rbp-28h] BYREF
char s[8]; // [rsp+10h] [rbp-18h] BYREF
__int64 v8; // [rsp+18h] [rbp-10h]

*(_QWORD *)s = 43LL;
v8 = 0LL;
v6[0] = 45LL;
v6[1] = 0LL;
features_0 = 0;
v4 = (const char *)FMod_Response_Text(a1, a2, a3, a4);
func15(strcmp(v4, "all models ok") != 0, (__int64)"m", (__int64)s, 16LL, (__int64)v6, 16LL);
func15(allow_scripts[16], (__int64)"s", (__int64)s, 16LL, (__int64)v6, 16LL);
func15(enemyforceskins[16], (__int64)"f", (__int64)s, 16LL, (__int64)v6, 16LL);
func15(cl_iDrive[16], (__int64)"i", (__int64)s, 16LL, (__int64)v6, 16LL);
if ( strlen(s) > 1 )
strlcat(&features_0, s, 32LL);
if ( strlen((const char *)v6) > 1 )
strlcat(&features_0, v6, 32LL);
return &features_0;
}

original_code:
const char* FChecks_RulesetAdditionString()
{
 char feat_on_buf[16] = "+";
 char feat_off_buf[16] = "-";
 static char features[32] = "";
 *features = '\0';
 FChecks_RulesetFeatureAppend(((strcmp(FMod_Response_Text(), "all models ok") != 0)),("m"),feat_on_buf,sizeof (feat_on_buf),feat_off_buf,sizeof (feat_off_buf));
 FChecks_RulesetFeatureAppend(((allow_scripts.integer)),("s"),feat_on_buf,sizeof (feat_on_buf),feat_off_buf,sizeof (feat_off_buf));
 FChecks_RulesetFeatureAppend(((enemyforceskins.integer)),("f"),feat_on_buf,sizeof (feat_on_buf),feat_off_buf,sizeof (feat_off_buf));
 FChecks_RulesetFeatureAppend(((cl_iDrive.integer)),("i"),feat_on_buf,sizeof (feat_on_buf),feat_off_buf,sizeof (feat_off_buf));
 if (strlen(feat_on_buf) > 1) {
  strlcat(features, feat_on_buf, sizeof (features));
 }
 if (strlen(feat_off_buf) > 1) {
  strlcat(features, feat_off_buf, sizeof (features));
 }
 return features;
}

canonical_original_code:
char *FChecks_RulesetAdditionString()
{
 char feat_on_buf[16] = "+";
 char feat_off_buf[16] = "-";
 static char features[32] = "";
 *features = '\0';
 FChecks_RulesetFeatureAppend(((strcmp(FMod_Response_Text(), "all models ok") != 0)),("m"),feat_on_buf,sizeof (feat_on_buf),feat_off_buf,sizeof (feat_off_buf));
 FChecks_RulesetFeatureAppend(((allow_scripts.integer)),("s"),feat_on_buf,sizeof (feat_on_buf),feat_off_buf,sizeof (feat_off_buf));
 FChecks_RulesetFeatureAppend(((enemyforceskins.integer)),("f"),feat_on_buf,sizeof (feat_on_buf),feat_off_buf,sizeof (feat_off_buf));
 FChecks_RulesetFeatureAppend(((cl_iDrive.integer)),("i"),feat_on_buf,sizeof (feat_on_buf),feat_off_buf,sizeof (feat_off_buf));
 if (strlen(feat_on_buf) > 1) {
  strlcat(features, feat_on_buf, sizeof (features));
 }
 if (strlen(feat_off_buf) > 1) {
  strlcat(features, feat_off_buf, sizeof (features));
 }
 return features;
}

variable_types:
features
char [32]


repo: jite/jquake

decompiled_code:
__int64 FChecks_Init()
{
Cvar_SetCurrentGroup("Chat Settings");
Cvar_Register(allow_f_system);
Cvar_Register(allow_f_cmdline);
Cvar_ResetCurrentGroup();
FMod_Init();
Cmd_AddCommand("f_server", FChecks_FServerResponse);
return Cmd_AddCommand("f_ruleset", FChecks_FRuleset_cmd);
}

canonical_decompiled_code:
__int64 func19()
{
Cvar_SetCurrentGroup("Chat Settings");
Cvar_Register(allow_f_system);
Cvar_Register(allow_f_cmdline);
Cvar_ResetCurrentGroup();
FMod_Init();
Cmd_AddCommand("f_server", FChecks_FServerResponse);
return Cmd_AddCommand("f_ruleset", FChecks_FRuleset_cmd);
}

original_code:
void FChecks_Init (void)
{
 Cvar_SetCurrentGroup ("Chat Settings");
 Cvar_Register (&allow_f_system);
 Cvar_Register (&allow_f_cmdline);
 Cvar_ResetCurrentGroup();
 FMod_Init();
 Cmd_AddCommand ("f_server", FChecks_FServerResponse);
 Cmd_AddCommand ("f_ruleset", FChecks_FRuleset_cmd);
}

canonical_original_code:
void FChecks_Init()
{
 Cvar_SetCurrentGroup ("Chat Settings");
 Cvar_Register (&allow_f_system);
 Cvar_Register (&allow_f_cmdline);
 Cvar_ResetCurrentGroup();
 FMod_Init();
 Cmd_AddCommand ("f_server", FChecks_FServerResponse);
 Cmd_AddCommand ("f_ruleset", FChecks_FRuleset_cmd);
}

return_type: void


decompiled_code:
__int64 __fastcall VFSPAK_Tell(__int64 a1)
{
return *(_QWORD *)(a1 + 88) - *(_QWORD *)(a1 + 72);
}

original_code:
static unsigned long VFSPAK_Tell (struct vfsfile_s *vfs)
{
 vfspack_t *vfsp = (vfspack_t*)vfs;
 return vfsp->currentpos - vfsp->startpos;
}

canonical_original_code:
static unsigned long VFSPAK_Tell(struct vfsfile_s *vfs)
{
 struct vfspack_t *vfsp = (vfspack_t*)vfs;
 return vfsp->currentpos - vfsp->startpos;
}

variable_types: struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } *

variable_types: struct vfspack_t { struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } funcs; struct pack_s { char filename[128]; struct vfsfile_s *handle; unsigned int filepos; int references; int numfiles; struct packfile_t { char name[64]; int filepos; } *files; } *parentpak; unsigned long startpos; unsigned long length; unsigned long currentpos; } *

return_type: unsigned long

user_defined_types: struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool seekingisabadplan; enum qbool copyprotected; }

user_defined_types: struct vfspack_t { struct vfsfile_s funcs; struct pack_s *parentpak; unsigned long startpos; unsigned long length; unsigned long currentpos; }

user_defined_types: struct pack_s { char filename[128]; struct vfsfile_s *handle; unsigned int filepos; int references; int numfiles; struct packfile_t *files; }


decompiled_code:
__int64 __fastcall VFSPAK_GetLen(__int64 a1)
{
return *(_QWORD *)(a1 + 80);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
return *(_QWORD *)(a1 + 80);
}

original_code:
static unsigned long VFSPAK_GetLen (struct vfsfile_s *vfs)
{
 vfspack_t *vfsp = (vfspack_t*)vfs;
 return vfsp->length;
}

canonical_original_code:
static unsigned long VFSPAK_GetLen(struct vfsfile_s *vfs)
{
 struct vfspack_t *vfsp = (vfspack_t*)vfs;
 return vfsp->length;
}

user_defined_types: enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 }

user_defined_types: struct packfile_t { char name[64]; int filepos; }


decompiled_code:
__int64 __fastcall FSPAK_OpenVFS(__int64 a1, int *a2, const char *a3)
{
__int64 result; // rax
__int64 v5; // rdx
__int64 (__fastcall *v6)(); // rdx
__int64 (__fastcall *v7)(); // rdx

result = 0LL;
if ( !strcmp(a3, "rb") )
{
result = Q_calloc(1LL, 96LL);
*(_QWORD *)(result + 64) = a1;
++*(_DWORD *)(a1 + 140);
v5 = a2[35];
*(_QWORD *)(result + 72) = v5;
*(_QWORD *)(result + 80) = a2[36];
*(_QWORD *)(result + 88) = v5;
v6 = VFSPAK_ReadBytes;
if ( strcmp(a3, "rb") )
v6 = 0LL;
*(_QWORD *)result = v6;
v7 = VFSPAK_WriteBytes;
if ( strcmp(a3, "wb") )
v7 = 0LL;
*(_QWORD *)(result + 8) = v7;
*(_QWORD *)(result + 16) = VFSPAK_Seek;
*(_QWORD *)(result + 24) = VFSPAK_Tell;
*(_QWORD *)(result + 32) = VFSPAK_GetLen;
*(_QWORD *)(result + 40) = VFSPAK_Close;
*(_QWORD *)(result + 48) = 0LL;
if ( *(_QWORD *)a2 )
*(_DWORD *)(result + 60) = *(_DWORD *)(*(_QWORD *)a2 + 8LL);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, int *a2, const char *a3)
{
__int64 result; // rax
__int64 v5; // rdx
__int64 (__fastcall *v6)(); // rdx
__int64 (__fastcall *v7)(); // rdx

result = 0LL;
if ( !strcmp(a3, "rb") )
{
result = Q_calloc(1LL, 96LL);
*(_QWORD *)(result + 64) = a1;
++*(_DWORD *)(a1 + 140);
v5 = a2[35];
*(_QWORD *)(result + 72) = v5;
*(_QWORD *)(result + 80) = a2[36];
*(_QWORD *)(result + 88) = v5;
v6 = VFSPAK_ReadBytes;
if ( strcmp(a3, "rb") )
v6 = 0LL;
*(_QWORD *)result = v6;
v7 = VFSPAK_WriteBytes;
if ( strcmp(a3, "wb") )
v7 = 0LL;
*(_QWORD *)(result + 8) = v7;
*(_QWORD *)(result + 16) = VFSPAK_Seek;
*(_QWORD *)(result + 24) = VFSPAK_Tell;
*(_QWORD *)(result + 32) = VFSPAK_GetLen;
*(_QWORD *)(result + 40) = VFSPAK_Close;
*(_QWORD *)(result + 48) = 0LL;
if ( *(_QWORD *)a2 )
*(_DWORD *)(result + 60) = *(_DWORD *)(*(_QWORD *)a2 + 8LL);
}
return result;
}

original_code:
static vfsfile_t *FSPAK_OpenVFS(void *handle, flocation_t *loc, char *mode)
{
 pack_t *pack = (pack_t*)handle;
 vfspack_t *vfsp;
 if (strcmp(mode, "rb"))
  return ((void *)0);
 vfsp = Q_calloc(1, sizeof(*vfsp));
 vfsp->parentpak = pack;
 vfsp->parentpak->references++;
 vfsp->startpos = loc->offset;
 vfsp->length = loc->len;
 vfsp->currentpos = vfsp->startpos;
 vfsp->funcs.ReadBytes = strcmp(mode, "rb") ? ((void *)0) : VFSPAK_ReadBytes;
 vfsp->funcs.WriteBytes = strcmp(mode, "wb") ? ((void *)0) : VFSPAK_WriteBytes;
 vfsp->funcs.Seek = VFSPAK_Seek;
 vfsp->funcs.Tell = VFSPAK_Tell;
 vfsp->funcs.GetLen = VFSPAK_GetLen;
 vfsp->funcs.Close = VFSPAK_Close;
 vfsp->funcs.Flush = ((void *)0);
 if (loc->search)
  vfsp->funcs.copyprotected = loc->search->copyprotected;
 return (vfsfile_t *)vfsp;
}

canonical_original_code:
static struct vfsfile_s *FSPAK_OpenVFS(void *handle, struct flocation_t *loc, char *mode)
{
 struct pack_s *pack = (pack_t*)handle;
 struct vfspack_t *vfsp;
 if (strcmp(mode, "rb"))
  return ((void *)0);
 vfsp = Q_calloc(1, sizeof(*vfsp));
 vfsp->parentpak = pack;
 vfsp->parentpak->references++;
 vfsp->startpos = loc->offset;
 vfsp->length = loc->len;
 vfsp->currentpos = vfsp->startpos;
 vfsp->funcs.ReadBytes = strcmp(mode, "rb") ? ((void *)0) : VFSPAK_ReadBytes;
 vfsp->funcs.WriteBytes = strcmp(mode, "wb") ? ((void *)0) : VFSPAK_WriteBytes;
 vfsp->funcs.Seek = VFSPAK_Seek;
 vfsp->funcs.Tell = VFSPAK_Tell;
 vfsp->funcs.GetLen = VFSPAK_GetLen;
 vfsp->funcs.Close = VFSPAK_Close;
 vfsp->funcs.Flush = ((void *)0);
 if (loc->search)
  vfsp->funcs.copyprotected = loc->search->copyprotected;
 return (struct vfsfile_s *)vfsp;
}

variable_types:
handle
void *

variable_types: struct flocation_t { struct searchpath_s { struct searchpathfuncs_t { void (*PrintPath)(void *handle); void (*ClosePath)(void *handle); void (*BuildHash)(void *handle); enum qbool { false=0, true=1 } (*FindFile)(void *handle, struct flocation_t *loc, char *name, void *hashedresult); void (*ReadFile)(void *handle, struct flocation_t *loc, char *buffer); int (*EnumerateFiles)(void *handle, char *match, int (*func)(char *, int, void *), void *parm); void *(*OpenNew)(struct vfsfile_s *file, char *desc); int (*GeneratePureCRC)(void *handle, int seed, int usepure); struct vfsfile_s *(*OpenVFS)(void *handle, struct flocation_t *loc, char *mode); } *funcs; enum qbool { false=0, true=1 } copyprotected; enum qbool { false=0, true=1 } istemporary; void *handle; int crc_check; int crc_reply; struct searchpath_s *nextpure; struct searchpath_s *next; } *search; int index; char rawname[128]; int offset; int len; } *

variable_types:
mode
char *

variable_types: struct pack_s { char filename[128]; struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } *handle; unsigned int filepos; int references; int numfiles; struct packfile_t { char name[64]; int filepos; } *files; } *

user_defined_types: struct flocation_t { struct searchpath_s *search; int index; char rawname[128]; int offset; int len; }

user_defined_types: struct searchpath_s { struct searchpathfuncs_t *funcs; enum qbool copyprotected; enum qbool istemporary; void *handle; int crc_check; int crc_reply; struct searchpath_s *nextpure; struct searchpath_s *next; }

user_defined_types: struct searchpathfuncs_t { void (*PrintPath)(void *handle); void (*ClosePath)(void *handle); void (*BuildHash)(void *handle); enum qbool (*FindFile)(void *handle, struct flocation_t *loc, char *name, void *hashedresult); void (*ReadFile)(void *handle, struct flocation_t *loc, char *buffer); int (*EnumerateFiles)(void *handle, char *match, int (*func)(char *, int, void *), void *parm); void *(*OpenNew)(struct vfsfile_s *file, char *desc); int (*GeneratePureCRC)(void *handle, int seed, int usepure); struct vfsfile_s *(*OpenVFS)(void *handle, struct flocation_t *loc, char *mode); }


decompiled_code:
__int64 VFSPAK_WriteBytes()
{
Sys_Error("VFSPAK_WriteBytes: Cannot write to pak files");
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
Sys_Error("VFSPAK_WriteBytes: Cannot write to pak files");
return 0LL;
}

original_code:
static int VFSPAK_WriteBytes (struct vfsfile_s *vfs, const void *buffer, int bytestoread)
{
 Sys_Error("VFSPAK_WriteBytes: Cannot write to pak files");
 return 0;
}

canonical_original_code:
static int VFSPAK_WriteBytes(struct vfsfile_s *vfs, void *buffer, int bytestoread)
{
 Sys_Error("VFSPAK_WriteBytes: Cannot write to pak files");
 return 0;
}

variable_types:
buffer
void *

variable_types: bytestoread int

return_type: int


decompiled_code:
__int64 __fastcall VFSPAK_Seek(_QWORD *a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

if ( a3 == 1 )
{
a1[11] += a2;
}
else if ( a3 == 2 )
{
a1[11] = a2 + a1[9] + a1[10];
}
else
{
if ( a3 )
{
Sys_Error("VFSTAR_Seek: Unknown whence value(%d)\n", a3);
return 0xFFFFFFFFLL;
}
a1[11] = a1[9] + a2;
}
result = 0LL;
if ( a1[11] > a1[10] )
{
Com_Printf("VFSPAK_Seek: Warning seeking past the file's size\n");
result = 0LL;
}
return result;
}

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

if ( a3 == 1 )
{
a1[11] += a2;
}
else if ( a3 == 2 )
{
a1[11] = a2 + a1[9] + a1[10];
}
else
{
if ( a3 )
{
Sys_Error("VFSTAR_Seek: Unknown whence value(%d)\n", a3);
return 0xFFFFFFFFLL;
}
a1[11] = a1[9] + a2;
}
result = 0LL;
if ( a1[11] > a1[10] )
{
Com_Printf("VFSPAK_Seek: Warning seeking past the file's size\n");
result = 0LL;
}
return result;
}

original_code:
static int VFSPAK_Seek (struct vfsfile_s *vfs, unsigned long offset, int whence)
{
 vfspack_t *vfsp = (vfspack_t*)vfs;
 switch(whence) {
 case 0:
  vfsp->currentpos = vfsp->startpos + offset;
  break;
 case 1:
  vfsp->currentpos += offset;
  break;
 case 2:
  vfsp->currentpos = vfsp->startpos + vfsp->length + offset;
  break;
 default:
  Sys_Error("VFSTAR_Seek: Unknown whence value(%d)\n", whence);
  return -1;
 }
 if (vfsp->currentpos > vfsp->length) {
  Com_Printf("VFSPAK_Seek: Warning seeking past the file's size\n");
 }
 return 0;
}

canonical_original_code:
static int VFSPAK_Seek(struct vfsfile_s *vfs, unsigned long offset, int whence)
{
 struct vfspack_t *vfsp = (vfspack_t*)vfs;
 switch(whence) {
 case 0:
  vfsp->currentpos = vfsp->startpos + offset;
  break;
 case 1:
  vfsp->currentpos += offset;
  break;
 case 2:
  vfsp->currentpos = vfsp->startpos + vfsp->length + offset;
  break;
 default:
  Sys_Error("VFSTAR_Seek: Unknown whence value(%d)\n", whence);
  return -1;
 }
 if (vfsp->currentpos > vfsp->length) {
  Com_Printf("VFSPAK_Seek: Warning seeking past the file's size\n");
 }
 return 0;
}

variable_types:
offset
unsigned long

variable_types: whence int


decompiled_code:
__int64 __fastcall FSPAK_PrintPath(__int64 a1)
{
int v1; // edx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 140);
if ( v1 == 1 )
result = Com_Printf("%s\n", (const char *)a1);
else
result = Com_Printf("%s (%i)\n", (const char *)a1, (unsigned int)(v1 - 1));
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
int v1; // edx
__int64 result; // rax

v1 = *(_DWORD *)(a1 + 140);
if ( v1 == 1 )
result = Com_Printf("%s\n", (const char *)a1);
else
result = Com_Printf("%s (%i)\n", (const char *)a1, (unsigned int)(v1 - 1));
return result;
}

original_code:
static void FSPAK_PrintPath(void *handle)
{
 pack_t *pak = handle;
 if (pak->references != 1)
  Com_Printf("%s (%i)\n", pak->filename, pak->references-1);
 else
  Com_Printf("%s\n", pak->filename);
}

canonical_original_code:
static void FSPAK_PrintPath(void *handle)
{
 struct pack_s *pak = handle;
 if (pak->references != 1)
  Com_Printf("%s (%i)\n", pak->filename, pak->references-1);
 else
  Com_Printf("%s\n", pak->filename);
}


original_code:
static int VFSPAK_ReadBytes (struct vfsfile_s *vfs, void *buffer, int bytestoread, vfserrno_t *err)
{
 vfspack_t *vfsp = (vfspack_t*)vfs;
 int read;
 if (vfsp->currentpos - vfsp->startpos + bytestoread > vfsp->length)
  bytestoread = vfsp->length - (vfsp->currentpos - vfsp->startpos);
 if (bytestoread <= 0)
  return -1;
 if (vfsp->parentpak->filepos != vfsp->currentpos) {
  VFS_SEEK(vfsp->parentpak->handle, vfsp->currentpos, 0);
 }
 read = VFS_READ(vfsp->parentpak->handle, buffer, bytestoread, err);
 vfsp->currentpos += read;
 vfsp->parentpak->filepos = vfsp->currentpos;
 return read;
}

canonical_original_code:
static int VFSPAK_ReadBytes(struct vfsfile_s *vfs, void *buffer, int bytestoread, enum vfserrno_t *err)
{
 struct vfspack_t *vfsp = (vfspack_t*)vfs;
 int read;
 if (vfsp->currentpos - vfsp->startpos + bytestoread > vfsp->length)
  bytestoread = vfsp->length - (vfsp->currentpos - vfsp->startpos);
 if (bytestoread <= 0)
  return -1;
 if (vfsp->parentpak->filepos != vfsp->currentpos) {
  VFS_SEEK(vfsp->parentpak->handle, vfsp->currentpos, 0);
 }
 read = VFS_READ(vfsp->parentpak->handle, buffer, bytestoread, err);
 vfsp->currentpos += read;
 vfsp->parentpak->filepos = vfsp->currentpos;
 return read;
}

variable_types: enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *

variable_types: read int


original_code:
static void *FSPAK_LoadPackFile (vfsfile_t *file, const char *desc)
{
 dpackheader_t header;
 int i;
 packfile_t *newfiles;
 int numpackfiles;
 pack_t *pack;
 vfsfile_t *packhandle;
 dpackfile_t info;
 vfserrno_t err;
 packhandle = file;
 if (packhandle == ((void *)0))
  return ((void *)0);
 VFS_READ(packhandle, &header, sizeof(header), &err);
 if (header.id[0] != 'P' || header.id[1] != 'A'
 || header.id[2] != 'C' || header.id[3] != 'K')
 {
  return ((void *)0);
 }
 header.dirofs = (header.dirofs);
 header.dirlen = (header.dirlen);
 numpackfiles = header.dirlen / sizeof(dpackfile_t);
 newfiles = (packfile_t*)Q_malloc (numpackfiles * sizeof(packfile_t));
 VFS_SEEK(packhandle, header.dirofs, 0);
 pack = (pack_t *)Q_calloc(1, sizeof (pack_t));
 for (i=0 ; i<numpackfiles ; i++)
 {
  *info.name = '\0';
  (void) VFS_READ(packhandle, &info, sizeof(info), &err);
  strlcpy (newfiles[i].name, info.name, 64);
  newfiles[i].filepos = (info.filepos);
  newfiles[i].filelen = (info.filelen);
 }
 strlcpy (pack->filename, desc, sizeof (pack->filename));
 pack->handle = packhandle;
 pack->numfiles = numpackfiles;
 pack->files = newfiles;
 pack->filepos = 0;
 VFS_SEEK(packhandle, pack->filepos, 0);
 pack->references++;
 return pack;
}

canonical_original_code:
static void *FSPAK_LoadPackFile(struct vfsfile_s *file, char *desc)
{
 struct dpackheader_t header;
 int i;
 struct packfile_t *newfiles;
 int numpackfiles;
 struct pack_s *pack;
 struct vfsfile_s *packhandle;
 struct dpackfile_t info;
 enum vfserrno_t err;
 packhandle = file;
 if (packhandle == ((void *)0))
  return ((void *)0);
 VFS_READ(packhandle, &header, sizeof(header), &err);
 if (header.id[0] != 'P' || header.id[1] != 'A'
 || header.id[2] != 'C' || header.id[3] != 'K')
 {
  return ((void *)0);
 }
 header.dirofs = (header.dirofs);
 header.dirlen = (header.dirlen);
 numpackfiles = header.dirlen / sizeof(dpackfile_t);
 newfiles = (struct packfile_t *)Q_malloc (numpackfiles * sizeof(packfile_t));
 VFS_SEEK(packhandle, header.dirofs, 0);
 pack = (struct pack_s *)Q_calloc(1, sizeof (pack_t));
 for (i=0 ; i<numpackfiles ; i++)
 {
  *info.name = '\0';
  (void) VFS_READ(packhandle, &info, sizeof(info), &err);
  strlcpy (newfiles[i].name, info.name, 64);
  newfiles[i].filepos = (info.filepos);
  newfiles[i].filelen = (info.filelen);
 }
 strlcpy (pack->filename, desc, sizeof (pack->filename));
 pack->handle = packhandle;
 pack->numfiles = numpackfiles;
 pack->files = newfiles;
 pack->filepos = 0;
 VFS_SEEK(packhandle, pack->filepos, 0);
 pack->references++;
 return pack;
}

variable_types:
desc
char *

variable_types: struct dpackheader_t { char id[4]; int dirofs; int dirlen; }

variable_types: i int

variable_types: struct packfile_t { char name[64]; int filepos; } *

variable_types: numpackfiles int

variable_types: struct dpackfile_t { char name[56]; int filepos; }

variable_types: enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 }

return_type: void *


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

if ( *(int *)(a1 + 144) <= 0 )
return 1LL;
v6 = 0LL;
while ( 1 )
{
if ( (unsigned int)wildcmp(a2, *(_QWORD *)(a1 + 152) + 72 * v6) )
{
result = a3(*(_QWORD *)(a1 + 152) + 72 * v6, *(unsigned int *)(*(_QWORD *)(a1 + 152) + 72 * v6 + 68), a4);
if ( !(_DWORD)result )
break;
}
if ( *(_DWORD *)(a1 + 144) <= (int)++v6 )
return 1LL;
}
return result;
}

original_code:
static int FSPAK_EnumerateFiles (void *handle, char *match, int (*func)(char *, int, void *), void *parm)
{
 pack_t *pak = handle;
 int num;
 for (num = 0; num<(int)pak->numfiles; num++)
 {
  if (wildcmp(match, pak->files[num].name))
  {
   if (!func(pak->files[num].name, pak->files[num].filelen, parm))
    return false;
  }
 }
 return true;
}

canonical_original_code:
static int FSPAK_EnumerateFiles(void *handle, char *match, int (*func)(char *, int, void *), void *parm)
{
 struct pack_s *pak = handle;
 int num;
 for (num = 0; num<(int)pak->numfiles; num++)
 {
  if (wildcmp(match, pak->files[num].name))
  {
   if (!func(pak->files[num].name, pak->files[num].filelen, parm))
    return false;
  }
 }
 return true;
}

variable_types:
handle
void *

variable_types:
match
char *

variable_types:
func
int (*)(char *, int, void *)

variable_types:
parm
void *

variable_types: num int


original_code:
static qbool FSPAK_FLocate(void *handle, flocation_t *loc, const char *filename, void *hashedresult)
{
 packfile_t *pf = hashedresult;
 int i;
 pack_t *pak = handle;
 if (pf)
 {
  if (pf < pak->files || pf > pak->files + pak->numfiles)
   return false;
 }
 else
 {
  for (i=0 ; i<pak->numfiles ; i++)
  {
   if (!strcmp (pak->files[i].name, filename))
   {
    pf = &pak->files[i];
    break;
   }
  }
 }
 if (pf)
 {
  if (loc)
  {
   loc->index = pf - pak->files;
   snprintf(loc->rawname, sizeof(loc->rawname), "%s/%s", pak->filename, filename);
   loc->offset = pf->filepos;
   loc->len = pf->filelen;
  }
  return true;
 }
 return false;
}

canonical_original_code:
static enum qbool FSPAK_FLocate(void *handle, struct flocation_t *loc, char *filename, void *hashedresult)
{
 struct packfile_t *pf = hashedresult;
 int i;
 struct pack_s *pak = handle;
 if (pf)
 {
  if (pf < pak->files || pf > pak->files + pak->numfiles)
   return false;
 }
 else
 {
  for (i=0 ; i<pak->numfiles ; i++)
  {
   if (!strcmp (pak->files[i].name, filename))
   {
    pf = &pak->files[i];
    break;
   }
  }
 }
 if (pf)
 {
  if (loc)
  {
   loc->index = pf - pak->files;
   snprintf(loc->rawname, sizeof(loc->rawname), "%s/%s", pak->filename, filename);
   loc->offset = pf->filepos;
   loc->len = pf->filelen;
  }
  return true;
 }
 return false;
}

variable_types: struct flocation_t { struct searchpath_s { struct searchpathfuncs_t { void (*PrintPath)(void *handle); void (*ClosePath)(void *handle); void (*BuildHash)(void *handle); enum qbool { false=0, true=1 } (*FindFile)(void *handle, struct flocation_t *loc, char *name, void *hashedresult); void (*ReadFile)(void *handle, struct flocation_t *loc, char *buffer); int (*EnumerateFiles)(void *handle, char *match, int (*func)(char *, int, void *), void *parm); void *(*OpenNew)(struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } *file, char *desc); int (*GeneratePureCRC)(void *handle, int seed, int usepure); struct vfsfile_s *(*OpenVFS)(void *handle, struct flocation_t *loc, char *mode); } *funcs; enum qbool { false=0, true=1 } copyprotected; enum qbool { false=0, true=1 } istemporary; void *handle; int crc_check; int crc_reply; struct searchpath_s *nextpure; struct searchpath_s *next; } *search; int index; char rawname[128]; int offset; int len; } *

variable_types:
filename
char *

variable_types:
hashedresult
void *

variable_types: struct pack_s { char filename[128]; struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } *handle; unsigned int filepos; int references; int numfiles; struct packfile_t { char name[64]; int filepos; } *files; } *

return_type: enum qbool { false=0, true=1 }


decompiled_code:
void __fastcall FSPAK_BuildHash(__int64 a1)
{
__int64 v1; // rbx

if ( *(int *)(a1 + 144) > 0 )
{
v1 = 0LL;
do
{
if ( Hash_GetInsensitive(filesystemhash, *(_QWORD *)(a1 + 152) + 72 * v1) )
{
++fs_hash_dups;
}
else
{
Hash_AddInsensitive(filesystemhash, *(_QWORD *)(a1 + 152) + 72 * v1, *(_QWORD *)(a1 + 152) + 72 * v1);
++fs_hash_files;
}
++v1;
}
while ( *(_DWORD *)(a1 + 144) > (int)v1 );
}
}

canonical_decompiled_code:
void __fastcall func10(__int64 a1)
{
__int64 v1; // rbx

if ( *(int *)(a1 + 144) > 0 )
{
v1 = 0LL;
do
{
if ( Hash_GetInsensitive(filesystemhash, *(_QWORD *)(a1 + 152) + 72 * v1) )
{
++fs_hash_dups;
}
else
{
Hash_AddInsensitive(filesystemhash, *(_QWORD *)(a1 + 152) + 72 * v1, *(_QWORD *)(a1 + 152) + 72 * v1);
++fs_hash_files;
}
++v1;
}
while ( *(_DWORD *)(a1 + 144) > (int)v1 );
}
}

original_code:
static void FSPAK_BuildHash(void *handle)
{
 pack_t *pak = handle;
 int i;
 for (i = 0; i < pak->numfiles; i++)
 {
  if (!Hash_GetInsensitive(filesystemhash, pak->files[i].name))
  {
   Hash_AddInsensitive(filesystemhash, pak->files[i].name, &pak->files[i]);
   fs_hash_files++;
  }
  else
   fs_hash_dups++;
 }
}

canonical_original_code:
static void FSPAK_BuildHash(void *handle)
{
 struct pack_s *pak = handle;
 int i;
 for (i = 0; i < pak->numfiles; i++)
 {
  if (!Hash_GetInsensitive(filesystemhash, pak->files[i].name))
  {
   Hash_AddInsensitive(filesystemhash, pak->files[i].name, &pak->files[i]);
   fs_hash_files++;
  }
  else
   fs_hash_dups++;
 }
}


decompiled_code:
void __fastcall FSPAK_ClosePath(void *ptr)
{
int v1; // eax
void *v3; // rdi

v1 = *((_DWORD *)ptr + 35) - 1;
*((_DWORD *)ptr + 35) = v1;
if ( v1 <= 0 )
{
VFS_CLOSE(*((_QWORD *)ptr + 16));
v3 = (void *)*((_QWORD *)ptr + 19);
if ( v3 )
free(v3);
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func11(void *ptr)
{
int v1; // eax
void *v3; // rdi

v1 = *((_DWORD *)ptr + 35) - 1;
*((_DWORD *)ptr + 35) = v1;
if ( v1 <= 0 )
{
VFS_CLOSE(*((_QWORD *)ptr + 16));
v3 = (void *)*((_QWORD *)ptr + 19);
if ( v3 )
free(v3);
free(ptr);
}
}

original_code:
static void FSPAK_ClosePath(void *handle)
{
 pack_t *pak = handle;
 pak->references--;
 if (pak->references > 0)
  return;
 VFS_CLOSE (pak->handle);
 if (pak->files)
  if(pak->files) { free(pak->files); pak->files = ((void *)0); };
 if(pak) { free(pak); pak = ((void *)0); };
}

canonical_original_code:
static void FSPAK_ClosePath(void *handle)
{
 struct pack_s *pak = handle;
 pak->references--;
 if (pak->references > 0)
  return;
 VFS_CLOSE (pak->handle);
 if (pak->files)
  if(pak->files) { free(pak->files); pak->files = ((void *)0); };
 if(pak) { free(pak); pak = ((void *)0); };
}


decompiled_code:
void __fastcall VFSPAK_Close(void *ptr)
{
FSPAK_ClosePath(*((void **)ptr + 8));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func12(void *ptr)
{
func11(*((void **)ptr + 8));
free(ptr);
}

original_code:
static void VFSPAK_Close(vfsfile_t *vfs)
{
 vfspack_t *vfsp = (vfspack_t*)vfs;
 FSPAK_ClosePath(vfsp->parentpak);
 if(vfsp) { free(vfsp); vfsp = ((void *)0); };
}

canonical_original_code:
static void VFSPAK_Close(struct vfsfile_s *vfs)
{
 struct vfspack_t *vfsp = (vfspack_t*)vfs;
 FSPAK_ClosePath(vfsp->parentpak);
 if(vfsp) { free(vfsp); vfsp = ((void *)0); };
}

variable_types: struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } *

variable_types: struct vfspack_t { struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } funcs; struct pack_s { char filename[128]; struct vfsfile_s *handle; unsigned int filepos; int references; int numfiles; struct packfile_t { char name[64]; int filepos; } *files; } *parentpak; unsigned long startpos; unsigned long length; unsigned long currentpos; } *


decompiled_code:
__int64 __fastcall Hash_InitTable(int a1)
{
__int64 v1; // rbx

v1 = Q_malloc(16LL);
*(_QWORD *)(v1 + 8) = Q_calloc(a1, 8LL);
*(_DWORD *)v1 = a1;
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
__int64 v1; // rbx

v1 = Q_malloc(16LL);
*(_QWORD *)(v1 + 8) = Q_calloc(a1, 8LL);
*(_DWORD *)v1 = a1;
return v1;
}

original_code:
hashtable_t *Hash_InitTable(int numbucks)
{
 hashtable_t *table;
 table = Q_malloc(sizeof(*table));
 table->bucket = (bucket_t**)Q_calloc(numbucks, sizeof(bucket_t *));
 table->numbuckets = numbucks;
 return table;
}

canonical_original_code:
struct hashtable_s *Hash_InitTable(int numbucks)
{
 struct hashtable_s *table;
 table = Q_malloc(sizeof(*table));
 table->bucket = (struct bucket_s **)Q_calloc(numbucks, sizeof(struct bucket_s *));
 table->numbuckets = numbucks;
 return table;
}

variable_types: numbucks int

variable_types: struct hashtable_s { int numbuckets; struct bucket_s { void *data; char *keystring; struct bucket_s *next; } **bucket; } *

user_defined_types: struct hashtable_s { int numbuckets; struct bucket_s **bucket; }


original_code:
void Hash_Remove(hashtable_t *table, char *name)
{
 int bucknum = Hash_Key(name, table->numbuckets);
 bucket_t *buck;
 buck = table->bucket[bucknum];
 if (!(((*name)!=(*buck->keystring)) || strcmp(name+1,buck->keystring+1)))
 {
  table->bucket[bucknum] = buck->next;
  if(buck->keystring) { free(buck->keystring); buck->keystring = ((void *)0); };
  if(buck) { free(buck); buck = ((void *)0); };
  return;
 }
 while(buck->next)
 {
  if (!(((*name)!=(*buck->next->keystring)) || strcmp(name+1,buck->next->keystring+1)))
  {
   buck->next = buck->next->next;
   if(buck->next->keystring) { free(buck->next->keystring); buck->next->keystring = ((void *)0); };
   if(buck->next) { free(buck->next); buck->next = ((void *)0); };
   return;
  }
  buck = buck->next;
 }
 return;
}

canonical_original_code:
void Hash_Remove(struct hashtable_s *table, char *name)
{
 int bucknum = Hash_Key(name, table->numbuckets);
 struct bucket_s *buck;
 buck = table->bucket[bucknum];
 if (!(((*name)!=(*buck->keystring)) || strcmp(name+1,buck->keystring+1)))
 {
  table->bucket[bucknum] = buck->next;
  if(buck->keystring) { free(buck->keystring); buck->keystring = ((void *)0); };
  if(buck) { free(buck); buck = ((void *)0); };
  return;
 }
 while(buck->next)
 {
  if (!(((*name)!=(*buck->next->keystring)) || strcmp(name+1,buck->next->keystring+1)))
  {
   buck->next = buck->next->next;
   if(buck->next->keystring) { free(buck->next->keystring); buck->next->keystring = ((void *)0); };
   if(buck->next) { free(buck->next); buck->next = ((void *)0); };
   return;
  }
  buck = buck->next;
 }
 return;
}

variable_types:
name
char *

variable_types: bucknum int

variable_types: struct bucket_s { void *data; char *keystring; struct bucket_s *next; } *


original_code:
void Hash_RemoveData(hashtable_t *table, char *name, void *data)
{
 int bucknum = Hash_Key(name, table->numbuckets);
 bucket_t *buck;
 buck = table->bucket[bucknum];
 if (buck->data == data)
  if (!(((*name)!=(*buck->keystring)) || strcmp(name+1,buck->keystring+1)))
  {
   table->bucket[bucknum] = buck->next;
   if(buck->keystring) { free(buck->keystring); buck->keystring = ((void *)0); };
   if(buck) { free(buck); buck = ((void *)0); };
   return;
  }
 while(buck->next)
 {
  if (buck->next->data == data)
   if (!(((*name)!=(*buck->next->keystring)) || strcmp(name+1,buck->next->keystring+1)))
   {
    buck->next = buck->next->next;
    if(buck->next->keystring) { free(buck->next->keystring); buck->next->keystring = ((void *)0); };
    if(buck->next) { free(buck->next); buck->next = ((void *)0); };
    return;
   }
  buck = buck->next;
 }
 return;
}

canonical_original_code:
void Hash_RemoveData(struct hashtable_s *table, char *name, void *data)
{
 int bucknum = Hash_Key(name, table->numbuckets);
 struct bucket_s *buck;
 buck = table->bucket[bucknum];
 if (buck->data == data)
  if (!(((*name)!=(*buck->keystring)) || strcmp(name+1,buck->keystring+1)))
  {
   table->bucket[bucknum] = buck->next;
   if(buck->keystring) { free(buck->keystring); buck->keystring = ((void *)0); };
   if(buck) { free(buck); buck = ((void *)0); };
   return;
  }
 while(buck->next)
 {
  if (buck->next->data == data)
   if (!(((*name)!=(*buck->next->keystring)) || strcmp(name+1,buck->next->keystring+1)))
   {
    buck->next = buck->next->next;
    if(buck->next->keystring) { free(buck->next->keystring); buck->next->keystring = ((void *)0); };
    if(buck->next) { free(buck->next); buck->next = ((void *)0); };
    return;
   }
  buck = buck->next;
 }
 return;
}

variable_types:
data
void *

user_defined_types: struct bucket_s { void *data; char *keystring; struct bucket_s *next; }


original_code:
void Hash_RemoveKey(hashtable_t *table, char *key)
{
 int bucknum = ((long) key) % table->numbuckets;
 bucket_t *buck;
 buck = table->bucket[bucknum];
 if (buck->keystring == key)
 {
  table->bucket[bucknum] = buck->next;
  if(buck->keystring) { free(buck->keystring); buck->keystring = ((void *)0); };
  if(buck) { free(buck); buck = ((void *)0); };
  return;
 }
 while(buck->next)
 {
  if (buck->next->keystring == key)
  {
   buck->next = buck->next->next;
   if(buck->next->keystring) { free(buck->next->keystring); buck->next->keystring = ((void *)0); };
   if(buck->next) { free(buck->next); buck->next = ((void *)0); };
   return;
  }
  buck = buck->next;
 }
 return;
}

canonical_original_code:
void Hash_RemoveKey(struct hashtable_s *table, char *key)
{
 int bucknum = ((long) key) % table->numbuckets;
 struct bucket_s *buck;
 buck = table->bucket[bucknum];
 if (buck->keystring == key)
 {
  table->bucket[bucknum] = buck->next;
  if(buck->keystring) { free(buck->keystring); buck->keystring = ((void *)0); };
  if(buck) { free(buck); buck = ((void *)0); };
  return;
 }
 while(buck->next)
 {
  if (buck->next->keystring == key)
  {
   buck->next = buck->next->next;
   if(buck->next->keystring) { free(buck->next->keystring); buck->next->keystring = ((void *)0); };
   if(buck->next) { free(buck->next); buck->next = ((void *)0); };
   return;
  }
  buck = buck->next;
 }
 return;
}

variable_types:
key
char *


original_code:
void Hash_Flush(hashtable_t *table)
{
 int i;
 for (i = 0; i < table->numbuckets; i++)
 {
  bucket_t *bucket, *next;
  bucket = table->bucket[i];
  table->bucket[i] = ((void *)0);
  while (bucket)
  {
   next = bucket->next;
   if(bucket->keystring) { free(bucket->keystring); bucket->keystring = ((void *)0); };
   if(bucket) { free(bucket); bucket = ((void *)0); };
   bucket = next;
  }
 }
 return;
}

canonical_original_code:
void Hash_Flush(struct hashtable_s *table)
{
 int i;
 for (i = 0; i < table->numbuckets; i++)
 {
  struct bucket_s *bucket; struct bucket_s *next;
  bucket = table->bucket[i];
  table->bucket[i] = ((void *)0);
  while (bucket)
  {
   next = bucket->next;
   if(bucket->keystring) { free(bucket->keystring); bucket->keystring = ((void *)0); };
   if(bucket) { free(bucket); bucket = ((void *)0); };
   bucket = next;
  }
 }
 return;
}

variable_types: i int


decompiled_code:
__int64 __fastcall Hash_Key(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 v2; // dl
unsigned int v3; // eax

v2 = *a1;
if ( *a1 )
{
v3 = 5381;
do
{
v3 += 32 * v3 + v2;
v2 = *++a1;
}
while ( *a1 );
}
else
{
v3 = 5381;
}
return v3 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 v2; // dl
unsigned int v3; // eax

v2 = *a1;
if ( *a1 )
{
v3 = 5381;
do
{
v3 += 32 * v3 + v2;
v2 = *++a1;
}
while ( *a1 );
}
else
{
v3 = 5381;
}
return v3 % a2;
}

original_code:
int Hash_Key(char *name, int modulus) {
 unsigned int key = 5381;
 for (key = 5381; *name; name++)
  key = ((key << 5) + key) + *name;
 return (int) (key % modulus);
}

variable_types: modulus int

variable_types:
key
unsigned int


decompiled_code:
__int64 __fastcall Hash_KeyInsensitive(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 v2; // bl
unsigned __int8 *v3; // rbp
const __int32_t *v4; // rcx
unsigned int v5; // eax

v2 = *a1;
if ( *a1 )
{
v3 = a1;
v4 = *_ctype_tolower_loc();
v5 = 5381;
do
{
v5 += v4[v2] + 32 * v5;
v2 = *++v3;
}
while ( *v3 );
}
else
{
v5 = 5381;
}
return v5 % a2;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 *a1, unsigned int a2)
{
unsigned __int8 v2; // bl
unsigned __int8 *v3; // rbp
const __int32_t *v4; // rcx
unsigned int v5; // eax

v2 = *a1;
if ( *a1 )
{
v3 = a1;
v4 = *_ctype_tolower_loc();
v5 = 5381;
do
{
v5 += v4[v2] + 32 * v5;
v2 = *++v3;
}
while ( *v3 );
}
else
{
v5 = 5381;
}
return v5 % a2;
}

original_code:
int Hash_KeyInsensitive(const char *name, int modulus) {
 unsigned int key = 5381;
 for (key = 5381; *name; name++)
  key = ((key << 5) + key) + tolower(*name);
 return (int) (key % modulus);
}

canonical_original_code:
int Hash_KeyInsensitive(char *name, int modulus) {
 unsigned int key = 5381;
 for (key = 5381; *name; name++)
  key = ((key << 5) + key) + tolower(*name);
 return (int) (key % modulus);
}


decompiled_code:
__int64 VFSTCP_GetLen()
{
Com_Printf("VFSTCP: GetLen non functional\n");
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
Com_Printf("VFSTCP: GetLen non functional\n");
return 0LL;
}

original_code:
unsigned long VFSTCP_GetLen (struct vfsfile_s *file)
{
 Com_Printf("VFSTCP: GetLen non functional\n");
 return 0;
}

canonical_original_code:
unsigned long VFSTCP_GetLen(struct vfsfile_s *file)
{
 Com_Printf("VFSTCP: GetLen non functional\n");
 return 0;
}


decompiled_code:
int __fastcall VFSTCP_Error(__int64 a1)
{
int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 64);
if ( v2 != -1 )
{
result = close(v2);
*(_DWORD *)(a1 + 64) = -1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1)
{
int v2; // edi
int result; // eax

v2 = *(_DWORD *)(a1 + 64);
if ( v2 != -1 )
{
result = close(v2);
*(_DWORD *)(a1 + 64) = -1;
}
return result;
}

original_code:
void VFSTCP_Error(tcpfile_t *f)
{
 if (f->sock != -1)
 {
  close(f->sock);
  f->sock = -1;
 }
}

canonical_original_code:
void VFSTCP_Error(struct tcpfile_s *f)
{
 if (f->sock != -1)
 {
  close(f->sock);
  f->sock = -1;
 }
}

variable_types: struct tcpfile_s { struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } funcs; int sock; char readbuffer[-1]; int readbuffered; char writebuffer[-1]; int writebuffered; struct tcpfile_s *next; } *

user_defined_types: struct tcpfile_s { struct vfsfile_s funcs; int sock; char readbuffer[-1]; int readbuffered; char writebuffer[-1]; int writebuffered; struct tcpfile_s *next; }


decompiled_code:
__int64 __fastcall VFSTCP_ReadBytes(_DWORD *a1, void *a2, int a3, _BOOL4 *a4)
{
int v7; // edi
int v8; // er12
_BOOL4 v9; // eax
int v10; // eax
unsigned int v12; // er12
char *v13; // rax
int v14; // edx

if ( a3 < 0 )
Sys_Error("VFSTCP_ReadBytes: bytestoread < 0");
v7 = a1[16];
if ( v7 == -1 )
{
LABEL_12:
v8 = a1[81937];
if ( v8 < a3 )
{
if ( v8 <= 0 )
{
v8 = 0;
if ( !a4 )
return (unsigned int)v8;
v9 = a1[16] == -1;
v8 = 0;
goto LABEL_7;
}
goto LABEL_6;
}
LABEL_13:
if ( a3 > 0 )
{
memcpy(a2, a1 + 17, a3);
v14 = a1[81937] - a3;
a1[81937] = v14;
memmove(a1 + 17, (char *)a1 + a3 + 68, v14);
}
v8 = a3;
if ( a4 )
*a4 = 0;
return (unsigned int)v8;
}
v8 = a1[81937];
if ( v8 != 327680 )
{
v10 = recv(v7, (char *)a1 + v8 + 68, 327680LL - v8, 0);
if ( v10 != -2 )
{
if ( v10 == -1 )
{
v12 = *_errno_location();
if ( v12 != 11 )
{
if ( v12 - 103 <= 1 )
{
Com_Printf("VFSTCP: Connection lost or aborted\n");
}
else
{
v13 = strerror(v12);
Com_Printf("VFSTCP: Error (%i): %s\n", v12, v13);
}
VFSTCP_Error((__int64)a1);
}
}
else if ( v10 )
{
a1[81937] += v10;
}
else
{
Com_Printf("VFSTCP: EOF on socket\n");
VFSTCP_Error((__int64)a1);
}
}
goto LABEL_12;
}
if ( a3 <= 327680 )
goto LABEL_13;
LABEL_6:
memcpy(a2, a1 + 17, v8);
a1[81937] = 0;
v9 = 0;
if ( a4 )
LABEL_7:
*a4 = v9;
return (unsigned int)v8;
}

original_code:
int VFSTCP_ReadBytes (struct vfsfile_s *file, void *buffer, int bytestoread, vfserrno_t *err)
{
 tcpfile_t *tf = (tcpfile_t*)file;
 if (bytestoread < 0)
  Sys_Error("VFSTCP_ReadBytes: bytestoread < 0");
 if (tf->sock != -1)
 {
  int len;
  if (sizeof(tf->readbuffer) == tf->readbuffered)
   len = -2;
  else
   len = recv(tf->sock, tf->readbuffer + tf->readbuffered, sizeof(tf->readbuffer) - tf->readbuffered, 0);
  if (len == -2) {
   ;
  }
  else if (len == -1)
  {
   int e = (*__errno_location ());
   if (e == 11) {
    ;
   } else {
    if (e == 103 || e == 104)
     Com_Printf ("VFSTCP: Connection lost or aborted\n");
    else
     Com_Printf ("VFSTCP: Error (%i): %s\n", e, strerror(e));
    VFSTCP_Error(tf);
   }
  }
  else if (len == 0) {
   Com_Printf ("VFSTCP: EOF on socket\n");
   VFSTCP_Error(tf);
  }
  else
   tf->readbuffered += len;
 }
 if (bytestoread <= tf->readbuffered)
 {
  if (bytestoread > 0) {
   memcpy(buffer, tf->readbuffer, bytestoread);
   tf->readbuffered -= bytestoread;
   memmove(tf->readbuffer, tf->readbuffer+bytestoread, tf->readbuffered);
  }
  if (err)
   *err = VFSERR_NONE;
  return bytestoread;
 }
 else
 {
  if (tf->readbuffered > 0) {
   bytestoread = tf->readbuffered;
   memcpy(buffer, tf->readbuffer, tf->readbuffered);
   tf->readbuffered = 0;
  }
  else
   bytestoread = 0;
  if (err)
   *err = ((bytestoread || tf->sock != -1) ? VFSERR_NONE : VFSERR_EOF);
  return bytestoread;
 }
}

canonical_original_code:
int VFSTCP_ReadBytes(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t *err)
{
 struct tcpfile_s *tf = (tcpfile_t*)file;
 if (bytestoread < 0)
  Sys_Error("VFSTCP_ReadBytes: bytestoread < 0");
 if (tf->sock != -1)
 {
  int len;
  if (sizeof(tf->readbuffer) == tf->readbuffered)
   len = -2;
  else
   len = recv(tf->sock, tf->readbuffer + tf->readbuffered, sizeof(tf->readbuffer) - tf->readbuffered, 0);
  if (len == -2) {
   ;
  }
  else if (len == -1)
  {
   int e = (*__errno_location ());
   if (e == 11) {
    ;
   } else {
    if (e == 103 || e == 104)
     Com_Printf ("VFSTCP: Connection lost or aborted\n");
    else
     Com_Printf ("VFSTCP: Error (%i): %s\n", e, strerror(e));
    VFSTCP_Error(tf);
   }
  }
  else if (len == 0) {
   Com_Printf ("VFSTCP: EOF on socket\n");
   VFSTCP_Error(tf);
  }
  else
   tf->readbuffered += len;
 }
 if (bytestoread <= tf->readbuffered)
 {
  if (bytestoread > 0) {
   memcpy(buffer, tf->readbuffer, bytestoread);
   tf->readbuffered -= bytestoread;
   memmove(tf->readbuffer, tf->readbuffer+bytestoread, tf->readbuffered);
  }
  if (err)
   *err = VFSERR_NONE;
  return bytestoread;
 }
 else
 {
  if (tf->readbuffered > 0) {
   bytestoread = tf->readbuffered;
   memcpy(buffer, tf->readbuffer, tf->readbuffered);
   tf->readbuffered = 0;
  }
  else
   bytestoread = 0;
  if (err)
   *err = ((bytestoread || tf->sock != -1) ? VFSERR_NONE : VFSERR_EOF);
  return bytestoread;
 }
}

variable_types:
buffer
void *

variable_types: bytestoread int

variable_types: enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *

variable_types: len int

variable_types: e int


decompiled_code:
__int64 __fastcall VFSTCP_WriteBytes(int *a1, const void *a2, int a3)
{
unsigned int v5; // edx
int v6; // edi
int v7; // edx
int v8; // eax
int v9; // edx
unsigned int v11; // eax

if ( a3 < 0 )
Sys_Error("VFSTCP_WriteBytes: bytestowrite < 0");
v5 = 0;
if ( a1[16] != -1 )
{
v6 = a1[163858];
if ( 327680 - v6 < a3 )
{
Com_Printf("VFSTCP: failed to write %d bytes, buffer overflow, closing link\n", (unsigned int)a3);
VFSTCP_Error((__int64)a1);
v5 = 0;
}
else
{
memmove((char *)a1 + v6 + 327752, a2, a3);
v7 = a1[163858] + a3;
a1[163858] = v7;
v8 = send(a1[16], a1 + 81938, v7, 0);
if ( v8 < 0 )
{
v11 = *_errno_location();
v5 = a3;
if ( v11 != 11 )
{
Com_Printf("VFSTCP: failed to write %d bytes, closing link, socket error %d\n", (unsigned int)a3, v11);
VFSTCP_Error((__int64)a1);
v5 = 0;
}
}
else
{
v5 = a3;
if ( v8 > 0 )
{
v9 = a1[163858] - v8;
a1[163858] = v9;
memmove(a1 + 81938, (char *)a1 + v8 + 327752, v9);
v5 = a3;
}
}
}
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func3(int *a1, const void *a2, int a3)
{
unsigned int v5; // edx
int v6; // edi
int v7; // edx
int v8; // eax
int v9; // edx
unsigned int v11; // eax

if ( a3 < 0 )
Sys_Error("VFSTCP_WriteBytes: bytestowrite < 0");
v5 = 0;
if ( a1[16] != -1 )
{
v6 = a1[163858];
if ( 327680 - v6 < a3 )
{
Com_Printf("VFSTCP: failed to write %d bytes, buffer overflow, closing link\n", (unsigned int)a3);
func1((__int64)a1);
v5 = 0;
}
else
{
memmove((char *)a1 + v6 + 327752, a2, a3);
v7 = a1[163858] + a3;
a1[163858] = v7;
v8 = send(a1[16], a1 + 81938, v7, 0);
if ( v8 < 0 )
{
v11 = *_errno_location();
v5 = a3;
if ( v11 != 11 )
{
Com_Printf("VFSTCP: failed to write %d bytes, closing link, socket error %d\n", (unsigned int)a3, v11);
func1((__int64)a1);
v5 = 0;
}
}
else
{
v5 = a3;
if ( v8 > 0 )
{
v9 = a1[163858] - v8;
a1[163858] = v9;
memmove(a1 + 81938, (char *)a1 + v8 + 327752, v9);
v5 = a3;
}
}
}
}
return v5;
}

original_code:
int VFSTCP_WriteBytes (struct vfsfile_s *file, const void *buffer, int bytestowrite)
{
 tcpfile_t *tf = (tcpfile_t*)file;
 int len;
 if (bytestowrite < 0)
  Sys_Error("VFSTCP_WriteBytes: bytestowrite < 0");
 if (tf->sock == -1)
  return 0;
 if (bytestowrite > (int)sizeof(tf->writebuffer) - tf->writebuffered)
 {
  Com_Printf("VFSTCP: failed to write %d bytes, buffer overflow, closing link\n", bytestowrite);
  VFSTCP_Error(tf);
  return 0;
 }
 memmove(tf->writebuffer + tf->writebuffered, buffer, bytestowrite);
 tf->writebuffered += bytestowrite;
 len = send(tf->sock, tf->writebuffer, tf->writebuffered, 0);
 if (len < 0)
 {
  int err = (*__errno_location ());
  if (err != 11 )
  {
   Com_Printf("VFSTCP: failed to write %d bytes, closing link, socket error %d\n", bytestowrite, err);
   VFSTCP_Error(tf);
   return 0;
  }
 }
 else if (len > 0)
 {
  tf->writebuffered -= len;
  memmove(tf->writebuffer, tf->writebuffer + len, tf->writebuffered);
 }
 else
 {
 }
 return bytestowrite;
}

canonical_original_code:
int VFSTCP_WriteBytes(struct vfsfile_s *file, void *buffer, int bytestowrite)
{
 struct tcpfile_s *tf = (tcpfile_t*)file;
 int len;
 if (bytestowrite < 0)
  Sys_Error("VFSTCP_WriteBytes: bytestowrite < 0");
 if (tf->sock == -1)
  return 0;
 if (bytestowrite > (int)sizeof(tf->writebuffer) - tf->writebuffered)
 {
  Com_Printf("VFSTCP: failed to write %d bytes, buffer overflow, closing link\n", bytestowrite);
  VFSTCP_Error(tf);
  return 0;
 }
 memmove(tf->writebuffer + tf->writebuffered, buffer, bytestowrite);
 tf->writebuffered += bytestowrite;
 len = send(tf->sock, tf->writebuffer, tf->writebuffered, 0);
 if (len < 0)
 {
  int err = (*__errno_location ());
  if (err != 11 )
  {
   Com_Printf("VFSTCP: failed to write %d bytes, closing link, socket error %d\n", bytestowrite, err);
   VFSTCP_Error(tf);
   return 0;
  }
 }
 else if (len > 0)
 {
  tf->writebuffered -= len;
  memmove(tf->writebuffer, tf->writebuffer + len, tf->writebuffered);
 }
 else
 {
 }
 return bytestowrite;
}

variable_types: struct vfsfile_s { int (*ReadBytes)(struct vfsfile_s *file, void *buffer, int bytestoread, enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 } *err); int (*WriteBytes)(struct vfsfile_s *file, void *buffer, int bytestowrite); int (*Seek)(struct vfsfile_s *file, unsigned long pos, int whence); unsigned long (*Tell)(struct vfsfile_s *file); unsigned long (*GetLen)(struct vfsfile_s *file); void (*Close)(struct vfsfile_s *file); void (*Flush)(struct vfsfile_s *file); enum qbool { false=0, true=1 } seekingisabadplan; enum qbool { false=0, true=1 } copyprotected; } *

variable_types: bytestowrite int

variable_types: err int


decompiled_code:
__int64 __fastcall VFSTCP_Seek(__int64 a1)
{
Com_Printf("VFSTCP: seek is illegal, closing link\n");
VFSTCP_Error(a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
Com_Printf("VFSTCP: seek is illegal, closing link\n");
func1(a1);
return 0xFFFFFFFFLL;
}

original_code:
int VFSTCP_Seek (struct vfsfile_s *file, unsigned long pos, int whence)
{
 Com_Printf("VFSTCP: seek is illegal, closing link\n");
 VFSTCP_Error((tcpfile_t*)file);
 return -1;
}

canonical_original_code:
int VFSTCP_Seek(struct vfsfile_s *file, unsigned long pos, int whence)
{
 Com_Printf("VFSTCP: seek is illegal, closing link\n");
 VFSTCP_Error((struct tcpfile_s *)file);
 return -1;
}

variable_types:
pos
unsigned long

variable_types: whence int


decompiled_code:
__int64 __fastcall VFSTCP_Tell(__int64 a1)
{
Com_Printf("VFSTCP: tell is illegal, closing link\n");
VFSTCP_Error(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
Com_Printf("VFSTCP: tell is illegal, closing link\n");
func1(a1);
return 0LL;
}

original_code:
unsigned long VFSTCP_Tell (struct vfsfile_s *file)
{
 Com_Printf("VFSTCP: tell is illegal, closing link\n");
 VFSTCP_Error((tcpfile_t*)file);
 return 0;
}

canonical_original_code:
unsigned long VFSTCP_Tell(struct vfsfile_s *file)
{
 Com_Printf("VFSTCP: tell is illegal, closing link\n");
 VFSTCP_Error((struct tcpfile_s *)file);
 return 0;
}


decompiled_code:
void __fastcall VFSTCP_Close(void *ptr, __int64 a2)
{
_QWORD *v2; // rdx
_QWORD *v3; // rax

VFSTCP_Error((__int64)ptr);
if ( !vfs_tcp_list )
{
LABEL_12:
Com_Printf("VFSTCP: Close: not found in list\n", a2, v2);
goto LABEL_13;
}
if ( ptr != (void *)vfs_tcp_list )
{
v3 = (_QWORD *)vfs_tcp_list;
while ( 1 )
{
v2 = v3;
v3 = (_QWORD *)v3[81930];
if ( !v3 )
goto LABEL_12;
if ( ptr == v3 )
{
if ( (_QWORD *)vfs_tcp_list == v3 )
goto LABEL_11;
v2[81930] = v3[81930];
goto LABEL_8;
}
}
}
v3 = (_QWORD *)vfs_tcp_list;
LABEL_11:
vfs_tcp_list = v3[81930];
LABEL_13:
if ( ptr )
LABEL_8:
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr, __int64 a2)
{
_QWORD *v2; // rdx
_QWORD *v3; // rax

func1((__int64)ptr);
if ( !vfs_tcp_list )
{
LABEL_12:
Com_Printf("VFSTCP: Close: not found in list\n", a2, v2);
goto LABEL_13;
}
if ( ptr != (void *)vfs_tcp_list )
{
v3 = (_QWORD *)vfs_tcp_list;
while ( 1 )
{
v2 = v3;
v3 = (_QWORD *)v3[81930];
if ( !v3 )
goto LABEL_12;
if ( ptr == v3 )
{
if ( (_QWORD *)vfs_tcp_list == v3 )
goto LABEL_11;
v2[81930] = v3[81930];
goto LABEL_8;
}
}
}
v3 = (_QWORD *)vfs_tcp_list;
LABEL_11:
vfs_tcp_list = v3[81930];
LABEL_13:
if ( ptr )
LABEL_8:
free(ptr);
}

original_code:
void VFSTCP_Close (struct vfsfile_s *file)
{
 tcpfile_t *tmp, *prev;
 VFSTCP_Error((tcpfile_t*)file);
 for (tmp = prev = vfs_tcp_list; tmp; tmp = tmp->next)
 {
  if (tmp == (tcpfile_t*)file)
  {
   if (tmp == vfs_tcp_list)
    vfs_tcp_list = tmp->next;
   else
    prev->next = tmp->next;
   break;
  }
  prev = tmp;
 }
 if (!tmp)
  Com_Printf("VFSTCP: Close: not found in list\n");
 if(file) { free(file); file = ((void *)0); };
}

canonical_original_code:
void VFSTCP_Close(struct vfsfile_s *file)
{
 struct tcpfile_s *tmp; struct tcpfile_s *prev;
 VFSTCP_Error((struct tcpfile_s *)file);
 for (tmp = prev = vfs_tcp_list; tmp; tmp = tmp->next)
 {
  if (tmp == (struct tcpfile_s *)file)
  {
   if (tmp == vfs_tcp_list)
    vfs_tcp_list = tmp->next;
   else
    prev->next = tmp->next;
   break;
  }
  prev = tmp;
 }
 if (!tmp)
  Com_Printf("VFSTCP: Close: not found in list\n");
 if(file) { free(file); file = ((void *)0); };
}


decompiled_code:
__int64 VFSTCP_Tick()
{
__int64 i; // rbx
__int64 result; // rax
_BOOL4 v2; // [rsp+Ch] [rbp-Ch] BYREF

for ( i = vfs_tcp_list; i; i = *(_QWORD *)(i + 655440) )
{
VFSTCP_ReadBytes((_DWORD *)i, 0LL, 0, &v2);
result = VFSTCP_WriteBytes((int *)i, 0LL, 0);
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 i; // rbx
__int64 result; // rax
_BOOL4 v2; // [rsp+Ch] [rbp-Ch] BYREF

for ( i = vfs_tcp_list; i; i = *(_QWORD *)(i + 655440) )
{
func2((_DWORD *)i, 0LL, 0, &v2);
result = func3((int *)i, 0LL, 0);
}
return result;
}

original_code:
void VFSTCP_Tick(void)
{
 tcpfile_t *tmp;
 vfserrno_t err;
 for (tmp = vfs_tcp_list; tmp; tmp = tmp->next)
 {
  VFSTCP_ReadBytes ((vfsfile_t*)tmp, ((void *)0), 0, &err);
  VFSTCP_WriteBytes ((vfsfile_t*)tmp, ((void *)0), 0);
 }
}

canonical_original_code:
void VFSTCP_Tick()
{
 struct tcpfile_s *tmp;
 enum vfserrno_t err;
 for (tmp = vfs_tcp_list; tmp; tmp = tmp->next)
 {
  VFSTCP_ReadBytes ((struct vfsfile_s *)tmp, ((void *)0), 0, &err);
  VFSTCP_WriteBytes ((struct vfsfile_s *)tmp, ((void *)0), 0);
 }
}

variable_types: enum vfserrno_t { VFSERR_NONE=0, VFSERR_EOF=1 }


decompiled_code:
__int64 VFS_TICK()
{
return VFSTCP_Tick();
}

canonical_decompiled_code:
__int64 func8()
{
return func7();
}

original_code:
void VFS_TICK(void)
{
 VFSTCP_Tick();
}

canonical_original_code:
void VFS_TICK()
{
 VFSTCP_Tick();
}


decompiled_code:
__int64 CDAudio_GetAudioDiskInfo()
{
unsigned int v0; // ebx
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

cdValid = 0;
if ( ioctl(cdfile, 0x5305uLL, v2) == -1 )
{
v0 = -1;
Com_DPrintf("ioctl cdromreadtochdr failed\n");
}
else if ( v2[0] )
{
cdValid = 1;
maxTrack = v2[1];
v0 = 0;
}
else
{
Com_DPrintf("CDAudio: no music tracks\n");
v0 = -1;
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
char v2[10]; // [rsp+Eh] [rbp-Ah] BYREF

cdValid = 0;
if ( ioctl(cdfile, 0x5305uLL, v2) == -1 )
{
v0 = -1;
Com_DPrintf("ioctl cdromreadtochdr failed\n");
}
else if ( v2[0] )
{
cdValid = 1;
maxTrack = v2[1];
v0 = 0;
}
else
{
Com_DPrintf("CDAudio: no music tracks\n");
v0 = -1;
}
return v0;
}

original_code:
static int CDAudio_GetAudioDiskInfo(void)
{
 struct cdrom_tochdr tochdr;
 cdValid = false;
 if ( ioctl(cdfile, 0x5305, &tochdr) == -1 )
    {
      Com_DPrintf ("ioctl cdromreadtochdr failed\n");
   return -1;
    }
 if (tochdr.cdth_trk0 < 1)
 {
  Com_DPrintf ("CDAudio: no music tracks\n");
  return -1;
 }
 cdValid = true;
 maxTrack = tochdr.cdth_trk1;
 return 0;
}

canonical_original_code:
static int CDAudio_GetAudioDiskInfo()
{
 struct cdrom_tochdr tochdr;
 cdValid = false;
 if ( ioctl(cdfile, 0x5305, &tochdr) == -1 )
    {
      Com_DPrintf ("ioctl cdromreadtochdr failed\n");
   return -1;
    }
 if (tochdr.cdth_trk0 < 1)
 {
  Com_DPrintf ("CDAudio: no music tracks\n");
  return -1;
 }
 cdValid = true;
 maxTrack = tochdr.cdth_trk1;
 return 0;
}

variable_types: struct cdrom_tochdr { unsigned char cdth_trk0; unsigned char cdth_trk1; }


decompiled_code:
void CDAudio_CloseDoor()
{
if ( cdfile != -1 && enabled && ioctl(cdfile, 0x5319uLL) == -1 )
Com_DPrintf("ioctl cdromclosetray failed\n");
}

canonical_decompiled_code:
void func1()
{
if ( cdfile != -1 && enabled && ioctl(cdfile, 0x5319uLL) == -1 )
Com_DPrintf("ioctl cdromclosetray failed\n");
}

original_code:
static void CDAudio_CloseDoor(void)
{
 if (cdfile == -1 || !enabled)
  return;
 if ( ioctl(cdfile, 0x5319) == -1 )
  Com_DPrintf ("ioctl cdromclosetray failed\n");
}

canonical_original_code:
static void CDAudio_CloseDoor()
{
 if (cdfile == -1 || !enabled)
  return;
 if ( ioctl(cdfile, 0x5319) == -1 )
  Com_DPrintf ("ioctl cdromclosetray failed\n");
}


decompiled_code:
void CDAudio_Eject()
{
if ( cdfile != -1 && enabled && ioctl(cdfile, 0x5309uLL) == -1 )
Com_DPrintf("ioctl cdromeject failed\n");
}

canonical_decompiled_code:
void func2()
{
if ( cdfile != -1 && enabled && ioctl(cdfile, 0x5309uLL) == -1 )
Com_DPrintf("ioctl cdromeject failed\n");
}

original_code:
static void CDAudio_Eject(void)
{
 if (cdfile == -1 || !enabled)
  return;
 if ( ioctl(cdfile, 0x5309) == -1 )
  Com_DPrintf ("ioctl cdromeject failed\n");
}

canonical_original_code:
static void CDAudio_Eject()
{
 if (cdfile == -1 || !enabled)
  return;
 if ( ioctl(cdfile, 0x5309) == -1 )
  Com_DPrintf ("ioctl cdromeject failed\n");
}


decompiled_code:
void __fastcall CDAudio_Play(unsigned __int8 a1, int a2)
{
unsigned __int8 v2; // bl
int v3; // er12
char v4[4]; // [rsp+0h] [rbp-28h] BYREF
char v5[36]; // [rsp+4h] [rbp-24h] BYREF

if ( cdfile != -1 )
{
if ( enabled )
{
if ( cdValid || (CDAudio_GetAudioDiskInfo(), cdValid) )
{
v2 = remap[a1];
if ( !v2 || (unsigned __int8)maxTrack < v2 )
{
Com_DPrintf("CDAudio: Bad track number %u.\n", v2);
return;
}
v5[0] = remap[a1];
v5[2] = 2;
if ( ioctl(cdfile, 0x5306uLL, v5) == -1 )
{
Com_DPrintf("ioctl cdromreadtocentry failed\n");
return;
}
if ( (v5[1] & 0xF0) == 64 )
{
Com_Printf("CDAudio: track %i is not audio\n", v2);
return;
}
if ( playing )
{
if ( playTrack == v2 )
return;
CDAudio_Stop();
}
v4[0] = v2;
v4[2] = v2;
v4[1] = 1;
v4[3] = 99;
v3 = cdfile;
if ( ioctl(cdfile, 0x5304uLL, v4) == -1 )
{
Com_DPrintf("ioctl cdromplaytrkind failed\n");
}
else
{
if ( ioctl(v3, 0x5302uLL) == -1 )
Com_DPrintf("ioctl cdromresume failed\n");
playLooping = a2;
playTrack = v2;
playing = 1;
if ( *(float *)&cdvolume == 0.0 )
CDAudio_Pause();
}
}
}
}
}

canonical_decompiled_code:
void __fastcall func5(unsigned __int8 a1, int a2)
{
unsigned __int8 v2; // bl
int v3; // er12
char v4[4]; // [rsp+0h] [rbp-28h] BYREF
char v5[36]; // [rsp+4h] [rbp-24h] BYREF

if ( cdfile != -1 )
{
if ( enabled )
{
if ( cdValid || (func0(), cdValid) )
{
v2 = remap[a1];
if ( !v2 || (unsigned __int8)maxTrack < v2 )
{
Com_DPrintf("CDAudio: Bad track number %u.\n", v2);
return;
}
v5[0] = remap[a1];
v5[2] = 2;
if ( ioctl(cdfile, 0x5306uLL, v5) == -1 )
{
Com_DPrintf("ioctl cdromreadtocentry failed\n");
return;
}
if ( (v5[1] & 0xF0) == 64 )
{
Com_Printf("CDAudio: track %i is not audio\n", v2);
return;
}
if ( playing )
{
if ( playTrack == v2 )
return;
func3();
}
v4[0] = v2;
v4[2] = v2;
v4[1] = 1;
v4[3] = 99;
v3 = cdfile;
if ( ioctl(cdfile, 0x5304uLL, v4) == -1 )
{
Com_DPrintf("ioctl cdromplaytrkind failed\n");
}
else
{
if ( ioctl(v3, 0x5302uLL) == -1 )
Com_DPrintf("ioctl cdromresume failed\n");
playLooping = a2;
playTrack = v2;
playing = 1;
if ( *(float *)&cdvolume == 0.0 )
func4();
}
}
}
}
}

original_code:
void CDAudio_Play(byte track, qbool looping)
{
 struct cdrom_tocentry entry;
 struct cdrom_ti ti;
 if (cdfile == -1 || !enabled)
  return;
 if (!cdValid)
 {
  CDAudio_GetAudioDiskInfo();
  if (!cdValid)
   return;
 }
 track = remap[track];
 if (track < 1 || track > maxTrack)
 {
  Com_DPrintf ("CDAudio: Bad track number %u.\n", track);
  return;
 }
 entry.cdte_track = track;
 entry.cdte_format = 0x02;
    if ( ioctl(cdfile, 0x5306, &entry) == -1 )
 {
  Com_DPrintf ("ioctl cdromreadtocentry failed\n");
  return;
 }
 if (entry.cdte_ctrl == 0x04)
 {
  Com_Printf ("CDAudio: track %i is not audio\n", track);
  return;
 }
 if (playing)
 {
  if (playTrack == track)
   return;
  CDAudio_Stop();
 }
 ti.cdti_trk0 = track;
 ti.cdti_trk1 = track;
 ti.cdti_ind0 = 1;
 ti.cdti_ind1 = 99;
 if ( ioctl(cdfile, 0x5304, &ti) == -1 )
    {
  Com_DPrintf ("ioctl cdromplaytrkind failed\n");
  return;
    }
 if ( ioctl(cdfile, 0x5302) == -1 )
  Com_DPrintf ("ioctl cdromresume failed\n");
 playLooping = looping;
 playTrack = track;
 playing = true;
 if (cdvolume == 0.0)
  CDAudio_Pause ();
}

canonical_original_code:
void CDAudio_Play(unsigned char track, enum qbool looping)
{
 struct cdrom_tocentry entry;
 struct cdrom_ti ti;
 if (cdfile == -1 || !enabled)
  return;
 if (!cdValid)
 {
  CDAudio_GetAudioDiskInfo();
  if (!cdValid)
   return;
 }
 track = remap[track];
 if (track < 1 || track > maxTrack)
 {
  Com_DPrintf ("CDAudio: Bad track number %u.\n", track);
  return;
 }
 entry.cdte_track = track;
 entry.cdte_format = 0x02;
    if ( ioctl(cdfile, 0x5306, &entry) == -1 )
 {
  Com_DPrintf ("ioctl cdromreadtocentry failed\n");
  return;
 }
 if (entry.cdte_ctrl == 0x04)
 {
  Com_Printf ("CDAudio: track %i is not audio\n", track);
  return;
 }
 if (playing)
 {
  if (playTrack == track)
   return;
  CDAudio_Stop();
 }
 ti.cdti_trk0 = track;
 ti.cdti_trk1 = track;
 ti.cdti_ind0 = 1;
 ti.cdti_ind1 = 99;
 if ( ioctl(cdfile, 0x5304, &ti) == -1 )
    {
  Com_DPrintf ("ioctl cdromplaytrkind failed\n");
  return;
    }
 if ( ioctl(cdfile, 0x5302) == -1 )
  Com_DPrintf ("ioctl cdromresume failed\n");
 playLooping = looping;
 playTrack = track;
 playing = true;
 if (cdvolume == 0.0)
  CDAudio_Pause ();
}

variable_types:
track
unsigned char

variable_types:
looping
enum qbool { false=0, true=1 }

variable_types: struct cdrom_tocentry { unsigned char cdte_track; unsigned char cdte_adr; unsigned char cdte_ctrl; unsigned char cdte_format; union cdrom_addr { struct cdrom_msf0 { unsigned char minute; unsigned char second; unsigned char frame; } msf; int lba; } cdte_addr; unsigned char cdte_datamode; }

variable_types: struct cdrom_ti { unsigned char cdti_trk0; unsigned char cdti_ind0; unsigned char cdti_trk1; unsigned char cdti_ind1; }

user_defined_types: struct cdrom_tocentry { unsigned char cdte_track; unsigned char cdte_adr; unsigned char cdte_ctrl; unsigned char cdte_format; union cdrom_addr cdte_addr; unsigned char cdte_datamode; }

user_defined_types: union cdrom_addr { struct cdrom_msf0 msf; int lba; }


decompiled_code:
void CDAudio_Stop()
{
int *v0; // rax

if ( cdfile != -1 && enabled && playing )
{
if ( ioctl(cdfile, 0x5307uLL) == -1 )
{
v0 = _errno_location();
Com_DPrintf("ioctl cdromstop failed (%d)\n", (unsigned int)*v0);
}
wasPlaying = 0;
playing = 0;
}
}

canonical_decompiled_code:
void func3()
{
int *v0; // rax

if ( cdfile != -1 && enabled && playing )
{
if ( ioctl(cdfile, 0x5307uLL) == -1 )
{
v0 = _errno_location();
Com_DPrintf("ioctl cdromstop failed (%d)\n", (unsigned int)*v0);
}
wasPlaying = 0;
playing = 0;
}
}

original_code:
void CDAudio_Stop(void)
{
 if (cdfile == -1 || !enabled)
  return;
 if (!playing)
  return;
 if ( ioctl(cdfile, 0x5307) == -1 )
  Com_DPrintf ("ioctl cdromstop failed (%d)\n", (*__errno_location ()));
 wasPlaying = false;
 playing = false;
}

canonical_original_code:
void CDAudio_Stop()
{
 if (cdfile == -1 || !enabled)
  return;
 if (!playing)
  return;
 if ( ioctl(cdfile, 0x5307) == -1 )
  Com_DPrintf ("ioctl cdromstop failed (%d)\n", (*__errno_location ()));
 wasPlaying = false;
 playing = false;
}


decompiled_code:
void CDAudio_Pause()
{
if ( cdfile != -1 && enabled && playing )
{
if ( ioctl(cdfile, 0x5301uLL) == -1 )
Com_DPrintf("ioctl cdrompause failed\n");
wasPlaying = playing;
playing = 0;
}
}

canonical_decompiled_code:
void func4()
{
if ( cdfile != -1 && enabled && playing )
{
if ( ioctl(cdfile, 0x5301uLL) == -1 )
Com_DPrintf("ioctl cdrompause failed\n");
wasPlaying = playing;
playing = 0;
}
}

original_code:
void CDAudio_Pause(void)
{
 if (cdfile == -1 || !enabled)
  return;
 if (!playing)
  return;
 if ( ioctl(cdfile, 0x5301) == -1 )
  Com_DPrintf ("ioctl cdrompause failed\n");
 wasPlaying = playing;
 playing = false;
}

canonical_original_code:
void CDAudio_Pause()
{
 if (cdfile == -1 || !enabled)
  return;
 if (!playing)
  return;
 if ( ioctl(cdfile, 0x5301) == -1 )
  Com_DPrintf ("ioctl cdrompause failed\n");
 wasPlaying = playing;
 playing = false;
}


decompiled_code:
void CDAudio_Resume()
{
if ( cdfile != -1 && enabled && cdValid && wasPlaying )
{
if ( ioctl(cdfile, 0x5302uLL) == -1 )
Com_DPrintf("ioctl cdromresume failed\n");
playing = 1;
}
}

canonical_decompiled_code:
void func6()
{
if ( cdfile != -1 && enabled && cdValid && wasPlaying )
{
if ( ioctl(cdfile, 0x5302uLL) == -1 )
Com_DPrintf("ioctl cdromresume failed\n");
playing = 1;
}
}

original_code:
void CDAudio_Resume(void)
{
 if (cdfile == -1 || !enabled)
  return;
 if (!cdValid)
  return;
 if (!wasPlaying)
  return;
 if ( ioctl(cdfile, 0x5302) == -1 )
  Com_DPrintf ("ioctl cdromresume failed\n");
 playing = true;
}

canonical_original_code:
void CDAudio_Resume()
{
 if (cdfile == -1 || !enabled)
  return;
 if (!cdValid)
  return;
 if (!wasPlaying)
  return;
 if ( ioctl(cdfile, 0x5302) == -1 )
  Com_DPrintf ("ioctl cdromresume failed\n");
 playing = true;
}


decompiled_code:
void CD_f()
{
const char *v0; // rbx
const char *v1; // rax
__int64 i; // rax
int v3; // eax
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax
__int64 j; // rbx
__int64 v8; // rdx
__int64 v9; // rax
unsigned __int8 v10; // al
__int64 v11; // rax
unsigned __int8 v12; // al
const char *v13; // rax
const char *v14; // rsi
const char *v15; // rsi

if ( (int)Cmd_Argc() <= 1 )
{
v1 = (const char *)Cmd_Argv(0LL);
Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", v1);
}
else
{
v0 = (const char *)Cmd_Argv(1LL);
if ( !strcasecmp(v0, "on") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
enabled = 1;
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "off") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
CDAudio_Stop();
enabled = 0;
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "reset") )
{
if ( (unsigned int)Cmd_Argc() != 2 )
goto LABEL_56;
enabled = 1;
CDAudio_Stop();
for ( i = 0LL; i != 100; ++i )
remap[i] = i;
CDAudio_GetAudioDiskInfo();
}
else if ( !strcasecmp(v0, "remap") )
{
v3 = Cmd_Argc();
if ( v3 == 2 )
{
for ( j = 1LL; j != 100; ++j )
{
v8 = (unsigned __int8)remap[j];
if ( (_DWORD)v8 != (_DWORD)j )
Com_Printf(" %u -> %u\n", (unsigned int)j, v8);
}
}
else if ( v3 - 2 > 0 )
{
v4 = (unsigned int)(v3 - 3) + 3LL;
v5 = 2LL;
do
{
v6 = Cmd_Argv((unsigned int)v5);
byte_E7F[v5++] = Q_atoi(v6);
}
while ( v5 != v4 );
}
}
else
{
if ( !strcasecmp(v0, "close") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
CDAudio_CloseDoor();
return;
}
goto LABEL_56;
}
if ( !cdValid )
{
CDAudio_GetAudioDiskInfo();
if ( !cdValid )
{
Com_Printf("No CD in player.\n");
return;
}
}
if ( !strcasecmp(v0, "play") )
{
if ( (unsigned int)Cmd_Argc() == 3 )
{
v9 = Cmd_Argv(2LL);
v10 = Q_atoi(v9);
CDAudio_Play(v10, 0);
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "loop") )
{
if ( (unsigned int)Cmd_Argc() == 3 )
{
v11 = Cmd_Argv(2LL);
v12 = Q_atoi(v11);
CDAudio_Play(v12, 1);
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "stop") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
CDAudio_Stop();
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "pause") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
CDAudio_Pause();
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "resume") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
CDAudio_Resume();
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "eject") )
{
if ( (unsigned int)Cmd_Argc() != 2 )
{
LABEL_56:
v13 = (const char *)Cmd_Argv(0LL);
Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", v13);
return;
}
CDAudio_Stop();
CDAudio_Eject();
cdValid = 0;
}
else if ( !strcasecmp(v0, "info") )
{
if ( (unsigned int)Cmd_Argc() != 2 )
goto LABEL_56;
Com_Printf("%u tracks\n", (unsigned __int8)maxTrack);
if ( playing )
{
v14 = "looping";
if ( !playLooping )
v14 = "playing";
Com_Printf("Currently %s track %u\n", v14, (unsigned __int8)playTrack);
}
else if ( wasPlaying )
{
v15 = "looping";
if ( !playLooping )
v15 = "playing";
Com_Printf("Paused %s track %u\n", v15, (unsigned __int8)playTrack);
}
Com_Printf("Volume is %f\n", *(float *)&cdvolume);
}
}
}
}

canonical_decompiled_code:
void func7()
{
const char *v0; // rbx
const char *v1; // rax
__int64 i; // rax
int v3; // eax
__int64 v4; // rbp
__int64 v5; // rbx
__int64 v6; // rax
__int64 j; // rbx
__int64 v8; // rdx
__int64 v9; // rax
unsigned __int8 v10; // al
__int64 v11; // rax
unsigned __int8 v12; // al
const char *v13; // rax
const char *v14; // rsi
const char *v15; // rsi

if ( (int)Cmd_Argc() <= 1 )
{
v1 = (const char *)Cmd_Argv(0LL);
Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", v1);
}
else
{
v0 = (const char *)Cmd_Argv(1LL);
if ( !strcasecmp(v0, "on") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
enabled = 1;
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "off") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
func3();
enabled = 0;
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "reset") )
{
if ( (unsigned int)Cmd_Argc() != 2 )
goto LABEL_56;
enabled = 1;
func3();
for ( i = 0LL; i != 100; ++i )
remap[i] = i;
func0();
}
else if ( !strcasecmp(v0, "remap") )
{
v3 = Cmd_Argc();
if ( v3 == 2 )
{
for ( j = 1LL; j != 100; ++j )
{
v8 = (unsigned __int8)remap[j];
if ( (_DWORD)v8 != (_DWORD)j )
Com_Printf(" %u -> %u\n", (unsigned int)j, v8);
}
}
else if ( v3 - 2 > 0 )
{
v4 = (unsigned int)(v3 - 3) + 3LL;
v5 = 2LL;
do
{
v6 = Cmd_Argv((unsigned int)v5);
byte_E7F[v5++] = Q_atoi(v6);
}
while ( v5 != v4 );
}
}
else
{
if ( !strcasecmp(v0, "close") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
func1();
return;
}
goto LABEL_56;
}
if ( !cdValid )
{
func0();
if ( !cdValid )
{
Com_Printf("No CD in player.\n");
return;
}
}
if ( !strcasecmp(v0, "play") )
{
if ( (unsigned int)Cmd_Argc() == 3 )
{
v9 = Cmd_Argv(2LL);
v10 = Q_atoi(v9);
func5(v10, 0);
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "loop") )
{
if ( (unsigned int)Cmd_Argc() == 3 )
{
v11 = Cmd_Argv(2LL);
v12 = Q_atoi(v11);
func5(v12, 1);
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "stop") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
func3();
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "pause") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
func4();
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "resume") )
{
if ( (unsigned int)Cmd_Argc() == 2 )
{
func6();
return;
}
goto LABEL_56;
}
if ( !strcasecmp(v0, "eject") )
{
if ( (unsigned int)Cmd_Argc() != 2 )
{
LABEL_56:
v13 = (const char *)Cmd_Argv(0LL);
Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", v13);
return;
}
func3();
func2();
cdValid = 0;
}
else if ( !strcasecmp(v0, "info") )
{
if ( (unsigned int)Cmd_Argc() != 2 )
goto LABEL_56;
Com_Printf("%u tracks\n", (unsigned __int8)maxTrack);
if ( playing )
{
v14 = "looping";
if ( !playLooping )
v14 = "playing";
Com_Printf("Currently %s track %u\n", v14, (unsigned __int8)playTrack);
}
else if ( wasPlaying )
{
v15 = "looping";
if ( !playLooping )
v15 = "playing";
Com_Printf("Paused %s track %u\n", v15, (unsigned __int8)playTrack);
}
Com_Printf("Volume is %f\n", *(float *)&cdvolume);
}
}
}
}

original_code:
void CD_f (void) {
 char *command;
 int ret, n;
 if (Cmd_Argc() < 2) {
  Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0));
  return;
 }
 command = Cmd_Argv (1);
 if (!strcasecmp(command, "on")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  enabled = true;
  return;
 } else if (!strcasecmp(command, "off")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Stop();
  enabled = false;
  return;
 } else if (!strcasecmp(command, "reset")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  enabled = true;
  CDAudio_Stop();
  for (n = 0; n < 100; n++)
   remap[n] = n;
  CDAudio_GetAudioDiskInfo();
  return;
 } else if (!strcasecmp(command, "remap")) {
  ret = Cmd_Argc() - 2;
  if (!ret) {
   for (n = 1; n < 100; n++)
    if (remap[n] != n)
     Com_Printf ("  %u -> %u\n", n, remap[n]);
  } else {
   for (n = 1; n <= ret; n++)
    remap[n] = Q_atoi(Cmd_Argv (n + 1));
  }
  return;
 } else if (!strcasecmp(command, "close")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_CloseDoor();
  return;
 }
 if (!cdValid) {
  CDAudio_GetAudioDiskInfo();
  if (!cdValid) {
   Com_Printf ("No CD in player.\n");
   return;
  }
 }
 if (!strcasecmp(command, "play")) {
  if (Cmd_Argc() != 3) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Play((byte) Q_atoi(Cmd_Argv(2)), false);
 } else if (!strcasecmp(command, "loop")) {
  if (Cmd_Argc() != 3) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Play((byte) Q_atoi(Cmd_Argv(2)), true);
 } else if (!strcasecmp(command, "stop")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Stop();
 } else if (!strcasecmp(command, "pause")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Pause();
 } else if (!strcasecmp(command, "resume")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Resume();
 } else if (!strcasecmp(command, "eject")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Stop();
  CDAudio_Eject();
  cdValid = false;
 } else if (!strcasecmp(command, "info")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  Com_Printf ("%u tracks\n", maxTrack);
  if (playing)
   Com_Printf ("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
  else if (wasPlaying)
   Com_Printf ("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
  Com_Printf ("Volume is %f\n", cdvolume);
 }
}

canonical_original_code:
void CD_f() {
 char *command;
 int ret; int n;
 if (Cmd_Argc() < 2) {
  Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0));
  return;
 }
 command = Cmd_Argv (1);
 if (!strcasecmp(command, "on")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  enabled = true;
  return;
 } else if (!strcasecmp(command, "off")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Stop();
  enabled = false;
  return;
 } else if (!strcasecmp(command, "reset")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  enabled = true;
  CDAudio_Stop();
  for (n = 0; n < 100; n++)
   remap[n] = n;
  CDAudio_GetAudioDiskInfo();
  return;
 } else if (!strcasecmp(command, "remap")) {
  ret = Cmd_Argc() - 2;
  if (!ret) {
   for (n = 1; n < 100; n++)
    if (remap[n] != n)
     Com_Printf ("  %u -> %u\n", n, remap[n]);
  } else {
   for (n = 1; n <= ret; n++)
    remap[n] = Q_atoi(Cmd_Argv (n + 1));
  }
  return;
 } else if (!strcasecmp(command, "close")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_CloseDoor();
  return;
 }
 if (!cdValid) {
  CDAudio_GetAudioDiskInfo();
  if (!cdValid) {
   Com_Printf ("No CD in player.\n");
   return;
  }
 }
 if (!strcasecmp(command, "play")) {
  if (Cmd_Argc() != 3) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Play((unsigned char) Q_atoi(Cmd_Argv(2)), false);
 } else if (!strcasecmp(command, "loop")) {
  if (Cmd_Argc() != 3) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Play((unsigned char) Q_atoi(Cmd_Argv(2)), true);
 } else if (!strcasecmp(command, "stop")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Stop();
 } else if (!strcasecmp(command, "pause")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Pause();
 } else if (!strcasecmp(command, "resume")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Resume();
 } else if (!strcasecmp(command, "eject")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  CDAudio_Stop();
  CDAudio_Eject();
  cdValid = false;
 } else if (!strcasecmp(command, "info")) {
  if (Cmd_Argc() != 2) { Com_Printf("Usage: %s <on|off|reset|remap|close|play|loop|stop|pause|resume|eject|info>\n", Cmd_Argv(0)); return; };
  Com_Printf ("%u tracks\n", maxTrack);
  if (playing)
   Com_Printf ("Currently %s track %u\n", playLooping ? "looping" : "playing", playTrack);
  else if (wasPlaying)
   Com_Printf ("Paused %s track %u\n", playLooping ? "looping" : "playing", playTrack);
  Com_Printf ("Volume is %f\n", cdvolume);
 }
}

variable_types:
command
char *

variable_types: ret int

variable_types: n int


decompiled_code:
void CDAudio_Update()
{
char v0[24]; // [rsp+0h] [rbp-18h] BYREF

if ( enabled )
{
if ( *(float *)&cdvolume != bgmvolume[8] )
{
if ( *(float *)&cdvolume == 0.0 )
{
Cvar_SetValue(bgmvolume, COERCE_DOUBLE((unsigned __int64)LC33));
cdvolume = LODWORD(bgmvolume[8]);
CDAudio_Resume();
}
else
{
Cvar_SetValue(bgmvolume, 0.0);
cdvolume = LODWORD(bgmvolume[8]);
CDAudio_Pause();
}
}
if ( playing && time(0LL) > lastchk_0 )
{
lastchk_0 = time(0LL) + 2;
v0[0] = 2;
if ( ioctl(cdfile, 0x530BuLL, v0) == -1 )
{
Com_DPrintf("ioctl cdromsubchnl failed\n");
playing = 0;
}
else if ( (unsigned __int8)(v0[1] - 17) > 1u )
{
playing = 0;
if ( playLooping )
CDAudio_Play(playTrack, 1);
}
}
}
}

canonical_decompiled_code:
void func8()
{
char v0[24]; // [rsp+0h] [rbp-18h] BYREF

if ( enabled )
{
if ( *(float *)&cdvolume != bgmvolume[8] )
{
if ( *(float *)&cdvolume == 0.0 )
{
Cvar_SetValue(bgmvolume, COERCE_DOUBLE((unsigned __int64)LC33));
cdvolume = LODWORD(bgmvolume[8]);
func6();
}
else
{
Cvar_SetValue(bgmvolume, 0.0);
cdvolume = LODWORD(bgmvolume[8]);
func4();
}
}
if ( playing && time(0LL) > lastchk_0 )
{
lastchk_0 = time(0LL) + 2;
v0[0] = 2;
if ( ioctl(cdfile, 0x530BuLL, v0) == -1 )
{
Com_DPrintf("ioctl cdromsubchnl failed\n");
playing = 0;
}
else if ( (unsigned __int8)(v0[1] - 17) > 1u )
{
playing = 0;
if ( playLooping )
func5(playTrack, 1);
}
}
}
}

original_code:
void CDAudio_Update(void)
{
 struct cdrom_subchnl subchnl;
 static time_t lastchk;
 if (!enabled)
  return;
 if (bgmvolume.value != cdvolume)
 {
  if (cdvolume)
  {
   Cvar_SetValue (&bgmvolume, 0.0);
   cdvolume = bgmvolume.value;
   CDAudio_Pause ();
  }
  else
  {
   Cvar_SetValue (&bgmvolume, 1.0);
   cdvolume = bgmvolume.value;
   CDAudio_Resume ();
  }
 }
 if (playing && lastchk < time(((void *)0))) {
  lastchk = time(((void *)0)) + 2;
  subchnl.cdsc_format = 0x02;
  if (ioctl(cdfile, 0x530b, &subchnl) == -1 ) {
   Com_DPrintf ("ioctl cdromsubchnl failed\n");
   playing = false;
   return;
  }
  if (subchnl.cdsc_audiostatus != 0x11 &&
   subchnl.cdsc_audiostatus != 0x12) {
   playing = false;
   if (playLooping)
    CDAudio_Play(playTrack, true);
  }
 }
}

canonical_original_code:
void CDAudio_Update()
{
 struct cdrom_subchnl subchnl;
 static long lastchk;
 if (!enabled)
  return;
 if (bgmvolume.value != cdvolume)
 {
  if (cdvolume)
  {
   Cvar_SetValue (&bgmvolume, 0.0);
   cdvolume = bgmvolume.value;
   CDAudio_Pause ();
  }
  else
  {
   Cvar_SetValue (&bgmvolume, 1.0);
   cdvolume = bgmvolume.value;
   CDAudio_Resume ();
  }
 }
 if (playing && lastchk < time(((void *)0))) {
  lastchk = time(((void *)0)) + 2;
  subchnl.cdsc_format = 0x02;
  if (ioctl(cdfile, 0x530b, &subchnl) == -1 ) {
   Com_DPrintf ("ioctl cdromsubchnl failed\n");
   playing = false;
   return;
  }
  if (subchnl.cdsc_audiostatus != 0x11 &&
   subchnl.cdsc_audiostatus != 0x12) {
   playing = false;
   if (playLooping)
    CDAudio_Play(playTrack, true);
  }
 }
}

variable_types: struct cdrom_subchnl { unsigned char cdsc_format; unsigned char cdsc_audiostatus; unsigned char cdsc_adr; unsigned char cdsc_ctrl; unsigned char cdsc_trk; unsigned char cdsc_ind; union cdrom_addr { struct cdrom_msf0 { unsigned char minute; unsigned char second; unsigned char frame; } msf; int lba; } cdsc_absaddr; union cdrom_addr cdsc_reladdr; }

variable_types: lastchk long

user_defined_types: struct cdrom_subchnl { unsigned char cdsc_format; unsigned char cdsc_audiostatus; unsigned char cdsc_adr; unsigned char cdsc_ctrl; unsigned char cdsc_trk; unsigned char cdsc_ind; union cdrom_addr cdsc_absaddr; union cdrom_addr cdsc_reladdr; }


decompiled_code:
__int64 CDAudio_Init()
{
signed int v0; // ebx
unsigned int v1; // ebx
__int64 i; // rax
__int64 v4; // rax
int *v5; // rax

if ( !(unsigned int)COM_CheckParm("-cdaudio") )
return (unsigned int)-1;
v0 = COM_CheckParm("-cddev");
if ( v0 && (int)(COM_Argc() - 1) > v0 )
{
v4 = COM_Argv((unsigned int)(v0 + 1));
strlcpy(cd_dev, v4, 64LL);
}
v1 = open(cd_dev, 0);
cdfile = v1;
if ( v1 == -1 )
{
v5 = _errno_location();
Com_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, (unsigned int)*v5);
cdfile = -1;
}
else
{
for ( i = 0LL; i != 100; ++i )
remap[i] = i;
initialized = 1;
enabled = 1;
if ( (unsigned int)CDAudio_GetAudioDiskInfo() )
{
Com_Printf("CDAudio_Init: No CD in player.\n");
cdValid = 0;
}
Cmd_AddCommand("cd", CD_f);
Com_Printf("CD Audio Initialized\n");
v1 = 0;
}
return v1;
}

canonical_decompiled_code:
__int64 func9()
{
signed int v0; // ebx
unsigned int v1; // ebx
__int64 i; // rax
__int64 v4; // rax
int *v5; // rax

if ( !(unsigned int)COM_CheckParm("-cdaudio") )
return (unsigned int)-1;
v0 = COM_CheckParm("-cddev");
if ( v0 && (int)(COM_Argc() - 1) > v0 )
{
v4 = COM_Argv((unsigned int)(v0 + 1));
strlcpy(cd_dev, v4, 64LL);
}
v1 = open(cd_dev, 0);
cdfile = v1;
if ( v1 == -1 )
{
v5 = _errno_location();
Com_Printf("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, (unsigned int)*v5);
cdfile = -1;
}
else
{
for ( i = 0LL; i != 100; ++i )
remap[i] = i;
initialized = 1;
enabled = 1;
if ( (unsigned int)func0() )
{
Com_Printf("CDAudio_Init: No CD in player.\n");
cdValid = 0;
}
Cmd_AddCommand("cd", CD_f);
Com_Printf("CD Audio Initialized\n");
v1 = 0;
}
return v1;
}

original_code:
int CDAudio_Init(void)
{
 int i;
 if (!COM_CheckParm("-cdaudio"))
  return -1;
 if ((i = COM_CheckParm("-cddev")) != 0 && i < COM_Argc() - 1)
  strlcpy (cd_dev, COM_Argv(i + 1), sizeof(cd_dev));
 if ((cdfile = open(cd_dev, 00)) == -1) {
  Com_Printf ("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, (*__errno_location ()));
  cdfile = -1;
  return -1;
 }
 for (i = 0; i < 100; i++)
  remap[i] = i;
 initialized = true;
 enabled = true;
 if (CDAudio_GetAudioDiskInfo())
 {
  Com_Printf ("CDAudio_Init: No CD in player.\n");
  cdValid = false;
 }
 Cmd_AddCommand ("cd", CD_f);
 Com_Printf ("CD Audio Initialized\n");
 return 0;
}

canonical_original_code:
int CDAudio_Init()
{
 int i;
 if (!COM_CheckParm("-cdaudio"))
  return -1;
 if ((i = COM_CheckParm("-cddev")) != 0 && i < COM_Argc() - 1)
  strlcpy (cd_dev, COM_Argv(i + 1), sizeof(cd_dev));
 if ((cdfile = open(cd_dev, 00)) == -1) {
  Com_Printf ("CDAudio_Init: open of \"%s\" failed (%i)\n", cd_dev, (*__errno_location ()));
  cdfile = -1;
  return -1;
 }
 for (i = 0; i < 100; i++)
  remap[i] = i;
 initialized = true;
 enabled = true;
 if (CDAudio_GetAudioDiskInfo())
 {
  Com_Printf ("CDAudio_Init: No CD in player.\n");
  cdValid = false;
 }
 Cmd_AddCommand ("cd", CD_f);
 Com_Printf ("CD Audio Initialized\n");
 return 0;
}

variable_types: i int


decompiled_code:
int CDAudio_Shutdown()
{
int result; // eax

if ( initialized )
{
CDAudio_Stop();
result = close(cdfile);
cdfile = -1;
}
return result;
}

canonical_decompiled_code:
int func10()
{
int result; // eax

if ( initialized )
{
func3();
result = close(cdfile);
cdfile = -1;
}
return result;
}

original_code:
void CDAudio_Shutdown(void)
{
 if (!initialized)
  return;
 CDAudio_Stop();
 close(cdfile);
 cdfile = -1;
}

canonical_original_code:
void CDAudio_Shutdown()
{
 if (!initialized)
  return;
 CDAudio_Stop();
 close(cdfile);
 cdfile = -1;
}


decompiled_code:
const char *M_CG_bm_type_r()
{
const char *v0; // rdx

v0 = "Arena";
if ( (unsigned int)(bm_type_var - 1) <= 3 )
v0 = bm_type_desc[bm_type_var];
return v0;
}

canonical_decompiled_code:
const char *func0()
{
const char *v0; // rdx

v0 = "Arena";
if ( (unsigned int)(bm_type_var - 1) <= 3 )
v0 = bm_type_desc[bm_type_var];
return v0;
}

original_code: static const char* M_CG_bm_type_r(void) { if (((bm_type_var) > 0) && ((bm_type_var) < bm_type_max)) { return bm_type_desc[bm_type_var]; } else { return bm_type_desc[0]; } }

canonical_original_code: static char *M_CG_bm_type_r() { if (((bm_type_var) > 0) && ((bm_type_var) < bm_type_max)) { return bm_type_desc[bm_type_var]; } else { return bm_type_desc[0]; } }

return_type: char *


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

result = (a1 == 0 ? 2 : 0) + bm_type_var - 1;
if ( (unsigned int)result > 4 )
result = 0LL;
bm_type_var = result;
return result;
}

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

result = (a1 == 0 ? 2 : 0) + bm_type_var - 1;
if ( (unsigned int)result > 4 )
result = 0LL;
bm_type_var = result;
return result;
}

original_code: static void M_CG_bm_type_t(qbool back) { (bm_type_var) += back ? -1 : 1; if ((bm_type_var) >= bm_type_max) { (bm_type_var) = 0; } else if ((bm_type_var) < 0) { (bm_type_var) = bm_type_max - 1; } }

canonical_original_code: static void M_CG_bm_type_t(enum qbool back) { (bm_type_var) += back ? -1 : 1; if ((bm_type_var) >= bm_type_max) { (bm_type_var) = 0; } else if ((bm_type_var) < 0) { (bm_type_var) = bm_type_max - 1; } }

variable_types:
back
enum qbool { false=0, true=1 }


decompiled_code:
const char *M_CG_bm_map_r()
{
const char *v0; // rdx

v0 = "dm3";
if ( (unsigned int)(bm_map_var - 1) <= 0xB )
v0 = bm_map_desc[bm_map_var];
return v0;
}

canonical_decompiled_code:
const char *func2()
{
const char *v0; // rdx

v0 = "dm3";
if ( (unsigned int)(bm_map_var - 1) <= 0xB )
v0 = bm_map_desc[bm_map_var];
return v0;
}

original_code: static const char* M_CG_bm_map_r(void) { if (((bm_map_var) > 0) && ((bm_map_var) < bm_map_max)) { return bm_map_desc[bm_map_var]; } else { return bm_map_desc[0]; } }

canonical_original_code: static char *M_CG_bm_map_r() { if (((bm_map_var) > 0) && ((bm_map_var) < bm_map_max)) { return bm_map_desc[bm_map_var]; } else { return bm_map_desc[0]; } }


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

result = (a1 == 0 ? 2 : 0) + bm_map_var - 1;
if ( (unsigned int)result > 0xC )
result = 0LL;
bm_map_var = result;
return result;
}

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

result = (a1 == 0 ? 2 : 0) + bm_map_var - 1;
if ( (unsigned int)result > 0xC )
result = 0LL;
bm_map_var = result;
return result;
}

original_code: static void M_CG_bm_map_t(qbool back) { (bm_map_var) += back ? -1 : 1; if ((bm_map_var) >= bm_map_max) { (bm_map_var) = 0; } else if ((bm_map_var) < 0) { (bm_map_var) = bm_map_max - 1; } }

canonical_original_code: static void M_CG_bm_map_t(enum qbool back) { (bm_map_var) += back ? -1 : 1; if ((bm_map_var) >= bm_map_max) { (bm_map_var) = 0; } else if ((bm_map_var) < 0) { (bm_map_var) = bm_map_max - 1; } }


decompiled_code:
const char *M_CG_game_skill_r()
{
const char *v0; // rdx

v0 = "Easy";
if ( (unsigned int)(game_skill_var - 1) <= 2 )
v0 = game_skill_desc[game_skill_var];
return v0;
}

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

v0 = "Easy";
if ( (unsigned int)(game_skill_var - 1) <= 2 )
v0 = game_skill_desc[game_skill_var];
return v0;
}

original_code: static const char* M_CG_game_skill_r(void) { if (((game_skill_var) > 0) && ((game_skill_var) < game_skill_max)) { return game_skill_desc[game_skill_var]; } else { return game_skill_desc[0]; } }

canonical_original_code: static char *M_CG_game_skill_r() { if (((game_skill_var) > 0) && ((game_skill_var) < game_skill_max)) { return game_skill_desc[game_skill_var]; } else { return game_skill_desc[0]; } }


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

result = (a1 == 0 ? 2 : 0) + game_skill_var - 1;
if ( (unsigned int)result > 3 )
result = 0LL;
game_skill_var = result;
return result;
}

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

result = (a1 == 0 ? 2 : 0) + game_skill_var - 1;
if ( (unsigned int)result > 3 )
result = 0LL;
game_skill_var = result;
return result;
}

original_code: static void M_CG_game_skill_t(qbool back) { (game_skill_var) += back ? -1 : 1; if ((game_skill_var) >= game_skill_max) { (game_skill_var) = 0; } else if ((game_skill_var) < 0) { (game_skill_var) = game_skill_max - 1; } }

canonical_original_code: static void M_CG_game_skill_t(enum qbool back) { (game_skill_var) += back ? -1 : 1; if ((game_skill_var) >= game_skill_max) { (game_skill_var) = 0; } else if ((game_skill_var) < 0) { (game_skill_var) = game_skill_max - 1; } }


decompiled_code:
const char *M_CG_cg_teamdamage_r()
{
const char *result; // rax

result = "off";
if ( cg_teamdamage_var == 1 )
result = "on";
return result;
}

canonical_decompiled_code:
const char *func6()
{
const char *result; // rax

result = "off";
if ( cg_teamdamage_var == 1 )
result = "on";
return result;
}

original_code: static const char* M_CG_cg_teamdamage_r(void) { if (((cg_teamdamage_var) > 0) && ((cg_teamdamage_var) < cg_teamdamage_max)) { return cg_teamdamage_desc[cg_teamdamage_var]; } else { return cg_teamdamage_desc[0]; } }

canonical_original_code: static char *M_CG_cg_teamdamage_r() { if (((cg_teamdamage_var) > 0) && ((cg_teamdamage_var) < cg_teamdamage_max)) { return cg_teamdamage_desc[cg_teamdamage_var]; } else { return cg_teamdamage_desc[0]; } }


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

result = (a1 == 0 ? 2 : 0) + cg_teamdamage_var - 1;
if ( (unsigned int)result > 1 )
result = 0LL;
cg_teamdamage_var = result;
return result;
}

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

result = (a1 == 0 ? 2 : 0) + cg_teamdamage_var - 1;
if ( (unsigned int)result > 1 )
result = 0LL;
cg_teamdamage_var = result;
return result;
}

original_code: static void M_CG_cg_teamdamage_t(qbool back) { (cg_teamdamage_var) += back ? -1 : 1; if ((cg_teamdamage_var) >= cg_teamdamage_max) { (cg_teamdamage_var) = 0; } else if ((cg_teamdamage_var) < 0) { (cg_teamdamage_var) = cg_teamdamage_max - 1; } }

canonical_original_code: static void M_CG_cg_teamdamage_t(enum qbool back) { (cg_teamdamage_var) += back ? -1 : 1; if ((cg_teamdamage_var) >= cg_teamdamage_max) { (cg_teamdamage_var) = 0; } else if ((cg_teamdamage_var) < 0) { (cg_teamdamage_var) = cg_teamdamage_max - 1; } }


decompiled_code:
const char *M_CG_game_map_group_r()
{
const char *v0; // rdx

v0 = "Doomed Dimension";
if ( (unsigned int)(game_map_group_var - 1) <= 3 )
v0 = game_map_group_desc[game_map_group_var];
return v0;
}

canonical_decompiled_code:
const char *func8()
{
const char *v0; // rdx

v0 = "Doomed Dimension";
if ( (unsigned int)(game_map_group_var - 1) <= 3 )
v0 = game_map_group_desc[game_map_group_var];
return v0;
}

original_code: static const char* M_CG_game_map_group_r(void) { if (((game_map_group_var) > 0) && ((game_map_group_var) < game_map_group_max)) { return game_map_group_desc[game_map_group_var]; } else { return game_map_group_desc[0]; } }

canonical_original_code: static char *M_CG_game_map_group_r() { if (((game_map_group_var) > 0) && ((game_map_group_var) < game_map_group_max)) { return game_map_group_desc[game_map_group_var]; } else { return game_map_group_desc[0]; } }


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

result = (a1 == 0 ? 2 : 0) + game_map_group_var - 1;
if ( (unsigned int)result > 4 )
result = 0LL;
game_map_group_var = result;
return result;
}

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

result = (a1 == 0 ? 2 : 0) + game_map_group_var - 1;
if ( (unsigned int)result > 4 )
result = 0LL;
game_map_group_var = result;
return result;
}

original_code: static void M_CG_game_map_group_t(qbool back) { (game_map_group_var) += back ? -1 : 1; if ((game_map_group_var) >= game_map_group_max) { (game_map_group_var) = 0; } else if ((game_map_group_var) < 0) { (game_map_group_var) = game_map_group_max - 1; } }

canonical_original_code: static void M_CG_game_map_group_t(enum qbool back) { (game_map_group_var) += back ? -1 : 1; if ((game_map_group_var) >= game_map_group_max) { (game_map_group_var) = 0; } else if ((game_map_group_var) < 0) { (game_map_group_var) = game_map_group_max - 1; } }


decompiled_code:
const char *M_CG_DM_game_mode_r()
{
const char *v0; // rdx

v0 = "Free For All";
if ( (unsigned int)(DM_game_mode_var - 1) <= 2 )
v0 = DM_game_mode_desc[DM_game_mode_var];
return v0;
}

canonical_decompiled_code:
const char *func10()
{
const char *v0; // rdx

v0 = "Free For All";
if ( (unsigned int)(DM_game_mode_var - 1) <= 2 )
v0 = DM_game_mode_desc[DM_game_mode_var];
return v0;
}

original_code: static const char* M_CG_DM_game_mode_r(void) { if (((DM_game_mode_var) > 0) && ((DM_game_mode_var) < DM_game_mode_max)) { return DM_game_mode_desc[DM_game_mode_var]; } else { return DM_game_mode_desc[0]; } }

canonical_original_code: static char *M_CG_DM_game_mode_r() { if (((DM_game_mode_var) > 0) && ((DM_game_mode_var) < DM_game_mode_max)) { return DM_game_mode_desc[DM_game_mode_var]; } else { return DM_game_mode_desc[0]; } }


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

result = (a1 == 0 ? 2 : 0) + DM_game_mode_var - 1;
if ( (unsigned int)result > 3 )
result = 0LL;
DM_game_mode_var = result;
return result;
}

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

result = (a1 == 0 ? 2 : 0) + DM_game_mode_var - 1;
if ( (unsigned int)result > 3 )
result = 0LL;
DM_game_mode_var = result;
return result;
}

original_code: static void M_CG_DM_game_mode_t(qbool back) { (DM_game_mode_var) += back ? -1 : 1; if ((DM_game_mode_var) >= DM_game_mode_max) { (DM_game_mode_var) = 0; } else if ((DM_game_mode_var) < 0) { (DM_game_mode_var) = DM_game_mode_max - 1; } }

canonical_original_code: static void M_CG_DM_game_mode_t(enum qbool back) { (DM_game_mode_var) += back ? -1 : 1; if ((DM_game_mode_var) >= DM_game_mode_max) { (DM_game_mode_var) = 0; } else if ((DM_game_mode_var) < 0) { (DM_game_mode_var) = DM_game_mode_max - 1; } }