decompiled_code:
__int64 __fastcall Skin_NextDownload(double a1)
{
__int64 result; // rax
unsigned int v2; // edi
char *v3; // r8
__int64 v4; // rdi
char *v5; // rbx
__int64 v6; // rbx
__int64 v7; // rdi
__int64 v8; // rax
__int64 v9; // rax

result = (unsigned int)cls[2374];
v2 = result;
if ( !(_DWORD)result )
{
if ( com_serveractive )
{
a1 = 0.0;
if ( developer[8] == 0.0 )
{
cls[2375] = 4;
goto LABEL_10;
}
}
Com_Printf("Checking skins...\n");
result = (unsigned int)cls[2374];
v2 = cls[2374];
}
cls[2375] = 4;
if ( (unsigned int)result <= 0x1F )
{
while ( 1 )
{
LABEL_10:
v4 = 19720LL * (int)v2;
v5 = &s + v4;
if ( !*(&s + v4 + 1395324) )
goto LABEL_9;
Skin_Find((__int64)(&s + v4 + 1394296));
if ( *(float *)&noskins[4] != 0.0 )
goto LABEL_12;
v3 = Skin_Cache(*((_QWORD *)v5 + 176731), 1);
LODWORD(result) = cls[2374];
if ( !v3 )
{
v8 = va("skins/%s.pcx", *((const char **)v5 + 176731));
result = CL_CheckOrDownloadFile(v8, a1, 0.0);
if ( !(_DWORD)result )
return result;
LABEL_12:
v2 = cls[2374] + 1;
cls[2374] = v2;
result = v2;
if ( v2 > 0x1F )
break;
}
else
{
LABEL_9:
v2 = result + 1;
cls[2374] = result + 1;
result = (unsigned int)(result + 1);
if ( v2 > 0x1F )
break;
}
}
}
cls[2375] = 0;
v6 = (unsigned int)((_DWORD)&s + 1394296);
do
{
if ( *(_BYTE *)(v6 + 1028) )
{
v7 = *(_QWORD *)(v6 + 19552);
if ( !v7 )
{
Skin_Find(v6);
v7 = *(_QWORD *)(v6 + 19552);
}
result = (__int64)Skin_Cache(v7, 0);
*(_QWORD *)(v6 + 19552) = 0LL;
}
v6 += 19720LL;
}
while ( (_DWORD)&s + 2025336 != v6 );
if ( cls[0] == 3 )
{
MSG_WriteByte((unsigned int)((_DWORD)cls + 160), 4LL);
v9 = va("begin %i", *(unsigned int *)&s);
result = MSG_WriteString((unsigned int)((_DWORD)cls + 160), v9);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(double a1)
{
__int64 result; // rax
unsigned int v2; // edi
char *v3; // r8
__int64 v4; // rdi
char *v5; // rbx
__int64 v6; // rbx
__int64 v7; // rdi
__int64 v8; // rax
__int64 v9; // rax

result = (unsigned int)cls[2374];
v2 = result;
if ( !(_DWORD)result )
{
if ( com_serveractive )
{
a1 = 0.0;
if ( developer[8] == 0.0 )
{
cls[2375] = 4;
goto LABEL_10;
}
}
Com_Printf("Checking skins...\n");
result = (unsigned int)cls[2374];
v2 = cls[2374];
}
cls[2375] = 4;
if ( (unsigned int)result <= 0x1F )
{
while ( 1 )
{
LABEL_10:
v4 = 19720LL * (int)v2;
v5 = &s + v4;
if ( !*(&s + v4 + 1395324) )
goto LABEL_9;
func7((__int64)(&s + v4 + 1394296));
if ( *(float *)&noskins[4] != 0.0 )
goto LABEL_12;
v3 = func4(*((_QWORD *)v5 + 176731), 1);
LODWORD(result) = cls[2374];
if ( !v3 )
{
v8 = va("skins/%s.pcx", *((const char **)v5 + 176731));
result = CL_CheckOrDownloadFile(v8, a1, 0.0);
if ( !(_DWORD)result )
return result;
LABEL_12:
v2 = cls[2374] + 1;
cls[2374] = v2;
result = v2;
if ( v2 > 0x1F )
break;
}
else
{
LABEL_9:
v2 = result + 1;
cls[2374] = result + 1;
result = (unsigned int)(result + 1);
if ( v2 > 0x1F )
break;
}
}
}
cls[2375] = 0;
v6 = (unsigned int)((_DWORD)&s + 1394296);
do
{
if ( *(_BYTE *)(v6 + 1028) )
{
v7 = *(_QWORD *)(v6 + 19552);
if ( !v7 )
{
func7(v6);
v7 = *(_QWORD *)(v6 + 19552);
}
result = (__int64)func4(v7, 0);
*(_QWORD *)(v6 + 19552) = 0LL;
}
v6 += 19720LL;
}
while ( (_DWORD)&s + 2025336 != v6 );
if ( cls[0] == 3 )
{
MSG_WriteByte((unsigned int)((_DWORD)cls + 160), 4LL);
v9 = va("begin %i", *(unsigned int *)&s);
result = MSG_WriteString((unsigned int)((_DWORD)cls + 160), v9);
}
return result;
}

original_code:
void Skin_NextDownload (void) {
 player_info_t *sc;
 int i;
 if (cls.downloadnumber == 0)
  if (!com_serveractive || developer.value)
   Com_Printf ("Checking skins...\n");
 cls.downloadtype = dl_skin;
 for ( ; cls.downloadnumber >= 0 && cls.downloadnumber < 32; cls.downloadnumber++) {
  sc = &cl.players[cls.downloadnumber];
  if (!sc->name[0])
   continue;
  Skin_Find (sc);
  if (noskins.value)
   continue;
  if (Skin_Cache (sc->skin, true))
   continue;
  if (!CL_CheckOrDownloadFile(va("skins/%s.pcx", sc->skin->name)))
   return;
 }
 cls.downloadtype = dl_none;
 for (i = 0; i < 32; i++) {
  sc = &cl.players[i];
  if (!sc->name[0])
   continue;
  if (!sc->skin)
   Skin_Find (sc);
  Skin_Cache (sc->skin, false);
  sc->skin = ((void *)0);
 }
 if (cls.state == ca_onserver ) {
  MSG_WriteByte (&cls.netchan.message, 4);
  MSG_WriteString (&cls.netchan.message, va("begin %i", cl.servercount));
 }
}

canonical_original_code:
void Skin_NextDownload() {
 struct player_info_s *sc;
 int i;
 if (cls.downloadnumber == 0)
  if (!com_serveractive || developer.value)
   Com_Printf ("Checking skins...\n");
 cls.downloadtype = dl_skin;
 for ( ; cls.downloadnumber >= 0 && cls.downloadnumber < 32; cls.downloadnumber++) {
  sc = &cl.players[cls.downloadnumber];
  if (!sc->name[0])
   continue;
  Skin_Find (sc);
  if (noskins.value)
   continue;
  if (Skin_Cache (sc->skin, true))
   continue;
  if (!CL_CheckOrDownloadFile(va("skins/%s.pcx", sc->skin->name)))
   return;
 }
 cls.downloadtype = dl_none;
 for (i = 0; i < 32; i++) {
  sc = &cl.players[i];
  if (!sc->name[0])
   continue;
  if (!sc->skin)
   Skin_Find (sc);
  Skin_Cache (sc->skin, false);
  sc->skin = ((void *)0);
 }
 if (cls.state == ca_onserver ) {
  MSG_WriteByte (&cls.netchan.message, 4);
  MSG_WriteString (&cls.netchan.message, va("begin %i", cl.servercount));
 }
}


repo: jite/jquake

decompiled_code:
void Skins_PreCache()
{
const char *v0; // rsi
char *v1; // rbx
int v2; // ebp
char *v3; // rcx
unsigned int v4; // eax

if ( skins_need_preache )
{
v0 = (const char *)cl_teamskin[1];
skins_need_preache = 0;
Skin_Find_Ex(0LL, v0);
Skin_Find_Ex(0LL, (const char *)cl_enemyskin[1]);
Skin_Find_Ex(0LL, (const char *)cl_teamquadskin[1]);
Skin_Find_Ex(0LL, (const char *)cl_enemyquadskin[1]);
Skin_Find_Ex(0LL, (const char *)cl_teampentskin[1]);
Skin_Find_Ex(0LL, (const char *)cl_enemypentskin[1]);
Skin_Find_Ex(0LL, (const char *)cl_teambothskin[1]);
Skin_Find_Ex(0LL, (const char *)cl_enemybothskin[1]);
Skin_Find_Ex(0LL, baseskin[1]);
Skin_Find_Ex(0LL, "base");
if ( numskins > 0 )
{
v1 = skins;
v2 = 0;
do
{
v3 = Skin_Cache((__int64)v1, 0);
if ( v3 && *((_DWORD *)v1 + 8) == 4 && !*((_DWORD *)v1 + 9) )
{
v4 = GL_LoadTexture(
v1,
*((unsigned int *)v1 + 6),
*((unsigned int *)v1 + 7),
v3,
gl_playermip[16] == 0 ? 32 : 34,
4LL);
*((_DWORD *)v1 + 9) = v4;
Com_DPrintf("skin precache: %s, texnum %d\n", v1, v4);
}
++v2;
v1 += 48;
}
while ( numskins > v2 );
}
}
}

canonical_decompiled_code:
void func9()
{
const char *v0; // rsi
char *v1; // rbx
int v2; // ebp
char *v3; // rcx
unsigned int v4; // eax

if ( skins_need_preache )
{
v0 = (const char *)cl_teamskin[1];
skins_need_preache = 0;
func6(0LL, v0);
func6(0LL, (const char *)cl_enemyskin[1]);
func6(0LL, (const char *)cl_teamquadskin[1]);
func6(0LL, (const char *)cl_enemyquadskin[1]);
func6(0LL, (const char *)cl_teampentskin[1]);
func6(0LL, (const char *)cl_enemypentskin[1]);
func6(0LL, (const char *)cl_teambothskin[1]);
func6(0LL, (const char *)cl_enemybothskin[1]);
func6(0LL, baseskin[1]);
func6(0LL, "base");
if ( numskins > 0 )
{
v1 = skins;
v2 = 0;
do
{
v3 = func4((__int64)v1, 0);
if ( v3 && *((_DWORD *)v1 + 8) == 4 && !*((_DWORD *)v1 + 9) )
{
v4 = GL_LoadTexture(
v1,
*((unsigned int *)v1 + 6),
*((unsigned int *)v1 + 7),
v3,
gl_playermip[16] == 0 ? 32 : 34,
4LL);
*((_DWORD *)v1 + 9) = v4;
Com_DPrintf("skin precache: %s, texnum %d\n", v1, v4);
}
++v2;
v1 += 48;
}
while ( numskins > v2 );
}
}
}

original_code:
void Skins_PreCache(void)
{
 int i;
 byte *tex;
 if (!skins_need_preache)
  return;
 skins_need_preache = false;
 Skin_Find_Ex(((void *)0), cl_teamskin.string);
 Skin_Find_Ex(((void *)0), cl_enemyskin.string);
 Skin_Find_Ex(((void *)0), cl_teamquadskin.string);
 Skin_Find_Ex(((void *)0), cl_enemyquadskin.string);
 Skin_Find_Ex(((void *)0), cl_teampentskin.string);
 Skin_Find_Ex(((void *)0), cl_enemypentskin.string);
 Skin_Find_Ex(((void *)0), cl_teambothskin.string);
 Skin_Find_Ex(((void *)0), cl_enemybothskin.string);
 Skin_Find_Ex(((void *)0), baseskin.string);
 Skin_Find_Ex(((void *)0), "base");
 for (i = 0; i < numskins; i++)
 {
  tex = Skin_Cache (&skins[i], false);
  if (!tex)
   continue;
  if (skins[i].bpp != 4)
   continue;
  if (skins[i].texnum)
   continue;
  skins[i].texnum = GL_LoadTexture (skins[i].name, skins[i].width, skins[i].height, tex, (gl_playermip.integer ? (1<<1) : 0) | (1<<5), 4);
  Com_DPrintf("skin precache: %s, texnum %d\n", skins[i].name, skins[i].texnum);
 }
}

canonical_original_code:
void Skins_PreCache()
{
 int i;
 unsigned char *tex;
 if (!skins_need_preache)
  return;
 skins_need_preache = false;
 Skin_Find_Ex(((void *)0), cl_teamskin.string);
 Skin_Find_Ex(((void *)0), cl_enemyskin.string);
 Skin_Find_Ex(((void *)0), cl_teamquadskin.string);
 Skin_Find_Ex(((void *)0), cl_enemyquadskin.string);
 Skin_Find_Ex(((void *)0), cl_teampentskin.string);
 Skin_Find_Ex(((void *)0), cl_enemypentskin.string);
 Skin_Find_Ex(((void *)0), cl_teambothskin.string);
 Skin_Find_Ex(((void *)0), cl_enemybothskin.string);
 Skin_Find_Ex(((void *)0), baseskin.string);
 Skin_Find_Ex(((void *)0), "base");
 for (i = 0; i < numskins; i++)
 {
  tex = Skin_Cache (&skins[i], false);
  if (!tex)
   continue;
  if (skins[i].bpp != 4)
   continue;
  if (skins[i].texnum)
   continue;
  skins[i].texnum = GL_LoadTexture (skins[i].name, skins[i].width, skins[i].height, tex, (gl_playermip.integer ? (1<<1) : 0) | (1<<5), 4);
  Com_DPrintf("skin precache: %s, texnum %d\n", skins[i].name, skins[i].texnum);
 }
}

variable_types: i int

variable_types:
tex
unsigned char *

return_type: void


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

if ( LODWORD(teamforceskins[8]) && (unsigned int)((__int64 (*)(void))TP_ThisPOV_IsHisTeam)() )
return LODWORD(teamforceskins[8]);
if ( LODWORD(enemyforceskins[8]) && !(unsigned int)TP_ThisPOV_IsHisTeam(a1) )
{
if ( cls[2427] | *((_DWORD *)&s + 148) || (*((_DWORD *)&s + 134) & 0x300) == 0 )
return LODWORD(enemyforceskins[8]);
return 0LL;
}
result = LODWORD(cl_name_as_skin[8]);
if ( !(_DWORD)result || !(cls[2427] | *((_DWORD *)&s + 148)) )
return 0LL;
return result;
}

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

if ( LODWORD(teamforceskins[8]) && (unsigned int)((__int64 (*)(void))TP_ThisPOV_IsHisTeam)() )
return LODWORD(teamforceskins[8]);
if ( LODWORD(enemyforceskins[8]) && !(unsigned int)TP_ThisPOV_IsHisTeam(a1) )
{
if ( cls[2427] | *((_DWORD *)&s + 148) || (*((_DWORD *)&s + 134) & 0x300) == 0 )
return LODWORD(enemyforceskins[8]);
return 0LL;
}
result = LODWORD(cl_name_as_skin[8]);
if ( !(_DWORD)result || !(cls[2427] | *((_DWORD *)&s + 148)) )
return 0LL;
return result;
}

original_code:
static int Skin_ForcingType(const char *team)
{
 if (teamforceskins.integer && TP_ThisPOV_IsHisTeam(team))
  return teamforceskins.integer;
 if (enemyforceskins.integer && !TP_ThisPOV_IsHisTeam(team)) {
  if (cls.demoplayback || cl.spectator) {
   return enemyforceskins.integer;
  } else {
   if (!(cl.fpd & 256) && !(cl.fpd & 512))
    return enemyforceskins.integer;
   else
    return 0;
  }
 }
 if (cl_name_as_skin.integer && (cls.demoplayback || cl.spectator)) {
  return cl_name_as_skin.integer;
 }
 return 0;
}

canonical_original_code:
static int Skin_ForcingType(char *team)
{
 if (teamforceskins.integer && TP_ThisPOV_IsHisTeam(team))
  return teamforceskins.integer;
 if (enemyforceskins.integer && !TP_ThisPOV_IsHisTeam(team)) {
  if (cls.demoplayback || cl.spectator) {
   return enemyforceskins.integer;
  } else {
   if (!(cl.fpd & 256) && !(cl.fpd & 512))
    return enemyforceskins.integer;
   else
    return 0;
  }
 }
 if (cl_name_as_skin.integer && (cls.demoplayback || cl.spectator)) {
  return cl_name_as_skin.integer;
 }
 return 0;
}

variable_types:
team
char *

return_type: int


decompiled_code:
__int64 Skin_Skins_f()
{
unsigned __int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

if ( numskins > 0 )
{
v0 = (unsigned int)((_DWORD)skins + 40);
v1 = 0;
do
{
if ( *(_QWORD *)v0 )
Cache_Free(v0);
++v1;
v0 += 48LL;
}
while ( numskins > v1 );
}
numskins = 0;
skins_need_preache = 1;
*(_QWORD *)&cls[2374] = 0x400000000LL;
result = Skin_NextDownload();
if ( cls[3434] == 2 && (_UNKNOWN *)cbuf_current != &cbuf_main )
cls[3437] = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned __int64 v0; // rbx
int v1; // ebp
__int64 result; // rax

if ( numskins > 0 )
{
v0 = (unsigned int)((_DWORD)skins + 40);
v1 = 0;
do
{
if ( *(_QWORD *)v0 )
Cache_Free(v0);
++v1;
v0 += 48LL;
}
while ( numskins > v1 );
}
numskins = 0;
skins_need_preache = 1;
*(_QWORD *)&cls[2374] = 0x400000000LL;
result = func8();
if ( cls[3434] == 2 && (_UNKNOWN *)cbuf_current != &cbuf_main )
cls[3437] = 0;
return result;
}

original_code:
void Skin_Skins_f (void) {
 int i;
 for (i = 0; i < numskins; i++) {
  if (skins[i].cache.data)
   Cache_Free (&skins[i].cache);
 }
 numskins = 0;
 skins_need_preache = true;
 cls.downloadnumber = 0;
 cls.downloadtype = dl_skin;
 Skin_NextDownload ();
 if (cls.mvdplayback == 2 && cbuf_current != &cbuf_main)
 {
  cls.qtv_donotbuffer = false;
 }
}

canonical_original_code:
void Skin_Skins_f() {
 int i;
 for (i = 0; i < numskins; i++) {
  if (skins[i].cache.data)
   Cache_Free (&skins[i].cache);
 }
 numskins = 0;
 skins_need_preache = true;
 cls.downloadnumber = 0;
 cls.downloadtype = dl_skin;
 Skin_NextDownload ();
 if (cls.mvdplayback == 2 && cbuf_current != &cbuf_main)
 {
  cls.qtv_donotbuffer = false;
 }
}


decompiled_code:
__int64 Skin_AllSkins_f()
{
const char *v0; // rax
__int64 result; // rax
__int64 v2; // rsi

if ( (unsigned int)Cmd_Argc() == 1 )
return Com_Printf("allskins set to \"%s\"\n", &allskins);
if ( (unsigned int)Cmd_Argc() == 2 )
{
v2 = Cmd_Argv(1LL);
strlcpy(&allskins, v2, 128LL);
result = Skin_Skins_f();
}
else
{
v0 = (const char *)Cmd_Argv(0LL);
result = Com_Printf("Usage: %s [skin]\n", v0);
}
return result;
}

canonical_decompiled_code:
__int64 func10()
{
const char *v0; // rax
__int64 result; // rax
__int64 v2; // rsi

if ( (unsigned int)Cmd_Argc() == 1 )
return Com_Printf("allskins set to \"%s\"\n", &allskins);
if ( (unsigned int)Cmd_Argc() == 2 )
{
v2 = Cmd_Argv(1LL);
strlcpy(&allskins, v2, 128LL);
result = func5();
}
else
{
v0 = (const char *)Cmd_Argv(0LL);
result = Com_Printf("Usage: %s [skin]\n", v0);
}
return result;
}

original_code:
void Skin_AllSkins_f (void) {
 if (Cmd_Argc() == 1) {
  Com_Printf("allskins set to \"%s\"\n", allskins);
  return;
 }
 if (Cmd_Argc() != 2) {
  Com_Printf("Usage: %s [skin]\n", Cmd_Argv(0));
  return;
 }
 strlcpy (allskins, Cmd_Argv(1), sizeof(allskins));
 Skin_Skins_f();
}

canonical_original_code:
void Skin_AllSkins_f() {
 if (Cmd_Argc() == 1) {
  Com_Printf("allskins set to \"%s\"\n", allskins);
  return;
 }
 if (Cmd_Argc() != 2) {
  Com_Printf("Usage: %s [skin]\n", Cmd_Argv(0));
  return;
 }
 strlcpy (allskins, Cmd_Argv(1), sizeof(allskins));
 Skin_Skins_f();
}


original_code:
void Skin_ShowSkins_f (void) {
 int i, count, maxlen;
 maxlen = sizeof("name") - 1;
 for (i = 0; i < 32; i++)
  if (cl.players[i].name[0] && !cl.players[i].spectator)
   maxlen = ((maxlen) >= (17) ? (maxlen) : (strlen(cl.players[i].name)) < (maxlen) ? (maxlen) : (strlen(cl.players[i].name)) > (17) ? (17) : (strlen(cl.players[i].name)));
 for (i = count = 0; i < 32; i++)
  if (cl.players[i].name[0] && !cl.players[i].spectator) {
   if (!count)
    Com_Printf("\x02%-*.*s %s\n", maxlen, maxlen, "name", "skin");
   Com_Printf("%-*.*s %s\n", maxlen, maxlen, cl.players[i].name, Skin_FindName(&cl.players[i]));
   count++;
  }
}

canonical_original_code:
void Skin_ShowSkins_f() {
 int i; int count; int maxlen;
 maxlen = sizeof("name") - 1;
 for (i = 0; i < 32; i++)
  if (cl.players[i].name[0] && !cl.players[i].spectator)
   maxlen = ((maxlen) >= (17) ? (maxlen) : (strlen(cl.players[i].name)) < (maxlen) ? (maxlen) : (strlen(cl.players[i].name)) > (17) ? (17) : (strlen(cl.players[i].name)));
 for (i = count = 0; i < 32; i++)
  if (cl.players[i].name[0] && !cl.players[i].spectator) {
   if (!count)
    Com_Printf("\x02%-*.*s %s\n", maxlen, maxlen, "name", "skin");
   Com_Printf("%-*.*s %s\n", maxlen, maxlen, cl.players[i].name, Skin_FindName(&cl.players[i]));
   count++;
  }
}

variable_types: count int

variable_types: maxlen int


decompiled_code:
__int64 __fastcall W_LoadWadFile(const char *a1)
{
_DWORD *v2; // rbp
bool v3; // cf
bool v4; // zf
void *v5; // rbx
__int64 v6; // rdx
__int64 v7; // rbx
__int64 result; // rax
const char *v9; // rbx
unsigned int v10; // ebp
unsigned int v11; // eax
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi

W_FreeWadFile();
wad_base = (void *)FS_LoadHeapFile(a1, &wad_filesize);
v2 = wad_base;
v3 = 0;
v4 = wad_base == 0LL;
if ( !wad_base )
{
v12 = "gfx.wad";
v13 = 8LL;
v14 = a1;
do
{
if ( !v13 )
break;
v3 = *v14 < (unsigned int)*v12;
v4 = *v14++ == *v12++;
--v13;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
Sys_Error(
"Couldn't load gfx.wad.\n"
"This usually happens when you don't have original Quake 1 files in id1 subdirectory.\n"
"Ensure you have pak0.pak and pak1.pak in subdirectory id1.",
v14);
else
Sys_Error("W_LoadWadFile: couldn't load %s", a1);
v2 = wad_base;
}
v5 = v2;
if ( *v2 != 843333975 )
{
Sys_Error("Wad file %s doesn't have WAD2 id\n", a1);
v5 = wad_base;
}
v6 = (int)v2[2];
wad_numlumps = v2[1];
v7 = (__int64)v5 + v6;
result = wad_numlumps;
wad_lumps = v7;
if ( v6 + 8LL * wad_numlumps > (unsigned __int64)wad_filesize )
{
Sys_Error("Wad lump table exceeds file size");
v7 = wad_lumps;
result = (unsigned int)wad_numlumps;
}
v9 = (const char *)(v7 + 16);
v10 = 0;
if ( (_DWORD)result )
{
do
{
W_CleanupName((__int64)v9, (__int64)v9);
v11 = *((_DWORD *)v9 - 4);
if ( v11 <= 0xB || (result = *((_DWORD *)v9 - 3) + v11, (int)result > wad_filesize) )
result = Sys_Error("Wad lump %s exceeds file size", v9);
++v10;
v9 += 32;
}
while ( wad_numlumps > v10 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
_DWORD *v2; // rbp
bool v3; // cf
bool v4; // zf
void *v5; // rbx
__int64 v6; // rdx
__int64 v7; // rbx
__int64 result; // rax
const char *v9; // rbx
unsigned int v10; // ebp
unsigned int v11; // eax
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi

func3();
wad_base = (void *)FS_LoadHeapFile(a1, &wad_filesize);
v2 = wad_base;
v3 = 0;
v4 = wad_base == 0LL;
if ( !wad_base )
{
v12 = "gfx.wad";
v13 = 8LL;
v14 = a1;
do
{
if ( !v13 )
break;
v3 = *v14 < (unsigned int)*v12;
v4 = *v14++ == *v12++;
--v13;
}
while ( v4 );
if ( (!v3 && !v4) == v3 )
Sys_Error(
"Couldn't load gfx.wad.\n"
"This usually happens when you don't have original Quake 1 files in id1 subdirectory.\n"
"Ensure you have pak0.pak and pak1.pak in subdirectory id1.",
v14);
else
Sys_Error("W_LoadWadFile: couldn't load %s", a1);
v2 = wad_base;
}
v5 = v2;
if ( *v2 != 843333975 )
{
Sys_Error("Wad file %s doesn't have WAD2 id\n", a1);
v5 = wad_base;
}
v6 = (int)v2[2];
wad_numlumps = v2[1];
v7 = (__int64)v5 + v6;
result = wad_numlumps;
wad_lumps = v7;
if ( v6 + 8LL * wad_numlumps > (unsigned __int64)wad_filesize )
{
Sys_Error("Wad lump table exceeds file size");
v7 = wad_lumps;
result = (unsigned int)wad_numlumps;
}
v9 = (const char *)(v7 + 16);
v10 = 0;
if ( (_DWORD)result )
{
do
{
func2((__int64)v9, (__int64)v9);
v11 = *((_DWORD *)v9 - 4);
if ( v11 <= 0xB || (result = *((_DWORD *)v9 - 3) + v11, (int)result > wad_filesize) )
result = Sys_Error("Wad lump %s exceeds file size", v9);
++v10;
v9 += 32;
}
while ( wad_numlumps > v10 );
}
return result;
}

original_code:
void W_LoadWadFile (char *filename) {
 lumpinfo_t *lump_p;
 wadinfo_t *header;
 unsigned i;
 int infotableofs;
 W_FreeWadFile ();
 wad_base = FS_LoadHeapFile (filename, &wad_filesize);
 if (!wad_base) {
  if (!strcmp(filename, "gfx.wad"))
   Sys_Error("Couldn't load gfx.wad.\n"
       "This usually happens when you don't have original Quake 1 files in id1 subdirectory.\n"
       "Ensure you have pak0.pak and pak1.pak in subdirectory id1.");
  else
   Sys_Error ("W_LoadWadFile: couldn't load %s", filename);
 }
 header = (wadinfo_t *)wad_base;
 if (memcmp(header->identification, "WAD2", 4))
  Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename);
 wad_numlumps = (header->numlumps);
 infotableofs = (header->infotableofs);
 wad_lumps = (lumpinfo_t *)(wad_base + infotableofs);
 if (infotableofs + wad_numlumps * sizeof(lump_t) > wad_filesize)
  Sys_Error ("Wad lump table exceeds file size");
 for (i = 0, lump_p = wad_lumps; i < wad_numlumps; i++,lump_p++) {
  lump_p->filepos = (lump_p->filepos);
  lump_p->size = (lump_p->size);
  W_CleanupName (lump_p->name, lump_p->name);
  if (lump_p->filepos < sizeof(wadinfo_t) || lump_p->filepos + (lump_p->disksize) > wad_filesize)
   Sys_Error ("Wad lump %s exceeds file size", lump_p->name);
  if (lump_p->type == 66)
   SwapPic ( (qpic_t *)(wad_base + lump_p->filepos));
 }
}

canonical_original_code:
void W_LoadWadFile(char *filename) {
 struct lumpinfo_t *lump_p;
 struct wadinfo_t *header;
 unsigned int i;
 int infotableofs;
 W_FreeWadFile ();
 wad_base = FS_LoadHeapFile (filename, &wad_filesize);
 if (!wad_base) {
  if (!strcmp(filename, "gfx.wad"))
   Sys_Error("Couldn't load gfx.wad.\n"
       "This usually happens when you don't have original Quake 1 files in id1 subdirectory.\n"
       "Ensure you have pak0.pak and pak1.pak in subdirectory id1.");
  else
   Sys_Error ("W_LoadWadFile: couldn't load %s", filename);
 }
 header = (struct wadinfo_t *)wad_base;
 if (memcmp(header->identification, "WAD2", 4))
  Sys_Error ("Wad file %s doesn't have WAD2 id\n",filename);
 wad_numlumps = (header->numlumps);
 infotableofs = (header->infotableofs);
 wad_lumps = (struct lumpinfo_t *)(wad_base + infotableofs);
 if (infotableofs + wad_numlumps * sizeof(lump_t) > wad_filesize)
  Sys_Error ("Wad lump table exceeds file size");
 for (i = 0, lump_p = wad_lumps; i < wad_numlumps; i++,lump_p++) {
  lump_p->filepos = (lump_p->filepos);
  lump_p->size = (lump_p->size);
  W_CleanupName (lump_p->name, lump_p->name);
  if (lump_p->filepos < sizeof(wadinfo_t) || lump_p->filepos + (lump_p->disksize) > wad_filesize)
   Sys_Error ("Wad lump %s exceeds file size", lump_p->name);
  if (lump_p->type == 66)
   SwapPic ( (struct qpic_t *)(wad_base + lump_p->filepos));
 }
}

variable_types:
filename
char *

variable_types: struct lumpinfo_t { int filepos; int disksize; int size; char type; char compression; char pad1; char name[16]; } *

variable_types: struct wadinfo_t { char identification[4]; int numlumps; int infotableofs; } *

variable_types:
i
unsigned int

variable_types: infotableofs int

user_defined_types: struct qpic_t { int width; unsigned char data[4]; }


decompiled_code:
__int64 __fastcall W_GetLumpinfo(const char *a1)
{
__int64 v1; // r12
__int64 v2; // rbx
__int64 result; // rax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

W_CleanupName((__int64)a1, (__int64)v4);
v1 = wad_lumps;
if ( wad_numlumps <= 0 )
{
LABEL_6:
Sys_Error("W_GetLumpinfo: %s not found", a1);
result = 0LL;
}
else
{
v2 = wad_lumps + 32LL * wad_numlumps;
while ( strcmp(v4, (const char *)(v1 + 16)) )
{
v1 += 32LL;
if ( v1 == v2 )
goto LABEL_6;
}
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(const char *a1)
{
__int64 v1; // r12
__int64 v2; // rbx
__int64 result; // rax
char v4[40]; // [rsp+0h] [rbp-28h] BYREF

func2((__int64)a1, (__int64)v4);
v1 = wad_lumps;
if ( wad_numlumps <= 0 )
{
LABEL_6:
Sys_Error("W_GetLumpinfo: %s not found", a1);
result = 0LL;
}
else
{
v2 = wad_lumps + 32LL * wad_numlumps;
while ( strcmp(v4, (const char *)(v1 + 16)) )
{
v1 += 32LL;
if ( v1 == v2 )
goto LABEL_6;
}
result = v1;
}
return result;
}

original_code:
lumpinfo_t *W_GetLumpinfo (char *name) {
 int i;
 lumpinfo_t *lump_p;
 char clean[16];
 W_CleanupName (name, clean);
 for (lump_p = wad_lumps, i = 0; i < wad_numlumps; i++,lump_p++) {
  if (!strcmp(clean, lump_p->name))
   return lump_p;
 }
 Sys_Error ("W_GetLumpinfo: %s not found", name);
 return ((void *)0);
}

canonical_original_code:
struct lumpinfo_t *W_GetLumpinfo(char *name) {
 int i;
 struct lumpinfo_t *lump_p;
 char clean[16];
 W_CleanupName (name, clean);
 for (lump_p = wad_lumps, i = 0; i < wad_numlumps; i++,lump_p++) {
  if (!strcmp(clean, lump_p->name))
   return lump_p;
 }
 Sys_Error ("W_GetLumpinfo: %s not found", name);
 return ((void *)0);
}

variable_types:
name
char *

variable_types:
clean
char [16]

return_type: struct lumpinfo_t { int filepos; int disksize; int size; char type; char compression; char pad1; char name[16]; } *


decompiled_code:
char *__fastcall W_GetLumpName(const char *a1)
{
char *v1; // rax
char *v2; // r12
__int64 v3; // rax
char *v4; // r9
__int16 v6; // ax

v1 = (char *)W_GetLumpinfo(a1);
v2 = v1;
if ( v1 )
{
v3 = *(int *)v1;
v4 = (char *)wad_base;
if ( !strcmp(a1, "conchars") && *((_DWORD *)v2 + 2) + (int)v3 < wad_filesize )
{
v6 = CRC_Block((char *)wad_base + v3);
v4 = (char *)wad_base;
if ( v6 == 798 )
W_InsertOcranaLeds((__int64)wad_base + *(int *)v2);
v3 = *(int *)v2;
}
v2 = &v4[v3];
}
return v2;
}

canonical_decompiled_code:
char *__fastcall func6(const char *a1)
{
char *v1; // rax
char *v2; // r12
__int64 v3; // rax
char *v4; // r9
__int16 v6; // ax

v1 = (char *)func5(a1);
v2 = v1;
if ( v1 )
{
v3 = *(int *)v1;
v4 = (char *)wad_base;
if ( !strcmp(a1, "conchars") && *((_DWORD *)v2 + 2) + (int)v3 < wad_filesize )
{
v6 = CRC_Block((char *)wad_base + v3);
v4 = (char *)wad_base;
if ( v6 == 798 )
func0((__int64)wad_base + *(int *)v2);
v3 = *(int *)v2;
}
v2 = &v4[v3];
}
return v2;
}

original_code:
void *W_GetLumpName (char *name) {
 lumpinfo_t *lump;
 lump = W_GetLumpinfo (name);
 if(!lump)
      return ((void *)0);
 if (!strcmp(name, "conchars"))
 {
  if (lump->filepos + lump->size < wad_filesize
   && CRC_Block (wad_base + lump->filepos, lump->size) == 798)
  {
   W_InsertOcranaLeds (wad_base + lump->filepos);
  }
 }
 return (void *) (wad_base + lump->filepos);
}

canonical_original_code:
void *W_GetLumpName(char *name) {
 struct lumpinfo_t *lump;
 lump = W_GetLumpinfo (name);
 if(!lump)
      return ((void *)0);
 if (!strcmp(name, "conchars"))
 {
  if (lump->filepos + lump->size < wad_filesize
   && CRC_Block (wad_base + lump->filepos, lump->size) == 798)
  {
   W_InsertOcranaLeds (wad_base + lump->filepos);
  }
 }
 return (void *) (wad_base + lump->filepos);
}

return_type: void *

user_defined_types: struct lumpinfo_t { int filepos; int disksize; int size; char type; char compression; char pad1; char name[16]; }


decompiled_code:
char *__fastcall W_GetLumpNum(int a1)
{
if ( a1 < 0 || wad_numlumps < a1 )
Sys_Error("W_GetLumpNum: bad number: %i", (unsigned int)a1);
return (char *)wad_base + *(int *)(wad_lumps + 32LL * a1);
}

canonical_decompiled_code:
char *__fastcall func7(int a1)
{
if ( a1 < 0 || wad_numlumps < a1 )
Sys_Error("W_GetLumpNum: bad number: %i", (unsigned int)a1);
return (char *)wad_base + *(int *)(wad_lumps + 32LL * a1);
}

original_code:
void *W_GetLumpNum (int num) {
 lumpinfo_t *lump;
 if (num < 0 || num > wad_numlumps)
  Sys_Error ("W_GetLumpNum: bad number: %i", num);
 lump = wad_lumps + num;
 return (void *) (wad_base + lump->filepos);
}

canonical_original_code:
void *W_GetLumpNum(int num) {
 struct lumpinfo_t *lump;
 if (num < 0 || num > wad_numlumps)
  Sys_Error ("W_GetLumpNum: bad number: %i", num);
 lump = wad_lumps + num;
 return (void *) (wad_base + lump->filepos);
}

variable_types: num int


decompiled_code:
void __fastcall WAD3_LoadWadFile(const char *a1)
{
__int64 v1; // rax
__int64 v2; // r12
int v3; // er13
__int64 v4; // rbx
__int64 v5; // r15
unsigned int v6; // er13
__int64 v7; // rax
__int64 v8; // rbp
const char *v9; // r14
__int64 v10; // r13
int v11; // er15
const char *v12; // rbp
__int64 v13; // rbx
__int64 v14; // rax
__int64 v15; // rax
char *v16; // rdi
unsigned __int64 v17; // rax
unsigned int v18; // [rsp+0h] [rbp-4Ch]
char v19[4]; // [rsp+4h] [rbp-48h] BYREF
int v20; // [rsp+8h] [rbp-44h] BYREF
unsigned int v21; // [rsp+Ch] [rbp-40h]
int v22; // [rsp+10h] [rbp-3Ch]

if ( wad3_numlumps != 0x4000 )
{
v1 = va("textures/halflife/%s", a1);
v2 = FS_OpenVFS(v1, "rb", 5LL);
if ( v2
|| (v14 = va("textures/wad3/%s", a1), (v2 = FS_OpenVFS(v14, "rb", 5LL)) != 0)
|| (v15 = va("textures/%s", a1), (v2 = FS_OpenVFS(v15, "rb", 5LL)) != 0)
|| (v2 = FS_OpenVFS(a1, "rb", 5LL)) != 0 )
{
if ( (unsigned int)VFS_READ(v2, &v20, 12LL, v19) == 12 )
{
if ( v20 == 860111191 )
{
v3 = v21;
v4 = v21 - 1;
if ( (unsigned int)v4 > 0x3FFF )
{
Com_Printf("WAD3_LoadWadFile: invalid number of lumps (%i)\n", v21);
}
else if ( (unsigned int)VFS_SEEK(v2, v22, 0LL) )
{
Com_Printf("WAD3_LoadWadFile: unable to seek to lump table\n");
}
else
{
v5 = v3;
v6 = 32 * v3;
v18 = Hunk_LowMark();
v7 = Hunk_Alloc(v6);
v8 = v7;
if ( v7 )
{
if ( (int)VFS_READ(v2, v7, v6, v19) == 32 * v5 )
{
v9 = (const char *)(v8 + 16);
v10 = v8 + 32 * v4 + 48;
while ( 2 )
{
while ( 1 )
{
W_CleanupName((__int64)v9, (__int64)v9);
v11 = wad3_numlumps;
if ( wad3_numlumps > 0 )
break;
v16 = texwadlump;
v13 = 0LL;
LABEL_25:
strlcpy(v16, v9, 64LL);
v17 = 20 * v13;
qword_C80[v17 / 2] = v2;
dword_C88[v17] = *((_DWORD *)v9 - 4);
dword_C8C[v17] = *((_DWORD *)v9 - 3);
if ( ++wad3_numlumps != 0x4000 )
{
v9 += 32;
if ( v9 != (const char *)v10 )
continue;
}
goto LABEL_15;
}
v12 = texwadlump;
LODWORD(v13) = 0;
while ( strcmp(v9, v12) )
{
LODWORD(v13) = v13 + 1;
v12 += 80;
if ( (_DWORD)v13 == v11 )
{
v13 = (int)v13;
v16 = &texwadlump[80 * (int)v13];
goto LABEL_25;
}
}
v9 += 32;
if ( v9 != (const char *)v10 )
continue;
break;
}
LABEL_15:
Hunk_FreeToLowMark(v18);
}
else
{
Com_Printf("WAD3_LoadWadFile: unable to read lump table\n");
Hunk_FreeToLowMark(v18);
}
}
else
{
Com_Printf("WAD3_LoadWadFile: unable to allocate temporary memory for lump table\n");
}
}
}
else
{
Com_Printf("WAD3_LoadWadFile: Wad file %s doesn't have WAD3 id\n", a1);
}
}
else
{
Com_Printf("WAD3_LoadWadFile: unable to read wad header\n");
}
}
else
{
Com_Printf("WAD3_LoadWadFile: couldn't load halflife wad \"%s\"", a1);
}
}
}

canonical_decompiled_code:
void __fastcall func8(const char *a1)
{
__int64 v1; // rax
__int64 v2; // r12
int v3; // er13
__int64 v4; // rbx
__int64 v5; // r15
unsigned int v6; // er13
__int64 v7; // rax
__int64 v8; // rbp
const char *v9; // r14
__int64 v10; // r13
int v11; // er15
const char *v12; // rbp
__int64 v13; // rbx
__int64 v14; // rax
__int64 v15; // rax
char *v16; // rdi
unsigned __int64 v17; // rax
unsigned int v18; // [rsp+0h] [rbp-4Ch]
char v19[4]; // [rsp+4h] [rbp-48h] BYREF
int v20; // [rsp+8h] [rbp-44h] BYREF
unsigned int v21; // [rsp+Ch] [rbp-40h]
int v22; // [rsp+10h] [rbp-3Ch]

if ( wad3_numlumps != 0x4000 )
{
v1 = va("textures/halflife/%s", a1);
v2 = FS_OpenVFS(v1, "rb", 5LL);
if ( v2
|| (v14 = va("textures/wad3/%s", a1), (v2 = FS_OpenVFS(v14, "rb", 5LL)) != 0)
|| (v15 = va("textures/%s", a1), (v2 = FS_OpenVFS(v15, "rb", 5LL)) != 0)
|| (v2 = FS_OpenVFS(a1, "rb", 5LL)) != 0 )
{
if ( (unsigned int)VFS_READ(v2, &v20, 12LL, v19) == 12 )
{
if ( v20 == 860111191 )
{
v3 = v21;
v4 = v21 - 1;
if ( (unsigned int)v4 > 0x3FFF )
{
Com_Printf("WAD3_LoadWadFile: invalid number of lumps (%i)\n", v21);
}
else if ( (unsigned int)VFS_SEEK(v2, v22, 0LL) )
{
Com_Printf("WAD3_LoadWadFile: unable to seek to lump table\n");
}
else
{
v5 = v3;
v6 = 32 * v3;
v18 = Hunk_LowMark();
v7 = Hunk_Alloc(v6);
v8 = v7;
if ( v7 )
{
if ( (int)VFS_READ(v2, v7, v6, v19) == 32 * v5 )
{
v9 = (const char *)(v8 + 16);
v10 = v8 + 32 * v4 + 48;
while ( 2 )
{
while ( 1 )
{
func2((__int64)v9, (__int64)v9);
v11 = wad3_numlumps;
if ( wad3_numlumps > 0 )
break;
v16 = texwadlump;
v13 = 0LL;
LABEL_25:
strlcpy(v16, v9, 64LL);
v17 = 20 * v13;
qword_C80[v17 / 2] = v2;
dword_C88[v17] = *((_DWORD *)v9 - 4);
dword_C8C[v17] = *((_DWORD *)v9 - 3);
if ( ++wad3_numlumps != 0x4000 )
{
v9 += 32;
if ( v9 != (const char *)v10 )
continue;
}
goto LABEL_15;
}
v12 = texwadlump;
LODWORD(v13) = 0;
while ( strcmp(v9, v12) )
{
LODWORD(v13) = v13 + 1;
v12 += 80;
if ( (_DWORD)v13 == v11 )
{
v13 = (int)v13;
v16 = &texwadlump[80 * (int)v13];
goto LABEL_25;
}
}
v9 += 32;
if ( v9 != (const char *)v10 )
continue;
break;
}
LABEL_15:
Hunk_FreeToLowMark(v18);
}
else
{
Com_Printf("WAD3_LoadWadFile: unable to read lump table\n");
Hunk_FreeToLowMark(v18);
}
}
else
{
Com_Printf("WAD3_LoadWadFile: unable to allocate temporary memory for lump table\n");
}
}
}
else
{
Com_Printf("WAD3_LoadWadFile: Wad file %s doesn't have WAD3 id\n", a1);
}
}
else
{
Com_Printf("WAD3_LoadWadFile: unable to read wad header\n");
}
}
else
{
Com_Printf("WAD3_LoadWadFile: couldn't load halflife wad \"%s\"", a1);
}
}
}

original_code:
void WAD3_LoadWadFile (char *filename)
{
 lumpinfo_t *lumps, *lump_p;
 wadinfo_t header;
 int i, j, infotableofs, numlumps, lowmark;
 vfsfile_t *file;
 vfserrno_t err;
 if (wad3_numlumps == 16384)
  return;
 if (!(file = FS_OpenVFS(va("textures/halflife/%s", filename), "rb", FS_ANY)))
  if (!(file = FS_OpenVFS(va("textures/wad3/%s", filename), "rb", FS_ANY)))
   if (!(file = FS_OpenVFS(va("textures/%s", filename), "rb", FS_ANY)))
    if (!(file = FS_OpenVFS(filename, "rb", FS_ANY)))
    {
     Com_Printf ("WAD3_LoadWadFile: couldn't load halflife wad \"%s\"", filename);
     return;
    }
 if (VFS_READ(file, &header, sizeof(wadinfo_t), &err) != sizeof(wadinfo_t)) {
  Com_Printf ("WAD3_LoadWadFile: unable to read wad header\n");
  return;
 }
 if (memcmp(header.identification, "WAD3", 4)) {
  Com_Printf ("WAD3_LoadWadFile: Wad file %s doesn't have WAD3 id\n",filename);
  return;
 }
 numlumps = (header.numlumps);
 if (numlumps < 1 || numlumps > 16384) {
  Com_Printf ("WAD3_LoadWadFile: invalid number of lumps (%i)\n", numlumps);
  return;
 }
 infotableofs = (header.infotableofs);
 if (VFS_SEEK(file, infotableofs, 0)) {
  Com_Printf ("WAD3_LoadWadFile: unable to seek to lump table\n");
  return;
 }
 lowmark = Hunk_LowMark();
 if (!(lumps = Hunk_Alloc(sizeof(lumpinfo_t) * numlumps))) {
  Com_Printf ("WAD3_LoadWadFile: unable to allocate temporary memory for lump table\n");
  return;
 }
 if (((size_t) VFS_READ(file, lumps, sizeof(lumpinfo_t)*numlumps, &err)) != sizeof(lumpinfo_t) * numlumps) {
  Com_Printf ("WAD3_LoadWadFile: unable to read lump table\n");
  Hunk_FreeToLowMark(lowmark);
  return;
 }
 for (i = 0, lump_p = lumps; i < numlumps; i++,lump_p++) {
  W_CleanupName (lump_p->name, lump_p->name);
  for (j = 0; j < wad3_numlumps; j++) {
   if (!strcmp(lump_p->name, texwadlump[j].name))
    goto skip_duplicate;
  }
  strlcpy (texwadlump[j].name, lump_p->name, sizeof(texwadlump[j].name));
  texwadlump[j].file = file;
  texwadlump[j].position = (lump_p->filepos);
  texwadlump[j].size = (lump_p->disksize);
  wad3_numlumps++;
  if (wad3_numlumps == 16384)
   break;
skip_duplicate:;
 }
 Hunk_FreeToLowMark(lowmark);
}

canonical_original_code:
void WAD3_LoadWadFile(char *filename)
{
 struct lumpinfo_t *lumps; struct lumpinfo_t *lump_p;
 struct wadinfo_t header;
 int i; int j; int infotableofs; int numlumps; int lowmark;
 struct vfsfile_s *file;
 enum vfserrno_t err;
 if (wad3_numlumps == 16384)
  return;
 if (!(file = FS_OpenVFS(va("textures/halflife/%s", filename), "rb", FS_ANY)))
  if (!(file = FS_OpenVFS(va("textures/wad3/%s", filename), "rb", FS_ANY)))
   if (!(file = FS_OpenVFS(va("textures/%s", filename), "rb", FS_ANY)))
    if (!(file = FS_OpenVFS(filename, "rb", FS_ANY)))
    {
     Com_Printf ("WAD3_LoadWadFile: couldn't load halflife wad \"%s\"", filename);
     return;
    }
 if (VFS_READ(file, &header, sizeof(wadinfo_t), &err) != sizeof(wadinfo_t)) {
  Com_Printf ("WAD3_LoadWadFile: unable to read wad header\n");
  return;
 }
 if (memcmp(header.identification, "WAD3", 4)) {
  Com_Printf ("WAD3_LoadWadFile: Wad file %s doesn't have WAD3 id\n",filename);
  return;
 }
 numlumps = (header.numlumps);
 if (numlumps < 1 || numlumps > 16384) {
  Com_Printf ("WAD3_LoadWadFile: invalid number of lumps (%i)\n", numlumps);
  return;
 }
 infotableofs = (header.infotableofs);
 if (VFS_SEEK(file, infotableofs, 0)) {
  Com_Printf ("WAD3_LoadWadFile: unable to seek to lump table\n");
  return;
 }
 lowmark = Hunk_LowMark();
 if (!(lumps = Hunk_Alloc(sizeof(lumpinfo_t) * numlumps))) {
  Com_Printf ("WAD3_LoadWadFile: unable to allocate temporary memory for lump table\n");
  return;
 }
 if (((unsigned long) VFS_READ(file, lumps, sizeof(lumpinfo_t)*numlumps, &err)) != sizeof(lumpinfo_t) * numlumps) {
  Com_Printf ("WAD3_LoadWadFile: unable to read lump table\n");
  Hunk_FreeToLowMark(lowmark);
  return;
 }
 for (i = 0, lump_p = lumps; i < numlumps; i++,lump_p++) {
  W_CleanupName (lump_p->name, lump_p->name);
  for (j = 0; j < wad3_numlumps; j++) {
   if (!strcmp(lump_p->name, texwadlump[j].name))
    goto skip_duplicate;
  }
  strlcpy (texwadlump[j].name, lump_p->name, sizeof(texwadlump[j].name));
  texwadlump[j].file = file;
  texwadlump[j].position = (lump_p->filepos);
  texwadlump[j].size = (lump_p->disksize);
  wad3_numlumps++;
  if (wad3_numlumps == 16384)
   break;
skip_duplicate:;
 }
 Hunk_FreeToLowMark(lowmark);
}

variable_types: struct wadinfo_t { char identification[4]; int numlumps; int infotableofs; }

variable_types: j int

variable_types: numlumps int

variable_types: lowmark int

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

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


original_code:
byte *ConvertWad3ToRGBA(int width, int height, byte *in, qbool alpha)
{
 byte *data, *pal;
 int i, p, image_size;
 image_size = width * height;
 data = Q_malloc (image_size * 4);
 pal = (byte *) in + ((image_size * 85) / 64) + 2;
 for (i = 0; i < image_size; i++) {
  p = *in++;
  if (p == 255 && alpha) {
   ((int *) data)[i] = 0;
  } else {
   p *= 3;
   data[i * 4 + 0] = pal[p];
   data[i * 4 + 1] = pal[p + 1];
   data[i * 4 + 2] = pal[p + 2];
   data[i * 4 + 3] = 255;
  }
 }
 return data;
}

canonical_original_code:
unsigned char *ConvertWad3ToRGBA(int width, int height, unsigned char *in, enum qbool alpha)
{
 unsigned char *data; unsigned char *pal;
 int i; int p; int image_size;
 image_size = width * height;
 data = Q_malloc (image_size * 4);
 pal = (unsigned char *) in + ((image_size * 85) / 64) + 2;
 for (i = 0; i < image_size; i++) {
  p = *in++;
  if (p == 255 && alpha) {
   ((int *) data)[i] = 0;
  } else {
   p *= 3;
   data[i * 4 + 0] = pal[p];
   data[i * 4 + 1] = pal[p + 1];
   data[i * 4 + 2] = pal[p + 2];
   data[i * 4 + 3] = 255;
  }
 }
 return data;
}

variable_types: width int

variable_types: height int

variable_types:
in
unsigned char *

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

variable_types:
data
unsigned char *

variable_types:
pal
unsigned char *

variable_types: i int

variable_types: p int

return_type: unsigned char *


decompiled_code:
__int64 __fastcall WAD3_LoadTexture(char *s1)
{
int v2; // er13
const char *v3; // r12
int v4; // ebp
char *v5; // rbp
__int64 v6; // r13
_DWORD *v7; // r12
int v8; // edi
int v9; // esi
__int64 v10; // r13
char v12[44]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( *((_DWORD *)s1 + 24) )
return ConvertWad3ToRGBA(*((_DWORD *)s1 + 4), *((_DWORD *)s1 + 5), (__int64)(s1 + 128), *s1 == 123);
v2 = wad3_numlumps;
v3 = texwadlump;
v4 = 0;
if ( wad3_numlumps <= 0 )
return 0LL;
if ( strcasecmp(s1, texwadlump) )
{
do
{
++v4;
v3 += 80;
if ( v2 == v4 )
return 0LL;
}
while ( strcasecmp(s1, v3) );
}
v5 = &texwadlump[80 * v4];
v6 = *((_QWORD *)v5 + 8);
if ( !(unsigned int)VFS_SEEK(v6, *((int *)v5 + 18), 0LL) )
{
v7 = (_DWORD *)Q_malloc(*((int *)v5 + 19));
if ( (int)VFS_READ(v6, v7, *((unsigned int *)v5 + 19), v12) >= *((_DWORD *)v5 + 19) )
{
v8 = v7[4];
v9 = v7[5];
if ( v8 == *((_DWORD *)s1 + 4) && v9 == *((_DWORD *)s1 + 5) )
{
v10 = ConvertWad3ToRGBA(v8, v9, (__int64)(v7 + 10), *s1 == 123);
free(v7);
return v10;
}
goto LABEL_12;
}
Com_Printf("WAD3_LoadTexture: corrupt WAD3 file\n");
if ( v7 )
LABEL_12:
free(v7);
return 0LL;
}
Com_Printf("WAD3_LoadTexture: corrupt WAD3 file\n");
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func10(char *s1)
{
int v2; // er13
const char *v3; // r12
int v4; // ebp
char *v5; // rbp
__int64 v6; // r13
_DWORD *v7; // r12
int v8; // edi
int v9; // esi
__int64 v10; // r13
char v12[44]; // [rsp+Ch] [rbp-2Ch] BYREF

if ( *((_DWORD *)s1 + 24) )
return func9(*((_DWORD *)s1 + 4), *((_DWORD *)s1 + 5), (__int64)(s1 + 128), *s1 == 123);
v2 = wad3_numlumps;
v3 = texwadlump;
v4 = 0;
if ( wad3_numlumps <= 0 )
return 0LL;
if ( strcasecmp(s1, texwadlump) )
{
do
{
++v4;
v3 += 80;
if ( v2 == v4 )
return 0LL;
}
while ( strcasecmp(s1, v3) );
}
v5 = &texwadlump[80 * v4];
v6 = *((_QWORD *)v5 + 8);
if ( !(unsigned int)VFS_SEEK(v6, *((int *)v5 + 18), 0LL) )
{
v7 = (_DWORD *)Q_malloc(*((int *)v5 + 19));
if ( (int)VFS_READ(v6, v7, *((unsigned int *)v5 + 19), v12) >= *((_DWORD *)v5 + 19) )
{
v8 = v7[4];
v9 = v7[5];
if ( v8 == *((_DWORD *)s1 + 4) && v9 == *((_DWORD *)s1 + 5) )
{
v10 = func9(v8, v9, (__int64)(v7 + 10), *s1 == 123);
free(v7);
return v10;
}
goto LABEL_12;
}
Com_Printf("WAD3_LoadTexture: corrupt WAD3 file\n");
if ( v7 )
LABEL_12:
free(v7);
return 0LL;
}
Com_Printf("WAD3_LoadTexture: corrupt WAD3 file\n");
return 0LL;
}

original_code:
byte *WAD3_LoadTexture (texture_t *tx)
{
 int i, j = 0;
 miptex_t *mt;
 byte *data;
 vfsfile_t *file;
 vfserrno_t err;
 if (tx->offsets[0])
  return ConvertWad3ToRGBA(tx->width, tx->height, (byte *)(tx + 1), (tx->name[0] == '{'));
 for (i = 0; i < wad3_numlumps; i++) {
  if (strcasecmp(tx->name, texwadlump[i].name))
   continue;
  file = texwadlump[i].file;
  if (VFS_SEEK(file, texwadlump[i].position, 0)) {
   Com_Printf("WAD3_LoadTexture: corrupt WAD3 file\n");
   return ((void *)0);
  }
  mt = Q_malloc(texwadlump[i].size);
  if (VFS_READ(file, mt, texwadlump[i].size, &err) < texwadlump[i].size) {
   Com_Printf("WAD3_LoadTexture: corrupt WAD3 file\n");
   if(mt) { free(mt); mt = ((void *)0); };
   return ((void *)0);
  }
  mt->width = (mt->width);
  mt->height = (mt->height);
  if (mt->width != tx->width || mt->height != tx->height) {
   if(mt) { free(mt); mt = ((void *)0); };
   return ((void *)0);
  }
  for (j = 0;j < 4;j++)
   mt->offsets[j] = (mt->offsets[j]);
  data = ConvertWad3ToRGBA(mt->width, mt->height, (byte *)(mt + 1), (tx->name[0] == '{'));
  if(mt) { free(mt); mt = ((void *)0); };
  return data;
 }
 return ((void *)0);
}

canonical_original_code:
unsigned char *WAD3_LoadTexture(struct texture_s *tx)
{
 int i; int j = 0;
 struct miptex_s *mt;
 unsigned char *data;
 struct vfsfile_s *file;
 enum vfserrno_t err;
 if (tx->offsets[0])
  return ConvertWad3ToRGBA(tx->width, tx->height, (unsigned char *)(tx + 1), (tx->name[0] == '{'));
 for (i = 0; i < wad3_numlumps; i++) {
  if (strcasecmp(tx->name, texwadlump[i].name))
   continue;
  file = texwadlump[i].file;
  if (VFS_SEEK(file, texwadlump[i].position, 0)) {
   Com_Printf("WAD3_LoadTexture: corrupt WAD3 file\n");
   return ((void *)0);
  }
  mt = Q_malloc(texwadlump[i].size);
  if (VFS_READ(file, mt, texwadlump[i].size, &err) < texwadlump[i].size) {
   Com_Printf("WAD3_LoadTexture: corrupt WAD3 file\n");
   if(mt) { free(mt); mt = ((void *)0); };
   return ((void *)0);
  }
  mt->width = (mt->width);
  mt->height = (mt->height);
  if (mt->width != tx->width || mt->height != tx->height) {
   if(mt) { free(mt); mt = ((void *)0); };
   return ((void *)0);
  }
  for (j = 0;j < 4;j++)
   mt->offsets[j] = (mt->offsets[j]);
  data = ConvertWad3ToRGBA(mt->width, mt->height, (unsigned char *)(mt + 1), (tx->name[0] == '{'));
  if(mt) { free(mt); mt = ((void *)0); };
  return data;
 }
 return ((void *)0);
}

variable_types: struct texture_s { char name[16]; unsigned int width; int gl_texturenum; int fb_texturenum; struct msurface_s { int visframe; struct mplane_s { float normal[3]; float dist; unsigned char type; unsigned char signbits; unsigned char pad[2]; } *plane; int flags; int firstedge; int numedges; short texturemins[2]; short extents[2]; int light_s; struct glpoly_s { struct glpoly_s *next; struct glpoly_s *chain; struct glpoly_s *fb_chain; struct glpoly_s *luma_chain; struct glpoly_s *caustics_chain; struct glpoly_s *detail_chain; int numverts; float verts[4][9]; } *polys; struct msurface_s *texturechain; struct mtexinfo_s { float vecs[2][4]; struct texture_s *texture; int flags; } *texinfo; int dlightframe; int dlightbits; int lightmaptexturenum; unsigned char styles[4]; int cached_light[4]; enum qbool { false=0, true=1 } cached_dlight; unsigned char *samples; } *texturechain[2]; struct msurface_s **texturechain_tail[2]; int anim_total; int anim_min; struct texture_s *anim_next; struct texture_s *alternate_anims; unsigned int offsets[4]; unsigned int flatcolor3ub; enum qbool { false=0, true=1 } loaded; int isLumaTexture; } *

variable_types: struct miptex_s { char name[16]; unsigned int width; unsigned int offsets[4]; } *

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

user_defined_types: struct texture_s { char name[16]; unsigned int width; int gl_texturenum; int fb_texturenum; struct msurface_s *texturechain[2]; struct msurface_s **texturechain_tail[2]; int anim_total; int anim_min; struct texture_s *anim_next; struct texture_s *alternate_anims; unsigned int offsets[4]; unsigned int flatcolor3ub; enum qbool loaded; int isLumaTexture; }

user_defined_types: struct msurface_s { int visframe; struct mplane_s *plane; int flags; int firstedge; int numedges; short texturemins[2]; short extents[2]; int light_s; struct glpoly_s *polys; struct msurface_s *texturechain; struct mtexinfo_s *texinfo; int dlightframe; int dlightbits; int lightmaptexturenum; unsigned char styles[4]; int cached_light[4]; enum qbool cached_dlight; unsigned char *samples; }


decompiled_code:
void W_FreeWadFile()
{
if ( wad_base )
free(wad_base);
wad_base = 0LL;
wad_lumps = 0LL;
wad_numlumps = 0;
wad_filesize = 0;
}

canonical_decompiled_code:
void func3()
{
if ( wad_base )
free(wad_base);
wad_base = 0LL;
wad_lumps = 0LL;
wad_numlumps = 0;
wad_filesize = 0;
}

original_code:
void W_FreeWadFile (void)
{
 if(wad_base) { free(wad_base); wad_base = ((void *)0); };
 wad_base = ((void *)0);
 wad_lumps = ((void *)0);
 wad_numlumps = 0;
 wad_filesize = 0;
}

canonical_original_code:
void W_FreeWadFile()
{
 if(wad_base) { free(wad_base); wad_base = ((void *)0); };
 wad_base = ((void *)0);
 wad_lumps = ((void *)0);
 wad_numlumps = 0;
 wad_filesize = 0;
}


decompiled_code:
__int64 Help_Browser_Mouse_Event()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 1LL;
}

original_code:
static qbool Help_Browser_Mouse_Event(const mouse_state_t *ms)
{
 return true;
}

canonical_original_code:
static enum qbool Help_Browser_Mouse_Event(struct mouse_state_s *ms)
{
 return true;
}

variable_types: struct mouse_state_s { double x; double y; double x_old; double y_old; enum qbool { false=0, true=1 } buttons[9]; int button_down; int button_up; } *

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

user_defined_types: struct mouse_state_s { double x; double y; double x_old; double y_old; enum qbool buttons[9]; int button_down; int button_up; }


decompiled_code:
__int64 __fastcall Help_Browser_Key(unsigned int a1, unsigned __int16 a2)
{
return CPageViewer_Key(&help_viewer, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1, unsigned __int16 a2)
{
return CPageViewer_Key(&help_viewer, a1, a2);
}

original_code:
int Help_Browser_Key(int key, unsigned short unichar, CTab_t *tab, CTabPage_t *page)
{
    return CPageViewer_Key(&help_viewer, key, unichar);
}

canonical_original_code:
int Help_Browser_Key(int key, unsigned short unichar, struct CTab_s *tab, struct CTabPage_s *page)
{
    return CPageViewer_Key(&help_viewer, key, unichar);
}

variable_types: key int

variable_types:
unichar
unsigned short

variable_types: struct CTab_s { struct CTabPage_s { char name[-1]; int id; struct CTabPage_Handlers_s { void (*draw)(int x, int y, int w, int h, struct CTab_s *, struct CTabPage_s *); int (*key)(int key, unsigned short unichar, struct CTab_s *, struct CTabPage_s *); void (*onshow)(); enum qbool { false=0, true=1 } (*mousemove)(struct mouse_state_s { double x; double y; double x_old; double y_old; enum qbool { false=0, true=1 } buttons[9]; int button_down; int button_up; } *ms); } handlers; } pages[16]; int nPages; int activePage; int lastViewedPage; int hoveredPage; int width; int height; struct { int x; } navi_boxes[16]; void *tag; } *

variable_types:
page
struct CTabPage_s *

user_defined_types: struct CTab_s { struct CTabPage_s pages[16]; int nPages; int activePage; int lastViewedPage; int hoveredPage; int width; int height; struct { int x; } navi_boxes[16]; void *tag; }

user_defined_types: struct CTabPage_s { char name[-1]; int id; struct CTabPage_Handlers_s handlers; }

user_defined_types: struct CTabPage_Handlers_s { void (*draw)(int x, int y, int w, int h, struct CTab_s *, struct CTabPage_s *); int (*key)(int key, unsigned short unichar, struct CTab_s *, struct CTabPage_s *); void (*onshow)(); enum qbool (*mousemove)(struct mouse_state_s *ms); }


decompiled_code:
__int64 __fastcall Help_Browser_Draw(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return CPageViewer_Draw(&help_viewer, a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return CPageViewer_Draw(&help_viewer, a1, a2, a3, a4);
}

original_code:
void Help_Browser_Draw(int x, int y, int w, int h, CTab_t *tab, CTabPage_t *page)
{
    CPageViewer_Draw(&help_viewer, x, y, w, h);
}

canonical_original_code:
void Help_Browser_Draw(int x, int y, int w, int h, struct CTab_s *tab, struct CTabPage_s *page)
{
    CPageViewer_Draw(&help_viewer, x, y, w, h);
}

variable_types: x int

variable_types: y int

variable_types: w int

variable_types: h int


decompiled_code:
__int64 __fastcall Help_Index_Draw(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return FL_Draw(&help_index_fl, a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return FL_Draw(&help_index_fl, a1, a2, a3, a4);
}

original_code:
static void Help_Index_Draw(int x, int y, int w, int h, CTab_t *tab, CTabPage_t *page)
{
    FL_Draw(&help_index_fl, x, y, w, h);
}

canonical_original_code:
static void Help_Index_Draw(int x, int y, int w, int h, struct CTab_s *tab, struct CTabPage_s *page)
{
    FL_Draw(&help_index_fl, x, y, w, h);
}


decompiled_code:
__int64 __fastcall Help_Tutorials_Draw(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return FL_Draw(&help_tutorials_fl, a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return FL_Draw(&help_tutorials_fl, a1, a2, a3, a4);
}

original_code:
static void Help_Tutorials_Draw(int x, int y, int w, int h, CTab_t *tab, CTabPage_t *page)
{
    FL_Draw(&help_tutorials_fl, x, y, w, h);
}

canonical_original_code:
static void Help_Tutorials_Draw(int x, int y, int w, int h, struct CTab_s *tab, struct CTabPage_s *page)
{
    FL_Draw(&help_tutorials_fl, x, y, w, h);
}


decompiled_code:
__int64 __fastcall Help_Tutorials_Key(unsigned int a1)
{
__int64 result; // rax
const char *v2; // rax
__int64 v3; // rax

result = FL_Key(&help_tutorials_fl, a1);
if ( !(_DWORD)result && (a1 == 13 || a1 == 200) )
{
M_LeaveMenus();
v2 = (const char *)FL_GetCurrentPath(&help_tutorials_fl);
v3 = va("playdemo \"%s\"\n", v2);
Cbuf_AddText(v3);
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1)
{
__int64 result; // rax
const char *v2; // rax
__int64 v3; // rax

result = FL_Key(&help_tutorials_fl, a1);
if ( !(_DWORD)result && (a1 == 13 || a1 == 200) )
{
M_LeaveMenus();
v2 = (const char *)FL_GetCurrentPath(&help_tutorials_fl);
v3 = va("playdemo \"%s\"\n", v2);
Cbuf_AddText(v3);
result = 1LL;
}
return result;
}

original_code:
static int Help_Tutorials_Key(int key, unsigned short unichar, CTab_t *tab, CTabPage_t *page)
{
    qbool processed;
    processed = FL_Key(&help_tutorials_fl, key);
    if (!processed)
    {
        if (key == K_ENTER || key == K_MOUSE1)
        {
   M_LeaveMenus();
   Cbuf_AddText(va("playdemo \"%s\"\n", FL_GetCurrentPath(&help_tutorials_fl)));
            processed = true;
        }
    }
    return processed;
}

canonical_original_code:
static int Help_Tutorials_Key(int key, unsigned short unichar, struct CTab_s *tab, struct CTabPage_s *page)
{
    enum qbool processed;
    processed = FL_Key(&help_tutorials_fl, key);
    if (!processed)
    {
        if (key == K_ENTER || key == K_MOUSE1)
        {
   M_LeaveMenus();
   Cbuf_AddText(va("playdemo \"%s\"\n", FL_GetCurrentPath(&help_tutorials_fl)));
            processed = true;
        }
    }
    return processed;
}

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


decompiled_code:
__int64 __fastcall Help_Tutorials_Mouse_Event(__int64 a1)
{
int v1; // edi

if ( !(unsigned int)FL_Mouse_Event(&help_tutorials_fl, a1) )
{
v1 = *(_DWORD *)(a1 + 72);
if ( (unsigned int)(v1 - 1) <= 1 )
Help_Tutorials_Key(v1 + 199);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
int v1; // edi

if ( !(unsigned int)FL_Mouse_Event(&help_tutorials_fl, a1) )
{
v1 = *(_DWORD *)(a1 + 72);
if ( (unsigned int)(v1 - 1) <= 1 )
func5(v1 + 199);
}
return 1LL;
}

original_code:
static qbool Help_Tutorials_Mouse_Event(const mouse_state_t *ms)
{
    if (FL_Mouse_Event(&help_tutorials_fl, ms)) {
        return true;
    } else if (ms->button_up >= 1 && ms->button_up <= 2) {
        Help_Tutorials_Key(K_MOUSE1 - 1 + ms->button_up, 0, &help_tab, help_tab.pages + HELPM_TUTORIALS);
        return true;
    }
 return true;
}

canonical_original_code:
static enum qbool Help_Tutorials_Mouse_Event(struct mouse_state_s *ms)
{
    if (FL_Mouse_Event(&help_tutorials_fl, ms)) {
        return true;
    } else if (ms->button_up >= 1 && ms->button_up <= 2) {
        Help_Tutorials_Key(K_MOUSE1 - 1 + ms->button_up, 0, &help_tab, help_tab.pages + HELPM_TUTORIALS);
        return true;
    }
 return true;
}


decompiled_code:
__int64 Help_Browser_Init()
{
CPageViewer_Init(&help_viewer);
return CPageViewer_GoUrl(&help_viewer, "help/index.xml");
}

canonical_decompiled_code:
__int64 func9()
{
CPageViewer_Init(&help_viewer);
return CPageViewer_GoUrl(&help_viewer, "help/index.xml");
}

original_code:
void Help_Browser_Init(void)
{
    CPageViewer_Init(&help_viewer);
    CPageViewer_GoUrl(&help_viewer, "help/index.xml");
}

canonical_original_code:
void Help_Browser_Init()
{
    CPageViewer_Init(&help_viewer);
    CPageViewer_GoUrl(&help_viewer, "help/index.xml");
}


decompiled_code:
__int64 Help_Browser_Focus()
{
return CTab_SetCurrentId(&help_tab, 0LL);
}

canonical_decompiled_code:
__int64 func10()
{
return CTab_SetCurrentId(&help_tab, 0LL);
}

original_code:
void Help_Browser_Focus(void)
{
    CTab_SetCurrentId(&help_tab, HELPM_BROWSER);
}

canonical_original_code:
void Help_Browser_Focus()
{
    CTab_SetCurrentId(&help_tab, HELPM_BROWSER);
}


decompiled_code:
__int64 __fastcall Help_Index_Key(unsigned int a1)
{
__int64 result; // rax
__int64 v2; // rax

result = FL_Key(&help_index_fl, a1);
if ( !(_DWORD)result && (a1 == 13 || a1 == 200) )
{
v2 = FL_GetCurrentPath(&help_index_fl);
CPageViewer_Go(&help_viewer, v2, 0LL);
Help_Browser_Focus();
result = 1LL;
}
return result;
}

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

result = FL_Key(&help_index_fl, a1);
if ( !(_DWORD)result && (a1 == 13 || a1 == 200) )
{
v2 = FL_GetCurrentPath(&help_index_fl);
CPageViewer_Go(&help_viewer, v2, 0LL);
func10();
result = 1LL;
}
return result;
}

original_code:
static int Help_Index_Key(int key, unsigned short unichar, CTab_t *tab, CTabPage_t *page)
{
    qbool processed;
    processed = FL_Key(&help_index_fl, key);
    if (!processed)
    {
        if (key == K_ENTER || key == K_MOUSE1)
        {
            CPageViewer_Go(&help_viewer, FL_GetCurrentPath(&help_index_fl), ((void *)0));
            Help_Browser_Focus();
            processed = true;
        }
    }
    return processed;
}

canonical_original_code:
static int Help_Index_Key(int key, unsigned short unichar, struct CTab_s *tab, struct CTabPage_s *page)
{
    enum qbool processed;
    processed = FL_Key(&help_index_fl, key);
    if (!processed)
    {
        if (key == K_ENTER || key == K_MOUSE1)
        {
            CPageViewer_Go(&help_viewer, FL_GetCurrentPath(&help_index_fl), ((void *)0));
            Help_Browser_Focus();
            processed = true;
        }
    }
    return processed;
}


decompiled_code:
__int64 __fastcall Help_Index_Mouse_Event(__int64 a1)
{
int v1; // edi

if ( !(unsigned int)FL_Mouse_Event(&help_index_fl, a1) )
{
v1 = *(_DWORD *)(a1 + 72);
if ( (unsigned int)(v1 - 1) <= 1 )
Help_Index_Key(v1 + 199);
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // edi

if ( !(unsigned int)FL_Mouse_Event(&help_index_fl, a1) )
{
v1 = *(_DWORD *)(a1 + 72);
if ( (unsigned int)(v1 - 1) <= 1 )
func11(v1 + 199);
}
return 1LL;
}

original_code:
static qbool Help_Index_Mouse_Event(const mouse_state_t *ms)
{
    if (FL_Mouse_Event(&help_index_fl, ms)) {
        return true;
    } else if (ms->button_up >= 1 && ms->button_up <= 2) {
        Help_Index_Key(K_MOUSE1 - 1 + ms->button_up, 0, &help_tab, help_tab.pages + HELPM_INDEX);
        return true;
    }
 return true;
}

canonical_original_code:
static enum qbool Help_Index_Mouse_Event(struct mouse_state_s *ms)
{
    if (FL_Mouse_Event(&help_index_fl, ms)) {
        return true;
    } else if (ms->button_up >= 1 && ms->button_up <= 2) {
        Help_Index_Key(K_MOUSE1 - 1 + ms->button_up, 0, &help_tab, help_tab.pages + HELPM_INDEX);
        return true;
    }
 return true;
}


decompiled_code:
__int64 __fastcall Menu_Help_Key(unsigned int a1, unsigned __int16 a2)
{
__int64 result; // rax

result = CTab_Key(&help_tab, a1, a2);
if ( !(_DWORD)result && (a1 == 27 || a1 == 201) )
result = M_Menu_Main_f();
return result;
}

canonical_decompiled_code:
__int64 __fastcall func14(unsigned int a1, unsigned __int16 a2)
{
__int64 result; // rax

result = CTab_Key(&help_tab, a1, a2);
if ( !(_DWORD)result && (a1 == 27 || a1 == 201) )
result = M_Menu_Main_f();
return result;
}

original_code:
void Menu_Help_Key(int key, unsigned short unichar)
{
 extern void M_Menu_Main_f (void);
    int handled = CTab_Key(&help_tab, key, unichar);
    if (!handled)
    {
        if (key == K_ESCAPE || key == K_MOUSE2)
        {
            M_Menu_Main_f();
        }
    }
}

canonical_original_code:
void Menu_Help_Key(int key, unsigned short unichar)
{
 extern void M_Menu_Main_f();
    int handled = CTab_Key(&help_tab, key, unichar);
    if (!handled)
    {
        if (key == K_ESCAPE || key == K_MOUSE2)
        {
            M_Menu_Main_f();
        }
    }
}

variable_types: handled int


decompiled_code:
__int64 __fastcall Menu_Help_Draw(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return CTab_Draw(&help_tab, a1, a2, a3, a4);
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int a1, unsigned int a2, unsigned int a3, unsigned int a4)
{
return CTab_Draw(&help_tab, a1, a2, a3, a4);
}

original_code:
void Menu_Help_Draw(int x, int y, int w, int h)
{
    CTab_Draw(&help_tab, x, y, w, h);
}


original_code:
qbool Menu_Help_Mouse_Event(const mouse_state_t *ms)
{
 mouse_state_t nms = *ms;
    if (ms->button_up == 2) {
        Menu_Help_Key(K_MOUSE2, 0);
        return true;
    }
 nms.x -= 4;
 nms.y -= 4;
 nms.x_old -= 4;
 nms.y_old -= 4;
 if (nms.x < 0 || nms.y < 0) return false;
 return CTab_Mouse_Event(&help_tab, &nms);
}

canonical_original_code:
enum qbool Menu_Help_Mouse_Event(struct mouse_state_s *ms)
{
 struct mouse_state_s nms = *ms;
    if (ms->button_up == 2) {
        Menu_Help_Key(K_MOUSE2, 0);
        return true;
    }
 nms.x -= 4;
 nms.y -= 4;
 nms.x_old -= 4;
 nms.y_old -= 4;
 if (nms.x < 0 || nms.y < 0) return false;
 return CTab_Mouse_Event(&help_tab, &nms);
}

variable_types: struct mouse_state_s { double x; double y; double x_old; double y_old; enum qbool { false=0, true=1 } buttons[9]; int button_down; int button_up; }


variable_types: i int

variable_types: j int

variable_types:
tempanorms
float [162][3]

variable_types: forward float

variable_types: yaw float

variable_types: pitch float

variable_types: angle float

variable_types: sp float

variable_types: sy float

variable_types: cp float

variable_types: cy float

variable_types: precut float

variable_types:
normal
float [3]

variable_types:
lightvec
float [3]


decompiled_code:
__int64 VLight_DumpLightTable_f()
{
return FS_WriteFile("lighttable.raw", vlighttable, &unk_10000);
}

canonical_decompiled_code:
__int64 func3()
{
return FS_WriteFile("lighttable.raw", vlighttable, &unk_10000);
}

original_code:
void VLight_DumpLightTable_f(void)
{
 FS_WriteFile ("lighttable.raw", vlighttable, 256*256);
}

canonical_original_code:
void VLight_DumpLightTable_f()
{
 FS_WriteFile ("lighttable.raw", vlighttable, 256*256);
}


decompiled_code:
// attributes: thunk
__int64 VLight_ChangeLightAngle_f()
{
return Init_VLights();
}

canonical_decompiled_code:
__int64 func5()
{
return func4();
}

original_code:
void VLight_ChangeLightAngle_f(void)
{
 VLight_ResetAnormTable();
}

canonical_original_code:
void VLight_ChangeLightAngle_f()
{
 VLight_ResetAnormTable();
}


decompiled_code:
float __fastcall VLight_GetLightValue(int a1, float a2, float a3)
{
int v3; // ebx
float v5; // [rsp+0h] [rbp-Ch]

v3 = (int)(float)((float)((float)(a3 * 256.0) / 360.0) + (float)(unsigned __int8)anorm_yaw[a1]);
v5 = fmodf(
COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(int)(float)((float)((float)(a2 * 256.0) / 360.0)
+ (float)(unsigned __int8)anorm_pitch[a1])) & LC3),
256.0);
return (float)(unsigned __int8)vlighttable[256 * (unsigned __int64)(unsigned int)(int)v5
+ (unsigned int)(int)fmodf(
COERCE_FLOAT(COERCE_UNSIGNED_INT((float)v3) & LC3),
256.0)]
* 0.00390625;
}

canonical_decompiled_code:
float __fastcall func0(int a1, float a2, float a3)
{
int v3; // ebx
float v5; // [rsp+0h] [rbp-Ch]

v3 = (int)(float)((float)((float)(a3 * 256.0) / 360.0) + (float)(unsigned __int8)anorm_yaw[a1]);
v5 = fmodf(
COERCE_FLOAT(COERCE_UNSIGNED_INT((float)(int)(float)((float)((float)(a2 * 256.0) / 360.0)
+ (float)(unsigned __int8)anorm_pitch[a1])) & LC3),
256.0);
return (float)(unsigned __int8)vlighttable[256 * (unsigned __int64)(unsigned int)(int)v5
+ (unsigned int)(int)fmodf(
COERCE_FLOAT(COERCE_UNSIGNED_INT((float)v3) & LC3),
256.0)]
* 0.00390625;
}

original_code:
float VLight_GetLightValue(int index, float apitch, float ayaw)
{
 int pitchofs, yawofs;
 float retval;
 pitchofs = anorm_pitch[index] + (apitch * 256 / 360);
 yawofs = anorm_yaw[index] + (ayaw * 256 / 360);
 pitchofs = fmodf(fabsf(pitchofs), 256);
 yawofs = fmodf(fabsf(yawofs), 256);
 retval = vlighttable[(unsigned int)pitchofs][(unsigned int)yawofs];
 return retval / 256;
}

canonical_original_code:
float VLight_GetLightValue(int index, float apitch, float ayaw)
{
 int pitchofs; int yawofs;
 float retval;
 pitchofs = anorm_pitch[index] + (apitch * 256 / 360);
 yawofs = anorm_yaw[index] + (ayaw * 256 / 360);
 pitchofs = fmodf(fabsf(pitchofs), 256);
 yawofs = fmodf(fabsf(yawofs), 256);
 retval = vlighttable[(unsigned int)pitchofs][(unsigned int)yawofs];
 return retval / 256;
}

variable_types: index int

variable_types: apitch float

variable_types: ayaw float

variable_types: pitchofs int

variable_types: yawofs int

variable_types: retval float

return_type: float


decompiled_code:
float __fastcall VLight_LerpLight(int a1, int a2, float a3, float a4, float a5)
{
float v6; // [rsp+0h] [rbp-18h]

v6 = VLight_GetLightValue(a1, a4, a5);
return (float)((float)(1.0 - a3) * v6) + (float)(a3 * VLight_GetLightValue(a2, a4, a5));
}

canonical_decompiled_code:
float __fastcall func1(int a1, int a2, float a3, float a4, float a5)
{
float v6; // [rsp+0h] [rbp-18h]

v6 = func0(a1, a4, a5);
return (float)((float)(1.0 - a3) * v6) + (float)(a3 * func0(a2, a4, a5));
}

original_code:
float VLight_LerpLight(int index1, int index2, float ilerp, float apitch, float ayaw)
{
 float lightval1;
 float lightval2;
 float val;
 lightval1 = VLight_GetLightValue(index1, apitch, ayaw);
 lightval2 = VLight_GetLightValue(index2, apitch, ayaw);
 val = (lightval2*ilerp) + (lightval1*(1-ilerp));
 return val;
}

variable_types: ilerp float

variable_types: val float


decompiled_code:
__int64 Init_VLights()
{
return VLight_ResetAnormTable();
}

canonical_decompiled_code:
__int64 func4()
{
return func2();
}

original_code:
void Init_VLights(void)
{
 VLight_ResetAnormTable();
}

canonical_original_code:
void Init_VLights()
{
 VLight_ResetAnormTable();
}


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

for ( result = qtvuserlist; result; result = *(_QWORD *)(result + 72) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

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

for ( result = qtvuserlist; result; result = *(_QWORD *)(result + 72) )
{
if ( *(_DWORD *)result == a1 )
break;
}
return result;
}

original_code:
static qtvuser_t *QTV_UserById(int id)
{
 qtvuser_t *current;
 for (current = qtvuserlist; current; current = current->next)
  if (current->id == id)
   return current;
 return ((void *)0);
}

canonical_original_code:
static struct qtvuser_s *QTV_UserById(int id)
{
 struct qtvuser_s *current;
 for (current = qtvuserlist; current; current = current->next)
  if (current->id == id)
   return current;
 return ((void *)0);
}

variable_types: id int

variable_types: struct qtvuser_s { int id; char name[64]; struct qtvuser_s *next; } *


decompiled_code:
void __fastcall QTV_FreeUser(void *a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rcx

if ( a1 )
{
if ( a2 )
{
v2 = qtvuserlist;
v3 = 0LL;
while ( v2 )
{
if ( (void *)v2 == a1 )
{
if ( v3 )
*(_QWORD *)(v3 + 72) = *(_QWORD *)(v2 + 72);
else
qtvuserlist = *(_QWORD *)(v2 + 72);
break;
}
v3 = v2;
v2 = *(_QWORD *)(v2 + 72);
}
}
free(a1);
}
}

canonical_decompiled_code:
void __fastcall func2(void *a1, int a2)
{
__int64 v2; // rax
__int64 v3; // rcx

if ( a1 )
{
if ( a2 )
{
v2 = qtvuserlist;
v3 = 0LL;
while ( v2 )
{
if ( (void *)v2 == a1 )
{
if ( v3 )
*(_QWORD *)(v3 + 72) = *(_QWORD *)(v2 + 72);
else
qtvuserlist = *(_QWORD *)(v2 + 72);
break;
}
v3 = v2;
v2 = *(_QWORD *)(v2 + 72);
}
}
free(a1);
}
}

original_code:
static void QTV_FreeUser(qtvuser_t *user, qbool unlink)
{
 if (!user)
  return;
 if (unlink)
 {
  qtvuser_t *next, *prev, *current;
  prev = ((void *)0);
  current = qtvuserlist;
  for ( ; current; )
  {
   next = current->next;
   if (user == current)
   {
    if (prev)
     prev->next = next;
    else
     qtvuserlist = next;
    break;
   }
   prev = current;
   current = next;
  }
 }
 if(user) { free(user); user = ((void *)0); };
}

canonical_original_code:
static void QTV_FreeUser(struct qtvuser_s *user, enum qbool unlink)
{
 if (!user)
  return;
 if (unlink)
 {
  struct qtvuser_s *next; struct qtvuser_s *prev; struct qtvuser_s *current;
  prev = ((void *)0);
  current = qtvuserlist;
  for ( ; current; )
  {
   next = current->next;
   if (user == current)
   {
    if (prev)
     prev->next = next;
    else
     qtvuserlist = next;
    break;
   }
   prev = current;
   current = next;
  }
 }
 if(user) { free(user); user = ((void *)0); };
}

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

user_defined_types: struct qtvuser_s { int id; char name[64]; struct qtvuser_s *next; }


decompiled_code:
__int64 Qtvusers_f()
{
unsigned int v0; // ebp
const char *v1; // rbx
__int64 result; // rax
const char *v3; // r12
const char *v4; // rax
const char *v5; // rax

if ( cls[0] )
{
if ( cls[3434] == 2 )
{
v0 = 0;
Com_Printf("userid name\n");
Com_Printf("------ ----\n");
v1 = (const char *)qtvuserlist;
if ( qtvuserlist )
{
do
{
++v0;
Com_Printf("%6i %s\n", *(unsigned int *)v1, v1 + 4);
v1 = (const char *)*((_QWORD *)v1 + 9);
}
while ( v1 );
}
result = Com_Printf("%i total users\n", v0);
}
else
{
v3 = (const char *)Cmd_Args();
v4 = (const char *)Cmd_Argv(0LL);
result = CL_SendClientCommand(1LL, "%s %s", v4, v3);
}
}
else
{
v5 = (const char *)Cmd_Argv(0LL);
result = Com_Printf("Can't \"%s\", not connected\n", v5);
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // ebp
const char *v1; // rbx
__int64 result; // rax
const char *v3; // r12
const char *v4; // rax
const char *v5; // rax

if ( cls[0] )
{
if ( cls[3434] == 2 )
{
v0 = 0;
Com_Printf("userid name\n");
Com_Printf("------ ----\n");
v1 = (const char *)qtvuserlist;
if ( qtvuserlist )
{
do
{
++v0;
Com_Printf("%6i %s\n", *(unsigned int *)v1, v1 + 4);
v1 = (const char *)*((_QWORD *)v1 + 9);
}
while ( v1 );
}
result = Com_Printf("%i total users\n", v0);
}
else
{
v3 = (const char *)Cmd_Args();
v4 = (const char *)Cmd_Argv(0LL);
result = CL_SendClientCommand(1LL, "%s %s", v4, v3);
}
}
else
{
v5 = (const char *)Cmd_Argv(0LL);
result = Com_Printf("Can't \"%s\", not connected\n", v5);
}
return result;
}

original_code:
void Qtvusers_f (void)
{
 qtvuser_t *current;
 int c;
 if (cls.state == ca_disconnected)
 {
  Com_Printf ("Can't \"%s\", not connected\n", Cmd_Argv(0));
  return;
 }
 if (cls.mvdplayback != 2)
 {
  CL_SendClientCommand(true, "%s %s", Cmd_Argv(0), Cmd_Args());
  return;
 }
 c = 0;
 Com_Printf ("userid name\n");
 Com_Printf ("------ ----\n");
 for (current = qtvuserlist; current; current = current->next)
 {
  Com_Printf ("%6i %s\n", current->id, current->name);
  c++;
 }
 Com_Printf ("%i total users\n", c);
}

canonical_original_code:
void Qtvusers_f()
{
 struct qtvuser_s *current;
 int c;
 if (cls.state == ca_disconnected)
 {
  Com_Printf ("Can't \"%s\", not connected\n", Cmd_Argv(0));
  return;
 }
 if (cls.mvdplayback != 2)
 {
  CL_SendClientCommand(true, "%s %s", Cmd_Argv(0), Cmd_Args());
  return;
 }
 c = 0;
 Com_Printf ("userid name\n");
 Com_Printf ("------ ----\n");
 for (current = qtvuserlist; current; current = current->next)
 {
  Com_Printf ("%6i %s\n", current->id, current->name);
  c++;
 }
 Com_Printf ("%i total users\n", c);
}

variable_types: c int


ConsistantMVDDataEx

original_code:
int ConsistantMVDDataEx(unsigned char *buffer, int remaining, int *ms)
{
 qbool warn = true;
 int lengthofs;
 int length;
 int available = 0;
 if (ms)
  ms[0] = 0;
 while( 1 )
 {
  if (remaining < 2)
  {
   return available;
  }
  switch (buffer[1]&(7))
  {
  case 2:
   length = 10;
   goto gottotallength;
  case 3:
   lengthofs = 6;
   break;
  default:
   lengthofs = 2;
   break;
  }
  if (lengthofs+4 > remaining)
  {
   return available;
  }
  length = (buffer[lengthofs]<<0) + (buffer[lengthofs+1]<<8) + (buffer[lengthofs+2]<<16) + (buffer[lengthofs+3]<<24);
  if (length > (8192 - 100) && warn)
  {
   Com_Printf("Corrupt mvd, length: %d\n", length);
   warn = false;
  }
  length += lengthofs+4;
gottotallength:
  if (remaining < length)
  {
   return available;
  }
  if (ms)
   ms[0] += buffer[0];
  remaining -= length;
  available += length;
  buffer += length;
 }
}

canonical_original_code:
int ConsistantMVDDataEx(unsigned char *buffer, int remaining, int *ms)
{
 enum qbool warn = true;
 int lengthofs;
 int length;
 int available = 0;
 if (ms)
  ms[0] = 0;
 while( 1 )
 {
  if (remaining < 2)
  {
   return available;
  }
  switch (buffer[1]&(7))
  {
  case 2:
   length = 10;
   goto gottotallength;
  case 3:
   lengthofs = 6;
   break;
  default:
   lengthofs = 2;
   break;
  }
  if (lengthofs+4 > remaining)
  {
   return available;
  }
  length = (buffer[lengthofs]<<0) + (buffer[lengthofs+1]<<8) + (buffer[lengthofs+2]<<16) + (buffer[lengthofs+3]<<24);
  if (length > (8192 - 100) && warn)
  {
   Com_Printf("Corrupt mvd, length: %d\n", length);
   warn = false;
  }
  length += lengthofs+4;
gottotallength:
  if (remaining < length)
  {
   return available;
  }
  if (ms)
   ms[0] += buffer[0];
  remaining -= length;
  available += length;
  buffer += length;
 }
}

variable_types:
buffer
unsigned char *

variable_types: remaining int

variable_types:
ms
int *

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

variable_types: lengthofs int

variable_types: length int

variable_types: available int


decompiled_code:
__int64 __fastcall QTV_ForwardToServerEx(int a1, int a2)
{
__int64 result; // rax
unsigned __int8 *v4; // rax
unsigned __int8 v5; // bl
unsigned __int8 *v6; // rbp
const __int32_t **v7; // rdx
bool v8; // cf
bool v9; // zf
__int64 v10; // rax
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
_BYTE *v17; // rbp
int v18; // eax
__int64 v19; // rax
const char *v20; // rax
_QWORD v21[2]; // [rsp-8h] [rbp-8A8h] BYREF
unsigned int v22; // [rsp+Ch] [rbp-894h]
char s[1024]; // [rsp+18h] [rbp-888h] BYREF
__int128 v24; // [rsp+418h] [rbp-488h] BYREF
char v25[1104]; // [rsp+428h] [rbp-478h] BYREF
int v26; // [rsp+878h] [rbp-28h]

result = 0LL;
v9 = cls[3434] == 2;
v24 = 0LL;
memset(v25, 0, sizeof(v25));
v26 = 0;
if ( v9 )
{
if ( playbackfile )
{
if ( !a1 || (result = Cmd_Argc(), (int)result > 1) )
{
v4 = (unsigned __int8 *)Cmd_Argv(0LL);
v5 = *v4;
v6 = v4;
if ( *v4 )
{
v7 = _ctype_tolower_loc();
do
{
*v6++ = (*v7)[v5];
v5 = *v6;
}
while ( *v6 );
}
if ( cls[0] )
{
v10 = Cmd_Argv(0LL);
v11 = "say_team";
v12 = 9LL;
v13 = (const char *)v10;
do
{
if ( !v12 )
break;
v8 = *v13 < (unsigned int)*v11;
v9 = *v13++ == *v11++;
--v12;
}
while ( v9 );
if ( LODWORD(qtv_say_team[8]) | (char)((!v8 && !v9) - v8) )
{
SZ_Init(v21, &v24, 1124LL);
v14 = Cmd_Args();
v15 = TP_ParseMacroString(v14);
v16 = TP_ParseFunChars(v15, 1LL);
s[0] = 0;
v17 = (_BYTE *)v16;
if ( a2 )
{
v19 = Cmd_Argv(0LL);
strlcat(s, v19, 1024LL);
}
if ( *v17 )
{
strlcat(s, " ", 1024LL);
strlcat(s, v17, 1024LL);
}
v18 = strlen(s);
MSG_WriteShort(v21, (unsigned int)(v18 + 4));
MSG_WriteByte(v21, 1LL);
MSG_WriteString(v21, s);
result = VFS_WRITE(playbackfile, v21[1], v22);
}
else
{
result = Com_Printf("Cannot send team messages. Use qtv_say_team 1 to override.\n", v13);
}
}
else
{
v20 = (const char *)Cmd_Argv(0LL);
result = Com_Printf("Can't \"%s\", not connected\n", v20);
}
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int a1, int a2)
{
__int64 result; // rax
unsigned __int8 *v4; // rax
unsigned __int8 v5; // bl
unsigned __int8 *v6; // rbp
const __int32_t **v7; // rdx
bool v8; // cf
bool v9; // zf
__int64 v10; // rax
const char *v11; // rdi
__int64 v12; // rcx
const char *v13; // rsi
__int64 v14; // rax
__int64 v15; // rax
__int64 v16; // rax
_BYTE *v17; // rbp
int v18; // eax
__int64 v19; // rax
const char *v20; // rax
_QWORD v21[2]; // [rsp-8h] [rbp-8A8h] BYREF
unsigned int v22; // [rsp+Ch] [rbp-894h]
char s[1024]; // [rsp+18h] [rbp-888h] BYREF
__int128 v24; // [rsp+418h] [rbp-488h] BYREF
char v25[1104]; // [rsp+428h] [rbp-478h] BYREF
int v26; // [rsp+878h] [rbp-28h]

result = 0LL;
v9 = cls[3434] == 2;
v24 = 0LL;
memset(v25, 0, sizeof(v25));
v26 = 0;
if ( v9 )
{
if ( playbackfile )
{
if ( !a1 || (result = Cmd_Argc(), (int)result > 1) )
{
v4 = (unsigned __int8 *)Cmd_Argv(0LL);
v5 = *v4;
v6 = v4;
if ( *v4 )
{
v7 = _ctype_tolower_loc();
do
{
*v6++ = (*v7)[v5];
v5 = *v6;
}
while ( *v6 );
}
if ( cls[0] )
{
v10 = Cmd_Argv(0LL);
v11 = "say_team";
v12 = 9LL;
v13 = (const char *)v10;
do
{
if ( !v12 )
break;
v8 = *v13 < (unsigned int)*v11;
v9 = *v13++ == *v11++;
--v12;
}
while ( v9 );
if ( LODWORD(qtv_say_team[8]) | (char)((!v8 && !v9) - v8) )
{
SZ_Init(v21, &v24, 1124LL);
v14 = Cmd_Args();
v15 = TP_ParseMacroString(v14);
v16 = TP_ParseFunChars(v15, 1LL);
s[0] = 0;
v17 = (_BYTE *)v16;
if ( a2 )
{
v19 = Cmd_Argv(0LL);
strlcat(s, v19, 1024LL);
}
if ( *v17 )
{
strlcat(s, " ", 1024LL);
strlcat(s, v17, 1024LL);
}
v18 = strlen(s);
MSG_WriteShort(v21, (unsigned int)(v18 + 4));
MSG_WriteByte(v21, 1LL);
MSG_WriteString(v21, s);
result = VFS_WRITE(playbackfile, v21[1], v22);
}
else
{
result = Com_Printf("Cannot send team messages. Use qtv_say_team 1 to override.\n", v13);
}
}
else
{
v20 = (const char *)Cmd_Argv(0LL);
result = Com_Printf("Can't \"%s\", not connected\n", v20);
}
}
}
}
return result;
}

original_code:
void QTV_ForwardToServerEx (qbool skip_if_no_params, qbool use_first_argument)
{
 char data[1024 + 100] = {0}, text[1024], *s;
 sizebuf_t buf;
 if ( cls.mvdplayback != 2
  || !playbackfile
    )
  return;
 if (skip_if_no_params)
  if (Cmd_Argc() < 2)
   return;
 for (s = Cmd_Argv(0); *s; s++)
  *s = (char) tolower(*s);
 if (cls.state == ca_disconnected) {
  Com_Printf ("Can't \"%s\", not connected\n", Cmd_Argv(0));
  return;
 }
 if (strcmp(Cmd_Argv(0), "say_team") == 0 && !qtv_say_team.integer) {
  Com_Printf("Cannot send team messages. Use qtv_say_team 1 to override.\n");
  return;
 }
 SZ_Init(&buf, (byte*) data, sizeof(data));
 s = TP_ParseMacroString (Cmd_Args());
 s = TP_ParseFunChars (s, true);
 text[0] = 0;
 if (use_first_argument)
  strlcat(text, Cmd_Argv(0), sizeof(text));
 if (s[0])
 {
  strlcat(text, " ", sizeof(text));
  strlcat(text, s, sizeof(text));
 }
 MSG_WriteShort (&buf, 2 + 1 + strlen(text) + 1);
 MSG_WriteByte (&buf, 1);
 MSG_WriteString (&buf, text);
 VFS_WRITE(playbackfile, buf.data, buf.cursize);
}

canonical_original_code:
void QTV_ForwardToServerEx(enum qbool skip_if_no_params, enum qbool use_first_argument)
{
 char data[-1] = {0}; char text[1024]; char *s;
 struct sizebuf_s buf;
 if ( cls.mvdplayback != 2
  || !playbackfile
    )
  return;
 if (skip_if_no_params)
  if (Cmd_Argc() < 2)
   return;
 for (s = Cmd_Argv(0); *s; s++)
  *s = (char) tolower(*s);
 if (cls.state == ca_disconnected) {
  Com_Printf ("Can't \"%s\", not connected\n", Cmd_Argv(0));
  return;
 }
 if (strcmp(Cmd_Argv(0), "say_team") == 0 && !qtv_say_team.integer) {
  Com_Printf("Cannot send team messages. Use qtv_say_team 1 to override.\n");
  return;
 }
 SZ_Init(&buf, (unsigned char *) data, sizeof(data));
 s = TP_ParseMacroString (Cmd_Args());
 s = TP_ParseFunChars (s, true);
 text[0] = 0;
 if (use_first_argument)
  strlcat(text, Cmd_Argv(0), sizeof(text));
 if (s[0])
 {
  strlcat(text, " ", sizeof(text));
  strlcat(text, s, sizeof(text));
 }
 MSG_WriteShort (&buf, 2 + 1 + strlen(text) + 1);
 MSG_WriteByte (&buf, 1);
 MSG_WriteString (&buf, text);
 VFS_WRITE(playbackfile, buf.data, buf.cursize);
}

variable_types:
data
char [-1]

variable_types:
text
char [1024]

variable_types:
s
char *

variable_types: struct sizebuf_s { enum qbool { false=0, true=1 } allowoverflow; enum qbool { false=0, true=1 } overflowed; unsigned char *data; int maxsize; int cursize; }

user_defined_types: struct sizebuf_s { enum qbool allowoverflow; enum qbool overflowed; unsigned char *data; int maxsize; int cursize; }


decompiled_code:
__int64 QTV_Say_f()
{
_BYTE v1[4760]; // [rsp+0h] [rbp-1298h] BYREF

Cmd_SaveContext(v1);
QTV_ForwardToServerEx(1, 1);
return Cmd_RestoreContext(v1);
}

canonical_decompiled_code:
__int64 func10()
{
_BYTE v1[4760]; // [rsp+0h] [rbp-1298h] BYREF

Cmd_SaveContext(v1);
func9(1, 1);
return Cmd_RestoreContext(v1);
}

original_code:
void QTV_Say_f (void)
{
 tokenizecontext_t tmpcontext;
 Cmd_SaveContext(&tmpcontext);
 QTV_ForwardToServerEx (true, true);
 Cmd_RestoreContext(&tmpcontext);
}

canonical_original_code:
void QTV_Say_f()
{
 struct tokenizecontext_s tmpcontext;
 Cmd_SaveContext(&tmpcontext);
 QTV_ForwardToServerEx (true, true);
 Cmd_RestoreContext(&tmpcontext);
}

variable_types: struct tokenizecontext_s { int cmd_argc; char *cmd_argv[80]; char argv_buf[1024]; char cmd_args[-1]; char text[1024]; }


decompiled_code:
__int64 QTV_Cmd_Printf(unsigned int a1, const char *a2, ...)
{
__int64 result; // rax
bool v3; // zf
gcc_va_list arg; // [rsp+8h] [rbp-1760h] BYREF
char s[16]; // [rsp+20h] [rbp-1748h] BYREF
char v6[1008]; // [rsp+30h] [rbp-1738h] BYREF
char v7[4752]; // [rsp+420h] [rbp-1348h] BYREF

result = 0LL;
memset(v6, 0, sizeof(v6));
v3 = cls[3434] == 2;
*(_OWORD *)s = 0LL;
if ( v3 )
{
result = a1 & cls[3436];
if ( (_DWORD)result == a1 )
{
va_start(arg, a2);
vsnprintf(s, 0x400uLL, a2, arg);
Cmd_SaveContext(v7);
Cmd_TokenizeString(s, 0.0);
QTV_Cmd_ForwardToServer();
result = Cmd_RestoreContext(v7);
}
}
return result;
}

canonical_decompiled_code:
__int64 func13(unsigned int a1, const char *a2, ...)
{
__int64 result; // rax
bool v3; // zf
gcc_va_list arg; // [rsp+8h] [rbp-1760h] BYREF
char s[16]; // [rsp+20h] [rbp-1748h] BYREF
char v6[1008]; // [rsp+30h] [rbp-1738h] BYREF
char v7[4752]; // [rsp+420h] [rbp-1348h] BYREF

result = 0LL;
memset(v6, 0, sizeof(v6));
v3 = cls[3434] == 2;
*(_OWORD *)s = 0LL;
if ( v3 )
{
result = a1 & cls[3436];
if ( (_DWORD)result == a1 )
{
va_start(arg, a2);
vsnprintf(s, 0x400uLL, a2, arg);
Cmd_SaveContext(v7);
Cmd_TokenizeString(s, 0.0);
func11();
result = Cmd_RestoreContext(v7);
}
}
return result;
}

original_code:
void QTV_Cmd_Printf(int qtv_ext, char *fmt, ...)
{
 va_list argptr;
 char msg[1024] = {0};
 tokenizecontext_t tmpcontext;
 if (cls.mvdplayback != 2 || (qtv_ext & cls.qtv_ezquake_ext) != qtv_ext)
  return;
 __builtin_va_start(argptr,fmt);
 vsnprintf (msg, sizeof(msg), fmt, argptr);
 __builtin_va_end(argptr);
 Cmd_SaveContext(&tmpcontext);
 Cmd_TokenizeString(msg);
 QTV_Cmd_ForwardToServer ();
 Cmd_RestoreContext(&tmpcontext);
}

canonical_original_code:
void QTV_Cmd_Printf(int qtv_ext, char *fmt, ...)
{
 __builtin_va_list argptr;
 char msg[1024] = {0};
 struct tokenizecontext_s tmpcontext;
 if (cls.mvdplayback != 2 || (qtv_ext & cls.qtv_ezquake_ext) != qtv_ext)
  return;
 __builtin_va_start(argptr,fmt);
 vsnprintf (msg, sizeof(msg), fmt, argptr);
 __builtin_va_end(argptr);
 Cmd_SaveContext(&tmpcontext);
 Cmd_TokenizeString(msg);
 QTV_Cmd_ForwardToServer ();
 Cmd_RestoreContext(&tmpcontext);
}

variable_types:
fmt
char *

variable_types:
msg
char [1024]

user_defined_types: struct tokenizecontext_s { int cmd_argc; char *cmd_argv[80]; char argv_buf[1024]; char cmd_args[-1]; char text[1024]; }


decompiled_code:
void QTV_FreeUserList()
{
__int64 v0; // rbx
void *v1; // rdi

v0 = qtvuserlist;
while ( v0 )
{
v1 = (void *)v0;
v0 = *(_QWORD *)(v0 + 72);
QTV_FreeUser(v1, 0);
}
qtvuserlist = 0LL;
}

canonical_decompiled_code:
void func14()
{
__int64 v0; // rbx
void *v1; // rdi

v0 = qtvuserlist;
while ( v0 )
{
v1 = (void *)v0;
v0 = *(_QWORD *)(v0 + 72);
func2(v1, 0);
}
qtvuserlist = 0LL;
}

original_code:
void QTV_FreeUserList(void)
{
 qtvuser_t *next, *current;
 current = qtvuserlist;
 for ( ; current; current = next)
 {
  next = current->next;
  QTV_FreeUser(current, false);
 }
 qtvuserlist = ((void *)0);
}

canonical_original_code:
void QTV_FreeUserList()
{
 struct qtvuser_s *next; struct qtvuser_s *current;
 current = qtvuserlist;
 for ( ; current; current = next)
 {
  next = current->next;
  QTV_FreeUser(current, false);
 }
 qtvuserlist = ((void *)0);
}

variable_types: struct qtvuser_s { int id; char name[64]; struct qtvuser_s *next; } *


decompiled_code:
void __fastcall QTV_JoinEvent(int *a1)
{
__int64 v1; // rdx
const char *v2; // rcx

if ( *qtv_event_join[1] && cls[0] > 1u && !QTV_UserById(*a1) )
Com_Printf("%s%s%s\n", "QTV: ", (const char *)(v1 + 4), v2);
}

canonical_decompiled_code:
void __fastcall func15(int *a1)
{
__int64 v1; // rdx
const char *v2; // rcx

if ( *qtv_event_join[1] && cls[0] > 1u && !func0(*a1) )
Com_Printf("%s%s%s\n", "QTV: ", (const char *)(v1 + 4), v2);
}

original_code:
void QTV_JoinEvent(qtvuser_t *user)
{
 if (!qtv_event_join.string[0])
  return;
 if (cls.state <= ca_demostart)
  return;
 if (QTV_UserById(user->id))
 {
  return;
 }
 Com_Printf("%s%s%s\n", "QTV: ", user->name, qtv_event_join.string);
}

canonical_original_code:
void QTV_JoinEvent(struct qtvuser_s *user)
{
 if (!qtv_event_join.string[0])
  return;
 if (cls.state <= ca_demostart)
  return;
 if (QTV_UserById(user->id))
 {
  return;
 }
 Com_Printf("%s%s%s\n", "QTV: ", user->name, qtv_event_join.string);
}


decompiled_code:
void __fastcall QTV_LeaveEvent(int *a1)
{
__int64 v1; // rax
const char *v2; // rcx

if ( *qtv_event_leave[1] )
{
v1 = QTV_UserById(*a1);
if ( v1 )
Com_Printf("%s%s%s\n", "QTV: ", (const char *)(v1 + 4), v2);
}
}

canonical_decompiled_code:
void __fastcall func16(int *a1)
{
__int64 v1; // rax
const char *v2; // rcx

if ( *qtv_event_leave[1] )
{
v1 = func0(*a1);
if ( v1 )
Com_Printf("%s%s%s\n", "QTV: ", (const char *)(v1 + 4), v2);
}
}

original_code:
void QTV_LeaveEvent(qtvuser_t *user)
{
 qtvuser_t *olduser;
 if (!qtv_event_leave.string[0])
  return;
 if (!(olduser = QTV_UserById(user->id)))
 {
  return;
 }
 Com_Printf("%s%s%s\n", "QTV: ", olduser->name, qtv_event_leave.string);
}

canonical_original_code:
void QTV_LeaveEvent(struct qtvuser_s *user)
{
 struct qtvuser_s *olduser;
 if (!qtv_event_leave.string[0])
  return;
 if (!(olduser = QTV_UserById(user->id)))
 {
  return;
 }
 Com_Printf("%s%s%s\n", "QTV: ", olduser->name, qtv_event_leave.string);
}


decompiled_code:
void __fastcall QTV_ChangeEvent(int *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
const char *v3; // rcx

if ( *qtv_event_changename[1] )
{
v1 = QTV_UserById(*a1);
if ( v1 )
Com_Printf("%s%s%s%s\n", "QTV: ", (const char *)(v1 + 4), v3, (const char *)(v2 + 4));
else
Com_DPrintf("qtv: change event without olduser\n");
}
}

canonical_decompiled_code:
void __fastcall func17(int *a1)
{
__int64 v1; // rax
__int64 v2; // rdx
const char *v3; // rcx

if ( *qtv_event_changename[1] )
{
v1 = func0(*a1);
if ( v1 )
Com_Printf("%s%s%s%s\n", "QTV: ", (const char *)(v1 + 4), v3, (const char *)(v2 + 4));
else
Com_DPrintf("qtv: change event without olduser\n");
}
}

original_code:
void QTV_ChangeEvent(qtvuser_t *user)
{
 qtvuser_t *olduser;
 if (!qtv_event_changename.string[0])
  return;
 if (!(olduser = QTV_UserById(user->id)))
 {
  Com_DPrintf("qtv: change event without olduser\n");
  return;
 }
 Com_Printf("%s%s%s%s\n", "QTV: ", olduser->name, qtv_event_changename.string, user->name);
}

canonical_original_code:
void QTV_ChangeEvent(struct qtvuser_s *user)
{
 struct qtvuser_s *olduser;
 if (!qtv_event_changename.string[0])
  return;
 if (!(olduser = QTV_UserById(user->id)))
 {
  Com_DPrintf("qtv: change event without olduser\n");
  return;
 }
 Com_Printf("%s%s%s%s\n", "QTV: ", olduser->name, qtv_event_changename.string, user->name);
}


decompiled_code:
void __fastcall Parse_QtvUserList(__int64 a1)
{
const char *v1; // rax
unsigned int v2; // ebp
const char *v3; // rax
__int64 v4; // rax
void *v5; // rax
__m128i v6[5]; // [rsp+0h] [rbp-58h] BYREF

v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
Cmd_TokenizeString(a1, 0.0);
v1 = (const char *)Cmd_Argv(1LL);
v2 = atoi(v1);
v3 = (const char *)Cmd_Argv(2LL);
v6[0].m128i_i32[0] = atoi(v3);
v4 = Cmd_Argv(3LL);
strlcpy((char *)v6[0].m128i_i64 + 4, v4, 64LL);
switch ( v2 )
{
case 2u:
QTV_ChangeEvent((int *)v6);
QTV_NewUser_isra_0(v6);
break;
case 3u:
QTV_LeaveEvent((int *)v6);
v5 = (void *)QTV_UserById(v6[0].m128i_i32[0]);
QTV_FreeUser(v5, 1);
break;
case 1u:
QTV_JoinEvent((int *)v6);
QTV_NewUser_isra_0(v6);
break;
default:
Com_Printf("Parse_QtvUserList: unknown action %d\n", v2);
break;
}
}

canonical_decompiled_code:
void __fastcall func18(__int64 a1)
{
const char *v1; // rax
unsigned int v2; // ebp
const char *v3; // rax
__int64 v4; // rax
void *v5; // rax
__m128i v6[5]; // [rsp+0h] [rbp-58h] BYREF

v6[0] = 0LL;
v6[1] = 0LL;
v6[2] = 0LL;
v6[3] = 0LL;
v6[4] = 0LL;
Cmd_TokenizeString(a1, 0.0);
v1 = (const char *)Cmd_Argv(1LL);
v2 = atoi(v1);
v3 = (const char *)Cmd_Argv(2LL);
v6[0].m128i_i32[0] = atoi(v3);
v4 = Cmd_Argv(3LL);
strlcpy((char *)v6[0].m128i_i64 + 4, v4, 64LL);
switch ( v2 )
{
case 2u:
func17((int *)v6);
func4(v6);
break;
case 3u:
func16((int *)v6);
v5 = (void *)func0(v6[0].m128i_i32[0]);
func2(v5, 1);
break;
case 1u:
func15((int *)v6);
func4(v6);
break;
default:
Com_Printf("Parse_QtvUserList: unknown action %d\n", v2);
break;
}
}

original_code:
void Parse_QtvUserList(char *s)
{
 qtvuser_t tmpuser;
 qtvuserlist_t action;
 int cnt = 1;
 memset(&tmpuser, 0, sizeof(tmpuser));
 Cmd_TokenizeString( s );
 action = atoi( Cmd_Argv( cnt++ ) );
 tmpuser.id = atoi( Cmd_Argv( cnt++ ) );
 strlcpy(tmpuser.name, Cmd_Argv( cnt++ ), sizeof(tmpuser.name));
 switch ( action )
 {
  case QUL_ADD:
   QTV_JoinEvent(&tmpuser);
   QTV_NewUser(&tmpuser);
  break;
  case QUL_CHANGE:
   QTV_ChangeEvent(&tmpuser);
   QTV_NewUser(&tmpuser);
  break;
  case QUL_DEL:
   QTV_LeaveEvent(&tmpuser);
   QTV_FreeUser(QTV_UserById(tmpuser.id), true);
  break;
  default:
   Com_Printf("Parse_QtvUserList: unknown action %d\n", action);
  return;
 }
}

canonical_original_code:
void Parse_QtvUserList(char *s)
{
 struct qtvuser_s tmpuser;
 enum qtvuserlist_t action;
 int cnt = 1;
 memset(&tmpuser, 0, sizeof(tmpuser));
 Cmd_TokenizeString( s );
 action = atoi( Cmd_Argv( cnt++ ) );
 tmpuser.id = atoi( Cmd_Argv( cnt++ ) );
 strlcpy(tmpuser.name, Cmd_Argv( cnt++ ), sizeof(tmpuser.name));
 switch ( action )
 {
  case QUL_ADD:
   QTV_JoinEvent(&tmpuser);
   QTV_NewUser(&tmpuser);
  break;
  case QUL_CHANGE:
   QTV_ChangeEvent(&tmpuser);
   QTV_NewUser(&tmpuser);
  break;
  case QUL_DEL:
   QTV_LeaveEvent(&tmpuser);
   QTV_FreeUser(QTV_UserById(tmpuser.id), true);
  break;
  default:
   Com_Printf("Parse_QtvUserList: unknown action %d\n", action);
  return;
 }
}

variable_types: struct qtvuser_s { int id; char name[64]; struct qtvuser_s *next; }

variable_types: enum qtvuserlist_t { QUL_NONE=0, QUL_ADD=1, QUL_CHANGE=2, QUL_DEL=3 }

variable_types: cnt int


decompiled_code:
__int64 __fastcall QTV_FindBestNick(char *needle, _BYTE *a2, __int64 a3)
{
__int64 v3; // r15
int v4; // er14
__int64 v5; // rbp
unsigned __int8 v6; // r13
const __int32_t *v7; // rsi
char *v8; // rax
char *v9; // rax
signed __int64 v10; // rax
char haystack[184]; // [rsp+10h] [rbp-B8h] BYREF

v3 = qtvuserlist;
*a2 = 0;
if ( !v3 )
return 0LL;
v4 = 999999;
v5 = 0LL;
do
{
while ( 1 )
{
if ( *(_BYTE *)(v3 + 4) )
{
strlcpy(haystack, v3 + 4, 128LL);
RemoveColors(haystack, 128LL);
v6 = haystack[0];
if ( haystack[0] )
{
v7 = *_ctype_tolower_loc();
v8 = haystack;
do
{
*v8++ = v7[v6];
v6 = *v8;
}
while ( *v8 );
if ( haystack[0] )
{
v9 = strstr(haystack, needle);
if ( v9 )
break;
}
}
}
v3 = *(_QWORD *)(v3 + 72);
if ( !v3 )
goto LABEL_15;
}
v10 = v9 - haystack;
if ( v10 < v4 )
v5 = v3;
v3 = *(_QWORD *)(v3 + 72);
if ( v10 < v4 )
v4 = v10;
}
while ( v3 );
LABEL_15:
if ( !v5 )
return 0LL;
strlcpy(a2, v5 + 4, a3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func19(char *needle, _BYTE *a2, __int64 a3)
{
__int64 v3; // r15
int v4; // er14
__int64 v5; // rbp
unsigned __int8 v6; // r13
const __int32_t *v7; // rsi
char *v8; // rax
char *v9; // rax
signed __int64 v10; // rax
char haystack[184]; // [rsp+10h] [rbp-B8h] BYREF

v3 = qtvuserlist;
*a2 = 0;
if ( !v3 )
return 0LL;
v4 = 999999;
v5 = 0LL;
do
{
while ( 1 )
{
if ( *(_BYTE *)(v3 + 4) )
{
strlcpy(haystack, v3 + 4, 128LL);
RemoveColors(haystack, 128LL);
v6 = haystack[0];
if ( haystack[0] )
{
v7 = *_ctype_tolower_loc();
v8 = haystack;
do
{
*v8++ = v7[v6];
v6 = *v8;
}
while ( *v8 );
if ( haystack[0] )
{
v9 = strstr(haystack, needle);
if ( v9 )
break;
}
}
}
v3 = *(_QWORD *)(v3 + 72);
if ( !v3 )
goto LABEL_15;
}
v10 = v9 - haystack;
if ( v10 < v4 )
v5 = v3;
v3 = *(_QWORD *)(v3 + 72);
if ( v10 < v4 )
v4 = v10;
}
while ( v3 );
LABEL_15:
if ( !v5 )
return 0LL;
strlcpy(a2, v5 + 4, a3);
return 1LL;
}

original_code:
qbool QTV_FindBestNick (const char *nick, char *result, size_t result_len)
{
 int best = 999999;
 char name[128], *match;
 qtvuser_t *current = ((void *)0), *bestplayer = ((void *)0);
 result[0] = 0;
 for (current = qtvuserlist; current; current = current->next)
 {
  if (!current->name[0])
   continue;
  strlcpy(name, current->name, sizeof(name));
  RemoveColors(name, sizeof (name));
  for (match = name; match[0]; match++)
   match[0] = tolower(match[0]);
  if (!name[0])
   continue;
  if ((match = strstr(name, nick)) && match - name < best)
  {
   best = match - name;
   bestplayer = current;
  }
 }
 if (bestplayer)
 {
  strlcpy(result, bestplayer->name, result_len);
  return true;
 }
 return false;
}

canonical_original_code:
enum qbool QTV_FindBestNick(char *nick, char *result, unsigned long result_len)
{
 int best = 999999;
 char name[128]; char *match;
 struct qtvuser_s *current = ((void *)0); struct qtvuser_s *bestplayer = ((void *)0);
 result[0] = 0;
 for (current = qtvuserlist; current; current = current->next)
 {
  if (!current->name[0])
   continue;
  strlcpy(name, current->name, sizeof(name));
  RemoveColors(name, sizeof (name));
  for (match = name; match[0]; match++)
   match[0] = tolower(match[0]);
  if (!name[0])
   continue;
  if ((match = strstr(name, nick)) && match - name < best)
  {
   best = match - name;
   bestplayer = current;
  }
 }
 if (bestplayer)
 {
  strlcpy(result, bestplayer->name, result_len);
  return true;
 }
 return false;
}

variable_types:
nick
char *

variable_types:
result
char *

variable_types: best int

variable_types:
name
char [128]

variable_types:
match
char *


decompiled_code:
__int64 QTV_Init()
{
Cvar_SetCurrentGroup("QTV Settings");
Cvar_Register(qtv_buffertime);
Cvar_Register(qtv_chatprefix);
Cvar_Register(qtv_gamechatprefix);
Cvar_Register(qtv_skipchained);
Cvar_Register(qtv_adjustbuffer);
Cvar_Register(qtv_adjustminspeed);
Cvar_Register(qtv_adjustmaxspeed);
Cvar_Register(qtv_adjustlowstart);
Cvar_Register(qtv_adjusthighstart);
Cvar_Register(qtv_say_team);
Cvar_Register(qtv_event_join);
Cvar_Register(qtv_event_leave);
Cvar_Register(qtv_event_changename);
Cvar_ResetCurrentGroup();
return Cmd_AddCommand("qtvusers", Qtvusers_f);
}

canonical_decompiled_code:
__int64 func5()
{
Cvar_SetCurrentGroup("QTV Settings");
Cvar_Register(qtv_buffertime);
Cvar_Register(qtv_chatprefix);
Cvar_Register(qtv_gamechatprefix);
Cvar_Register(qtv_skipchained);
Cvar_Register(qtv_adjustbuffer);
Cvar_Register(qtv_adjustminspeed);
Cvar_Register(qtv_adjustmaxspeed);
Cvar_Register(qtv_adjustlowstart);
Cvar_Register(qtv_adjusthighstart);
Cvar_Register(qtv_say_team);
Cvar_Register(qtv_event_join);
Cvar_Register(qtv_event_leave);
Cvar_Register(qtv_event_changename);
Cvar_ResetCurrentGroup();
return Cmd_AddCommand("qtvusers", Qtvusers_f);
}

original_code:
void QTV_Init(void)
{
 Cvar_SetCurrentGroup("QTV Settings");
 Cvar_Register(&qtv_buffertime);
 Cvar_Register(&qtv_chatprefix);
 Cvar_Register(&qtv_gamechatprefix);
 Cvar_Register(&qtv_skipchained);
 Cvar_Register(&qtv_adjustbuffer);
 Cvar_Register(&qtv_adjustminspeed);
 Cvar_Register(&qtv_adjustmaxspeed);
 Cvar_Register(&qtv_adjustlowstart);
 Cvar_Register(&qtv_adjusthighstart);
 Cvar_Register(&qtv_say_team);
 Cvar_Register(&qtv_event_join);
 Cvar_Register(&qtv_event_leave);
 Cvar_Register(&qtv_event_changename);
 Cvar_ResetCurrentGroup();
 Cmd_AddCommand ("qtvusers", Qtvusers_f);
}

canonical_original_code:
void QTV_Init()
{
 Cvar_SetCurrentGroup("QTV Settings");
 Cvar_Register(&qtv_buffertime);
 Cvar_Register(&qtv_chatprefix);
 Cvar_Register(&qtv_gamechatprefix);
 Cvar_Register(&qtv_skipchained);
 Cvar_Register(&qtv_adjustbuffer);
 Cvar_Register(&qtv_adjustminspeed);
 Cvar_Register(&qtv_adjustmaxspeed);
 Cvar_Register(&qtv_adjustlowstart);
 Cvar_Register(&qtv_adjusthighstart);
 Cvar_Register(&qtv_say_team);
 Cvar_Register(&qtv_event_join);
 Cvar_Register(&qtv_event_leave);
 Cvar_Register(&qtv_event_changename);
 Cvar_ResetCurrentGroup();
 Cmd_AddCommand ("qtvusers", Qtvusers_f);
}


decompiled_code:
char *__fastcall QTV_CL_HEADER(unsigned int a1, float a2)
{
snprintf(header_0, 0x400uLL, "QTV\nVERSION: %g\nQTV_EZQUAKE_EXT: %d\n", a2, a1);
return header_0;
}

canonical_decompiled_code:
char *__fastcall func6(unsigned int a1, float a2)
{
snprintf(header_0, 0x400uLL, "QTV\nVERSION: %g\nQTV_EZQUAKE_EXT: %d\n", a2, a1);
return header_0;
}

original_code:
char *QTV_CL_HEADER(float qtv_ver, int qtv_ezquake_ext)
{
 static char header[1024];
 snprintf(header, sizeof(header), "QTV\n" "VERSION: %g\n" "QTV_EZQUAKE_EXT" ": %d\n", qtv_ver, qtv_ezquake_ext);
 return header;
}

variable_types:
header
char [1024]

return_type: char *


ConsistantMVDData

decompiled_code:
__int64 __fastcall ConsistantMVDData(unsigned __int8 *a1, int a2)
{
return ConsistantMVDDataEx(a1, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int8 *a1, int a2)
{
return func7(a1, a2, 0LL);
}

original_code:
int ConsistantMVDData(unsigned char *buffer, int remaining)
{
 return ConsistantMVDDataEx(buffer, remaining, ((void *)0));
}

variable_types:
buffer
unsigned char *

variable_types: remaining int


decompiled_code:
__int64 QTV_Cmd_ForwardToServer()
{
return QTV_ForwardToServerEx(0, 1);
}

canonical_decompiled_code:
__int64 func11()
{
return func9(0, 1);
}

original_code:
void QTV_Cmd_ForwardToServer (void)
{
 QTV_ForwardToServerEx (false, true);
}

canonical_original_code:
void QTV_Cmd_ForwardToServer()
{
 QTV_ForwardToServerEx (false, true);
}


decompiled_code:
__int64 QTV_Cl_ForwardToServer_f()
{
return QTV_ForwardToServerEx(0, 0);
}

canonical_decompiled_code:
__int64 func12()
{
return func9(0, 0);
}

original_code:
void QTV_Cl_ForwardToServer_f (void)
{
 QTV_ForwardToServerEx (false, false);
}

canonical_original_code:
void QTV_Cl_ForwardToServer_f()
{
 QTV_ForwardToServerEx (false, false);
}