decompiled_code:
__int64 __fastcall SNDDMA_Init_OSS_Legacy(_QWORD *a1)
{
const char *v2; // r12
int v3; // eax
int v4; // ebp
const char *v5; // rdi
int v6; // eax
int v7; // ebp
__int64 v8; // rax
__int64 v9; // r13
int v10; // ecx
__int64 result; // rax
int v12; // [rsp+0h] [rbp-48h] BYREF
int v13; // [rsp+4h] [rbp-44h] BYREF
int v14; // [rsp+8h] [rbp-40h] BYREF
int v15; // [rsp+Ch] [rbp-3Ch] BYREF
char v16[4]; // [rsp+10h] [rbp-38h] BYREF
int v17; // [rsp+14h] [rbp-34h]
int v18; // [rsp+18h] [rbp-30h]

v2 = (const char *)Cvar_String("s_oss_device");
v3 = open(v2, 2050);
audio_fd = v3;
if ( v3 < 0 )
{
perror(v2);
Com_Printf("Could not open %s\n", v2);
return 0LL;
}
v4 = v3;
v12 = ioctl(v3, 0x5000uLL, 0LL);
if ( v12 < 0 )
{
perror(v2);
Com_Printf("Could not reset %s\n", v2);
goto LABEL_25;
}
if ( ioctl(v4, 0x8004500FuLL, &v15) == -1 )
{
perror(v2);
v5 = "Sound driver too old\n";
goto LABEL_22;
}
v5 = "Sorry but your soundcard can't do this\n";
if ( (v15 & 0x3000) != 12288 )
{
LABEL_22:
Com_Printf(v5);
close(audio_fd);
return 0LL;
}
*(_DWORD *)(shm + 4LL) = (int)(float)(0.125 * s_bits[8]);
v6 = SND_Rate((unsigned int)(int)s_khz[8]);
v7 = audio_fd;
*shm = v6;
v8 = shm;
*(_DWORD *)(shm + 8LL) = 1 - (((int)s_stereo[8] == 0) - 1);
if ( *(_DWORD *)(v8 + 4) != 2 && *(_DWORD *)(v8 + 4) != 1 )
{
ioctl(v7, 0x8004500BuLL, &v13);
v8 = shm;
if ( (v13 & 0x10) != 0 )
{
*(_DWORD *)(shm + 4LL) = 2;
v8 = shm;
}
else if ( (v13 & 8) != 0 )
{
*(_DWORD *)(shm + 4LL) = 1;
v8 = shm;
}
}
v14 = *(_DWORD *)(v8 + 8) == 2;
v12 = ioctl(v7, 0xC0045003uLL, &v14);
if ( v12 < 0 )
{
perror(v2);
Com_Printf("Could not set %s to stereo", v2);
LABEL_25:
close(audio_fd);
return 0LL;
}
v12 = ioctl(v7, 0xC0045002uLL, shm);
if ( v12 < 0 )
{
perror(v2);
Com_Printf("Could not set %s speed to %d", v2, (unsigned int)*shm);
close(audio_fd);
result = 0LL;
}
else
{
if ( *(_DWORD *)(shm + 4LL) == 2 )
{
v12 = 16;
v12 = ioctl(v7, 0xC0045005uLL, &v12);
if ( v12 < 0 )
{
perror(v2);
v5 = "Could not support 16-bit data. Try 8-bit.\n";
goto LABEL_22;
}
goto LABEL_15;
}
if ( *(_DWORD *)(shm + 4LL) == 1 )
{
v12 = 8;
v12 = ioctl(v7, 0xC0045005uLL, &v12);
if ( v12 < 0 )
{
perror(v2);
v5 = "Could not support 8-bit data.\n";
goto LABEL_22;
}
LABEL_15:
if ( ioctl(v7, 0x8010500CuLL, v16) != -1 )
{
v9 = shm;
v10 = v18 * v17;
*(_DWORD *)(shm + 12LL) = (unsigned int)(v18 * v17) / *(_DWORD *)(shm + 4LL) / *(_DWORD *)(shm + 8LL);
*(_DWORD *)(v9 + 16) = *(_DWORD *)(v9 + 8) * *(_DWORD *)(v9 + 12);
*(_DWORD *)(v9 + 32) = v10;
*(_QWORD *)(v9 + 24) = mmap(0LL, *(int *)(v9 + 32), 2, 1, v7, 0LL);
if ( *(_QWORD *)(shm + 24LL) && *(_QWORD *)(shm + 24LL) != -1LL )
{
v14 = 0;
v12 = ioctl(v7, 0x40045010uLL, &v14);
if ( v12 >= 0 )
{
v14 = 2;
v12 = ioctl(v7, 0x40045010uLL, &v14);
if ( v12 >= 0 )
{
*(_DWORD *)(shm + 20LL) = 0;
result = 1LL;
a1[2] = SNDDMA_GetDMAPos_OSS_Legacy;
a1[1] = 0LL;
a1[3] = 0LL;
a1[4] = SNDDMA_Shutdown_OSS_Legacy;
*a1 = "snd_oss (legacy)";
return result;
}
}
perror(v2);
v5 = "Could not toggle.\n";
goto LABEL_22;
}
perror(v2);
Com_Printf("Could not mmap %s\n", v2);
goto LABEL_25;
}
perror("GETOSPACE");
v5 = "Um, can't do GETOSPACE?\n";
goto LABEL_22;
}
perror(v2);
Com_Printf("%d-bit sound not supported.", (unsigned int)(8 * *(_DWORD *)(shm + 4LL)));
close(audio_fd);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
const char *v2; // r12
int v3; // eax
int v4; // ebp
const char *v5; // rdi
int v6; // eax
int v7; // ebp
__int64 v8; // rax
__int64 v9; // r13
int v10; // ecx
__int64 result; // rax
int v12; // [rsp+0h] [rbp-48h] BYREF
int v13; // [rsp+4h] [rbp-44h] BYREF
int v14; // [rsp+8h] [rbp-40h] BYREF
int v15; // [rsp+Ch] [rbp-3Ch] BYREF
char v16[4]; // [rsp+10h] [rbp-38h] BYREF
int v17; // [rsp+14h] [rbp-34h]
int v18; // [rsp+18h] [rbp-30h]

v2 = (const char *)Cvar_String("s_oss_device");
v3 = open(v2, 2050);
audio_fd = v3;
if ( v3 < 0 )
{
perror(v2);
Com_Printf("Could not open %s\n", v2);
return 0LL;
}
v4 = v3;
v12 = ioctl(v3, 0x5000uLL, 0LL);
if ( v12 < 0 )
{
perror(v2);
Com_Printf("Could not reset %s\n", v2);
goto LABEL_25;
}
if ( ioctl(v4, 0x8004500FuLL, &v15) == -1 )
{
perror(v2);
v5 = "Sound driver too old\n";
goto LABEL_22;
}
v5 = "Sorry but your soundcard can't do this\n";
if ( (v15 & 0x3000) != 12288 )
{
LABEL_22:
Com_Printf(v5);
close(audio_fd);
return 0LL;
}
*(_DWORD *)(shm + 4LL) = (int)(float)(0.125 * s_bits[8]);
v6 = SND_Rate((unsigned int)(int)s_khz[8]);
v7 = audio_fd;
*shm = v6;
v8 = shm;
*(_DWORD *)(shm + 8LL) = 1 - (((int)s_stereo[8] == 0) - 1);
if ( *(_DWORD *)(v8 + 4) != 2 && *(_DWORD *)(v8 + 4) != 1 )
{
ioctl(v7, 0x8004500BuLL, &v13);
v8 = shm;
if ( (v13 & 0x10) != 0 )
{
*(_DWORD *)(shm + 4LL) = 2;
v8 = shm;
}
else if ( (v13 & 8) != 0 )
{
*(_DWORD *)(shm + 4LL) = 1;
v8 = shm;
}
}
v14 = *(_DWORD *)(v8 + 8) == 2;
v12 = ioctl(v7, 0xC0045003uLL, &v14);
if ( v12 < 0 )
{
perror(v2);
Com_Printf("Could not set %s to stereo", v2);
LABEL_25:
close(audio_fd);
return 0LL;
}
v12 = ioctl(v7, 0xC0045002uLL, shm);
if ( v12 < 0 )
{
perror(v2);
Com_Printf("Could not set %s speed to %d", v2, (unsigned int)*shm);
close(audio_fd);
result = 0LL;
}
else
{
if ( *(_DWORD *)(shm + 4LL) == 2 )
{
v12 = 16;
v12 = ioctl(v7, 0xC0045005uLL, &v12);
if ( v12 < 0 )
{
perror(v2);
v5 = "Could not support 16-bit data. Try 8-bit.\n";
goto LABEL_22;
}
goto LABEL_15;
}
if ( *(_DWORD *)(shm + 4LL) == 1 )
{
v12 = 8;
v12 = ioctl(v7, 0xC0045005uLL, &v12);
if ( v12 < 0 )
{
perror(v2);
v5 = "Could not support 8-bit data.\n";
goto LABEL_22;
}
LABEL_15:
if ( ioctl(v7, 0x8010500CuLL, v16) != -1 )
{
v9 = shm;
v10 = v18 * v17;
*(_DWORD *)(shm + 12LL) = (unsigned int)(v18 * v17) / *(_DWORD *)(shm + 4LL) / *(_DWORD *)(shm + 8LL);
*(_DWORD *)(v9 + 16) = *(_DWORD *)(v9 + 8) * *(_DWORD *)(v9 + 12);
*(_DWORD *)(v9 + 32) = v10;
*(_QWORD *)(v9 + 24) = mmap(0LL, *(int *)(v9 + 32), 2, 1, v7, 0LL);
if ( *(_QWORD *)(shm + 24LL) && *(_QWORD *)(shm + 24LL) != -1LL )
{
v14 = 0;
v12 = ioctl(v7, 0x40045010uLL, &v14);
if ( v12 >= 0 )
{
v14 = 2;
v12 = ioctl(v7, 0x40045010uLL, &v14);
if ( v12 >= 0 )
{
*(_DWORD *)(shm + 20LL) = 0;
result = 1LL;
a1[2] = SNDDMA_GetDMAPos_OSS_Legacy;
a1[1] = 0LL;
a1[3] = 0LL;
a1[4] = SNDDMA_Shutdown_OSS_Legacy;
*a1 = "snd_oss (legacy)";
return result;
}
}
perror(v2);
v5 = "Could not toggle.\n";
goto LABEL_22;
}
perror(v2);
Com_Printf("Could not mmap %s\n", v2);
goto LABEL_25;
}
perror("GETOSPACE");
v5 = "Um, can't do GETOSPACE?\n";
goto LABEL_22;
}
perror(v2);
Com_Printf("%d-bit sound not supported.", (unsigned int)(8 * *(_DWORD *)(shm + 4LL)));
close(audio_fd);
result = 0LL;
}
return result;
}

original_code:
qbool SNDDMA_Init_OSS_Legacy(qsoundhandler_t *sd)
{
 int rc, fmt, tmp, caps;
 char *snd_dev = ((void *)0);
 struct audio_buf_info info;
 snd_dev = Cvar_String("s_oss_device");
 if ((audio_fd = open(snd_dev, 02 | 04000)) < 0) {
  perror(snd_dev);
  Com_Printf("Could not open %s\n", snd_dev);
  return 0;
 }
 if ((rc = ioctl(audio_fd, (((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((0)) << 0) | ((0) << ((0 +8)+8))), 0)) < 0) {
  perror(snd_dev);
  Com_Printf("Could not reset %s\n", snd_dev);
  close(audio_fd);
  return 0;
 }
 if (ioctl(audio_fd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((15)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &caps) == -1) {
  perror(snd_dev);
  Com_Printf("Sound driver too old\n");
  close(audio_fd);
  return 0;
 }
 if (!(caps & 0x00001000) || !(caps & 0x00002000)) {
  Com_Printf("Sorry but your soundcard can't do this\n");
  close(audio_fd);
  return 0;
 }
 shm->format.width = (int) (s_bits.value / 8);
 shm->format.speed = SND_Rate((int)s_khz.value);
 shm->format.channels = ((int) s_stereo.value == 0) ? 1 : 2;
 if (shm->format.width != 2 && shm->format.width != 1) {
  ioctl(audio_fd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((11)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &fmt);
  if (fmt & 0x00000010)
   shm->format.width = 2;
  else if (fmt & 0x00000008)
   shm->format.width = 1;
 }
 tmp = (shm->format.channels == 2);
 if ((rc = ioctl(audio_fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((3)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &tmp)) < 0) {
  perror(snd_dev);
  Com_Printf ("Could not set %s to stereo", snd_dev);
  close(audio_fd);
  return 0;
 }
 if ((rc = ioctl(audio_fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &shm->format.speed)) < 0) {
  perror(snd_dev);
  Com_Printf("Could not set %s speed to %d", snd_dev, shm->format.speed);
  close(audio_fd);
  return 0;
 }
 if (shm->format.width == 2) {
  rc = 0x00000010;
  rc = ioctl(audio_fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &rc);
  if (rc < 0) {
   perror(snd_dev);
   Com_Printf("Could not support 16-bit data.  Try 8-bit.\n");
   close(audio_fd);
   return 0;
  }
 } else if (shm->format.width == 1) {
  rc = 0x00000008;
  rc = ioctl(audio_fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &rc);
  if (rc < 0) {
   perror(snd_dev);
   Com_Printf("Could not support 8-bit data.\n");
   close(audio_fd);
   return 0;
  }
 } else {
  perror(snd_dev);
  Com_Printf("%d-bit sound not supported.", shm->format.width * 8);
   close(audio_fd);
   return 0;
  }
 if (ioctl(audio_fd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((12)) << 0) | ((((sizeof(audio_buf_info)))) << ((0 +8)+8))), &info) == -1) {
  perror("GETOSPACE");
  Com_Printf ("Um, can't do GETOSPACE?\n");
  close(audio_fd);
  return 0;
     }
 shm->sampleframes = info.fragstotal * info.fragsize / shm->format.width / shm->format.channels;
 shm->samples = shm->sampleframes * shm->format.channels;
 shm->bufferlength = info.fragstotal * info.fragsize;
 shm->buffer = (unsigned char *) mmap(((void *)0), shm->bufferlength, 0x2, 0|0x01, audio_fd, 0);
 if (!shm->buffer || shm->buffer == (unsigned char *)-1) {
  perror(snd_dev);
  Com_Printf ("Could not mmap %s\n", snd_dev);
  close(audio_fd);
  return 0;
 }
 tmp = 0;
 rc = ioctl(audio_fd, (((1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((16)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &tmp);
 if (rc < 0) {
  perror(snd_dev);
  Com_Printf("Could not toggle.\n");
  close(audio_fd);
  return 0;
 }
 tmp = 0x00000002;
 rc = ioctl(audio_fd, (((1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((16)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &tmp);
 if (rc < 0) {
  perror(snd_dev);
  Com_Printf("Could not toggle.\n");
  close(audio_fd);
  return 0;
 }
 shm->samplepos = 0;
 sd->GetDMAPos = SNDDMA_GetDMAPos_OSS_Legacy;
 sd->GetAvail = ((void *)0);
 sd->Submit = ((void *)0);
 sd->Shutdown = SNDDMA_Shutdown_OSS_Legacy;
 sd->name = "snd_oss (legacy)";
 return 1;
}

canonical_original_code:
enum qbool SNDDMA_Init_OSS_Legacy(struct qsoundhandler_s *sd)
{
 int rc; int fmt; int tmp; int caps;
 char *snd_dev = ((void *)0);
 struct audio_buf_info info;
 snd_dev = Cvar_String("s_oss_device");
 if ((audio_fd = open(snd_dev, 02 | 04000)) < 0) {
  perror(snd_dev);
  Com_Printf("Could not open %s\n", snd_dev);
  return 0;
 }
 if ((rc = ioctl(audio_fd, (((0U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((0)) << 0) | ((0) << ((0 +8)+8))), 0)) < 0) {
  perror(snd_dev);
  Com_Printf("Could not reset %s\n", snd_dev);
  close(audio_fd);
  return 0;
 }
 if (ioctl(audio_fd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((15)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &caps) == -1) {
  perror(snd_dev);
  Com_Printf("Sound driver too old\n");
  close(audio_fd);
  return 0;
 }
 if (!(caps & 0x00001000) || !(caps & 0x00002000)) {
  Com_Printf("Sorry but your soundcard can't do this\n");
  close(audio_fd);
  return 0;
 }
 shm->format.width = (int) (s_bits.value / 8);
 shm->format.speed = SND_Rate((int)s_khz.value);
 shm->format.channels = ((int) s_stereo.value == 0) ? 1 : 2;
 if (shm->format.width != 2 && shm->format.width != 1) {
  ioctl(audio_fd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((11)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &fmt);
  if (fmt & 0x00000010)
   shm->format.width = 2;
  else if (fmt & 0x00000008)
   shm->format.width = 1;
 }
 tmp = (shm->format.channels == 2);
 if ((rc = ioctl(audio_fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((3)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &tmp)) < 0) {
  perror(snd_dev);
  Com_Printf ("Could not set %s to stereo", snd_dev);
  close(audio_fd);
  return 0;
 }
 if ((rc = ioctl(audio_fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((2)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &shm->format.speed)) < 0) {
  perror(snd_dev);
  Com_Printf("Could not set %s speed to %d", snd_dev, shm->format.speed);
  close(audio_fd);
  return 0;
 }
 if (shm->format.width == 2) {
  rc = 0x00000010;
  rc = ioctl(audio_fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &rc);
  if (rc < 0) {
   perror(snd_dev);
   Com_Printf("Could not support 16-bit data.  Try 8-bit.\n");
   close(audio_fd);
   return 0;
  }
 } else if (shm->format.width == 1) {
  rc = 0x00000008;
  rc = ioctl(audio_fd, (((2U|1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((5)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &rc);
  if (rc < 0) {
   perror(snd_dev);
   Com_Printf("Could not support 8-bit data.\n");
   close(audio_fd);
   return 0;
  }
 } else {
  perror(snd_dev);
  Com_Printf("%d-bit sound not supported.", shm->format.width * 8);
   close(audio_fd);
   return 0;
  }
 if (ioctl(audio_fd, (((2U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((12)) << 0) | ((((sizeof(audio_buf_info)))) << ((0 +8)+8))), &info) == -1) {
  perror("GETOSPACE");
  Com_Printf ("Um, can't do GETOSPACE?\n");
  close(audio_fd);
  return 0;
     }
 shm->sampleframes = info.fragstotal * info.fragsize / shm->format.width / shm->format.channels;
 shm->samples = shm->sampleframes * shm->format.channels;
 shm->bufferlength = info.fragstotal * info.fragsize;
 shm->buffer = (unsigned char *) mmap(((void *)0), shm->bufferlength, 0x2, 0|0x01, audio_fd, 0);
 if (!shm->buffer || shm->buffer == (unsigned char *)-1) {
  perror(snd_dev);
  Com_Printf ("Could not mmap %s\n", snd_dev);
  close(audio_fd);
  return 0;
 }
 tmp = 0;
 rc = ioctl(audio_fd, (((1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((16)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &tmp);
 if (rc < 0) {
  perror(snd_dev);
  Com_Printf("Could not toggle.\n");
  close(audio_fd);
  return 0;
 }
 tmp = 0x00000002;
 rc = ioctl(audio_fd, (((1U) << (((0 +8)+8)+14)) | ((('P')) << (0 +8)) | (((16)) << 0) | ((((sizeof(int)))) << ((0 +8)+8))), &tmp);
 if (rc < 0) {
  perror(snd_dev);
  Com_Printf("Could not toggle.\n");
  close(audio_fd);
  return 0;
 }
 shm->samplepos = 0;
 sd->GetDMAPos = SNDDMA_GetDMAPos_OSS_Legacy;
 sd->GetAvail = ((void *)0);
 sd->Submit = ((void *)0);
 sd->Shutdown = SNDDMA_Shutdown_OSS_Legacy;
 sd->name = "snd_oss (legacy)";
 return 1;
}

variable_types: struct qsoundhandler_s { char *name; int (*GetAvail)(); int (*GetDMAPos)(); void (*Submit)(unsigned int count); void (*Shutdown)(); } *

variable_types: rc int

variable_types: fmt int

variable_types: caps int

variable_types: struct audio_buf_info { int fragments; int fragstotal; int fragsize; int bytes; }


AngleMod

repo: jite/jquake

decompiled_code:
float __fastcall AngleMod(float result)
{
if ( result > 180.0 )
result = result - 360.0;
if ( result <= -180.0 )
result = result + 360.0;
return result;
}

canonical_decompiled_code:
float __fastcall func0(float result)
{
if ( result > 180.0 )
result = result - 360.0;
if ( result <= -180.0 )
result = result + 360.0;
return result;
}

original_code:
static float AngleMod (float a)
{
 if (a > 180)
  a -= 360;
 if (a <= - 180)
  a += 360;
 return a;
}

canonical_original_code:
static float AngleMod(float a)
{
 if (a > 180)
  a -= 360;
 if (a <= - 180)
  a += 360;
 return a;
}

variable_types: a float

return_type: float


Accelerate

original_code:
static void Accelerate (vec3_t wishdir, float wishspd, vec3_t velocity)
{
 int i;
 float addspeed, accelspeed, currentspeed;
 float wishspd_orig = wishspd;
 currentspeed = ((velocity)[0] * (wishdir)[0] + (velocity)[1] * (wishdir)[1] + (velocity)[2] * (wishdir)[2]);
 addspeed = wishspd - currentspeed;
 if (addspeed <= 0)
  return;
 accelspeed = movevars.accelerate * wishspd_orig * pm_frametime;
 if (accelspeed > addspeed)
  accelspeed = addspeed;
 for (i=0 ; i<3 ; i++)
  velocity[i] += accelspeed*wishdir[i];
}

canonical_original_code:
static void Accelerate(float wishdir[3], float wishspd, float velocity[3])
{
 int i;
 float addspeed; float accelspeed; float currentspeed;
 float wishspd_orig = wishspd;
 currentspeed = ((velocity)[0] * (wishdir)[0] + (velocity)[1] * (wishdir)[1] + (velocity)[2] * (wishdir)[2]);
 addspeed = wishspd - currentspeed;
 if (addspeed <= 0)
  return;
 accelspeed = movevars.accelerate * wishspd_orig * pm_frametime;
 if (accelspeed > addspeed)
  accelspeed = addspeed;
 for (i=0 ; i<3 ; i++)
  velocity[i] += accelspeed*wishdir[i];
}

variable_types:
wishdir
float [3]

variable_types: wishspd float

variable_types:
velocity
float [3]

variable_types: i int

variable_types: addspeed float

variable_types: accelspeed float

variable_types: currentspeed float

return_type: void


Autohop

decompiled_code:
__int64 __fastcall Autohop(__int64 a1)
{
__int64 result; // rax
float v2; // xmm1_4

result = *(unsigned __int8 *)(a1 + 22);
if ( (result & 2) != 0 )
{
if ( *(float *)&cl_autohop[4] != 0.0 )
{
v2 = unk_F68[331519];
if ( v2 <= 0.0 && *(float *)&oldzvel_0 > 0.0 )
{
result = (unsigned int)result & 0xFFFFFFFD;
*(_BYTE *)(a1 + 22) = result;
v2 = unk_F68[331519];
}
oldzvel_0 = LODWORD(v2);
}
}
else
{
oldzvel_0 = LODWORD(unk_F68[331519]);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax
float v2; // xmm1_4

result = *(unsigned __int8 *)(a1 + 22);
if ( (result & 2) != 0 )
{
if ( *(float *)&cl_autohop[4] != 0.0 )
{
v2 = unk_F68[331519];
if ( v2 <= 0.0 && *(float *)&oldzvel_0 > 0.0 )
{
result = (unsigned int)result & 0xFFFFFFFD;
*(_BYTE *)(a1 + 22) = result;
v2 = unk_F68[331519];
}
oldzvel_0 = LODWORD(v2);
}
}
else
{
oldzvel_0 = LODWORD(unk_F68[331519]);
}
return result;
}

original_code:
static void Autohop (usercmd_t *cmd)
{
 static float oldzvel;
 if (!(cmd->buttons & 2))
 {
  oldzvel = cl.simvel[2];
  return;
 }
 if (!cl_autohop.value)
  return;
 if (cl.simvel[2] <= 0 && oldzvel > 0)
  cmd->buttons &= ~2;
 oldzvel = cl.simvel[2];
}

canonical_original_code:
static void Autohop(struct usercmd_s *cmd)
{
 static float oldzvel;
 if (!(cmd->buttons & 2))
 {
  oldzvel = cl.simvel[2];
  return;
 }
 if (!cl_autohop.value)
  return;
 if (cl.simvel[2] <= 0 && oldzvel > 0)
  cmd->buttons &= ~2;
 oldzvel = cl.simvel[2];
}

variable_types: struct usercmd_s { unsigned char msec; float angles[3]; short forwardmove; unsigned char buttons; unsigned char impulse; } *

variable_types: oldzvel float


Friction

decompiled_code:
void __fastcall Friction(__int64 a1)
{
double v1; // xmm0_8
float v2; // xmm1_4
float v3; // xmm2_4
float v4; // xmm0_4

v1 = VectorLength();
v2 = *(float *)&v1;
if ( *(float *)&v1 < 1.0 )
{
*(_QWORD *)a1 = 0LL;
}
else
{
v3 = fmaxf(
0.0,
*(float *)&v1 - (float)(*(float *)&pm_frametime * (float)(fmaxf(movevars[1], *(float *)&v1) * movevars[7])));
*(float *)a1 = *(float *)a1 * (float)(v3 / *(float *)&v1);
v4 = (float)(v3 / *(float *)&v1) * *(float *)(a1 + 8);
*(float *)(a1 + 4) = *(float *)(a1 + 4) * (float)(v3 / v2);
*(float *)(a1 + 8) = v4;
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
double v1; // xmm0_8
float v2; // xmm1_4
float v3; // xmm2_4
float v4; // xmm0_4

v1 = VectorLength();
v2 = *(float *)&v1;
if ( *(float *)&v1 < 1.0 )
{
*(_QWORD *)a1 = 0LL;
}
else
{
v3 = fmaxf(
0.0,
*(float *)&v1 - (float)(*(float *)&pm_frametime * (float)(fmaxf(movevars[1], *(float *)&v1) * movevars[7])));
*(float *)a1 = *(float *)a1 * (float)(v3 / *(float *)&v1);
v4 = (float)(v3 / *(float *)&v1) * *(float *)(a1 + 8);
*(float *)(a1 + 4) = *(float *)(a1 + 4) * (float)(v3 / v2);
*(float *)(a1 + 8) = v4;
}
}

original_code:
static void Friction (vec3_t velocity)
{
 float speed, newspeed, control;
 float friction;
 float drop;
 speed = VectorLength(velocity);
 if (speed < 1)
 {
  velocity[0] = 0;
  velocity[1] = 0;
  return;
 }
 friction = movevars.friction;
 control = speed < movevars.stopspeed ? movevars.stopspeed : speed;
 drop = control*friction*pm_frametime;
 newspeed = speed - drop;
 if (newspeed < 0)
  newspeed = 0;
 do { float scale = (newspeed / speed); (velocity)[0] = (velocity)[0] * (scale); (velocity)[1] = (velocity)[1] * (scale); (velocity)[2] = (velocity)[2] * (scale); } while (0);;
}

canonical_original_code:
static void Friction(float velocity[3])
{
 float speed; float newspeed; float control;
 float friction;
 float drop;
 speed = VectorLength(velocity);
 if (speed < 1)
 {
  velocity[0] = 0;
  velocity[1] = 0;
  return;
 }
 friction = movevars.friction;
 control = speed < movevars.stopspeed ? movevars.stopspeed : speed;
 drop = control*friction*pm_frametime;
 newspeed = speed - drop;
 if (newspeed < 0)
  newspeed = 0;
 do { float scale = (newspeed / speed); (velocity)[0] = (velocity)[0] * (scale); (velocity)[1] = (velocity)[1] * (scale); (velocity)[2] = (velocity)[2] * (scale); } while (0);;
}

variable_types: speed float

variable_types: newspeed float

variable_types: control float

variable_types: friction float

variable_types: drop float

variable_types: scale float


RankAngle

decompiled_code:
__m128 __fastcall RankAngle(float a1)
{
float v1; // xmm0_4
int v2; // xmm0_4
__m128 v3; // xmm0
double v5; // [rsp+0h] [rbp-48h] BYREF
double sinx; // [rsp+8h] [rbp-40h] BYREF
int v7[3]; // [rsp+10h] [rbp-38h] BYREF
char v8[4]; // [rsp+1Ch] [rbp-2Ch] BYREF
float v9; // [rsp+20h] [rbp-28h]
char v10[4]; // [rsp+28h] [rbp-20h] BYREF
float v11; // [rsp+2Ch] [rbp-1Ch]
__int64 v12; // [rsp+34h] [rbp-14h] BYREF
int v13; // [rsp+3Ch] [rbp-Ch]

sincos((float)(a1 / 180.0) * 3.141592653589793, &sinx, &v5);
v1 = v5;
*(float *)v7 = v1;
*(float *)&v2 = sinx;
v7[1] = v2;
v12 = ra_curvel;
v13 = dword_D70;
v7[2] = 0;
Friction((__int64)&v12);
Accelerate((float *)v7, (float *)&v12, movevars[2]);
vectoangles(&v12, v8);
vectoangles(&ra_intentions, v10);
v3 = (__m128)LODWORD(v11);
v3.m128_f32[0] = AngleMod(v11 - v9);
return _mm_or_ps(v3, (__m128)LC7);
}

canonical_decompiled_code:
__m128 __fastcall func4(float a1)
{
float v1; // xmm0_4
int v2; // xmm0_4
__m128 v3; // xmm0
double v5; // [rsp+0h] [rbp-48h] BYREF
double sinx; // [rsp+8h] [rbp-40h] BYREF
int v7[3]; // [rsp+10h] [rbp-38h] BYREF
char v8[4]; // [rsp+1Ch] [rbp-2Ch] BYREF
float v9; // [rsp+20h] [rbp-28h]
char v10[4]; // [rsp+28h] [rbp-20h] BYREF
float v11; // [rsp+2Ch] [rbp-1Ch]
__int64 v12; // [rsp+34h] [rbp-14h] BYREF
int v13; // [rsp+3Ch] [rbp-Ch]

sincos((float)(a1 / 180.0) * 3.141592653589793, &sinx, &v5);
v1 = v5;
*(float *)v7 = v1;
*(float *)&v2 = sinx;
v7[1] = v2;
v12 = ra_curvel;
v13 = dword_D70;
v7[2] = 0;
func3((__int64)&v12);
func1((float *)v7, (float *)&v12, movevars[2]);
vectoangles(&v12, v8);
vectoangles(&ra_intentions, v10);
v3 = (__m128)LODWORD(v11);
v3.m128_f32[0] = func0(v11 - v9);
return _mm_or_ps(v3, (__m128)LC7);
}

original_code:
static float RankAngle (float a)
{
 vec3_t wishdir;
 float delta;
 vec3_t ang1, ang2;
 vec3_t newvel;
 wishdir[0] = cos(a / 180 * 3.14159265358979323846);
 wishdir[1] = sin(a / 180 * 3.14159265358979323846);
 wishdir[2] = 0;
 ((newvel)[0] = (ra_curvel)[0], (newvel)[1] = (ra_curvel)[1], (newvel)[2] = (ra_curvel)[2]);
 Friction (newvel);
 Accelerate (wishdir, movevars.maxspeed, newvel);
 vectoangles (newvel, ang1);
 vectoangles (ra_intentions, ang2);
 delta = AngleMod(ang2[1] - ang1[1]);
 return -fabs(delta);
}

canonical_original_code:
static float RankAngle(float a)
{
 float wishdir[3];
 float delta;
 float ang1[3]; float ang2[3];
 float newvel[3];
 wishdir[0] = cos(a / 180 * 3.14159265358979323846);
 wishdir[1] = sin(a / 180 * 3.14159265358979323846);
 wishdir[2] = 0;
 ((newvel)[0] = (ra_curvel)[0], (newvel)[1] = (ra_curvel)[1], (newvel)[2] = (ra_curvel)[2]);
 Friction (newvel);
 Accelerate (wishdir, movevars.maxspeed, newvel);
 vectoangles (newvel, ang1);
 vectoangles (ra_intentions, ang2);
 delta = AngleMod(ang2[1] - ang1[1]);
 return -fabs(delta);
}

variable_types: delta float

variable_types:
newvel
float [3]


ZeroAngle

decompiled_code:
float __fastcall ZeroAngle(float a1)
{
float result; // xmm0_4

if ( a1 == 0.0 )
result = 0.0;
else
result = acos((float)(30.0 / a1)) / 3.141592653589793 * 180.0;
return result;
}

canonical_decompiled_code:
float __fastcall func5(float a1)
{
float result; // xmm0_4

if ( a1 == 0.0 )
result = 0.0;
else
result = acos((float)(30.0 / a1)) / 3.141592653589793 * 180.0;
return result;
}

original_code:
static float ZeroAngle (float speed)
{
 if (!speed)
  return 0;
 return acos(30/speed)/3.14159265358979323846*180;
}

canonical_original_code:
static float ZeroAngle(float speed)
{
 if (!speed)
  return 0;
 return acos(30/speed)/3.14159265358979323846*180;
}


TweakMovement

decompiled_code:
void __fastcall TweakMovement(__int64 a1)
{
float v1; // ebp
int v2; // xmm0_4
float v3; // xmm1_4
__int64 v4; // rax
float v5; // xmm1_4
unsigned __int16 v6; // ax
unsigned __int16 v7; // dx
double v8; // xmm5_8
int v9; // xmm2_4
__int64 v10; // xmm3_8
float v11; // xmm0_4
float v12; // xmm0_4
int v13; // xmm2_4
float v14; // xmm0_4
float v15; // [rsp+0h] [rbp-80h]
float v16; // [rsp+8h] [rbp-78h] BYREF
float v17; // [rsp+Ch] [rbp-74h]
float v18; // [rsp+10h] [rbp-70h]
float v19; // [rsp+14h] [rbp-6Ch] BYREF
float v20; // [rsp+18h] [rbp-68h]
float v21; // [rsp+1Ch] [rbp-64h]
float v22; // [rsp+20h] [rbp-60h] BYREF
float v23; // [rsp+24h] [rbp-5Ch]
float v24; // [rsp+28h] [rbp-58h]
__int64 v25; // [rsp+2Ch] [rbp-54h] BYREF
int v26; // [rsp+34h] [rbp-4Ch]
int v27; // [rsp+38h] [rbp-48h] BYREF
float v28; // [rsp+3Ch] [rbp-44h]
int v29; // [rsp+40h] [rbp-40h]
int v30[3]; // [rsp+44h] [rbp-3Ch] BYREF
char v31[4]; // [rsp+50h] [rbp-30h] BYREF
float v32; // [rsp+54h] [rbp-2Ch]
int v33[9]; // [rsp+5Ch] [rbp-24h] BYREF

if ( *(float *)&cl_easymove[4] != 0.0 )
{
v1 = unk_F68[507362];
if ( v1 == 0.0 )
{
if ( !*(_DWORD *)(a1 + 16) )
{
oldmove_5 = 0;
return;
}
if ( LODWORD(unk_F68[331528]) )
{
LODWORD(v1) = 1;
if ( (*(_BYTE *)(a1 + 22) & 2) != 0 )
LODWORD(v1) = em_jump_held != 0;
}
v2 = *(_DWORD *)(a1 + 8);
v33[0] = 0;
v33[1] = v2;
v33[2] = 0;
AngleVectors(v33, &v16, &v19, 0LL);
v3 = (float)*(__int16 *)(a1 + 16);
mathlib_temp_float1 = (float)*(__int16 *)(a1 + 18);
*(float *)v30 = (float)(v19 * mathlib_temp_float1) + (float)(v16 * v3);
*(float *)&v30[1] = (float)(v20 * mathlib_temp_float1) + (float)(v17 * v3);
*(float *)&v30[2] = (float)(mathlib_temp_float1 * v21) + (float)(v3 * v18);
vectoangles(v30, v31);
v4 = *(_QWORD *)&unk_F68[331517];
v26 = 0;
v25 = v4;
if ( VectorLength(&v25) >= 30.0 )
{
vectoangles(&v25, &v27);
v15 = v32;
v5 = AngleMod(v32 - v28);
if ( !locked_4 && -1.0 == *(double *)&startlock_3 )
startlock_3 = curtime;
v6 = *(_WORD *)(a1 + 16);
v7 = *(_WORD *)(a1 + 18);
if ( oldmove_5 != __PAIR32__(v7, v6) && (v1 == 0.0 || oldmove_5) )
{
locked_4 = 0;
v8 = curtime;
olddelta_valid_2 = 0;
startlock_3 = curtime;
}
else
{
v8 = *(double *)&startlock_3;
}
LOWORD(oldmove_5) = v6;
v9 = LODWORD(v5) & LC6;
HIWORD(oldmove_5) = v7;
if ( COERCE_FLOAT(LODWORD(v5) & LC6) < 0.5
|| olddelta_valid_2
&& (*(float *)&olddelta_1 >= 0.0 && v5 <= 0.0
|| *(float *)&olddelta_1 <= 0.0 && v5 >= 0.0
|| *(float *)&v9 > COERCE_FLOAT(LC6 & olddelta_1) + 0.1) )
{
locked_4 = 1;
}
olddelta_valid_2 = 1;
v10 = LC14;
olddelta_1 = LODWORD(v5);
if ( v1 == 0.0 )
v10 = LC15;
if ( curtime - v8 <= *(double *)&v10 )
{
if ( *(float *)&v9 <= 95.0 )
{
if ( !locked_4 )
return;
LABEL_27:
if ( em_touch_wall )
return;
if ( v1 == 0.0 )
{
v13 = LC4;
if ( v5 <= 0.0 )
v13 = LC16;
v14 = VectorLength(&v25);
v11 = (float)(ZeroAngle(v14) * *(float *)&v13) + v15;
}
else
{
if ( *(float *)&v9 < 0.5 )
return;
LODWORD(v11) = BestAngle_constprop_0((__int64)&v25, (__int64)v30).m128_u32[0];
}
v28 = v11;
v29 = 0;
v27 = 0;
AngleVectors(&v27, &v22, 0LL, 0LL);
v12 = (float)((float)((float)(v22 * v19) + (float)(v23 * v20)) + (float)(v24 * v21)) * 500.0;
*(_WORD *)(a1 + 16) = (int)(float)((float)((float)((float)(v16 * v22) + (float)(v17 * v23))
+ (float)(v18 * v24))
* 500.0);
*(_WORD *)(a1 + 18) = (int)v12;
return;
}
}
else
{
locked_4 = 1;
if ( *(float *)&v9 <= 95.0 )
goto LABEL_27;
}
locked_4 = 1;
return;
}
}
}
}

original_code:
static void TweakMovement (usercmd_t *cmd)
{
 vec3_t fw, rt;
 vec3_t movevec;
 vec3_t v1, ang;
 float a;
 float delta;
 vec3_t intentions;
 vec3_t intentions_a;
 vec3_t cmd_ang;
 qbool onground;
 static qbool locked = false;
 static double startlock = -1;
 static float olddelta;
 static qbool olddelta_valid = false;
 static short oldmove[2];
 if (!cl_easymove.value || cl.waterlevel)
  return;
 if (!cmd->forwardmove && !cmd->sidemove)
 {
  oldmove[0] = oldmove[1] = 0;
  return;
 }
 onground = (cl.onground && !((cmd->buttons & (1 << 1)) && !em_jump_held));
 ((cmd_ang)[0] = (cmd->angles)[0], (cmd_ang)[1] = (cmd->angles)[1], (cmd_ang)[2] = (cmd->angles)[2]);
 cmd_ang[0] = 0;
 cmd_ang[2] = 0;
 AngleVectors (cmd_ang, fw, rt, ((void *)0));
 do { float scale = (cmd->forwardmove); (intentions)[0] = (fw)[0] * (scale); (intentions)[1] = (fw)[1] * (scale); (intentions)[2] = (fw)[2] * (scale); } while (0);;
 do { _mathlib_temp_float1 = (cmd->sidemove); (intentions)[0] = (intentions)[0] + _mathlib_temp_float1 * (rt)[0]; (intentions)[1] = (intentions)[1] + _mathlib_temp_float1 * (rt)[1]; (intentions)[2] = (intentions)[2] + _mathlib_temp_float1 * (rt)[2]; } while(0);;
 vectoangles (intentions, intentions_a);
 ((v1)[0] = (cl.simvel)[0], (v1)[1] = (cl.simvel)[1], (v1)[2] = (cl.simvel)[2]);
 v1[2] = 0;
 if (VectorLength(v1) < 30)
  return;
 vectoangles (v1, ang);
 delta = AngleMod(intentions_a[1] - ang[1]);
 if (!locked && startlock == -1)
  startlock = curtime;
 if ((cmd->forwardmove != oldmove[0] || cmd->sidemove != oldmove[1])
 && (!onground || (oldmove[0] || oldmove[1]))) {
  locked = false;
  olddelta_valid = false;
  startlock = curtime;
 }
 oldmove[0] = cmd->forwardmove;
 oldmove[1] = cmd->sidemove;
 if (fabs(delta) < 0.5 || (olddelta_valid && (
  (olddelta >= 0 && delta <= 0) || (olddelta <= 0 && delta >= 0)
  || fabs(delta) > fabs(olddelta) + 0.1)) ) {
   locked = true;
 }
 olddelta = delta;
 olddelta_valid = true;
 if (curtime - startlock > (onground ? 0.1 : 0.3))
  locked = true;
 if (fabs(delta) > 95) {
  locked = true;
  return;
 }
 if (!locked || em_touch_wall)
  return;
 if (onground)
 {
  if (fabs(delta) < 0.5)
   return;
  a = BestAngle (v1, intentions, onground);
 }
 else
 {
  a = intentions_a[1] + (delta > 0 ? 1 : -1)*ZeroAngle(VectorLength(v1));
 }
 ((ang)[0] = (ang)[1] = (ang)[2] = 0);
 ang[1] = a;
 AngleVectors (ang, movevec, ((void *)0), ((void *)0));
 cmd->forwardmove = ((movevec)[0] * (fw)[0] + (movevec)[1] * (fw)[1] + (movevec)[2] * (fw)[2]) * 500;
 cmd->sidemove = ((movevec)[0] * (rt)[0] + (movevec)[1] * (rt)[1] + (movevec)[2] * (rt)[2]) * 500;
}

canonical_original_code:
static void TweakMovement(struct usercmd_s *cmd)
{
 float fw[3]; float rt[3];
 float movevec[3];
 float v1[3]; float ang[3];
 float a;
 float delta;
 float intentions[3];
 float intentions_a[3];
 float cmd_ang[3];
 enum qbool onground;
 static enum qbool locked = false;
 static double startlock = -1;
 static float olddelta;
 static enum qbool olddelta_valid = false;
 static short oldmove[2];
 if (!cl_easymove.value || cl.waterlevel)
  return;
 if (!cmd->forwardmove && !cmd->sidemove)
 {
  oldmove[0] = oldmove[1] = 0;
  return;
 }
 onground = (cl.onground && !((cmd->buttons & (1 << 1)) && !em_jump_held));
 ((cmd_ang)[0] = (cmd->angles)[0], (cmd_ang)[1] = (cmd->angles)[1], (cmd_ang)[2] = (cmd->angles)[2]);
 cmd_ang[0] = 0;
 cmd_ang[2] = 0;
 AngleVectors (cmd_ang, fw, rt, ((void *)0));
 do { float scale = (cmd->forwardmove); (intentions)[0] = (fw)[0] * (scale); (intentions)[1] = (fw)[1] * (scale); (intentions)[2] = (fw)[2] * (scale); } while (0);;
 do { _mathlib_temp_float1 = (cmd->sidemove); (intentions)[0] = (intentions)[0] + _mathlib_temp_float1 * (rt)[0]; (intentions)[1] = (intentions)[1] + _mathlib_temp_float1 * (rt)[1]; (intentions)[2] = (intentions)[2] + _mathlib_temp_float1 * (rt)[2]; } while(0);;
 vectoangles (intentions, intentions_a);
 ((v1)[0] = (cl.simvel)[0], (v1)[1] = (cl.simvel)[1], (v1)[2] = (cl.simvel)[2]);
 v1[2] = 0;
 if (VectorLength(v1) < 30)
  return;
 vectoangles (v1, ang);
 delta = AngleMod(intentions_a[1] - ang[1]);
 if (!locked && startlock == -1)
  startlock = curtime;
 if ((cmd->forwardmove != oldmove[0] || cmd->sidemove != oldmove[1])
 && (!onground || (oldmove[0] || oldmove[1]))) {
  locked = false;
  olddelta_valid = false;
  startlock = curtime;
 }
 oldmove[0] = cmd->forwardmove;
 oldmove[1] = cmd->sidemove;
 if (fabs(delta) < 0.5 || (olddelta_valid && (
  (olddelta >= 0 && delta <= 0) || (olddelta <= 0 && delta >= 0)
  || fabs(delta) > fabs(olddelta) + 0.1)) ) {
   locked = true;
 }
 olddelta = delta;
 olddelta_valid = true;
 if (curtime - startlock > (onground ? 0.1 : 0.3))
  locked = true;
 if (fabs(delta) > 95) {
  locked = true;
  return;
 }
 if (!locked || em_touch_wall)
  return;
 if (onground)
 {
  if (fabs(delta) < 0.5)
   return;
  a = BestAngle (v1, intentions, onground);
 }
 else
 {
  a = intentions_a[1] + (delta > 0 ? 1 : -1)*ZeroAngle(VectorLength(v1));
 }
 ((ang)[0] = (ang)[1] = (ang)[2] = 0);
 ang[1] = a;
 AngleVectors (ang, movevec, ((void *)0), ((void *)0));
 cmd->forwardmove = ((movevec)[0] * (fw)[0] + (movevec)[1] * (fw)[1] + (movevec)[2] * (fw)[2]) * 500;
 cmd->sidemove = ((movevec)[0] * (rt)[0] + (movevec)[1] * (rt)[1] + (movevec)[2] * (rt)[2]) * 500;
}

variable_types:
fw
float [3]

variable_types:
rt
float [3]

variable_types:
movevec
float [3]

variable_types:
ang
float [3]

variable_types: a float

variable_types:
intentions
float [3]

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

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

variable_types: startlock double

variable_types: olddelta float

variable_types:
oldmove
short [2]

user_defined_types: struct usercmd_s { unsigned char msec; float angles[3]; short forwardmove; unsigned char buttons; unsigned char impulse; }


decompiled_code:
__int64 __fastcall CL_EasyMove(unsigned __int8 *a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = (unsigned int)(LODWORD(unk_F68[331534]) | LODWORD(unk_F68[148]));
if ( !(LODWORD(unk_F68[331534]) | LODWORD(unk_F68[148])) )
{
result = LODWORD(unk_F68[331416]);
if ( (int)result >= 0 )
{
*(float *)&v2 = (double)*a1 * 0.001;
pm_frametime = v2;
TweakMovement((__int64)a1);
result = Autohop((__int64)a1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned __int8 *a1)
{
__int64 result; // rax
int v2; // xmm0_4

result = (unsigned int)(LODWORD(unk_F68[331534]) | LODWORD(unk_F68[148]));
if ( !(LODWORD(unk_F68[331534]) | LODWORD(unk_F68[148])) )
{
result = LODWORD(unk_F68[331416]);
if ( (int)result >= 0 )
{
*(float *)&v2 = (double)*a1 * 0.001;
pm_frametime = v2;
func8((__int64)a1);
result = func2((__int64)a1);
}
}
return result;
}

original_code:
void CL_EasyMove (usercmd_t *cmd)
{
 if (cl.spectator || cl.intermission || cl.stats[0] < 0)
  return;
 pm_frametime = cmd->msec * 0.001;
 TweakMovement (cmd);
 Autohop (cmd);
}

canonical_original_code:
void CL_EasyMove(struct usercmd_s *cmd)
{
 if (cl.spectator || cl.intermission || cl.stats[0] < 0)
  return;
 pm_frametime = cmd->msec * 0.001;
 TweakMovement (cmd);
 Autohop (cmd);
}

variable_types: struct usercmd_s { unsigned char msec; float angles[3]; short forwardmove; unsigned char buttons; unsigned char impulse; } *


decompiled_code:
void MP3_Init()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code: void MP3_Init(void) {}

canonical_original_code: void MP3_Init() {}


decompiled_code:
void MP3_Shutdown()
{
;
}

canonical_decompiled_code:
void func1()
{
;
}

original_code: void MP3_Shutdown(void) {}

canonical_original_code: void MP3_Shutdown() {}


original_code:
void R_RemoveEfrags (entity_t *ent) {
 efrag_t *ef, *old, *walk, **prev;
 ef = ent->efrag;
 while (ef) {
  prev = &ef->leaf->efrags;
  while (1) {
   walk = *prev;
   if (!walk)
    break;
   if (walk == ef) {
    *prev = ef->leafnext;
    break;
   } else {
    prev = &walk->leafnext;
   }
  }
  old = ef;
  ef = ef->entnext;
  old->entnext = cl.free_efrags;
  cl.free_efrags = old;
 }
 ent->efrag = ((void *)0);
}

canonical_original_code:
void R_RemoveEfrags(struct entity_s *ent) {
 struct efrag_s *ef; struct efrag_s *old; struct efrag_s *walk; struct efrag_s **prev;
 ef = ent->efrag;
 while (ef) {
  prev = &ef->leaf->efrags;
  while (1) {
   walk = *prev;
   if (!walk)
    break;
   if (walk == ef) {
    *prev = ef->leafnext;
    break;
   } else {
    prev = &walk->leafnext;
   }
  }
  old = ef;
  ef = ef->entnext;
  old->entnext = cl.free_efrags;
  cl.free_efrags = old;
 }
 ent->efrag = ((void *)0);
}

variable_types: struct entity_s { float origin[3]; float angles[3]; struct model_s { char name[64]; enum qbool { false=0, true=1 } needload; unsigned short crc; int simpletexture[5]; enum modhint_t { MOD_NORMAL=0, MOD_PLAYER=1, MOD_EYES=2, MOD_FLAME=3, MOD_THUNDERBOLT=4, MOD_BACKPACK=5, MOD_FLAG=6, MOD_SPIKE=7, MOD_TF_TRAIL=8, MOD_GRENADE=9, MOD_TESLA=10, MOD_SENTRYGUN=11, MOD_DETPACK=12, MOD_LASER=13, MOD_DEMON=14, MOD_SOLDIER=15, MOD_OGRE=16, MOD_ENFORCER=17, MOD_VOORSPIKE=18, MOD_LAVABALL=19, MOD_RAIL=20, MOD_RAIL2=21, MOD_BUILDINGGIBS=22, MOD_CLUSTER=23, MOD_SHAMBLER=24, MOD_TELEPORTDESTINATION=25, MOD_GIB=26, MOD_VMODEL=27 } modhint; enum modtype_t { mod_brush=0, mod_sprite=1, mod_spr32=2, mod_alias=3, mod_alias3=4 } type; int numframes; enum synctype_t { ST_SYNC=0, ST_RAND=1 } synctype; int flags; float mins[3]; float radius; int firstmodelsurface; int numsubmodels; struct dmodel_t { float mins[3]; float origin[3]; int headnode[4]; int visleafs; int firstface; } *submodels; int numplanes; struct mplane_s { float normal[3]; float dist; unsigned char type; unsigned char signbits; unsigned char pad[2]; } *planes; int numleafs; struct mleaf_s { int contents; int visframe; float minmaxs[6]; struct mnode_s { int contents; int visframe; float minmaxs[6]; struct mnode_s *parent; struct mplane_s *plane; struct mnode_s *children[2]; unsigned short firstsurface; unsigned short numsurfaces; } *parent; unsigned char *compressed_vis; struct efrag_s { struct mleaf_s *leaf; struct efrag_s *leafnext; struct entity_s *entity; struct efrag_s *entnext; } *efrags; 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 { 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 { 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 { false=0, true=1 } loaded; int isLumaTexture; } *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; } **firstmarksurface; int nummarksurfaces; } *leafs; int numvertexes; struct mvertex_s { float position[3]; } *vertexes; int numedges; struct medge_s { unsigned short v[2]; unsigned int cachededgeoffset; } *edges; int numnodes; int firstnode; struct mnode_s *nodes; int numtexinfo; struct mtexinfo_s *texinfo; int numsurfaces; struct msurface_s *surfaces; int numsurfedges; int *surfedges; int nummarksurfaces; struct msurface_s **marksurfaces; int numtextures; struct texture_s **textures; unsigned char *visdata; unsigned char *lightdata; int bspversion; enum qbool { false=0, true=1 } isworldmodel; struct cache_user_s { void *data; } cache; } *model; unsigned char *colormap; int skinnum; struct player_info_s { int userid; char userinfo[1024]; char name[16]; float entertime; int frags; int ping; unsigned char pl; int topcolor; int bottomcolor; int _topcolor; int _bottomcolor; int real_topcolor; int real_bottomcolor; char team[1024]; char _team[1024]; int fps_msec; int last_fps; int fps; int fps_frames; double fps_measure_time; enum qbool { false=0, true=1 } isnear; int spectator; unsigned char translations[-1]; struct skin_t { char name[16]; enum qbool { false=0, true=1 } failedload; enum qbool { false=0, true=1 } warned; int width; int bpp; int texnum; struct cache_user_s cache; } *skin; int stats[32]; enum qbool { false=0, true=1 } skin_refresh; enum qbool { false=0, true=1 } ignored; enum qbool { false=0, true=1 } validated; char f_server[16]; enum qbool { false=0, true=1 } dead; } *scoreboard; int renderfx; int effects; int oldframe; int frame; float framelerp; struct efrag_s *efrag; int visframe; int dlightframe; int dlightbits; float alpha; int trivial_accept; struct mnode_s *topnode; } *

variable_types: struct efrag_s { struct mleaf_s { int contents; int visframe; float minmaxs[6]; struct mnode_s { int contents; int visframe; float minmaxs[6]; struct mnode_s *parent; struct mplane_s { float normal[3]; float dist; unsigned char type; unsigned char signbits; unsigned char pad[2]; } *plane; struct mnode_s *children[2]; unsigned short firstsurface; unsigned short numsurfaces; } *parent; unsigned char *compressed_vis; struct efrag_s *efrags; 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 { 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 { 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 { false=0, true=1 } loaded; int isLumaTexture; } *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; } **firstmarksurface; int nummarksurfaces; } *leaf; struct efrag_s *leafnext; struct entity_s { float origin[3]; float angles[3]; struct model_s { char name[64]; enum qbool { false=0, true=1 } needload; unsigned short crc; int simpletexture[5]; enum modhint_t { MOD_NORMAL=0, MOD_PLAYER=1, MOD_EYES=2, MOD_FLAME=3, MOD_THUNDERBOLT=4, MOD_BACKPACK=5, MOD_FLAG=6, MOD_SPIKE=7, MOD_TF_TRAIL=8, MOD_GRENADE=9, MOD_TESLA=10, MOD_SENTRYGUN=11, MOD_DETPACK=12, MOD_LASER=13, MOD_DEMON=14, MOD_SOLDIER=15, MOD_OGRE=16, MOD_ENFORCER=17, MOD_VOORSPIKE=18, MOD_LAVABALL=19, MOD_RAIL=20, MOD_RAIL2=21, MOD_BUILDINGGIBS=22, MOD_CLUSTER=23, MOD_SHAMBLER=24, MOD_TELEPORTDESTINATION=25, MOD_GIB=26, MOD_VMODEL=27 } modhint; enum modtype_t { mod_brush=0, mod_sprite=1, mod_spr32=2, mod_alias=3, mod_alias3=4 } type; int numframes; enum synctype_t { ST_SYNC=0, ST_RAND=1 } synctype; int flags; float mins[3]; float radius; int firstmodelsurface; int numsubmodels; struct dmodel_t { float mins[3]; float origin[3]; int headnode[4]; int visleafs; int firstface; } *submodels; int numplanes; struct mplane_s *planes; int numleafs; struct mleaf_s *leafs; int numvertexes; struct mvertex_s { float position[3]; } *vertexes; int numedges; struct medge_s { unsigned short v[2]; unsigned int cachededgeoffset; } *edges; int numnodes; int firstnode; struct mnode_s *nodes; int numtexinfo; struct mtexinfo_s *texinfo; int numsurfaces; struct msurface_s *surfaces; int numsurfedges; int *surfedges; int nummarksurfaces; struct msurface_s **marksurfaces; int numtextures; struct texture_s **textures; unsigned char *visdata; unsigned char *lightdata; int bspversion; enum qbool { false=0, true=1 } isworldmodel; struct cache_user_s { void *data; } cache; } *model; unsigned char *colormap; int skinnum; struct player_info_s { int userid; char userinfo[1024]; char name[16]; float entertime; int frags; int ping; unsigned char pl; int topcolor; int bottomcolor; int _topcolor; int _bottomcolor; int real_topcolor; int real_bottomcolor; char team[1024]; char _team[1024]; int fps_msec; int last_fps; int fps; int fps_frames; double fps_measure_time; enum qbool { false=0, true=1 } isnear; int spectator; unsigned char translations[-1]; struct skin_t { char name[16]; enum qbool { false=0, true=1 } failedload; enum qbool { false=0, true=1 } warned; int width; int bpp; int texnum; struct cache_user_s cache; } *skin; int stats[32]; enum qbool { false=0, true=1 } skin_refresh; enum qbool { false=0, true=1 } ignored; enum qbool { false=0, true=1 } validated; char f_server[16]; enum qbool { false=0, true=1 } dead; } *scoreboard; int renderfx; int effects; int oldframe; int frame; float framelerp; struct efrag_s *efrag; int visframe; int dlightframe; int dlightbits; float alpha; int trivial_accept; struct mnode_s *topnode; } *entity; struct efrag_s *entnext; } **

user_defined_types: struct entity_s { float origin[3]; float angles[3]; struct model_s *model; unsigned char *colormap; int skinnum; struct player_info_s *scoreboard; int renderfx; int effects; int oldframe; int frame; float framelerp; struct efrag_s *efrag; int visframe; int dlightframe; int dlightbits; float alpha; int trivial_accept; struct mnode_s *topnode; }

user_defined_types: struct model_s { char name[64]; enum qbool needload; unsigned short crc; int simpletexture[5]; enum modhint_t modhint; enum modtype_t type; int numframes; enum synctype_t synctype; int flags; float mins[3]; float radius; int firstmodelsurface; int numsubmodels; struct dmodel_t *submodels; int numplanes; struct mplane_s *planes; int numleafs; struct mleaf_s *leafs; int numvertexes; struct mvertex_s *vertexes; int numedges; struct medge_s *edges; int numnodes; int firstnode; struct mnode_s *nodes; int numtexinfo; struct mtexinfo_s *texinfo; int numsurfaces; struct msurface_s *surfaces; int numsurfedges; int *surfedges; int nummarksurfaces; struct msurface_s **marksurfaces; int numtextures; struct texture_s **textures; unsigned char *visdata; unsigned char *lightdata; int bspversion; enum qbool isworldmodel; struct cache_user_s cache; }

user_defined_types: struct player_info_s { int userid; char userinfo[1024]; char name[16]; float entertime; int frags; int ping; unsigned char pl; int topcolor; int bottomcolor; int _topcolor; int _bottomcolor; int real_topcolor; int real_bottomcolor; char team[1024]; char _team[1024]; int fps_msec; int last_fps; int fps; int fps_frames; double fps_measure_time; enum qbool isnear; int spectator; unsigned char translations[-1]; struct skin_t *skin; int stats[32]; enum qbool skin_refresh; enum qbool ignored; enum qbool validated; char f_server[16]; enum qbool dead; }

user_defined_types: struct mleaf_s { int contents; int visframe; float minmaxs[6]; struct mnode_s *parent; unsigned char *compressed_vis; struct efrag_s *efrags; struct msurface_s **firstmarksurface; int nummarksurfaces; }

user_defined_types: struct skin_t { char name[16]; enum qbool failedload; enum qbool warned; int width; int bpp; int texnum; struct cache_user_s cache; }

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

user_defined_types: struct mtexinfo_s { float vecs[2][4]; struct texture_s *texture; int flags; }

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


decompiled_code:
__int64 __fastcall R_SplitEntityOnNode(_QWORD *a1)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rax
float v5; // xmm0_4
int v6; // ebp
__int64 v7; // rdi

while ( 2 )
{
result = *(unsigned int *)a1;
if ( (_DWORD)result == -2 )
return result;
while ( 1 )
{
if ( (int)result < 0 )
{
if ( r_pefragtopnode )
{
result = unk_6C8[174257];
if ( result )
{
LABEL_19:
unk_6C8[174257] = *(_QWORD *)(result + 24);
*(_QWORD *)(result + 16) = r_addent;
*(_QWORD *)lastlink = result;
*(_QWORD *)(result + 24) = 0LL;
lastlink = result + 24;
*(_QWORD *)result = a1;
*(_QWORD *)(result + 8) = a1[6];
a1[6] = result;
return result;
}
}
else
{
result = unk_6C8[174257];
r_pefragtopnode = (__int64)a1;
if ( result )
goto LABEL_19;
}
return Com_Printf("Too many efrags!\n");
}
v3 = a1[5];
v4 = *(unsigned __int8 *)(v3 + 16);
if ( (unsigned __int8)v4 > 2u )
break;
v5 = *(float *)(v3 + 12);
if ( r_emins[v4] < v5 )
{
if ( v5 < r_emaxs[v4] )
{
LABEL_8:
if ( r_pefragtopnode )
{
R_SplitEntityOnNode(a1[6]);
}
else
{
v7 = a1[6];
r_pefragtopnode = (__int64)a1;
R_SplitEntityOnNode(v7);
}
}
goto LABEL_10;
}
a1 = (_QWORD *)a1[6];
result = *(unsigned int *)a1;
if ( (_DWORD)result == -2 )
return result;
}
result = BoxOnPlaneSide(r_emins, r_emaxs);
if ( (_DWORD)result == 3 )
goto LABEL_8;
v6 = result & 2;
if ( (result & 1) != 0 )
result = R_SplitEntityOnNode(a1[6]);
if ( v6 )
{
LABEL_10:
a1 = (_QWORD *)a1[7];
continue;
}
return result;
}
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 v4; // rax
float v5; // xmm0_4
int v6; // ebp
__int64 v7; // rdi

while ( 2 )
{
result = *(unsigned int *)a1;
if ( (_DWORD)result == -2 )
return result;
while ( 1 )
{
if ( (int)result < 0 )
{
if ( r_pefragtopnode )
{
result = unk_6C8[174257];
if ( result )
{
LABEL_19:
unk_6C8[174257] = *(_QWORD *)(result + 24);
*(_QWORD *)(result + 16) = r_addent;
*(_QWORD *)lastlink = result;
*(_QWORD *)(result + 24) = 0LL;
lastlink = result + 24;
*(_QWORD *)result = a1;
*(_QWORD *)(result + 8) = a1[6];
a1[6] = result;
return result;
}
}
else
{
result = unk_6C8[174257];
r_pefragtopnode = (__int64)a1;
if ( result )
goto LABEL_19;
}
return Com_Printf("Too many efrags!\n");
}
v3 = a1[5];
v4 = *(unsigned __int8 *)(v3 + 16);
if ( (unsigned __int8)v4 > 2u )
break;
v5 = *(float *)(v3 + 12);
if ( r_emins[v4] < v5 )
{
if ( v5 < r_emaxs[v4] )
{
LABEL_8:
if ( r_pefragtopnode )
{
func1(a1[6]);
}
else
{
v7 = a1[6];
r_pefragtopnode = (__int64)a1;
func1(v7);
}
}
goto LABEL_10;
}
a1 = (_QWORD *)a1[6];
result = *(unsigned int *)a1;
if ( (_DWORD)result == -2 )
return result;
}
result = BoxOnPlaneSide(r_emins, r_emaxs);
if ( (_DWORD)result == 3 )
goto LABEL_8;
v6 = result & 2;
if ( (result & 1) != 0 )
result = func1(a1[6]);
if ( v6 )
{
LABEL_10:
a1 = (_QWORD *)a1[7];
continue;
}
return result;
}
}

original_code:
void R_SplitEntityOnNode (mnode_t *node) {
 efrag_t *ef;
 mplane_t *splitplane;
 mleaf_t *leaf;
 int sides;
 if (node->contents == -2)
  return;
 if ( node->contents < 0) {
  if (!r_pefragtopnode)
   r_pefragtopnode = node;
  leaf = (mleaf_t *)node;
  if (!(ef = cl.free_efrags)) {
   Com_Printf ("Too many efrags!\n");
   return;
  }
  cl.free_efrags = cl.free_efrags->entnext;
  ef->entity = r_addent;
  *lastlink = ef;
  lastlink = &ef->entnext;
  ef->entnext = ((void *)0);
  ef->leaf = leaf;
  ef->leafnext = leaf->efrags;
  leaf->efrags = ef;
  return;
 }
 splitplane = node->plane;
 sides = (((splitplane)->type < 3) ? ( ((splitplane)->dist <= (r_emins)[(splitplane)->type]) ? 1 : ( ((splitplane)->dist >= (r_emaxs)[(splitplane)->type]) ? 2 : 3 ) ) : BoxOnPlaneSide((r_emins), (r_emaxs), (splitplane)));
 if (sides == 3) {
  if (!r_pefragtopnode)
   r_pefragtopnode = node;
 }
 if (sides & 1)
  R_SplitEntityOnNode (node->children[0]);
 if (sides & 2)
  R_SplitEntityOnNode (node->children[1]);
}

canonical_original_code:
void R_SplitEntityOnNode(struct mnode_s *node) {
 struct efrag_s *ef;
 struct mplane_s *splitplane;
 struct mleaf_s *leaf;
 int sides;
 if (node->contents == -2)
  return;
 if ( node->contents < 0) {
  if (!r_pefragtopnode)
   r_pefragtopnode = node;
  leaf = (struct mleaf_s *)node;
  if (!(ef = cl.free_efrags)) {
   Com_Printf ("Too many efrags!\n");
   return;
  }
  cl.free_efrags = cl.free_efrags->entnext;
  ef->entity = r_addent;
  *lastlink = ef;
  lastlink = &ef->entnext;
  ef->entnext = ((void *)0);
  ef->leaf = leaf;
  ef->leafnext = leaf->efrags;
  leaf->efrags = ef;
  return;
 }
 splitplane = node->plane;
 sides = (((splitplane)->type < 3) ? ( ((splitplane)->dist <= (r_emins)[(splitplane)->type]) ? 1 : ( ((splitplane)->dist >= (r_emaxs)[(splitplane)->type]) ? 2 : 3 ) ) : BoxOnPlaneSide((r_emins), (r_emaxs), (splitplane)));
 if (sides == 3) {
  if (!r_pefragtopnode)
   r_pefragtopnode = node;
 }
 if (sides & 1)
  R_SplitEntityOnNode (node->children[0]);
 if (sides & 2)
  R_SplitEntityOnNode (node->children[1]);
}

variable_types: struct efrag_s { struct mleaf_s { int contents; int visframe; float minmaxs[6]; struct mnode_s { int contents; int visframe; float minmaxs[6]; struct mnode_s *parent; struct mplane_s { float normal[3]; float dist; unsigned char type; unsigned char signbits; unsigned char pad[2]; } *plane; struct mnode_s *children[2]; unsigned short firstsurface; unsigned short numsurfaces; } *parent; unsigned char *compressed_vis; struct efrag_s *efrags; 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 { 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 { 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 { false=0, true=1 } loaded; int isLumaTexture; } *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; } **firstmarksurface; int nummarksurfaces; } *leaf; struct efrag_s *leafnext; struct entity_s { float origin[3]; float angles[3]; struct model_s { char name[64]; enum qbool { false=0, true=1 } needload; unsigned short crc; int simpletexture[5]; enum modhint_t { MOD_NORMAL=0, MOD_PLAYER=1, MOD_EYES=2, MOD_FLAME=3, MOD_THUNDERBOLT=4, MOD_BACKPACK=5, MOD_FLAG=6, MOD_SPIKE=7, MOD_TF_TRAIL=8, MOD_GRENADE=9, MOD_TESLA=10, MOD_SENTRYGUN=11, MOD_DETPACK=12, MOD_LASER=13, MOD_DEMON=14, MOD_SOLDIER=15, MOD_OGRE=16, MOD_ENFORCER=17, MOD_VOORSPIKE=18, MOD_LAVABALL=19, MOD_RAIL=20, MOD_RAIL2=21, MOD_BUILDINGGIBS=22, MOD_CLUSTER=23, MOD_SHAMBLER=24, MOD_TELEPORTDESTINATION=25, MOD_GIB=26, MOD_VMODEL=27 } modhint; enum modtype_t { mod_brush=0, mod_sprite=1, mod_spr32=2, mod_alias=3, mod_alias3=4 } type; int numframes; enum synctype_t { ST_SYNC=0, ST_RAND=1 } synctype; int flags; float mins[3]; float radius; int firstmodelsurface; int numsubmodels; struct dmodel_t { float mins[3]; float origin[3]; int headnode[4]; int visleafs; int firstface; } *submodels; int numplanes; struct mplane_s *planes; int numleafs; struct mleaf_s *leafs; int numvertexes; struct mvertex_s { float position[3]; } *vertexes; int numedges; struct medge_s { unsigned short v[2]; unsigned int cachededgeoffset; } *edges; int numnodes; int firstnode; struct mnode_s *nodes; int numtexinfo; struct mtexinfo_s *texinfo; int numsurfaces; struct msurface_s *surfaces; int numsurfedges; int *surfedges; int nummarksurfaces; struct msurface_s **marksurfaces; int numtextures; struct texture_s **textures; unsigned char *visdata; unsigned char *lightdata; int bspversion; enum qbool { false=0, true=1 } isworldmodel; struct cache_user_s { void *data; } cache; } *model; unsigned char *colormap; int skinnum; struct player_info_s { int userid; char userinfo[1024]; char name[16]; float entertime; int frags; int ping; unsigned char pl; int topcolor; int bottomcolor; int _topcolor; int _bottomcolor; int real_topcolor; int real_bottomcolor; char team[1024]; char _team[1024]; int fps_msec; int last_fps; int fps; int fps_frames; double fps_measure_time; enum qbool { false=0, true=1 } isnear; int spectator; unsigned char translations[-1]; struct skin_t { char name[16]; enum qbool { false=0, true=1 } failedload; enum qbool { false=0, true=1 } warned; int width; int bpp; int texnum; struct cache_user_s cache; } *skin; int stats[32]; enum qbool { false=0, true=1 } skin_refresh; enum qbool { false=0, true=1 } ignored; enum qbool { false=0, true=1 } validated; char f_server[16]; enum qbool { false=0, true=1 } dead; } *scoreboard; int renderfx; int effects; int oldframe; int frame; float framelerp; struct efrag_s *efrag; int visframe; int dlightframe; int dlightbits; float alpha; int trivial_accept; struct mnode_s *topnode; } *entity; struct efrag_s *entnext; } *

variable_types: struct mleaf_s { int contents; int visframe; float minmaxs[6]; struct mnode_s { int contents; int visframe; float minmaxs[6]; struct mnode_s *parent; struct mplane_s { float normal[3]; float dist; unsigned char type; unsigned char signbits; unsigned char pad[2]; } *plane; struct mnode_s *children[2]; unsigned short firstsurface; unsigned short numsurfaces; } *parent; unsigned char *compressed_vis; struct efrag_s { struct mleaf_s *leaf; struct efrag_s *leafnext; struct entity_s { float origin[3]; float angles[3]; struct model_s { char name[64]; enum qbool { false=0, true=1 } needload; unsigned short crc; int simpletexture[5]; enum modhint_t { MOD_NORMAL=0, MOD_PLAYER=1, MOD_EYES=2, MOD_FLAME=3, MOD_THUNDERBOLT=4, MOD_BACKPACK=5, MOD_FLAG=6, MOD_SPIKE=7, MOD_TF_TRAIL=8, MOD_GRENADE=9, MOD_TESLA=10, MOD_SENTRYGUN=11, MOD_DETPACK=12, MOD_LASER=13, MOD_DEMON=14, MOD_SOLDIER=15, MOD_OGRE=16, MOD_ENFORCER=17, MOD_VOORSPIKE=18, MOD_LAVABALL=19, MOD_RAIL=20, MOD_RAIL2=21, MOD_BUILDINGGIBS=22, MOD_CLUSTER=23, MOD_SHAMBLER=24, MOD_TELEPORTDESTINATION=25, MOD_GIB=26, MOD_VMODEL=27 } modhint; enum modtype_t { mod_brush=0, mod_sprite=1, mod_spr32=2, mod_alias=3, mod_alias3=4 } type; int numframes; enum synctype_t { ST_SYNC=0, ST_RAND=1 } synctype; int flags; float mins[3]; float radius; int firstmodelsurface; int numsubmodels; struct dmodel_t { float mins[3]; float origin[3]; int headnode[4]; int visleafs; int firstface; } *submodels; int numplanes; struct mplane_s *planes; int numleafs; struct mleaf_s *leafs; int numvertexes; struct mvertex_s { float position[3]; } *vertexes; int numedges; struct medge_s { unsigned short v[2]; unsigned int cachededgeoffset; } *edges; int numnodes; int firstnode; struct mnode_s *nodes; int numtexinfo; struct mtexinfo_s { float vecs[2][4]; struct texture_s { char name[16]; unsigned int width; int gl_texturenum; int fb_texturenum; 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 { 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 *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; } *texture; int flags; } *texinfo; int numsurfaces; struct msurface_s *surfaces; int numsurfedges; int *surfedges; int nummarksurfaces; struct msurface_s **marksurfaces; int numtextures; struct texture_s **textures; unsigned char *visdata; unsigned char *lightdata; int bspversion; enum qbool { false=0, true=1 } isworldmodel; struct cache_user_s { void *data; } cache; } *model; unsigned char *colormap; int skinnum; struct player_info_s { int userid; char userinfo[1024]; char name[16]; float entertime; int frags; int ping; unsigned char pl; int topcolor; int bottomcolor; int _topcolor; int _bottomcolor; int real_topcolor; int real_bottomcolor; char team[1024]; char _team[1024]; int fps_msec; int last_fps; int fps; int fps_frames; double fps_measure_time; enum qbool { false=0, true=1 } isnear; int spectator; unsigned char translations[-1]; struct skin_t { char name[16]; enum qbool { false=0, true=1 } failedload; enum qbool { false=0, true=1 } warned; int width; int bpp; int texnum; struct cache_user_s cache; } *skin; int stats[32]; enum qbool { false=0, true=1 } skin_refresh; enum qbool { false=0, true=1 } ignored; enum qbool { false=0, true=1 } validated; char f_server[16]; enum qbool { false=0, true=1 } dead; } *scoreboard; int renderfx; int effects; int oldframe; int frame; float framelerp; struct efrag_s *efrag; int visframe; int dlightframe; int dlightbits; float alpha; int trivial_accept; struct mnode_s *topnode; } *entity; struct efrag_s *entnext; } *efrags; struct msurface_s **firstmarksurface; int nummarksurfaces; } *

variable_types: sides int

user_defined_types: struct mnode_s { int contents; int visframe; float minmaxs[6]; struct mnode_s *parent; struct mplane_s *plane; struct mnode_s *children[2]; unsigned short firstsurface; unsigned short numsurfaces; }

user_defined_types: struct efrag_s { struct mleaf_s *leaf; struct efrag_s *leafnext; struct entity_s *entity; struct efrag_s *entnext; }


decompiled_code:
void __fastcall R_AddEfrags(__int64 a1)
{
__int64 v1; // rdx
__int64 i; // rax
float v3; // xmm0_4

v1 = *(_QWORD *)(a1 + 24);
if ( v1 )
{
r_addent = a1;
r_pefragtopnode = 0LL;
lastlink = a1 + 80;
for ( i = 0LL; i != 3; r_emaxs[i - 1] = v3 )
{
r_emins[i] = *(float *)(a1 + i * 4) + *(float *)(v1 + i * 4 + 112);
v3 = *(float *)(a1 + i * 4) + *(float *)(v1 + i * 4 + 124);
++i;
}
R_SplitEntityOnNode(*(_QWORD **)(unk_6C8[174256] + 232LL));
*(_QWORD *)(a1 + 112) = r_pefragtopnode;
}
}

original_code:
void R_AddEfrags (entity_t *ent) {
 model_t *entmodel;
 int i;
 if (!ent->model)
  return;
 r_addent = ent;
 lastlink = &ent->efrag;
 r_pefragtopnode = ((void *)0);
 entmodel = ent->model;
 for (i = 0; i < 3; i++) {
  r_emins[i] = ent->origin[i] + entmodel->mins[i];
  r_emaxs[i] = ent->origin[i] + entmodel->maxs[i];
 }
 R_SplitEntityOnNode (cl.worldmodel->nodes);
 ent->topnode = r_pefragtopnode;
}

canonical_original_code:
void R_AddEfrags(struct entity_s *ent) {
 struct model_s *entmodel;
 int i;
 if (!ent->model)
  return;
 r_addent = ent;
 lastlink = &ent->efrag;
 r_pefragtopnode = ((void *)0);
 entmodel = ent->model;
 for (i = 0; i < 3; i++) {
  r_emins[i] = ent->origin[i] + entmodel->mins[i];
  r_emaxs[i] = ent->origin[i] + entmodel->maxs[i];
 }
 R_SplitEntityOnNode (cl.worldmodel->nodes);
 ent->topnode = r_pefragtopnode;
}

variable_types: struct model_s { char name[64]; enum qbool { false=0, true=1 } needload; unsigned short crc; int simpletexture[5]; enum modhint_t { MOD_NORMAL=0, MOD_PLAYER=1, MOD_EYES=2, MOD_FLAME=3, MOD_THUNDERBOLT=4, MOD_BACKPACK=5, MOD_FLAG=6, MOD_SPIKE=7, MOD_TF_TRAIL=8, MOD_GRENADE=9, MOD_TESLA=10, MOD_SENTRYGUN=11, MOD_DETPACK=12, MOD_LASER=13, MOD_DEMON=14, MOD_SOLDIER=15, MOD_OGRE=16, MOD_ENFORCER=17, MOD_VOORSPIKE=18, MOD_LAVABALL=19, MOD_RAIL=20, MOD_RAIL2=21, MOD_BUILDINGGIBS=22, MOD_CLUSTER=23, MOD_SHAMBLER=24, MOD_TELEPORTDESTINATION=25, MOD_GIB=26, MOD_VMODEL=27 } modhint; enum modtype_t { mod_brush=0, mod_sprite=1, mod_spr32=2, mod_alias=3, mod_alias3=4 } type; int numframes; enum synctype_t { ST_SYNC=0, ST_RAND=1 } synctype; int flags; float mins[3]; float radius; int firstmodelsurface; int numsubmodels; struct dmodel_t { float mins[3]; float origin[3]; int headnode[4]; int visleafs; int firstface; } *submodels; int numplanes; struct mplane_s { float normal[3]; float dist; unsigned char type; unsigned char signbits; unsigned char pad[2]; } *planes; int numleafs; struct mleaf_s { int contents; int visframe; float minmaxs[6]; struct mnode_s { int contents; int visframe; float minmaxs[6]; struct mnode_s *parent; struct mplane_s *plane; struct mnode_s *children[2]; unsigned short firstsurface; unsigned short numsurfaces; } *parent; unsigned char *compressed_vis; struct efrag_s { struct mleaf_s *leaf; struct efrag_s *leafnext; struct entity_s { float origin[3]; float angles[3]; struct model_s *model; unsigned char *colormap; int skinnum; struct player_info_s { int userid; char userinfo[1024]; char name[16]; float entertime; int frags; int ping; unsigned char pl; int topcolor; int bottomcolor; int _topcolor; int _bottomcolor; int real_topcolor; int real_bottomcolor; char team[1024]; char _team[1024]; int fps_msec; int last_fps; int fps; int fps_frames; double fps_measure_time; enum qbool { false=0, true=1 } isnear; int spectator; unsigned char translations[-1]; struct skin_t { char name[16]; enum qbool { false=0, true=1 } failedload; enum qbool { false=0, true=1 } warned; int width; int bpp; int texnum; struct cache_user_s { void *data; } cache; } *skin; int stats[32]; enum qbool { false=0, true=1 } skin_refresh; enum qbool { false=0, true=1 } ignored; enum qbool { false=0, true=1 } validated; char f_server[16]; enum qbool { false=0, true=1 } dead; } *scoreboard; int renderfx; int effects; int oldframe; int frame; float framelerp; struct efrag_s *efrag; int visframe; int dlightframe; int dlightbits; float alpha; int trivial_accept; struct mnode_s *topnode; } *entity; struct efrag_s *entnext; } *efrags; 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 { 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 { 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 { false=0, true=1 } loaded; int isLumaTexture; } *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; } **firstmarksurface; int nummarksurfaces; } *leafs; int numvertexes; struct mvertex_s { float position[3]; } *vertexes; int numedges; struct medge_s { unsigned short v[2]; unsigned int cachededgeoffset; } *edges; int numnodes; int firstnode; struct mnode_s *nodes; int numtexinfo; struct mtexinfo_s *texinfo; int numsurfaces; struct msurface_s *surfaces; int numsurfedges; int *surfedges; int nummarksurfaces; struct msurface_s **marksurfaces; int numtextures; struct texture_s **textures; unsigned char *visdata; unsigned char *lightdata; int bspversion; enum qbool { false=0, true=1 } isworldmodel; struct cache_user_s cache; } *

variable_types: i int


decompiled_code:
void __fastcall R_StoreEfrags(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rsi

v1 = *a1;
if ( *a1 )
{
while ( 1 )
{
v2 = *(_QWORD *)(v1 + 16);
v3 = *(_QWORD *)(v2 + 24);
if ( *(_DWORD *)(v3 + 92) == 3 && r_drawflame[8] == 0.0 )
goto LABEL_5;
v4 = *(unsigned int *)(v3 + 96);
if ( (unsigned int)v4 <= 1 || (unsigned int)(v4 - 3) <= 1 )
{
if ( *(_DWORD *)(v2 + 88) != r_framecount )
{
CL_AddEntity(*(_QWORD *)(v1 + 16));
*(_DWORD *)(v2 + 88) = r_framecount;
}
LABEL_5:
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return;
}
else
{
Sys_Error("R_StoreEfrags: Bad entity type %d", v4);
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return;
}
}
}
}

canonical_decompiled_code:
void __fastcall func3(__int64 *a1)
{
__int64 v1; // rbx
__int64 v2; // rbp
__int64 v3; // rax
__int64 v4; // rsi

v1 = *a1;
if ( *a1 )
{
while ( 1 )
{
v2 = *(_QWORD *)(v1 + 16);
v3 = *(_QWORD *)(v2 + 24);
if ( *(_DWORD *)(v3 + 92) == 3 && r_drawflame[8] == 0.0 )
goto LABEL_5;
v4 = *(unsigned int *)(v3 + 96);
if ( (unsigned int)v4 <= 1 || (unsigned int)(v4 - 3) <= 1 )
{
if ( *(_DWORD *)(v2 + 88) != r_framecount )
{
CL_AddEntity(*(_QWORD *)(v1 + 16));
*(_DWORD *)(v2 + 88) = r_framecount;
}
LABEL_5:
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return;
}
else
{
Sys_Error("R_StoreEfrags: Bad entity type %d", v4);
v1 = *(_QWORD *)(v1 + 8);
if ( !v1 )
return;
}
}
}
}

original_code:
void R_StoreEfrags (efrag_t **ppefrag) {
 entity_t *pent;
 model_t *model;
 efrag_t *pefrag;
 for (pefrag = *ppefrag; pefrag; pefrag = pefrag->leafnext) {
  pent = pefrag->entity;
  model = pent->model;
  if (model->modhint == MOD_FLAME && !r_drawflame.value)
   continue;
  switch (model->type) {
  case mod_alias:
  case mod_alias3:
  case mod_brush:
  case mod_sprite:
   if (pent->visframe != r_framecount) {
    CL_AddEntity (pent);
    pent->visframe = r_framecount;
   }
   break;
  default:
   Sys_Error ("R_StoreEfrags: Bad entity type %d", model->type);
  }
 }
}

canonical_original_code:
void R_StoreEfrags(struct efrag_s **ppefrag) {
 struct entity_s *pent;
 struct model_s *model;
 struct efrag_s *pefrag;
 for (pefrag = *ppefrag; pefrag; pefrag = pefrag->leafnext) {
  pent = pefrag->entity;
  model = pent->model;
  if (model->modhint == MOD_FLAME && !r_drawflame.value)
   continue;
  switch (model->type) {
  case mod_alias:
  case mod_alias3:
  case mod_brush:
  case mod_sprite:
   if (pent->visframe != r_framecount) {
    CL_AddEntity (pent);
    pent->visframe = r_framecount;
   }
   break;
  default:
   Sys_Error ("R_StoreEfrags: Bad entity type %d", model->type);
  }
 }
}

user_defined_types: enum modhint_t { MOD_NORMAL=0, MOD_PLAYER=1, MOD_EYES=2, MOD_FLAME=3, MOD_THUNDERBOLT=4, MOD_BACKPACK=5, MOD_FLAG=6, MOD_SPIKE=7, MOD_TF_TRAIL=8, MOD_GRENADE=9, MOD_TESLA=10, MOD_SENTRYGUN=11, MOD_DETPACK=12, MOD_LASER=13, MOD_DEMON=14, MOD_SOLDIER=15, MOD_OGRE=16, MOD_ENFORCER=17, MOD_VOORSPIKE=18, MOD_LAVABALL=19, MOD_RAIL=20, MOD_RAIL2=21, MOD_BUILDINGGIBS=22, MOD_CLUSTER=23, MOD_SHAMBLER=24, MOD_TELEPORTDESTINATION=25, MOD_GIB=26, MOD_VMODEL=27 }

user_defined_types: enum modtype_t { mod_brush=0, mod_sprite=1, mod_spr32=2, mod_alias=3, mod_alias3=4 }

user_defined_types: enum synctype_t { ST_SYNC=0, ST_RAND=1 }

user_defined_types: struct dmodel_t { float mins[3]; float origin[3]; int headnode[4]; int visleafs; int firstface; }

user_defined_types: struct mplane_s { float normal[3]; float dist; unsigned char type; unsigned char signbits; unsigned char pad[2]; }

user_defined_types: struct medge_s { unsigned short v[2]; unsigned int cachededgeoffset; }

user_defined_types: 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]; }


VersionStringColored

decompiled_code:
char *VersionStringColored()
{
unsigned int v0; // eax

v0 = build_number();
snprintf(str_0, 0x40uLL, "&c2f2%s&r (%i)", "0.3-dev", v0);
return str_0;
}

canonical_decompiled_code:
char *func3()
{
unsigned int v0; // eax

v0 = func0();
snprintf(str_0, 0x40uLL, "&c2f2%s&r (%i)", "0.3-dev", v0);
return str_0;
}

original_code:
char *VersionStringColored (void)
{
 static char str[64];
 snprintf (str, sizeof(str), "&c2f2%s&r (%i)", "0.3-dev", build_number());
 return str;
}

canonical_original_code:
char *VersionStringColored()
{
 static char str[64];
 snprintf (str, sizeof(str), "&c2f2%s&r (%i)", "0.3-dev", build_number());
 return str;
}

variable_types:
str
char [64]

return_type: char *


original_code:
void CEditBox_Init(CEditBox *e, int width, int max)
{
 e->width = width;
 e->max = max;
 e->pos = 0;
 e->disp = 0;
 e->text[0] = 0;
}

canonical_original_code:
void CEditBox_Init(struct CEditBox_s *e, int width, int max)
{
 e->width = width;
 e->max = max;
 e->pos = 0;
 e->disp = 0;
 e->text[0] = 0;
}

variable_types: struct CEditBox_s { char text[-1]; unsigned int width; unsigned int max; unsigned int pos; unsigned int disp; } *

variable_types: width int

variable_types: max int


decompiled_code:
__int64 __fastcall CEditBox_Draw(char *s, unsigned int a2, unsigned int a3, int a4)
{
unsigned int v6; // edx
unsigned int v7; // ebx
unsigned int v8; // er14
unsigned int v9; // eax
size_t v10; // rax
__int64 result; // rax

v6 = *((_DWORD *)s + 67);
v7 = *((_DWORD *)s + 66);
v8 = *((_DWORD *)s + 64);
if ( v7 > v6 + v8 - 1 )
{
v9 = v6 + 1;
do
v6 = v9++;
while ( v8 - 2 + v9 < v7 );
*((_DWORD *)s + 67) = v6;
}
if ( v7 < v6 )
*((_DWORD *)s + 67) = v7;
else
v7 = *((_DWORD *)s + 67);
v10 = strlen(s);
if ( v7 > v10 - v8 + 1 )
*((_DWORD *)s + 67) = v10 - v8 + 1;
if ( a4 )
{
snprintf(buf, 0x100uLL, "%-*.*s", v8, v8, &s[*((unsigned int *)s + 67)]);
Draw_String(a2, a3, buf);
result = Draw_Character(a2 + 8 * (*((_DWORD *)s + 66) - *((_DWORD *)s + 67)), a3, ((int)(4.0 * cls[1]) & 1u) + 10);
}
else
{
snprintf(buf, 0x100uLL, "%-*.*s", v8, v8, s);
result = Draw_String(a2, a3, buf);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *s, unsigned int a2, unsigned int a3, int a4)
{
unsigned int v6; // edx
unsigned int v7; // ebx
unsigned int v8; // er14
unsigned int v9; // eax
size_t v10; // rax
__int64 result; // rax

v6 = *((_DWORD *)s + 67);
v7 = *((_DWORD *)s + 66);
v8 = *((_DWORD *)s + 64);
if ( v7 > v6 + v8 - 1 )
{
v9 = v6 + 1;
do
v6 = v9++;
while ( v8 - 2 + v9 < v7 );
*((_DWORD *)s + 67) = v6;
}
if ( v7 < v6 )
*((_DWORD *)s + 67) = v7;
else
v7 = *((_DWORD *)s + 67);
v10 = strlen(s);
if ( v7 > v10 - v8 + 1 )
*((_DWORD *)s + 67) = v10 - v8 + 1;
if ( a4 )
{
snprintf(buf, 0x100uLL, "%-*.*s", v8, v8, &s[*((unsigned int *)s + 67)]);
Draw_String(a2, a3, buf);
result = Draw_Character(a2 + 8 * (*((_DWORD *)s + 66) - *((_DWORD *)s + 67)), a3, ((int)(4.0 * cls[1]) & 1u) + 10);
}
else
{
snprintf(buf, 0x100uLL, "%-*.*s", v8, v8, s);
result = Draw_String(a2, a3, buf);
}
return result;
}

original_code:
void CEditBox_Draw(CEditBox *e, int x, int y, qbool active)
{
 while (e->pos > e->disp + e->width - 1)
  e->disp ++;
 if (e->disp > e->pos)
  e->disp = e->pos;
 if (e->disp > strlen(e->text) - e->width + 1)
  e->disp = strlen(e->text) - e->width + 1;
 snprintf(buf, sizeof (buf), "%-*.*s", e->width, e->width, active ? e->text+e->disp : e->text);
 Draw_String(x, y, buf);
 if (active)
  Draw_Character(x+8*(e->pos-e->disp), y, 10+((int)(cls.realtime*4)&1));
}

canonical_original_code:
void CEditBox_Draw(struct CEditBox_s *e, int x, int y, enum qbool active)
{
 while (e->pos > e->disp + e->width - 1)
  e->disp ++;
 if (e->disp > e->pos)
  e->disp = e->pos;
 if (e->disp > strlen(e->text) - e->width + 1)
  e->disp = strlen(e->text) - e->width + 1;
 snprintf(buf, sizeof (buf), "%-*.*s", e->width, e->width, active ? e->text+e->disp : e->text);
 Draw_String(x, y, buf);
 if (active)
  Draw_Character(x+8*(e->pos-e->disp), y, 10+((int)(cls.realtime*4)&1));
}

variable_types: x int

variable_types: y int

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

user_defined_types: struct CEditBox_s { char text[-1]; unsigned int width; unsigned int max; unsigned int pos; unsigned int disp; }


decompiled_code:
unsigned __int64 __fastcall CEditBox_Key(char *s, int a2, char a3)
{
size_t v4; // r14
int v5; // er13
size_t v6; // rax
unsigned __int64 result; // rax
size_t v8; // r8
size_t v9; // r13
__int64 v10; // r13
size_t v11; // rax
int v12; // eax
size_t v13; // rax
unsigned int v14; // eax
__int64 v15; // r14
size_t v16; // rax
const char *v17; // r15
size_t v18; // rax
unsigned int v19; // er13
size_t v20; // r14
int v21; // ecx
size_t v22; // rax
int v23; // [rsp+4h] [rbp-44h]

if ( a2 == 86 )
{
LABEL_3:
if ( (unsigned int)isCtrlDown() )
{
v17 = (const char *)ReadFromClipboard();
v18 = strlen(v17);
v19 = *((_DWORD *)s + 65);
v20 = v18;
v6 = strlen(s);
v21 = v19 - v6;
if ( v20 < v19 - v6 )
v21 = v20;
v4 = *((unsigned int *)s + 66);
v23 = v21;
v5 = *((_DWORD *)s + 66);
if ( v21 > 0 )
{
v22 = strlen(&s[v4]);
memmove(&s[v23 + v4], &s[v4], v22 + 1);
memcpy(&s[*((unsigned int *)s + 66)], v17, v23);
v4 = (unsigned int)(*((_DWORD *)s + 66) + v23);
*((_DWORD *)s + 66) = v4;
v5 = v4;
v6 = strlen(s);
}
}
else
{
LABEL_4:
v4 = *((unsigned int *)s + 66);
v5 = *((_DWORD *)s + 66);
v6 = strlen(s);
}
}
else
{
switch ( a2 )
{
case 118:
goto LABEL_3;
case 127:
v15 = *((unsigned int *)s + 66);
v5 = v15;
if ( (_DWORD)v15 )
{
v13 = strlen(&s[v15]);
memmove(&s[v15 - 1], &s[v15], v13 + 1);
LABEL_14:
v4 = (unsigned int)(*((_DWORD *)s + 66) - 1);
*((_DWORD *)s + 66) = v4;
v5 = v4;
v6 = strlen(s);
}
else
{
v6 = strlen(s);
v4 = 0LL;
}
break;
case 134:
goto LABEL_14;
case 135:
v4 = (unsigned int)(*((_DWORD *)s + 66) + 1);
*((_DWORD *)s + 66) = v4;
v5 = v4;
v6 = strlen(s);
break;
case 158:
v9 = *((unsigned int *)s + 66);
v6 = strlen(s);
if ( v9 >= v6 )
goto LABEL_11;
v16 = strlen(&s[v9 + 1]);
memmove(&s[v9], &s[v9 + 1], v16 + 1);
goto LABEL_4;
case 161:
*((_DWORD *)s + 66) = 0;
v4 = 0LL;
v5 = 0;
v6 = strlen(s);
break;
case 162:
v14 = strlen(s);
*((_DWORD *)s + 66) = v14;
v5 = v14;
v4 = v14;
v6 = strlen(s);
break;
default:
goto LABEL_4;
}
}
if ( v4 >= v6 )
LABEL_11:
v5 = v6;
*((_DWORD *)s + 66) = v5;
result = isCtrlDown();
if ( !(_DWORD)result && (unsigned int)(a2 - 32) <= 0x5D )
{
v8 = strlen(s);
result = *((unsigned int *)s + 65);
if ( v8 < result )
{
v10 = *((unsigned int *)s + 66);
v11 = strlen(&s[v10]);
memmove(&s[v10 + 1], &s[v10], v11 + 1);
v12 = *((_DWORD *)s + 66);
s[v12] = a3;
result = (unsigned int)(v12 + 1);
*((_DWORD *)s + 66) = result;
}
}
return result;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func2(char *s, int a2, char a3)
{
size_t v4; // r14
int v5; // er13
size_t v6; // rax
unsigned __int64 result; // rax
size_t v8; // r8
size_t v9; // r13
__int64 v10; // r13
size_t v11; // rax
int v12; // eax
size_t v13; // rax
unsigned int v14; // eax
__int64 v15; // r14
size_t v16; // rax
const char *v17; // r15
size_t v18; // rax
unsigned int v19; // er13
size_t v20; // r14
int v21; // ecx
size_t v22; // rax
int v23; // [rsp+4h] [rbp-44h]

if ( a2 == 86 )
{
LABEL_3:
if ( (unsigned int)isCtrlDown() )
{
v17 = (const char *)ReadFromClipboard();
v18 = strlen(v17);
v19 = *((_DWORD *)s + 65);
v20 = v18;
v6 = strlen(s);
v21 = v19 - v6;
if ( v20 < v19 - v6 )
v21 = v20;
v4 = *((unsigned int *)s + 66);
v23 = v21;
v5 = *((_DWORD *)s + 66);
if ( v21 > 0 )
{
v22 = strlen(&s[v4]);
memmove(&s[v23 + v4], &s[v4], v22 + 1);
memcpy(&s[*((unsigned int *)s + 66)], v17, v23);
v4 = (unsigned int)(*((_DWORD *)s + 66) + v23);
*((_DWORD *)s + 66) = v4;
v5 = v4;
v6 = strlen(s);
}
}
else
{
LABEL_4:
v4 = *((unsigned int *)s + 66);
v5 = *((_DWORD *)s + 66);
v6 = strlen(s);
}
}
else
{
switch ( a2 )
{
case 118:
goto LABEL_3;
case 127:
v15 = *((unsigned int *)s + 66);
v5 = v15;
if ( (_DWORD)v15 )
{
v13 = strlen(&s[v15]);
memmove(&s[v15 - 1], &s[v15], v13 + 1);
LABEL_14:
v4 = (unsigned int)(*((_DWORD *)s + 66) - 1);
*((_DWORD *)s + 66) = v4;
v5 = v4;
v6 = strlen(s);
}
else
{
v6 = strlen(s);
v4 = 0LL;
}
break;
case 134:
goto LABEL_14;
case 135:
v4 = (unsigned int)(*((_DWORD *)s + 66) + 1);
*((_DWORD *)s + 66) = v4;
v5 = v4;
v6 = strlen(s);
break;
case 158:
v9 = *((unsigned int *)s + 66);
v6 = strlen(s);
if ( v9 >= v6 )
goto LABEL_11;
v16 = strlen(&s[v9 + 1]);
memmove(&s[v9], &s[v9 + 1], v16 + 1);
goto LABEL_4;
case 161:
*((_DWORD *)s + 66) = 0;
v4 = 0LL;
v5 = 0;
v6 = strlen(s);
break;
case 162:
v14 = strlen(s);
*((_DWORD *)s + 66) = v14;
v5 = v14;
v4 = v14;
v6 = strlen(s);
break;
default:
goto LABEL_4;
}
}
if ( v4 >= v6 )
LABEL_11:
v5 = v6;
*((_DWORD *)s + 66) = v5;
result = isCtrlDown();
if ( !(_DWORD)result && (unsigned int)(a2 - 32) <= 0x5D )
{
v8 = strlen(s);
result = *((unsigned int *)s + 65);
if ( v8 < result )
{
v10 = *((unsigned int *)s + 66);
v11 = strlen(&s[v10]);
memmove(&s[v10 + 1], &s[v10], v11 + 1);
v12 = *((_DWORD *)s + 66);
s[v12] = a3;
result = (unsigned int)(v12 + 1);
*((_DWORD *)s + 66) = result;
}
}
return result;
}

original_code:
void CEditBox_Key(CEditBox *e, int key, unsigned short unichar)
{
 switch (key) {
   case K_LEFTARROW:
    e->pos--;
    break;
   case K_RIGHTARROW:
    e->pos++;
    break;
   case K_HOME:
    e->pos = 0;
    break;
   case K_END:
    e->pos = strlen(e->text);
    break;
   case K_DEL:
    if (e->pos < strlen(e->text))
     memmove(e->text + e->pos,
      e->text + e->pos + 1,
      strlen(e->text + e->pos + 1) + 1);
    break;
   case K_BACKSPACE:
    if (e->pos > 0) {
     memmove(e->text + e->pos - 1,
      e->text + e->pos,
      strlen(e->text + e->pos) + 1);
     e->pos --;
    }
   break;
   case 'v':
   case 'V':
    if (isCtrlDown()) {
     int len;
     char *clip = ReadFromClipboard();
     len = ((strlen(clip)) < (e->max - strlen(e->text)) ? (strlen(clip)) : (e->max - strlen(e->text)));
     if (len > 0) {
      memmove(e->text + e->pos + len,
       e->text + e->pos,
       strlen(e->text + e->pos) + 1);
      memcpy(e->text + e->pos, clip, len);
      e->pos += len;
     }
    }
   break;
 }
 e->pos = ((e->pos) > (0) ? (e->pos) : (0));
 e->pos = ((e->pos) < (strlen(e->text)) ? (e->pos) : (strlen(e->text)));
 if (!isCtrlDown() &&
  key >= ' ' && key <= '}' &&
  strlen(e->text) < e->max)
 {
  memmove(e->text + e->pos + 1,
   e->text + e->pos,
   strlen(e->text + e->pos) + 1);
  e->text[e->pos] = unichar;
  e->pos++;
 }
}

canonical_original_code:
void CEditBox_Key(struct CEditBox_s *e, int key, unsigned short unichar)
{
 switch (key) {
   case K_LEFTARROW:
    e->pos--;
    break;
   case K_RIGHTARROW:
    e->pos++;
    break;
   case K_HOME:
    e->pos = 0;
    break;
   case K_END:
    e->pos = strlen(e->text);
    break;
   case K_DEL:
    if (e->pos < strlen(e->text))
     memmove(e->text + e->pos,
      e->text + e->pos + 1,
      strlen(e->text + e->pos + 1) + 1);
    break;
   case K_BACKSPACE:
    if (e->pos > 0) {
     memmove(e->text + e->pos - 1,
      e->text + e->pos,
      strlen(e->text + e->pos) + 1);
     e->pos --;
    }
   break;
   case 'v':
   case 'V':
    if (isCtrlDown()) {
     int len;
     char *clip = ReadFromClipboard();
     len = ((strlen(clip)) < (e->max - strlen(e->text)) ? (strlen(clip)) : (e->max - strlen(e->text)));
     if (len > 0) {
      memmove(e->text + e->pos + len,
       e->text + e->pos,
       strlen(e->text + e->pos) + 1);
      memcpy(e->text + e->pos, clip, len);
      e->pos += len;
     }
    }
   break;
 }
 e->pos = ((e->pos) > (0) ? (e->pos) : (0));
 e->pos = ((e->pos) < (strlen(e->text)) ? (e->pos) : (strlen(e->text)));
 if (!isCtrlDown() &&
  key >= ' ' && key <= '}' &&
  strlen(e->text) < e->max)
 {
  memmove(e->text + e->pos + 1,
   e->text + e->pos,
   strlen(e->text + e->pos) + 1);
  e->text[e->pos] = unichar;
  e->pos++;
 }
}

variable_types: key int

variable_types:
unichar
unsigned short

variable_types: len int

variable_types:
clip
char *


decompiled_code:
__int64 __fastcall wc2koi(unsigned __int16 a1)
{
__int64 result; // rax

result = 63LL;
if ( (unsigned __int16)(a1 - 1024) <= 0x5Fu )
result = (unsigned int)(unsigned __int8)LC0[a1 - 1024] - 128;
return result;
}

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

result = 63LL;
if ( (unsigned __int16)(a1 - 1024) <= 0x5Fu )
result = (unsigned int)(unsigned __int8)LC0[a1 - 1024] - 128;
return result;
}

original_code:
static char wc2koi (unsigned short wc) {
 if (wc <= 127)
  return (char)wc;
 if (wc >= 0x400 && wc <= 0x45f)
  return wc2koi_table[wc - 0x400] + 128;
 else
  return '?';
}

canonical_original_code:
static char wc2koi(unsigned short wc) {
 if (wc <= 127)
  return (char)wc;
 if (wc >= 0x400 && wc <= 0x45f)
  return wc2koi_table[wc - 0x400] + 128;
 else
  return '?';
}

variable_types:
wc
unsigned short

return_type: char


decompiled_code:
__int16 __fastcall koi2wc(unsigned __int8 a1)
{
__int16 result; // ax

if ( a1 > 0xBFu )
return (unsigned __int8)koi2wc_table[a1 - 192] + 1024;
switch ( a1 )
{
case 0xA3:
return 1105;
case 0xB3:
return 1025;
case 0xB4:
return 1028;
case 0xA4:
return 1108;
case 0xB6:
return 1030;
case 0xA6:
return 1110;
case 0xB7:
return 1031;
case 0xA7:
return 1111;
case 0xBE:
return 1038;
case 0xAE:
return 1118;
}
result = a1;
if ( a1 == 0xAF )
result = 1066;
return result;
}

canonical_decompiled_code:
__int16 __fastcall func1(unsigned __int8 a1)
{
__int16 result; // ax

if ( a1 > 0xBFu )
return (unsigned __int8)koi2wc_table[a1 - 192] + 1024;
switch ( a1 )
{
case 0xA3:
return 1105;
case 0xB3:
return 1025;
case 0xB4:
return 1028;
case 0xA4:
return 1108;
case 0xB6:
return 1030;
case 0xA6:
return 1110;
case 0xB7:
return 1031;
case 0xA7:
return 1111;
case 0xBE:
return 1038;
case 0xAE:
return 1118;
}
result = a1;
if ( a1 == 0xAF )
result = 1066;
return result;
}

original_code:
static unsigned short koi2wc (char c)
{
 unsigned char uc = c;
 if (uc >= 192 )
  return koi2wc_table[(unsigned char)c - 192] + 0x400;
 else if (uc == '#' + 128)
  return 0x0451;
 else if (uc == '3' + 128)
  return 0x0401;
 else if (uc == '4' + 128)
  return 0x0404;
 else if (uc == '$' + 128)
  return 0x0454;
 else if (uc == '6' + 128)
  return 0x0406;
 else if (uc == '&' + 128)
  return 0x0456;
 else if (uc == '7' + 128)
  return 0x0407;
 else if (uc == '\'' + 128)
  return 0x0457;
 else if (uc == '>' + 128)
  return 0x040e;
 else if (uc == '.' + 128)
  return 0x045e;
 else if (uc == '/' + 128)
  return 0x042a;
 else
  return (unsigned short)(unsigned char)c;
}

canonical_original_code:
static unsigned short koi2wc(char c)
{
 unsigned char uc = c;
 if (uc >= 192 )
  return koi2wc_table[(unsigned char)c - 192] + 0x400;
 else if (uc == '#' + 128)
  return 0x0451;
 else if (uc == '3' + 128)
  return 0x0401;
 else if (uc == '4' + 128)
  return 0x0404;
 else if (uc == '$' + 128)
  return 0x0454;
 else if (uc == '6' + 128)
  return 0x0406;
 else if (uc == '&' + 128)
  return 0x0456;
 else if (uc == '7' + 128)
  return 0x0407;
 else if (uc == '\'' + 128)
  return 0x0457;
 else if (uc == '>' + 128)
  return 0x040e;
 else if (uc == '.' + 128)
  return 0x045e;
 else if (uc == '/' + 128)
  return 0x042a;
 else
  return (unsigned short)(unsigned char)c;
}

variable_types: c char

variable_types:
uc
unsigned char

return_type: unsigned short


decompiled_code:
__int64 __fastcall cp1251towc(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 > 0xBFu )
return (unsigned int)a1 + 848;
switch ( a1 )
{
case 0xA8:
return 1025LL;
case 0xB8:
return 1105LL;
case 0xAA:
return 1028LL;
case 0xBA:
return 1108LL;
case 0xB2:
return 1030LL;
case 0xB3:
return 1110LL;
case 0xAF:
return 1031LL;
case 0xBF:
return 1111LL;
case 0xA1:
return 1038LL;
}
result = 1118LL;
if ( a1 != 0xA2 )
result = a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned __int8 a1)
{
__int64 result; // rax

if ( a1 > 0xBFu )
return (unsigned int)a1 + 848;
switch ( a1 )
{
case 0xA8:
return 1025LL;
case 0xB8:
return 1105LL;
case 0xAA:
return 1028LL;
case 0xBA:
return 1108LL;
case 0xB2:
return 1030LL;
case 0xB3:
return 1110LL;
case 0xAF:
return 1031LL;
case 0xBF:
return 1111LL;
case 0xA1:
return 1038LL;
}
result = 1118LL;
if ( a1 != 0xA2 )
result = a1;
return result;
}

original_code:
static unsigned short cp1251towc (char c)
{
 unsigned char uc = c;
 if (uc >= 192)
  return 0x0410 + (uc - 192);
 else if (uc == 168)
  return 0x0401;
 else if (uc == 184)
  return 0x0451;
 else if (uc == 170)
  return 0x0404;
 else if (uc == 186)
  return 0x0454;
 else if (uc == 178)
  return 0x0406;
 else if (uc == 179)
  return 0x0456;
 else if (uc == 175)
  return 0x0407;
 else if (uc == 191)
  return 0x0457;
 else if (uc == 161)
  return 0x040e;
 else if (uc == 162)
  return 0x045e;
 return (unsigned short)uc;
}

canonical_original_code:
static unsigned short cp1251towc(char c)
{
 unsigned char uc = c;
 if (uc >= 192)
  return 0x0410 + (uc - 192);
 else if (uc == 168)
  return 0x0401;
 else if (uc == 184)
  return 0x0451;
 else if (uc == 170)
  return 0x0404;
 else if (uc == 186)
  return 0x0454;
 else if (uc == 178)
  return 0x0406;
 else if (uc == 179)
  return 0x0456;
 else if (uc == 175)
  return 0x0407;
 else if (uc == 191)
  return 0x0457;
 else if (uc == 161)
  return 0x040e;
 else if (uc == 162)
  return 0x045e;
 return (unsigned short)uc;
}


decompiled_code:
char *__fastcall encode_say(unsigned __int16 *a1)
{
unsigned __int16 v1; // ax
unsigned __int16 *v2; // rbx
__int64 v3; // rsi
unsigned __int64 v4; // rdx
char *v5; // rcx
unsigned __int16 v6; // ax
char *result; // rax
__int64 v8; // rax

v1 = *a1;
if ( *a1 )
{
v2 = a1;
while ( v1 <= 0xFFu )
{
v1 = v2[1];
++v2;
if ( !v1 )
goto LABEL_14;
}
v3 = wcs2str(a1);
v4 = v2 - a1 + 1;
if ( v4 > 0x400 )
v4 = 1024LL;
strlcpy(buf_3, v3, v4);
strlcat(buf_3, "=`k8:", 1024LL);
v5 = &buf_3[strlen(buf_3)];
v6 = *v2;
if ( *v2 )
{
do
{
++v5;
if ( v6 > 0xFFu )
LOBYTE(v6) = wc2koi(v6);
++v2;
*(v5 - 1) = v6;
v6 = *v2;
}
while ( *v2 && (unsigned __int64)(v5 - buf_3) <= 0x3FF );
}
strcpy(v5, "`=");
result = buf_3;
}
else
{
LABEL_14:
v8 = wcs2str(a1);
strlcpy(buf_3, v8, 1024LL);
result = buf_3;
}
return result;
}

canonical_decompiled_code:
char *__fastcall func5(unsigned __int16 *a1)
{
unsigned __int16 v1; // ax
unsigned __int16 *v2; // rbx
__int64 v3; // rsi
unsigned __int64 v4; // rdx
char *v5; // rcx
unsigned __int16 v6; // ax
char *result; // rax
__int64 v8; // rax

v1 = *a1;
if ( *a1 )
{
v2 = a1;
while ( v1 <= 0xFFu )
{
v1 = v2[1];
++v2;
if ( !v1 )
goto LABEL_14;
}
v3 = wcs2str(a1);
v4 = v2 - a1 + 1;
if ( v4 > 0x400 )
v4 = 1024LL;
strlcpy(buf_3, v3, v4);
strlcat(buf_3, "=`k8:", 1024LL);
v5 = &buf_3[strlen(buf_3)];
v6 = *v2;
if ( *v2 )
{
do
{
++v5;
if ( v6 > 0xFFu )
LOBYTE(v6) = func0(v6);
++v2;
*(v5 - 1) = v6;
v6 = *v2;
}
while ( *v2 && (unsigned __int64)(v5 - buf_3) <= 0x3FF );
}
strcpy(v5, "`=");
result = buf_3;
}
else
{
LABEL_14:
v8 = wcs2str(a1);
strlcpy(buf_3, v8, 1024LL);
result = buf_3;
}
return result;
}

original_code:
char *encode_say (unsigned short *in)
{
 static char buf[1024];
 unsigned short *p;
 char *out;
 for (p = in; *p; p++)
  if (*p > 255)
   goto encode;
 strlcpy (buf, wcs2str(in), sizeof(buf));
 return buf;
encode:
 strlcpy (buf, wcs2str(in), ((p - in + 1) < (sizeof(buf)) ? (p - in + 1) : (sizeof(buf))));
 in = p;
 strlcat (buf, "=`k8:", sizeof(buf));
 out = buf + strlen(buf);
 while (*in && (out - buf < sizeof(buf)/sizeof(buf[0])))
 {
  if (*in <= 255)
   *out++ = *in;
  else {
   *out++ = wc2koi(*in);
  }
  in++;
 }
 *out++ = '`';
 *out++ = '=';
 *out++ = 0;
 return buf;
}

canonical_original_code:
char *encode_say(unsigned short *in)
{
 static char buf[1024];
 unsigned short *p;
 char *out;
 for (p = in; *p; p++)
  if (*p > 255)
   goto encode;
 strlcpy (buf, wcs2str(in), sizeof(buf));
 return buf;
encode:
 strlcpy (buf, wcs2str(in), ((p - in + 1) < (sizeof(buf)) ? (p - in + 1) : (sizeof(buf))));
 in = p;
 strlcat (buf, "=`k8:", sizeof(buf));
 out = buf + strlen(buf);
 while (*in && (out - buf < sizeof(buf)/sizeof(buf[0])))
 {
  if (*in <= 255)
   *out++ = *in;
  else {
   *out++ = wc2koi(*in);
  }
  in++;
 }
 *out++ = '`';
 *out++ = '=';
 *out++ = 0;
 return buf;
}

variable_types:
in
unsigned short *

variable_types:
buf
char [1024]

variable_types:
p
unsigned short *

variable_types:
out
char *


decompiled_code:
void *__fastcall maybe_transliterate(unsigned __int16 *a1)
{
unsigned __int16 *v1; // rbp
_WORD *v2; // rbx
__int16 *v3; // r14
unsigned __int64 v4; // r8
int v5; // eax
void *v6; // rdi
size_t v7; // r12

v1 = a1;
v2 = &buf_0;
if ( *a1 )
{
do
{
if ( (unsigned int)R_CharAvailable() )
{
*v2++ = *v1;
}
else
{
v3 = transliterate_char(*v1);
v4 = qwcslen(v3);
v5 = &word_1C9E - v2;
if ( v4 < &word_1C9E - v2 )
v5 = qwcslen(v3);
v6 = v2;
v7 = 2LL * v5;
v2 = (_WORD *)((char *)v2 + v7);
memcpy(v6, v3, v7);
}
++v1;
}
while ( v2 < &word_1C9E && *v1 );
}
*v2 = 0;
return &buf_0;
}

canonical_decompiled_code:
void *__fastcall func6(unsigned __int16 *a1)
{
unsigned __int16 *v1; // rbp
_WORD *v2; // rbx
__int16 *v3; // r14
unsigned __int64 v4; // r8
int v5; // eax
void *v6; // rdi
size_t v7; // r12

v1 = a1;
v2 = &buf_0;
if ( *a1 )
{
do
{
if ( (unsigned int)R_CharAvailable() )
{
*v2++ = *v1;
}
else
{
v3 = transliterate_char(*v1);
v4 = qwcslen(v3);
v5 = &word_1C9E - v2;
if ( v4 < &word_1C9E - v2 )
v5 = qwcslen(v3);
v6 = v2;
v7 = 2LL * v5;
v2 = (_WORD *)((char *)v2 + v7);
memcpy(v6, v3, v7);
}
++v1;
}
while ( v2 < &word_1C9E && *v1 );
}
*v2 = 0;
return &buf_0;
}

original_code:
unsigned short *maybe_transliterate (unsigned short *src)
{
 unsigned short *dst, *trans;
 static unsigned short buf[2048];
 int len;
 dst = buf;
 while (*src && dst < buf+(sizeof(buf)/sizeof(buf[0]))-1) {
  if (R_CharAvailable(*src))
   *dst++ = *src;
  else {
   trans = transliterate_char (*src);
   len = ((qwcslen(trans)) < (buf+(sizeof(buf)/sizeof(buf[0]))-1 - dst) ? (qwcslen(trans)) : (buf+(sizeof(buf)/sizeof(buf[0]))-1 - dst));
   memcpy (dst, trans, len*sizeof(unsigned short));
   dst += len;
  }
  src++;
 }
 *dst = 0;
 return buf;
}

canonical_original_code:
unsigned short *maybe_transliterate(unsigned short *src)
{
 unsigned short *dst; unsigned short *trans;
 static unsigned short buf[2048];
 int len;
 dst = buf;
 while (*src && dst < buf+(sizeof(buf)/sizeof(buf[0]))-1) {
  if (R_CharAvailable(*src))
   *dst++ = *src;
  else {
   trans = transliterate_char (*src);
   len = ((qwcslen(trans)) < (buf+(sizeof(buf)/sizeof(buf[0]))-1 - dst) ? (qwcslen(trans)) : (buf+(sizeof(buf)/sizeof(buf[0]))-1 - dst));
   memcpy (dst, trans, len*sizeof(unsigned short));
   dst += len;
  }
  src++;
 }
 *dst = 0;
 return buf;
}

variable_types:
src
unsigned short *

variable_types:
dst
unsigned short *

variable_types:
trans
unsigned short *

variable_types:
buf
unsigned short [2048]

return_type: unsigned short *


decompiled_code:
void *__fastcall decode_string(char *haystack)
{
char *v1; // r12
char *v2; // rbp
char *v3; // rbx
__int64 v4; // r13
__int64 v5; // rbp
char *v6; // rdi
char *v7; // r12
__int64 v8; // rax
const unsigned __int16 *v9; // rsi
unsigned __int8 *i; // rax
__int64 v11; // rdx
char *v12; // rax
char *v13; // r12
char *v14; // rsi
unsigned __int64 v15; // rdx
__int64 v16; // rbp
const char *v17; // rsi
void *v18; // rbp
__int64 v19; // rax
char s1[13]; // [rsp+3h] [rbp-435h] BYREF
char v22[1064]; // [rsp+10h] [rbp-428h] BYREF

v1 = haystack;
v2 = haystack;
buf_2[0] = 0;
while ( 1 )
{
v3 = strstr(v2, "=`");
if ( !v3 )
break;
v4 = 2048LL;
v5 = v3 - v1 + 1;
if ( (unsigned __int64)(v5 + qwcslen(buf_2)) <= 0x7FF )
v4 = qwcslen(buf_2) + v5;
v6 = v1;
v7 = v3 + 2;
v8 = str2wcs(v6);
qwcslcat(buf_2, v8, v4);
v9 = *_ctype_b_loc();
for ( i = (unsigned __int8 *)(v3 + 2); ; ++i )
{
v11 = *i;
if ( (v9[v11] & 8) == 0 || i - (unsigned __int8 *)v7 > 11 )
break;
}
if ( !(_BYTE)v11 )
{
v1 = v3;
break;
}
v2 = v3 + 4;
if ( (_BYTE)v11 == 58 )
{
v2 = (char *)(i + 1);
strlcpy(s1, v3 + 2, i + 1 - (unsigned __int8 *)v7);
v12 = strstr(v2, "`=");
v13 = v12;
if ( v12 )
{
v14 = v2;
v15 = v12 - v2 + 1;
if ( v15 > 0x400 )
v15 = 1024LL;
v16 = 0LL;
strlcpy(v22, v14, v15);
v17 = "koi8q";
while ( strcasecmp(s1, v17) )
{
++v16;
v17 = (&decode_table)[2 * v16];
if ( !v17 )
{
v2 = v13 + 2;
goto LABEL_11;
}
}
v18 = (void *)((__int64 (__fastcall *)(const char *))*(&off_3188 + 2 * (int)v16))(v22);
qwcslcat(buf_2, v18, 2048LL);
if ( v18 )
free(v18);
v3 = v13 + 2;
v2 = v13 + 2;
}
}
LABEL_11:
v1 = v3;
}
v19 = str2wcs(v1);
qwcslcat(buf_2, v19, 2048LL);
return maybe_transliterate(buf_2);
}

original_code:
unsigned short *decode_string (const char *s)
{
 static unsigned short buf[2048];
 char encoding[13];
 char enc_str[1024];
 const char *p, *q, *r;
 unsigned short *decoded;
 int i;
 buf[0] = 0;
 p = s;
 while (1)
 {
  p = strstr(p, "=`");
  if (!p)
   break;
  qwcslcat (buf, str2wcs(s), ((p-s+qwcslen(buf)+1) < (sizeof(buf)/sizeof(buf[0])) ? (p-s+qwcslen(buf)+1) : (sizeof(buf)/sizeof(buf[0]))));
  s = p;
  p += 2;
  for (q = p; ((*__ctype_b_loc ())[(int) ((*q))] & (unsigned short int) _ISalnum) && q - p < 12; q++) {
   ;
  }
  if (!*q)
   break;
  if (*q != ':') {
   p += 2;
   continue;
  }
  q++;
  ((void) (0));
  strlcpy (encoding, p, q - p);
  r = strstr(q, "`=");
  if (!r) {
   p = q;
   continue;
  }
  strlcpy (enc_str, q, ((r - q + 1) < (sizeof(enc_str)) ? (r - q + 1) : (sizeof(enc_str))));
  for (i = 0; decode_table[i].name; i++) {
   if (!strcasecmp(encoding, decode_table[i].name))
    break;
  }
  if (!decode_table[i].name) {
   p = r + 2;
   continue;
  }
  decoded = decode_table[i].func(enc_str);
  qwcslcat (buf, decoded, sizeof(buf)/sizeof(buf[0]));
  if(decoded) { free(decoded); decoded = ((void *)0); };
  s = p = r + 2;
 }
 qwcslcat (buf, str2wcs(s), sizeof(buf)/sizeof(buf[0]));
 return maybe_transliterate(buf);
}

canonical_original_code:
unsigned short *decode_string(char *s)
{
 static unsigned short buf[2048];
 char encoding[13];
 char enc_str[1024];
 char *p; char *q; char *r;
 unsigned short *decoded;
 int i;
 buf[0] = 0;
 p = s;
 while (1)
 {
  p = strstr(p, "=`");
  if (!p)
   break;
  qwcslcat (buf, str2wcs(s), ((p-s+qwcslen(buf)+1) < (sizeof(buf)/sizeof(buf[0])) ? (p-s+qwcslen(buf)+1) : (sizeof(buf)/sizeof(buf[0]))));
  s = p;
  p += 2;
  for (q = p; ((*__ctype_b_loc ())[(int) ((*q))] & (unsigned short) _ISalnum) && q - p < 12; q++) {
   ;
  }
  if (!*q)
   break;
  if (*q != ':') {
   p += 2;
   continue;
  }
  q++;
  ((void) (0));
  strlcpy (encoding, p, q - p);
  r = strstr(q, "`=");
  if (!r) {
   p = q;
   continue;
  }
  strlcpy (enc_str, q, ((r - q + 1) < (sizeof(enc_str)) ? (r - q + 1) : (sizeof(enc_str))));
  for (i = 0; decode_table[i].name; i++) {
   if (!strcasecmp(encoding, decode_table[i].name))
    break;
  }
  if (!decode_table[i].name) {
   p = r + 2;
   continue;
  }
  decoded = decode_table[i].func(enc_str);
  qwcslcat (buf, decoded, sizeof(buf)/sizeof(buf[0]));
  if(decoded) { free(decoded); decoded = ((void *)0); };
  s = p = r + 2;
 }
 qwcslcat (buf, str2wcs(s), sizeof(buf)/sizeof(buf[0]));
 return maybe_transliterate(buf);
}

variable_types:
s
char *

variable_types:
encoding
char [13]

variable_types:
p
char *

variable_types:
q
char *

variable_types:
r
char *

variable_types:
decoded
unsigned short *

variable_types: i int