repo: bradharding/doomretro

decompiled_code:
__int64 I_InitMusic()
{
char v1[2]; // [rsp+6h] [rbp-12h] BYREF
int v2; // [rsp+8h] [rbp-10h] BYREF
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = 22050;
if ( !(unsigned int)Mix_QuerySpec(&v2, v1, v3)
&& (int)Mix_OpenAudioDevice(44100LL, 32784LL, 2LL, 1024LL, 0LL, 1LL) < 0 )
{
return 0LL;
}
music_initialized = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
char v1[2]; // [rsp+6h] [rbp-12h] BYREF
int v2; // [rsp+8h] [rbp-10h] BYREF
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = 22050;
if ( !(unsigned int)Mix_QuerySpec(&v2, v1, v3)
&& (int)Mix_OpenAudioDevice(44100LL, 32784LL, 2LL, 1024LL, 0LL, 1LL) < 0 )
{
return 0LL;
}
music_initialized = 1;
return 1LL;
}

original_code:
_Bool I_InitMusic(void)
{
    int freq = 22050;
    int channels;
    uint16_t format;
    if (!Mix_QuerySpec(&freq, &format, &channels))
        if (Mix_OpenAudioDevice(44100, 0x8010, 2,
            1024, ((void *)0), 0x00000001) < 0)
            return 0;
    music_initialized = 1;
    return music_initialized;
}

canonical_original_code:
_Bool I_InitMusic()
{
    int freq = 22050;
    int channels;
    unsigned short format;
    if (!Mix_QuerySpec(&freq, &format, &channels))
        if (Mix_OpenAudioDevice(44100, 0x8010, 2,
            1024, ((void *)0), 0x00000001) < 0)
            return 0;
    music_initialized = 1;
    return music_initialized;
}

variable_types: freq int

variable_types: channels int

variable_types:
format
unsigned short


decompiled_code:
__int64 __fastcall I_SetMusicVolume(int a1)
{
current_music_volume = a1;
return Mix_VolumeMusic();
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
current_music_volume = a1;
return Mix_VolumeMusic();
}

original_code:
void I_SetMusicVolume(int volume)
{
    current_music_volume = volume;
    Mix_VolumeMusic(current_music_volume);
}

variable_types: volume int

return_type: void


decompiled_code:
__int64 __fastcall I_PlaySong(__int64 a1, char a2)
{
__int64 result; // rax

if ( music_initialized )
result = Mix_PlayMusic(a1, a2 == 0 ? 1 : -1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2)
{
__int64 result; // rax

if ( music_initialized )
result = Mix_PlayMusic(a1, a2 == 0 ? 1 : -1);
return result;
}

original_code:
void I_PlaySong(void *handle, _Bool looping)
{
    if (!music_initialized)
        return;
    Mix_PlayMusic(handle, (looping ? -1 : 1));
}

variable_types:
handle
void *


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

if ( music_initialized )
{
if ( midimusictype )
{
paused_midi_volume = current_music_volume;
result = Mix_VolumeMusic(0LL);
}
else
{
result = Mix_PauseMusic();
}
}
return result;
}

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

if ( music_initialized )
{
if ( midimusictype )
{
paused_midi_volume = current_music_volume;
result = Mix_VolumeMusic(0LL);
}
else
{
result = Mix_PauseMusic();
}
}
return result;
}

original_code:
void I_PauseSong(void)
{
    if (!music_initialized)
        return;
    if (midimusictype)
    {
        paused_midi_volume = current_music_volume;
        Mix_VolumeMusic(0);
    }
    else
        Mix_PauseMusic();
}

canonical_original_code:
void I_PauseSong()
{
    if (!music_initialized)
        return;
    if (midimusictype)
    {
        paused_midi_volume = current_music_volume;
        Mix_VolumeMusic(0);
    }
    else
        Mix_PauseMusic();
}


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

if ( music_initialized )
{
if ( midimusictype )
result = Mix_VolumeMusic((unsigned int)paused_midi_volume);
else
result = Mix_ResumeMusic();
}
return result;
}

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

if ( music_initialized )
{
if ( midimusictype )
result = Mix_VolumeMusic((unsigned int)paused_midi_volume);
else
result = Mix_ResumeMusic();
}
return result;
}

original_code:
void I_ResumeSong(void)
{
    if (!music_initialized)
        return;
    if (midimusictype)
        Mix_VolumeMusic(paused_midi_volume);
    else
        Mix_ResumeMusic();
}

canonical_original_code:
void I_ResumeSong()
{
    if (!music_initialized)
        return;
    if (midimusictype)
        Mix_VolumeMusic(paused_midi_volume);
    else
        Mix_ResumeMusic();
}


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

if ( music_initialized )
result = Mix_HaltMusic();
return result;
}

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

if ( music_initialized )
result = Mix_HaltMusic();
return result;
}

original_code:
void I_StopSong(void)
{
    if (!music_initialized)
        return;
    Mix_HaltMusic();
}

canonical_original_code:
void I_StopSong()
{
    if (!music_initialized)
        return;
    Mix_HaltMusic();
}


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

if ( music_initialized )
{
if ( a1 )
result = Mix_FreeMusic();
}
return result;
}

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

if ( music_initialized )
{
if ( a1 )
result = Mix_FreeMusic();
}
return result;
}

original_code:
void I_UnregisterSong(void *handle)
{
    if (!music_initialized)
        return;
    if (handle)
        Mix_FreeMusic(handle);
}


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

if ( music_initialized )
{
music_initialized = 0;
if ( mus_playing )
I_UnregisterSong(*(_QWORD *)(mus_playing + 96LL));
result = Mix_CloseAudio();
}
return result;
}

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

if ( music_initialized )
{
music_initialized = 0;
if ( mus_playing )
func6(*(_QWORD *)(mus_playing + 96LL));
result = Mix_CloseAudio();
}
return result;
}

original_code:
void I_ShutdownMusic(void)
{
    if (!music_initialized)
        return;
    music_initialized = 0;
    if (mus_playing)
        I_UnregisterSong(mus_playing->handle);
    Mix_CloseAudio();
}

canonical_original_code:
void I_ShutdownMusic()
{
    if (!music_initialized)
        return;
    music_initialized = 0;
    if (mus_playing)
        I_UnregisterSong(mus_playing->handle);
    Mix_CloseAudio();
}


ABS

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

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

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

variable_types: a int

return_type: int


variable_types: number int

variable_types: color int

variable_types: shadow int

variable_types: x int

variable_types: y int

variable_types: struct patch_t { short width; short height; short leftoffset; short topoffset; int columnoffset[16384]; } *

variable_types:
lownums
char *[10]

variable_types: i int

variable_types: j int

variable_types: dot char


variable_types:
highnums
char *[10]

user_defined_types: struct patch_t { short width; short height; short leftoffset; short topoffset; int columnoffset[16384]; }


decompiled_code:
__int64 __fastcall STlib_DrawLowNumPatch(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5, __int64 a6)
{
return V_DrawPatch(a4, a5, 0LL, a6);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, __int64 a3, unsigned int a4, unsigned int a5, __int64 a6)
{
return V_DrawPatch(a4, a5, 0LL, a6);
}

original_code:
static void STlib_DrawLowNumPatch(int number, int color, int shadow, int x, int y, patch_t *patch)
{
    V_DrawPatch(x, y, 0, patch);
}

canonical_original_code:
static void STlib_DrawLowNumPatch(int number, int color, int shadow, int x, int y, struct patch_t *patch)
{
    V_DrawPatch(x, y, 0, patch);
}


original_code:
void STlib_InitNum(st_number_t *n, int x, int y, patch_t **pl, int *num, int width)
{
    n->x = x;
    n->y = y;
    n->width = width;
    n->num = num;
    n->p = pl;
}

canonical_original_code:
void STlib_InitNum(struct st_number_t *n, int x, int y, struct patch_t **pl, int *num, int width)
{
    n->x = x;
    n->y = y;
    n->width = width;
    n->num = num;
    n->p = pl;
}

variable_types: struct st_number_t { int x; int width; int *num; struct patch_t { short width; short height; short leftoffset; short topoffset; int columnoffset[16384]; } **p; int data; } *

variable_types:
pl
struct patch_t **

variable_types:
num
int *

variable_types: width int

user_defined_types: struct st_number_t { int x; int width; int *num; struct patch_t **p; int data; }


decompiled_code:
__int64 __fastcall STlib_UpdateBigAmmoNum(__int64 a1)
{
__int64 result; // rax
__int16 **v2; // rcx
unsigned int v3; // er14
unsigned int v4; // er12
int v5; // ebp
int v6; // ebx

result = **(unsigned int **)(a1 + 16);
if ( (_DWORD)result != 1994 )
{
if ( animatedstats )
LODWORD(result) = *((_DWORD *)&ammodiff + weaponinfo[148 * *(unsigned int *)(viewplayer + 120LL) + 2]) + result;
v2 = *(__int16 ***)(a1 + 24);
v3 = *(_DWORD *)(a1 + 4);
v4 = *(_DWORD *)a1 + ((_DWORD)result == 1);
v5 = **v2;
if ( (_DWORD)result )
{
while ( 1 )
{
v4 -= v5;
v6 = (int)result / 10;
V_DrawPatch(v4, v3, 0LL, v2[(int)result % 10]);
result = v6;
if ( v6 % 10 == 1 )
v4 += tallnum1width < 14;
if ( !v6 )
break;
v2 = *(__int16 ***)(a1 + 24);
}
}
else
{
result = V_DrawPatch(v4 - v5, v3, 0LL, *v2);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 result; // rax
__int16 **v2; // rcx
unsigned int v3; // er14
unsigned int v4; // er12
int v5; // ebp
int v6; // ebx

result = **(unsigned int **)(a1 + 16);
if ( (_DWORD)result != 1994 )
{
if ( animatedstats )
LODWORD(result) = *((_DWORD *)&ammodiff + weaponinfo[148 * *(unsigned int *)(viewplayer + 120LL) + 2]) + result;
v2 = *(__int16 ***)(a1 + 24);
v3 = *(_DWORD *)(a1 + 4);
v4 = *(_DWORD *)a1 + ((_DWORD)result == 1);
v5 = **v2;
if ( (_DWORD)result )
{
while ( 1 )
{
v4 -= v5;
v6 = (int)result / 10;
V_DrawPatch(v4, v3, 0LL, v2[(int)result % 10]);
result = v6;
if ( v6 % 10 == 1 )
v4 += tallnum1width < 14;
if ( !v6 )
break;
v2 = *(__int16 ***)(a1 + 24);
}
}
else
{
result = V_DrawPatch(v4 - v5, v3, 0LL, *v2);
}
}
return result;
}

original_code:
void STlib_UpdateBigAmmoNum(st_number_t *n)
{
    if (*n->num == 1994)
        return;
    else
    {
        int num = *n->num + (animatedstats ? ammodiff[weaponinfo[viewplayer->readyweapon].ammotype] : 0);
        int x = n->x + (num == 1);
        int y = n->y;
        const int width = ((signed short)(n->p[0]->width));
        if (!num)
            V_DrawPatch(x - width, y, 0, n->p[0]);
        else
            while (num)
            {
                V_DrawPatch((x -= width), y, 0, n->p[num % 10]);
                if ((num /= 10) % 10 == 1 && tallnum1width < 14)
                    x++;
            }
    }
}

canonical_original_code:
void STlib_UpdateBigAmmoNum(struct st_number_t *n)
{
    if (*n->num == 1994)
        return;
    else
    {
        int num = *n->num + (animatedstats ? ammodiff[weaponinfo[viewplayer->readyweapon].ammotype] : 0);
        int x = n->x + (num == 1);
        int y = n->y;
        int width = ((signed short)(n->p[0]->width));
        if (!num)
            V_DrawPatch(x - width, y, 0, n->p[0]);
        else
            while (num)
            {
                V_DrawPatch((x -= width), y, 0, n->p[num % 10]);
                if ((num /= 10) % 10 == 1 && tallnum1width < 14)
                    x++;
            }
    }
}

variable_types: num int


decompiled_code:
__int64 __fastcall STlib_UpdateBigArmorNum(__int64 a1)
{
__int64 result; // rax
__int16 **v2; // rcx
unsigned int v3; // er14
unsigned int v4; // er13
int v5; // er12
int v6; // ebx

LODWORD(result) = **(_DWORD **)(a1 + 16);
if ( animatedstats )
LODWORD(result) = armordiff + result;
v2 = *(__int16 ***)(a1 + 24);
v3 = *(_DWORD *)(a1 + 4);
v4 = *(_DWORD *)a1 + ((_DWORD)result == 1);
v5 = **v2;
if ( !(_DWORD)result )
return V_DrawPatch(v4 - v5, v3, 0LL, *v2);
while ( 1 )
{
v4 -= v5;
v6 = (int)result / 10;
V_DrawPatch(v4, v3, 0LL, v2[(int)result % 10]);
result = v6;
if ( v6 % 10 == 1 )
v4 += tallnum1width < 14;
if ( !v6 )
break;
v2 = *(__int16 ***)(a1 + 24);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 result; // rax
__int16 **v2; // rcx
unsigned int v3; // er14
unsigned int v4; // er13
int v5; // er12
int v6; // ebx

LODWORD(result) = **(_DWORD **)(a1 + 16);
if ( animatedstats )
LODWORD(result) = armordiff + result;
v2 = *(__int16 ***)(a1 + 24);
v3 = *(_DWORD *)(a1 + 4);
v4 = *(_DWORD *)a1 + ((_DWORD)result == 1);
v5 = **v2;
if ( !(_DWORD)result )
return V_DrawPatch(v4 - v5, v3, 0LL, *v2);
while ( 1 )
{
v4 -= v5;
v6 = (int)result / 10;
V_DrawPatch(v4, v3, 0LL, v2[(int)result % 10]);
result = v6;
if ( v6 % 10 == 1 )
v4 += tallnum1width < 14;
if ( !v6 )
break;
v2 = *(__int16 ***)(a1 + 24);
}
return result;
}

original_code:
void STlib_UpdateBigArmorNum(st_number_t *n)
{
    int num = *n->num + (animatedstats ? armordiff : 0);
    int x = n->x + (num == 1);
    int y = n->y;
    const int width = ((signed short)(n->p[0]->width));
    if (!num)
        V_DrawPatch(x - width, y, 0, n->p[0]);
    else
        while (num)
        {
            V_DrawPatch((x -= width), y, 0, n->p[num % 10]);
            if ((num /= 10) % 10 == 1 && tallnum1width < 14)
                x++;
        }
}

canonical_original_code:
void STlib_UpdateBigArmorNum(struct st_number_t *n)
{
    int num = *n->num + (animatedstats ? armordiff : 0);
    int x = n->x + (num == 1);
    int y = n->y;
    int width = ((signed short)(n->p[0]->width));
    if (!num)
        V_DrawPatch(x - width, y, 0, n->p[0]);
    else
        while (num)
        {
            V_DrawPatch((x -= width), y, 0, n->p[num % 10]);
            if ((num /= 10) % 10 == 1 && tallnum1width < 14)
                x++;
        }
}


decompiled_code:
__int64 __fastcall STlib_UpdateBigHealthNum(__int64 a1)
{
int v2; // edx
int v3; // edi
int v4; // eax
__int16 **v5; // rcx
unsigned int v6; // er14
unsigned int v7; // er13
int v8; // er12
int v9; // ebx
__int64 result; // rax

v2 = **(_DWORD **)(a1 + 16);
v3 = healthdiff + v2;
if ( !animatedstats )
v3 = v2;
if ( negativehealth )
v4 = ABS(v3);
else
v4 = MAX_constprop_0(v3);
v5 = *(__int16 ***)(a1 + 24);
v6 = *(_DWORD *)(a1 + 4);
v7 = *(_DWORD *)a1 + (v4 == 1);
v8 = **v5;
if ( v4 )
{
while ( 1 )
{
v7 -= v8;
v9 = v4 / 10;
V_DrawPatch(v7, v6, 0LL, v5[v4 % 10]);
v4 = v9;
if ( v9 % 10 == 1 )
v7 += tallnum1width < 14;
if ( !v9 )
break;
v5 = *(__int16 ***)(a1 + 24);
}
}
else
{
V_DrawPatch(v7 - v8, v6, 0LL, *v5);
}
result = **(unsigned int **)(a1 + 16);
if ( animatedstats )
result = (unsigned int)(healthdiff + result);
if ( (int)result < 0 && negativehealth && minuspatch )
{
if ( (unsigned int)(result + 79) <= 9 || (_DWORD)result == -7 )
{
++v7;
}
else if ( (unsigned int)(result + 19) <= 9 || (_DWORD)result == -1 )
{
v7 += 2;
}
result = V_DrawPatch(v7 - minuspatchwidth, v6, 0LL, minuspatch);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
int v2; // edx
int v3; // edi
int v4; // eax
__int16 **v5; // rcx
unsigned int v6; // er14
unsigned int v7; // er13
int v8; // er12
int v9; // ebx
__int64 result; // rax

v2 = **(_DWORD **)(a1 + 16);
v3 = healthdiff + v2;
if ( !animatedstats )
v3 = v2;
if ( negativehealth )
v4 = func0(v3);
else
v4 = func4(v3);
v5 = *(__int16 ***)(a1 + 24);
v6 = *(_DWORD *)(a1 + 4);
v7 = *(_DWORD *)a1 + (v4 == 1);
v8 = **v5;
if ( v4 )
{
while ( 1 )
{
v7 -= v8;
v9 = v4 / 10;
V_DrawPatch(v7, v6, 0LL, v5[v4 % 10]);
v4 = v9;
if ( v9 % 10 == 1 )
v7 += tallnum1width < 14;
if ( !v9 )
break;
v5 = *(__int16 ***)(a1 + 24);
}
}
else
{
V_DrawPatch(v7 - v8, v6, 0LL, *v5);
}
result = **(unsigned int **)(a1 + 16);
if ( animatedstats )
result = (unsigned int)(healthdiff + result);
if ( (int)result < 0 && negativehealth && minuspatch )
{
if ( (unsigned int)(result + 79) <= 9 || (_DWORD)result == -7 )
{
++v7;
}
else if ( (unsigned int)(result + 19) <= 9 || (_DWORD)result == -1 )
{
v7 += 2;
}
result = V_DrawPatch(v7 - minuspatchwidth, v6, 0LL, minuspatch);
}
return result;
}

original_code:
void STlib_UpdateBigHealthNum(st_number_t *n)
{
    int num = (negativehealth ? ABS(*n->num + (animatedstats ? healthdiff : 0)) :
                    MAX(0, *n->num + (animatedstats ? healthdiff : 0)));
    int x = n->x + (num == 1);
    const int y = n->y;
    const int width = ((signed short)(n->p[0]->width));
    if (!num)
        V_DrawPatch(x - width, y, 0, n->p[0]);
    else
    {
        while (num)
        {
            V_DrawPatch((x -= width), y, 0, n->p[num % 10]);
            if ((num /= 10) % 10 == 1 && tallnum1width < 14)
                x++;
        }
    }
    if ((num = *n->num + (animatedstats ? healthdiff : 0)) < 0 && negativehealth && minuspatch)
    {
        if ((num >= -79 && num <= -70) || num == -7)
            x++;
        else if ((num >= -19 && num <= -10) || num == -1)
            x += 2;
        V_DrawPatch(x - minuspatchwidth, y, 0, minuspatch);
    }
}

canonical_original_code:
void STlib_UpdateBigHealthNum(struct st_number_t *n)
{
    int num = (negativehealth ? ABS(*n->num + (animatedstats ? healthdiff : 0)) :
                    MAX(0, *n->num + (animatedstats ? healthdiff : 0)));
    int x = n->x + (num == 1);
    int y = n->y;
    int width = ((signed short)(n->p[0]->width));
    if (!num)
        V_DrawPatch(x - width, y, 0, n->p[0]);
    else
    {
        while (num)
        {
            V_DrawPatch((x -= width), y, 0, n->p[num % 10]);
            if ((num /= 10) % 10 == 1 && tallnum1width < 14)
                x++;
        }
    }
    if ((num = *n->num + (animatedstats ? healthdiff : 0)) < 0 && negativehealth && minuspatch)
    {
        if ((num >= -79 && num <= -70) || num == -7)
            x++;
        else if ((num >= -19 && num <= -10) || num == -1)
            x += 2;
        V_DrawPatch(x - minuspatchwidth, y, 0, minuspatch);
    }
}


decompiled_code:
__int64 __fastcall STlib_UpdateSmallAmmoNum(int *a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int v5; // ebx

LODWORD(result) = MAX_constprop_0(**((_DWORD **)a1 + 2) + *((_DWORD *)&ammodiff + a2));
v3 = *a1;
v4 = a1[1];
if ( !(_DWORD)result )
return statbarnumfunc(0LL, 160LL, 47LL, v3 - 4, v4, **((_QWORD **)a1 + 3));
do
{
v3 -= 4;
v5 = (int)result / 10;
statbarnumfunc((int)result % 10, 160LL, 47LL, v3, v4, *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * ((int)result % 10)));
result = v5;
}
while ( v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func9(int *a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int v5; // ebx

LODWORD(result) = func4(**((_DWORD **)a1 + 2) + *((_DWORD *)&ammodiff + a2));
v3 = *a1;
v4 = a1[1];
if ( !(_DWORD)result )
return statbarnumfunc(0LL, 160LL, 47LL, v3 - 4, v4, **((_QWORD **)a1 + 3));
do
{
v3 -= 4;
v5 = (int)result / 10;
statbarnumfunc((int)result % 10, 160LL, 47LL, v3, v4, *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * ((int)result % 10)));
result = v5;
}
while ( v5 );
return result;
}

original_code:
void STlib_UpdateSmallAmmoNum(st_number_t *n, ammotype_t ammotype)
{
    int num = MAX(0, *n->num + ammodiff[ammotype]);
    int x = n->x;
    int y = n->y;
    if (!num)
        statbarnumfunc(0, 160, 47, x - 4, y, n->p[0]);
    else
        while (num)
        {
            statbarnumfunc(num % 10, 160, 47, (x -= 4), y, n->p[num % 10]);
            num /= 10;
        }
}

canonical_original_code:
void STlib_UpdateSmallAmmoNum(struct st_number_t *n, enum ammotype_t ammotype)
{
    int num = MAX(0, *n->num + ammodiff[ammotype]);
    int x = n->x;
    int y = n->y;
    if (!num)
        statbarnumfunc(0, 160, 47, x - 4, y, n->p[0]);
    else
        while (num)
        {
            statbarnumfunc(num % 10, 160, 47, (x -= 4), y, n->p[num % 10]);
            num /= 10;
        }
}

variable_types: enum ammotype_t { am_clip=0, am_shell=1, am_cell=2, am_misl=3, NUMAMMO=4, am_noammo=5 }


decompiled_code:
__int64 __fastcall STlib_UpdateSmallMaxAmmoNum(int *a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int v5; // ebx

LODWORD(result) = MAX_constprop_0(**((_DWORD **)a1 + 2) + *((_DWORD *)&maxammodiff + a2));
v3 = *a1;
v4 = a1[1];
if ( !(_DWORD)result )
return statbarnumfunc(0LL, 160LL, 47LL, v3 - 4, v4, **((_QWORD **)a1 + 3));
do
{
v3 -= 4;
v5 = (int)result / 10;
statbarnumfunc((int)result % 10, 160LL, 47LL, v3, v4, *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * ((int)result % 10)));
result = v5;
}
while ( v5 );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(int *a1, unsigned int a2)
{
__int64 result; // rax
unsigned int v3; // er12
unsigned int v4; // er13
unsigned int v5; // ebx

LODWORD(result) = func4(**((_DWORD **)a1 + 2) + *((_DWORD *)&maxammodiff + a2));
v3 = *a1;
v4 = a1[1];
if ( !(_DWORD)result )
return statbarnumfunc(0LL, 160LL, 47LL, v3 - 4, v4, **((_QWORD **)a1 + 3));
do
{
v3 -= 4;
v5 = (int)result / 10;
statbarnumfunc((int)result % 10, 160LL, 47LL, v3, v4, *(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * ((int)result % 10)));
result = v5;
}
while ( v5 );
return result;
}

original_code:
void STlib_UpdateSmallMaxAmmoNum(st_number_t *n, ammotype_t ammotype)
{
    int num = MAX(0, *n->num + maxammodiff[ammotype]);
    int x = n->x;
    int y = n->y;
    if (!num)
        statbarnumfunc(0, 160, 47, x - 4, y, n->p[0]);
    else
        while (num)
        {
            statbarnumfunc(num % 10, 160, 47, (x -= 4), y, n->p[num % 10]);
            num /= 10;
        }
}

canonical_original_code:
void STlib_UpdateSmallMaxAmmoNum(struct st_number_t *n, enum ammotype_t ammotype)
{
    int num = MAX(0, *n->num + maxammodiff[ammotype]);
    int x = n->x;
    int y = n->y;
    if (!num)
        statbarnumfunc(0, 160, 47, x - 4, y, n->p[0]);
    else
        while (num)
        {
            statbarnumfunc(num % 10, 160, 47, (x -= 4), y, n->p[num % 10]);
            num /= 10;
        }
}

user_defined_types: enum ammotype_t { am_clip=0, am_shell=1, am_cell=2, am_misl=3, NUMAMMO=4, am_noammo=5 }


decompiled_code:
void __fastcall STlib_InitPercent(__int64 a1, int a2, int a3, __int64 a4, __int64 a5)
{
__int64 v5; // rax

STlib_InitNum(a1, a2, a3, a4, a5, 3);
*(_QWORD *)(a1 + 40) = v5;
}

original_code:
void STlib_InitPercent(st_percent_t *p, int x, int y, patch_t **pl, int *num, patch_t *percent)
{
    STlib_InitNum(&p->n, x, y, pl, num, 3);
    p->p = percent;
}

canonical_original_code:
void STlib_InitPercent(struct st_percent_t *p, int x, int y, struct patch_t **pl, int *num, struct patch_t *percent)
{
    STlib_InitNum(&p->n, x, y, pl, num, 3);
    p->p = percent;
}

variable_types: struct st_percent_t { struct st_number_t { int x; int width; int *num; struct patch_t { short width; short height; short leftoffset; short topoffset; int columnoffset[16384]; } **p; int data; } n; struct patch_t *p; } *

variable_types:
percent
struct patch_t *

user_defined_types: struct st_percent_t { struct st_number_t n; struct patch_t *p; }


decompiled_code:
__int64 __fastcall STlib_UpdateBigArmor(unsigned int *a1, int a2)
{
if ( a2 )
V_DrawPatch(*a1, a1[1], 0LL, *((_QWORD *)a1 + 5));
return STlib_UpdateBigArmorNum((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func12(unsigned int *a1, int a2)
{
if ( a2 )
V_DrawPatch(*a1, a1[1], 0LL, *((_QWORD *)a1 + 5));
return func7((__int64)a1);
}

original_code:
void STlib_UpdateBigArmor(st_percent_t *per, int refresh)
{
    if (refresh)
        V_DrawPatch(per->n.x, per->n.y, 0, per->p);
    STlib_UpdateBigArmorNum(&per->n);
}

canonical_original_code:
void STlib_UpdateBigArmor(struct st_percent_t *per, int refresh)
{
    if (refresh)
        V_DrawPatch(per->n.x, per->n.y, 0, per->p);
    STlib_UpdateBigArmorNum(&per->n);
}

variable_types: refresh int


decompiled_code:
__int64 __fastcall STlib_UpdateBigHealth(unsigned int *a1, int a2)
{
if ( a2 )
V_DrawPatch(*a1, a1[1], 0LL, *((_QWORD *)a1 + 5));
return STlib_UpdateBigHealthNum((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned int *a1, int a2)
{
if ( a2 )
V_DrawPatch(*a1, a1[1], 0LL, *((_QWORD *)a1 + 5));
return func8((__int64)a1);
}

original_code:
void STlib_UpdateBigHealth(st_percent_t *per, int refresh)
{
    if (refresh)
        V_DrawPatch(per->n.x, per->n.y, 0, per->p);
    STlib_UpdateBigHealthNum(&per->n);
}

canonical_original_code:
void STlib_UpdateBigHealth(struct st_percent_t *per, int refresh)
{
    if (refresh)
        V_DrawPatch(per->n.x, per->n.y, 0, per->p);
    STlib_UpdateBigHealthNum(&per->n);
}


original_code:
void STlib_InitMultIcon(st_multicon_t *mi, int x, int y, patch_t **il, int *inum)
{
    mi->x = x;
    mi->y = y;
    mi->oldinum = -1;
    mi->inum = inum;
    mi->patch = il;
}

canonical_original_code:
void STlib_InitMultIcon(struct st_multicon_t *mi, int x, int y, struct patch_t **il, int *inum)
{
    mi->x = x;
    mi->y = y;
    mi->oldinum = -1;
    mi->inum = inum;
    mi->patch = il;
}

variable_types: struct st_multicon_t { int x; int oldinum; int *inum; struct patch_t { short width; short height; short leftoffset; short topoffset; int columnoffset[16384]; } **patch; } *

variable_types: x int

variable_types:
il
struct patch_t **

variable_types:
inum
int *

user_defined_types: struct st_multicon_t { int x; int oldinum; int *inum; struct patch_t **patch; }


decompiled_code:
__int64 __fastcall STlib_UpdateMultIcon(unsigned int *a1, char a2)
{
__int64 result; // rax

result = **((int **)a1 + 2);
if ( (a1[2] != (_DWORD)result || a2) && (_DWORD)result != -1 )
{
V_DrawPatch(*a1, a1[1], 0LL, *(_QWORD *)(*((_QWORD *)a1 + 3) + 8 * result));
result = **((unsigned int **)a1 + 2);
a1[2] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func15(unsigned int *a1, char a2)
{
__int64 result; // rax

result = **((int **)a1 + 2);
if ( (a1[2] != (_DWORD)result || a2) && (_DWORD)result != -1 )
{
V_DrawPatch(*a1, a1[1], 0LL, *(_QWORD *)(*((_QWORD *)a1 + 3) + 8 * result));
result = **((unsigned int **)a1 + 2);
a1[2] = result;
}
return result;
}

original_code:
void STlib_UpdateMultIcon(st_multicon_t *mi, _Bool refresh)
{
    if ((mi->oldinum != *mi->inum || refresh) && *mi->inum != -1)
    {
        V_DrawPatch(mi->x, mi->y, 0, mi->patch[*mi->inum]);
        mi->oldinum = *mi->inum;
    }
}

canonical_original_code:
void STlib_UpdateMultIcon(struct st_multicon_t *mi, _Bool refresh)
{
    if ((mi->oldinum != *mi->inum || refresh) && *mi->inum != -1)
    {
        V_DrawPatch(mi->x, mi->y, 0, mi->patch[*mi->inum]);
        mi->oldinum = *mi->inum;
    }
}


decompiled_code:
signed int *__fastcall STlib_UpdateSmallWeaponNum(unsigned int *a1, char a2, int a3)
{
signed int *result; // rax
signed int v4; // ebp

result = (signed int *)*((_QWORD *)a1 + 2);
v4 = *result;
if ( (a1[2] != *result || a2) && v4 != -1 )
{
result = (signed int *)statbarnumfunc(
(unsigned int)(a3 + 2),
v4 == 0 ? 93 : 160,
47LL,
*a1,
a1[1],
*(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * v4));
a1[2] = v4;
}
return result;
}

canonical_decompiled_code:
signed int *__fastcall func16(unsigned int *a1, char a2, int a3)
{
signed int *result; // rax
signed int v4; // ebp

result = (signed int *)*((_QWORD *)a1 + 2);
v4 = *result;
if ( (a1[2] != *result || a2) && v4 != -1 )
{
result = (signed int *)statbarnumfunc(
(unsigned int)(a3 + 2),
v4 == 0 ? 93 : 160,
47LL,
*a1,
a1[1],
*(_QWORD *)(*((_QWORD *)a1 + 3) + 8LL * v4));
a1[2] = v4;
}
return result;
}

original_code:
void STlib_UpdateSmallWeaponNum(st_multicon_t *mi, _Bool refresh, int i)
{
    const int inum = *mi->inum;
    if ((mi->oldinum != inum || refresh) && inum != -1)
    {
        statbarnumfunc(i + 2, (inum ? 160 : 93), 47, mi->x, mi->y, mi->patch[inum]);
        mi->oldinum = inum;
    }
}

canonical_original_code:
void STlib_UpdateSmallWeaponNum(struct st_multicon_t *mi, _Bool refresh, int i)
{
    int inum = *mi->inum;
    if ((mi->oldinum != inum || refresh) && inum != -1)
    {
        statbarnumfunc(i + 2, (inum ? 160 : 93), 47, mi->x, mi->y, mi->patch[inum]);
        mi->oldinum = inum;
    }
}

variable_types: i int

variable_types: inum int


decompiled_code:
void *STLib_Init()
{
void *result; // rax

result = STlib_DrawLowNumPatch;
if ( usesmallnums )
{
result = STlib_DrawHighNum;
if ( r_detail != 1 )
result = STlib_DrawLowNum;
}
statbarnumfunc = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))result;
return result;
}

canonical_decompiled_code:
void *func17()
{
void *result; // rax

result = STlib_DrawLowNumPatch;
if ( usesmallnums )
{
result = STlib_DrawHighNum;
if ( r_detail != 1 )
result = STlib_DrawLowNum;
}
statbarnumfunc = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))result;
return result;
}

original_code:
void STLib_Init(void)
{
    statbarnumfunc = (!usesmallnums ? &STlib_DrawLowNumPatch :
        (r_detail == r_detail_high ? &STlib_DrawHighNum : &STlib_DrawLowNum));
}

canonical_original_code:
void STLib_Init()
{
    statbarnumfunc = (!usesmallnums ? &STlib_DrawLowNumPatch :
        (r_detail == r_detail_high ? &STlib_DrawHighNum : &STlib_DrawLowNum));
}


AllocatedSoundLink

decompiled_code:
__int64 __fastcall AllocatedSoundLink(__int64 a1)
{
__int64 result; // rax
bool v2; // zf

result = allocated_sounds_head;
v2 = allocated_sounds_tail == 0;
*(_QWORD *)(a1 + 40) = 0LL;
allocated_sounds_head = a1;
*(_QWORD *)(a1 + 48) = result;
if ( v2 )
allocated_sounds_tail = a1;
else
*(_QWORD *)(result + 40) = a1;
return result;
}

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

result = allocated_sounds_head;
v2 = allocated_sounds_tail == 0;
*(_QWORD *)(a1 + 40) = 0LL;
allocated_sounds_head = a1;
*(_QWORD *)(a1 + 48) = result;
if ( v2 )
allocated_sounds_tail = a1;
else
*(_QWORD *)(result + 40) = a1;
return result;
}

original_code:
static void AllocatedSoundLink(allocated_sound_t *snd)
{
    snd->prev = ((void *)0);
    snd->next = allocated_sounds_head;
    allocated_sounds_head = snd;
    if (!allocated_sounds_tail)
        allocated_sounds_tail = snd;
    else
        snd->next->prev = snd;
}

canonical_original_code:
static void AllocatedSoundLink(struct allocated_sound_s *snd)
{
    snd->prev = ((void *)0);
    snd->next = allocated_sounds_head;
    allocated_sounds_head = snd;
    if (!allocated_sounds_tail)
        allocated_sounds_tail = snd;
    else
        snd->next->prev = snd;
}

variable_types: struct allocated_sound_s { struct sfxinfo_t { char name1[9]; char name2[9]; int singularity; int priority; int lumpnum; } *sfxinfo; struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; } chunk; int use_count; int pitch; struct allocated_sound_s *prev; struct allocated_sound_s *next; } *

user_defined_types: struct allocated_sound_s { struct sfxinfo_t *sfxinfo; struct Mix_Chunk chunk; int use_count; int pitch; struct allocated_sound_s *prev; struct allocated_sound_s *next; }


LockAllocatedSound

decompiled_code:
__int64 __fastcall LockAllocatedSound(__int64 a1)
{
++*(_DWORD *)(a1 + 32);
AllocatedSoundUnlink(a1);
return AllocatedSoundLink(a1);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
++*(_DWORD *)(a1 + 32);
func1(a1);
return func0(a1);
}

original_code:
static void LockAllocatedSound(allocated_sound_t *snd)
{
    snd->use_count++;
    AllocatedSoundUnlink(snd);
    AllocatedSoundLink(snd);
}

canonical_original_code:
static void LockAllocatedSound(struct allocated_sound_s *snd)
{
    snd->use_count++;
    AllocatedSoundUnlink(snd);
    AllocatedSoundLink(snd);
}

user_defined_types: struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; }

user_defined_types: struct sfxinfo_t { char name1[9]; char name2[9]; int singularity; int priority; int lumpnum; }


UnlockAllocatedSound

decompiled_code:
void __fastcall UnlockAllocatedSound(__int64 a1)
{
--*(_DWORD *)(a1 + 32);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1)
{
--*(_DWORD *)(a1 + 32);
}

original_code:
static void UnlockAllocatedSound(allocated_sound_t *snd)
{
    snd->use_count--;
}

canonical_original_code:
static void UnlockAllocatedSound(struct allocated_sound_s *snd)
{
    snd->use_count--;
}


GetAllocatedSoundBySfxInfoAndPitch

decompiled_code:
__int64 __fastcall GetAllocatedSoundBySfxInfoAndPitch(__int64 a1, int a2)
{
__int64 result; // rax

for ( result = allocated_sounds_head; result; result = *(_QWORD *)(result + 48) )
{
if ( *(_QWORD *)result == a1 && *(_DWORD *)(result + 36) == a2 )
break;
}
return result;
}

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

for ( result = allocated_sounds_head; result; result = *(_QWORD *)(result + 48) )
{
if ( *(_QWORD *)result == a1 && *(_DWORD *)(result + 36) == a2 )
break;
}
return result;
}

original_code:
static allocated_sound_t *GetAllocatedSoundBySfxInfoAndPitch(const sfxinfo_t *sfxinfo, const int pitch)
{
    allocated_sound_t *p = allocated_sounds_head;
    while (p)
    {
        if (p->sfxinfo == sfxinfo && p->pitch == pitch)
            return p;
        p = p->next;
    }
    return ((void *)0);
}

canonical_original_code:
static struct allocated_sound_s *GetAllocatedSoundBySfxInfoAndPitch(struct sfxinfo_t *sfxinfo, int pitch)
{
    struct allocated_sound_s *p = allocated_sounds_head;
    while (p)
    {
        if (p->sfxinfo == sfxinfo && p->pitch == pitch)
            return p;
        p = p->next;
    }
    return ((void *)0);
}

variable_types:
sfxinfo
struct sfxinfo_t *

variable_types: pitch int

return_type: struct allocated_sound_s { struct sfxinfo_t { char name1[9]; char name2[9]; int singularity; int priority; int lumpnum; } *sfxinfo; struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; } chunk; int use_count; int pitch; struct allocated_sound_s *prev; struct allocated_sound_s *next; } *


FreeAllocatedSound

decompiled_code:
void __fastcall FreeAllocatedSound(void *ptr)
{
AllocatedSoundUnlink((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
func1((__int64)ptr);
free(ptr);
}

original_code:
static void FreeAllocatedSound(allocated_sound_t *snd)
{
    AllocatedSoundUnlink(snd);
    free(snd);
}

canonical_original_code:
static void FreeAllocatedSound(struct allocated_sound_s *snd)
{
    AllocatedSoundUnlink(snd);
    free(snd);
}


FindAndFreeSound

decompiled_code:
__int64 FindAndFreeSound()
{
__int64 v0; // rdi

v0 = allocated_sounds_tail;
if ( !allocated_sounds_tail )
return 0LL;
while ( *(_DWORD *)(v0 + 32) )
{
v0 = *(_QWORD *)(v0 + 40);
if ( !v0 )
return 0LL;
}
FreeAllocatedSound((void *)v0);
return 1LL;
}

canonical_decompiled_code:
__int64 func6()
{
__int64 v0; // rdi

v0 = allocated_sounds_tail;
if ( !allocated_sounds_tail )
return 0LL;
while ( *(_DWORD *)(v0 + 32) )
{
v0 = *(_QWORD *)(v0 + 40);
if ( !v0 )
return 0LL;
}
func5((void *)v0);
return 1LL;
}

original_code:
static _Bool FindAndFreeSound(void)
{
    allocated_sound_t *snd = allocated_sounds_tail;
    while (snd)
    {
        if (!snd->use_count)
        {
            FreeAllocatedSound(snd);
            return 1;
        }
        snd = snd->prev;
    }
    return 0;
}

canonical_original_code:
static _Bool FindAndFreeSound()
{
    struct allocated_sound_s *snd = allocated_sounds_tail;
    while (snd)
    {
        if (!snd->use_count)
        {
            FreeAllocatedSound(snd);
            return 1;
        }
        snd = snd->prev;
    }
    return 0;
}


ExpandSoundData

original_code:
static void ExpandSoundData(sfxinfo_t *sfxinfo, const byte *data, const int samplerate, const int bits, const int length)
{
    const unsigned int samplecount = length / (bits / 8);
    const unsigned int expanded_length = (unsigned int)(((uint64_t)samplecount * mixer_freq) / samplerate);
    allocated_sound_t *snd = AllocateSound(sfxinfo, expanded_length * 4);
    int16_t *expanded = (int16_t *)(&snd->chunk)->abuf;
    const int expand_ratio = (samplecount << 8) / expanded_length;
    const double dt = 1.0 / mixer_freq;
    const double alpha = dt / (1.0 / (3.14159265358979323846 * samplerate) + dt);
    if (bits == 8)
        for (unsigned int i = 0; i < expanded_length; i++)
        {
            const int src = data[(i * expand_ratio) >> 8];
            expanded[i * 2] = expanded[i * 2 + 1] = (src | (src << 8)) - 32768;
        }
    else
        for (unsigned int i = 0; i < expanded_length; i++)
        {
            const int src = ((i * expand_ratio) >> 8) * 2;
            expanded[i * 2] = expanded[i * 2 + 1] = (data[src] | (data[src + 1] << 8));
        }
    for (unsigned int i = 2; i < expanded_length * 2; i++)
        expanded[i] = (int16_t)(alpha * expanded[i] + (1.0 - alpha) * expanded[i - 2]);
}

canonical_original_code:
static void ExpandSoundData(struct sfxinfo_t *sfxinfo, unsigned char *data, int samplerate, int bits, int length)
{
    unsigned int samplecount = length / (bits / 8);
    unsigned int expanded_length = (unsigned int)(((uint64_t)samplecount * mixer_freq) / samplerate);
    struct allocated_sound_s *snd = AllocateSound(sfxinfo, expanded_length * 4);
    short *expanded = (int16_t *)(&snd->chunk)->abuf;
    int expand_ratio = (samplecount << 8) / expanded_length;
    double dt = 1.0 / mixer_freq;
    double alpha = dt / (1.0 / (3.14159265358979323846 * samplerate) + dt);
    if (bits == 8)
        for (unsigned int i = 0; i < expanded_length; i++)
        {
            int src = data[(i * expand_ratio) >> 8];
            expanded[i * 2] = expanded[i * 2 + 1] = (src | (src << 8)) - 32768;
        }
    else
        for (unsigned int i = 0; i < expanded_length; i++)
        {
            int src = ((i * expand_ratio) >> 8) * 2;
            expanded[i * 2] = expanded[i * 2 + 1] = (data[src] | (data[src + 1] << 8));
        }
    for (unsigned int i = 2; i < expanded_length * 2; i++)
        expanded[i] = (short)(alpha * expanded[i] + (1.0 - alpha) * expanded[i - 2]);
}

variable_types: struct sfxinfo_t { char name1[9]; char name2[9]; int singularity; int priority; int lumpnum; } *

variable_types:
data
unsigned char *

variable_types: samplerate int

variable_types: bits int

variable_types: length int

variable_types:
samplecount
unsigned int

variable_types:
expanded
short *

variable_types: dt double

variable_types: alpha double

variable_types:
i
unsigned int

variable_types: src int


ReleaseSoundOnChannel

decompiled_code:
void __fastcall ReleaseSoundOnChannel(int a1)
{
int *v1; // rbp

v1 = (int *)channels_playing[a1];
if ( v1 )
{
Mix_HaltChannel();
channels_playing[a1] = 0LL;
UnlockAllocatedSound((__int64)v1);
if ( v1[9] != 127 && v1[8] <= 0 )
FreeAllocatedSound(v1);
}
}

canonical_decompiled_code:
void __fastcall func8(int a1)
{
int *v1; // rbp

v1 = (int *)channels_playing[a1];
if ( v1 )
{
Mix_HaltChannel();
channels_playing[a1] = 0LL;
func3((__int64)v1);
if ( v1[9] != 127 && v1[8] <= 0 )
func5(v1);
}
}

original_code:
static void ReleaseSoundOnChannel(const int channel)
{
    allocated_sound_t *snd = channels_playing[channel];
    if (!snd)
        return;
    Mix_HaltChannel(channel);
    channels_playing[channel] = ((void *)0);
    UnlockAllocatedSound(snd);
    if (snd->pitch != 127 && snd->use_count <= 0)
        FreeAllocatedSound(snd);
}

canonical_original_code:
static void ReleaseSoundOnChannel(int channel)
{
    struct allocated_sound_s *snd = channels_playing[channel];
    if (!snd)
        return;
    Mix_HaltChannel(channel);
    channels_playing[channel] = ((void *)0);
    UnlockAllocatedSound(snd);
    if (snd->pitch != 127 && snd->use_count <= 0)
        FreeAllocatedSound(snd);
}

variable_types: channel int


decompiled_code:
__int64 __fastcall I_UpdateSoundParms(__int64 a1, char a2, char a3)
{
return Mix_SetPanning(a1, (unsigned __int8)((char)(a2 * (-2 - a3)) / 127), (unsigned __int8)((char)(a2 * a3) / 127));
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, char a2, char a3)
{
return Mix_SetPanning(a1, (unsigned __int8)((char)(a2 * (-2 - a3)) / 127), (unsigned __int8)((char)(a2 * a3) / 127));
}

original_code:
void I_UpdateSoundParms(const int channel, const int vol, const int sep)
{
    Mix_SetPanning(channel, (254 - sep) * vol / (128 - 1), sep * vol / (128 - 1));
}

canonical_original_code:
void I_UpdateSoundParms(int channel, int vol, int sep)
{
    Mix_SetPanning(channel, (254 - sep) * vol / (128 - 1), sep * vol / (128 - 1));
}

variable_types: vol int

variable_types: sep int


decompiled_code:
__int64 __fastcall I_StartSound(__int64 a1, unsigned int a2, char a3, char a4, int a5)
{
__int64 v8; // rax
__int64 v9; // rbp
__int64 v11; // rax
_DWORD *v12; // rax
__int64 v13; // rdi
__int64 v14; // rcx

ReleaseSoundOnChannel(a2);
v8 = GetAllocatedSoundBySfxInfoAndPitch(a1, a5);
if ( v8 )
{
v9 = v8;
LockAllocatedSound(v8);
LABEL_3:
Mix_PlayChannelTimed(a2, v9 + 8, 0LL, 0xFFFFFFFFLL);
channels_playing[a2] = v9;
I_UpdateSoundParms(a2, a3, a4);
return a2;
}
v11 = GetAllocatedSoundBySfxInfoAndPitch(a1, 127);
v9 = v11;
if ( v11 )
{
if ( s_randompitch && a5 && a5 != 127 )
{
v12 = PitchShift(v11, a5);
if ( v12 )
{
LockAllocatedSound((__int64)v12);
v13 = v9;
v9 = v14;
UnlockAllocatedSound(v13);
}
}
goto LABEL_3;
}
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, unsigned int a2, char a3, char a4, int a5)
{
__int64 v8; // rax
__int64 v9; // rbp
__int64 v11; // rax
_DWORD *v12; // rax
__int64 v13; // rdi
__int64 v14; // rcx

func8(a2);
v8 = func4(a1, a5);
if ( v8 )
{
v9 = v8;
func2(v8);
LABEL_3:
Mix_PlayChannelTimed(a2, v9 + 8, 0LL, 0xFFFFFFFFLL);
channels_playing[a2] = v9;
func10(a2, a3, a4);
return a2;
}
v11 = func4(a1, 127);
v9 = v11;
if ( v11 )
{
if ( s_randompitch && a5 && a5 != 127 )
{
v12 = PitchShift(v11, a5);
if ( v12 )
{
func2((__int64)v12);
v13 = v9;
v9 = v14;
func3(v13);
}
}
goto LABEL_3;
}
return 0xFFFFFFFFLL;
}

original_code:
int I_StartSound(const sfxinfo_t *sfxinfo, const int channel, const int vol, const int sep, const int pitch)
{
    allocated_sound_t *snd;
    ReleaseSoundOnChannel(channel);
    if (!(snd = GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, pitch)))
    {
        if (!(snd = GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, 127)))
            return -1;
        if (s_randompitch && pitch && pitch != 127)
        {
            allocated_sound_t *newsnd = PitchShift(snd, pitch);
            if (newsnd)
            {
                LockAllocatedSound(newsnd);
                UnlockAllocatedSound(snd);
                snd = newsnd;
            }
        }
    }
    else
        LockAllocatedSound(snd);
    Mix_PlayChannelTimed(channel,&snd->chunk,0,-1);
    channels_playing[channel] = snd;
    I_UpdateSoundParms(channel, vol, sep);
    return channel;
}

canonical_original_code:
int I_StartSound(struct sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch)
{
    struct allocated_sound_s *snd;
    ReleaseSoundOnChannel(channel);
    if (!(snd = GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, pitch)))
    {
        if (!(snd = GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, 127)))
            return -1;
        if (s_randompitch && pitch && pitch != 127)
        {
            struct allocated_sound_s *newsnd = PitchShift(snd, pitch);
            if (newsnd)
            {
                LockAllocatedSound(newsnd);
                UnlockAllocatedSound(snd);
                snd = newsnd;
            }
        }
    }
    else
        LockAllocatedSound(snd);
    Mix_PlayChannelTimed(channel,&snd->chunk,0,-1);
    channels_playing[channel] = snd;
    I_UpdateSoundParms(channel, vol, sep);
    return channel;
}

variable_types: struct allocated_sound_s { struct sfxinfo_t { char name1[9]; char name2[9]; int singularity; int priority; int lumpnum; } *sfxinfo; struct Mix_Chunk { int allocated; unsigned char *abuf; unsigned int alen; unsigned char volume; } chunk; int use_count; int pitch; struct allocated_sound_s *prev; struct allocated_sound_s *next; } *


decompiled_code:
// attributes: thunk
void __fastcall I_StopSound(int a1)
{
ReleaseSoundOnChannel(a1);
}

canonical_decompiled_code:
void __fastcall func12(int a1)
{
func8(a1);
}

original_code:
void I_StopSound(const int channel)
{
    ReleaseSoundOnChannel(channel);
}

canonical_original_code:
void I_StopSound(int channel)
{
    ReleaseSoundOnChannel(channel);
}


decompiled_code:
bool I_SoundIsPlaying()
{
return (unsigned int)Mix_Playing() != 0;
}

canonical_decompiled_code:
bool func13()
{
return (unsigned int)Mix_Playing() != 0;
}

original_code:
_Bool I_SoundIsPlaying(const int channel)
{
    return Mix_Playing(channel);
}

canonical_original_code:
_Bool I_SoundIsPlaying(int channel)
{
    return Mix_Playing(channel);
}


decompiled_code:
bool I_AnySoundStillPlaying()
{
return (unsigned int)Mix_Playing(0xFFFFFFFFLL) != 0;
}

canonical_decompiled_code:
bool func14()
{
return (unsigned int)Mix_Playing(0xFFFFFFFFLL) != 0;
}

original_code:
_Bool I_AnySoundStillPlaying(void)
{
    return Mix_Playing(-1);
}

canonical_original_code:
_Bool I_AnySoundStillPlaying()
{
    return Mix_Playing(-1);
}


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

if ( sound_initialized )
{
result = Mix_CloseAudio();
sound_initialized = 0;
}
return result;
}

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

if ( sound_initialized )
{
result = Mix_CloseAudio();
sound_initialized = 0;
}
return result;
}

original_code:
void I_ShutdownSound(void)
{
    if (!sound_initialized)
        return;
    Mix_CloseAudio();
    sound_initialized = 0;
}

canonical_original_code:
void I_ShutdownSound()
{
    if (!sound_initialized)
        return;
    Mix_CloseAudio();
    sound_initialized = 0;
}


decompiled_code:
__int64 I_InitSound()
{
_BYTE *v0; // rbx
char v2[2]; // [rsp+Ah] [rbp-Eh] BYREF
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = (_BYTE *)Mix_Linked_Version();
memset(channels_playing, 0, sizeof(channels_playing));
if ( *v0 != 2 || v0[1] )
I_Error("The wrong version of SDL2_mixer.so was found. DOOM Retro requires v%i.%i.%i.", 2LL, 0LL, 4LL);
if ( v0[2] != 4 )
C_Warning(1LL, &unk_AF8, 2LL, 0LL, 4LL);
if ( (int)Mix_OpenAudioDevice(44100LL, 32784LL, 2LL, 1024LL, 0LL, 1LL) < 0
|| !(unsigned int)Mix_QuerySpec(&mixer_freq, v2, v3) )
{
return 0LL;
}
Mix_AllocateChannels(64LL);
sound_initialized = 1;
return 1LL;
}

canonical_decompiled_code:
__int64 func16()
{
_BYTE *v0; // rbx
char v2[2]; // [rsp+Ah] [rbp-Eh] BYREF
char v3[12]; // [rsp+Ch] [rbp-Ch] BYREF

v0 = (_BYTE *)Mix_Linked_Version();
memset(channels_playing, 0, sizeof(channels_playing));
if ( *v0 != 2 || v0[1] )
I_Error("The wrong version of SDL2_mixer.so was found. DOOM Retro requires v%i.%i.%i.", 2LL, 0LL, 4LL);
if ( v0[2] != 4 )
C_Warning(1LL, &unk_AF8, 2LL, 0LL, 4LL);
if ( (int)Mix_OpenAudioDevice(44100LL, 32784LL, 2LL, 1024LL, 0LL, 1LL) < 0
|| !(unsigned int)Mix_QuerySpec(&mixer_freq, v2, v3) )
{
return 0LL;
}
Mix_AllocateChannels(64LL);
sound_initialized = 1;
return 1LL;
}

original_code:
_Bool I_InitSound(void)
{
    const SDL_version *linked = Mix_Linked_Version();
    uint16_t mixer_format;
    int mixer_channels;
    for (int i = 0; i < 64; i++)
        channels_playing[i] = ((void *)0);
    if (linked->major != 2 || linked->minor != 0)
        I_Error("The wrong version of " "SDL2_mixer.so" " was found. " "DOOM Retro" " requires v%i.%i.%i.",
            2, 0, 4);
    if (linked->patch != 4)
        C_Warning(1, "The wrong version of " "\x1A" "SDL2_mixer.so" "\x1B" " was found. " "\x1C" "DOOM Retro" "\x1D" " requires v%i.%i.%i.",
            2, 0, 4);
    if (Mix_OpenAudioDevice(44100, 0x8010, 2,
        1024, ((void *)0), 0x00000001) < 0)
        return 0;
    if (!Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels))
        return 0;
    Mix_AllocateChannels(64);
    sound_initialized = 1;
    return 1;
}

canonical_original_code:
_Bool I_InitSound()
{
    struct SDL_version *linked = Mix_Linked_Version();
    unsigned short mixer_format;
    int mixer_channels;
    for (int i = 0; i < 64; i++)
        channels_playing[i] = ((void *)0);
    if (linked->major != 2 || linked->minor != 0)
        I_Error("The wrong version of " "SDL2_mixer.so" " was found. " "DOOM Retro" " requires v%i.%i.%i.",
            2, 0, 4);
    if (linked->patch != 4)
        C_Warning(1, "The wrong version of " "\x1A" "SDL2_mixer.so" "\x1B" " was found. " "\x1C" "DOOM Retro" "\x1D" " requires v%i.%i.%i.",
            2, 0, 4);
    if (Mix_OpenAudioDevice(44100, 0x8010, 2,
        1024, ((void *)0), 0x00000001) < 0)
        return 0;
    if (!Mix_QuerySpec(&mixer_freq, &mixer_format, &mixer_channels))
        return 0;
    Mix_AllocateChannels(64);
    sound_initialized = 1;
    return 1;
}

variable_types: struct SDL_version { unsigned char major; unsigned char minor; unsigned char patch; } *

variable_types: i int


decompiled_code:
void SC_ScriptError()
{
void *v0; // rbp

v0 = (void *)commify(sc_Line);
C_Warning(1LL, &unk_928, v0, ScriptLumpName);
free(v0);
}

canonical_decompiled_code:
void func0()
{
void *v0; // rbp

v0 = (void *)commify(sc_Line);
C_Warning(1LL, &unk_928, v0, ScriptLumpName);
free(v0);
}

original_code:
static void SC_ScriptError(void)
{
    char *temp = commify(sc_Line);
    C_Warning(1, "Line %s in the " "\x1A" "%s" "\x1B" " lump is invalid.", temp, ScriptLumpName);
    free(temp);
}

canonical_original_code:
static void SC_ScriptError()
{
    char *temp = commify(sc_Line);
    C_Warning(1, "Line %s in the " "\x1A" "%s" "\x1B" " lump is invalid.", temp, ScriptLumpName);
    free(temp);
}

variable_types:
temp
char *


decompiled_code:
void SC_Close()
{
if ( ScriptOpen )
{
if ( ScriptLumpNum < 0 )
{
Z_Free(ScriptBuffer);
}
else
{
W_ReleaseLumpNum();
free(ScriptLumpName);
}
SkipComma = 0;
ScriptOpen = 0;
}
}

canonical_decompiled_code:
void func1()
{
if ( ScriptOpen )
{
if ( ScriptLumpNum < 0 )
{
Z_Free(ScriptBuffer);
}
else
{
W_ReleaseLumpNum();
free(ScriptLumpName);
}
SkipComma = 0;
ScriptOpen = 0;
}
}

original_code:
void SC_Close(void)
{
    if (ScriptOpen)
    {
        if (ScriptLumpNum >= 0)
        {
            W_ReleaseLumpNum(ScriptLumpNum);
            free(ScriptLumpName);
        }
        else
            Z_Free(ScriptBuffer);
        SkipComma = 0;
        ScriptOpen = 0;
    }
}

canonical_original_code:
void SC_Close()
{
    if (ScriptOpen)
    {
        if (ScriptLumpNum >= 0)
        {
            W_ReleaseLumpNum(ScriptLumpNum);
            free(ScriptLumpName);
        }
        else
            Z_Free(ScriptBuffer);
        SkipComma = 0;
        ScriptOpen = 0;
    }
}


decompiled_code:
__int64 __fastcall SC_Open(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

SC_Close();
ScriptLumpNum = W_GetNumForName(a1);
ScriptLumpName = (void *)M_StringDuplicate(a1);
if ( (unsigned __int8)M_StringCompare(ScriptLumpName, "BRGHTMPS") )
SkipComma = 1;
v1 = W_CacheLumpNum((unsigned int)ScriptLumpNum);
ScriptBuffer = v1;
ScriptPtr = v1;
LODWORD(result) = W_LumpLength((unsigned int)ScriptLumpNum);
ScriptOpen = 1;
result = (int)result;
AlreadyGot = 0;
sc_Line = 1;
ScriptEndPtr = (int)result + v1;
sc_String = (char *)&StringBuffer_0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
__int64 result; // rax

func1();
ScriptLumpNum = W_GetNumForName(a1);
ScriptLumpName = (void *)M_StringDuplicate(a1);
if ( (unsigned __int8)M_StringCompare(ScriptLumpName, "BRGHTMPS") )
SkipComma = 1;
v1 = W_CacheLumpNum((unsigned int)ScriptLumpNum);
ScriptBuffer = v1;
ScriptPtr = v1;
LODWORD(result) = W_LumpLength((unsigned int)ScriptLumpNum);
ScriptOpen = 1;
result = (int)result;
AlreadyGot = 0;
sc_Line = 1;
ScriptEndPtr = (int)result + v1;
sc_String = (char *)&StringBuffer_0;
return result;
}

original_code:
void SC_Open(const char *name)
{
    static char StringBuffer[1024];
    SC_Close();
    ScriptLumpNum = W_GetNumForName(name);
    if (M_StringCompare((ScriptLumpName = M_StringDuplicate(name)), "BRGHTMPS"))
        SkipComma = 1;
    ScriptBuffer = W_CacheLumpNum(ScriptLumpNum);
    ScriptPtr = ScriptBuffer;
    ScriptEndPtr = ScriptPtr + W_LumpLength(ScriptLumpNum);
    sc_Line = 1;
    sc_End = 0;
    ScriptOpen = 1;
    sc_String = StringBuffer;
    AlreadyGot = 0;
}

canonical_original_code:
void SC_Open(char *name)
{
    static char StringBuffer[1024];
    SC_Close();
    ScriptLumpNum = W_GetNumForName(name);
    if (M_StringCompare((ScriptLumpName = M_StringDuplicate(name)), "BRGHTMPS"))
        SkipComma = 1;
    ScriptBuffer = W_CacheLumpNum(ScriptLumpNum);
    ScriptPtr = ScriptBuffer;
    ScriptEndPtr = ScriptPtr + W_LumpLength(ScriptLumpNum);
    sc_Line = 1;
    sc_End = 0;
    ScriptOpen = 1;
    sc_String = StringBuffer;
    AlreadyGot = 0;
}

variable_types:
name
char *

variable_types:
StringBuffer
char [1024]


decompiled_code:
__int64 __fastcall SC_GetString(__int64 a1, int a2)
{
unsigned int v2; // er12
char *v3; // rcx
__int64 v4; // r8
char v5; // r11
char v6; // r10
char *v7; // rax
char v8; // dl
char *v9; // r9
bool v10; // si
__int64 result; // rax
char v12; // al
char *v13; // rcx
__int64 v14; // rdx
char v15; // al
char v16; // r9
_BYTE *v17; // rsi
__int64 v18; // rdx
char *v19; // r9
__int64 v20; // rdx

v2 = (unsigned __int8)AlreadyGot;
if ( AlreadyGot )
{
result = (unsigned __int8)AlreadyGot;
AlreadyGot = 0;
return result;
}
v3 = (char *)ScriptPtr;
v4 = ScriptEndPtr;
if ( ScriptPtr >= (unsigned __int64)ScriptEndPtr )
return v2;
v5 = SkipComma;
v6 = 0;
LABEL_4:
if ( ScriptEndPtr <= (unsigned __int64)v3 )
{
LABEL_13:
if ( !v6 )
return v2;
LABEL_14:
ScriptPtr = (__int64)v3;
return v2;
}
v7 = v3 + 1;
while ( 1 )
{
v8 = *(v7 - 1);
v9 = v7 - 1;
v3 = v7;
v10 = v8 == 61 || v8 <= 32;
if ( v10 )
{
if ( v8 == 10 )
{
++sc_Line;
v6 = v10;
goto LABEL_4;
}
goto LABEL_9;
}
if ( v8 != 44 )
{
v3 = v7 - 1;
if ( ScriptEndPtr <= (unsigned __int64)v9 )
goto LABEL_13;
v8 = *v9;
if ( *v9 != 59 && v8 != 47 )
goto LABEL_18;
LABEL_22:
while ( 1 )
{
++v3;
if ( v8 == 10 )
break;
if ( ScriptEndPtr <= (unsigned __int64)v3 )
goto LABEL_14;
v8 = *v3;
}
++sc_Line;
v6 = 1;
goto LABEL_4;
}
if ( SkipComma || *(v7 - 2) == 39 )
break;
LABEL_9:
++v7;
v6 = 1;
if ( ScriptEndPtr <= (unsigned __int64)v3 )
goto LABEL_13;
}
if ( ScriptEndPtr <= (unsigned __int64)v9 )
{
if ( v6 )
ScriptPtr = (__int64)(v7 - 1);
return v2;
}
LABEL_18:
v12 = *v7;
if ( v12 == 47 )
{
v8 = *v9;
v3 = v9;
goto LABEL_22;
}
if ( v6 )
ScriptPtr = (__int64)v9;
v13 = sc_String;
if ( v8 != 34 )
{
v14 = ScriptPtr;
v15 = *(_BYTE *)ScriptPtr;
while ( 1 )
{
v16 = v2;
LOBYTE(v2) = v15 > 32;
LOBYTE(a2) = v15 != 59;
v2 &= a2;
LOBYTE(v2) = (v15 != 47) & v2;
if ( !(_BYTE)v2 || *(_BYTE *)(v14 + 1) == 47 )
{
if ( !v16 )
goto LABEL_43;
LABEL_47:
ScriptPtr = v14;
goto LABEL_43;
}
v17 = (_BYTE *)v14;
if ( ((v15 - 123) & 0xFD) == 0 )
{
v17 = (_BYTE *)(v14 + 1);
v15 = *(_BYTE *)(v14 + 1);
}
*v13 = v15;
v15 = v17[1];
++v13;
v14 = (__int64)(v17 + 1);
if ( v15 == 61 || v15 == 44 && !v5 && *v17 != 39 )
{
ScriptPtr = (__int64)(v17 + 2);
goto LABEL_43;
}
if ( v4 == v14 )
break;
a2 = (_DWORD)sc_String + 1023;
if ( v13 == sc_String + 1023 )
goto LABEL_47;
}
ScriptPtr = v4;
goto LABEL_43;
}
v18 = (__int64)(v9 + 1);
v19 = v9 + 2;
ScriptPtr = v18;
while ( 2 )
{
if ( v12 != 34 )
{
v20 = (__int64)v19;
if ( v12 == 92 )
goto LABEL_51;
goto LABEL_50;
}
if ( *(v19 - 2) == 92 )
{
LABEL_50:
*v13 = v12;
v20 = (__int64)v19;
++v13;
LABEL_51:
if ( (char *)v4 == v19 || v13 == sc_String + 1023 )
goto LABEL_59;
v12 = *v19;
LOBYTE(v2) = 1;
++v19;
continue;
}
break;
}
if ( (_BYTE)v2 )
ScriptPtr = (__int64)(v19 - 1);
v20 = ScriptPtr;
LABEL_59:
ScriptPtr = v20 + 1;
LABEL_43:
*v13 = 0;
return 1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
unsigned int v2; // er12
char *v3; // rcx
__int64 v4; // r8
char v5; // r11
char v6; // r10
char *v7; // rax
char v8; // dl
char *v9; // r9
bool v10; // si
__int64 result; // rax
char v12; // al
char *v13; // rcx
__int64 v14; // rdx
char v15; // al
char v16; // r9
_BYTE *v17; // rsi
__int64 v18; // rdx
char *v19; // r9
__int64 v20; // rdx

v2 = (unsigned __int8)AlreadyGot;
if ( AlreadyGot )
{
result = (unsigned __int8)AlreadyGot;
AlreadyGot = 0;
return result;
}
v3 = (char *)ScriptPtr;
v4 = ScriptEndPtr;
if ( ScriptPtr >= (unsigned __int64)ScriptEndPtr )
return v2;
v5 = SkipComma;
v6 = 0;
LABEL_4:
if ( ScriptEndPtr <= (unsigned __int64)v3 )
{
LABEL_13:
if ( !v6 )
return v2;
LABEL_14:
ScriptPtr = (__int64)v3;
return v2;
}
v7 = v3 + 1;
while ( 1 )
{
v8 = *(v7 - 1);
v9 = v7 - 1;
v3 = v7;
v10 = v8 == 61 || v8 <= 32;
if ( v10 )
{
if ( v8 == 10 )
{
++sc_Line;
v6 = v10;
goto LABEL_4;
}
goto LABEL_9;
}
if ( v8 != 44 )
{
v3 = v7 - 1;
if ( ScriptEndPtr <= (unsigned __int64)v9 )
goto LABEL_13;
v8 = *v9;
if ( *v9 != 59 && v8 != 47 )
goto LABEL_18;
LABEL_22:
while ( 1 )
{
++v3;
if ( v8 == 10 )
break;
if ( ScriptEndPtr <= (unsigned __int64)v3 )
goto LABEL_14;
v8 = *v3;
}
++sc_Line;
v6 = 1;
goto LABEL_4;
}
if ( SkipComma || *(v7 - 2) == 39 )
break;
LABEL_9:
++v7;
v6 = 1;
if ( ScriptEndPtr <= (unsigned __int64)v3 )
goto LABEL_13;
}
if ( ScriptEndPtr <= (unsigned __int64)v9 )
{
if ( v6 )
ScriptPtr = (__int64)(v7 - 1);
return v2;
}
LABEL_18:
v12 = *v7;
if ( v12 == 47 )
{
v8 = *v9;
v3 = v9;
goto LABEL_22;
}
if ( v6 )
ScriptPtr = (__int64)v9;
v13 = sc_String;
if ( v8 != 34 )
{
v14 = ScriptPtr;
v15 = *(_BYTE *)ScriptPtr;
while ( 1 )
{
v16 = v2;
LOBYTE(v2) = v15 > 32;
LOBYTE(a2) = v15 != 59;
v2 &= a2;
LOBYTE(v2) = (v15 != 47) & v2;
if ( !(_BYTE)v2 || *(_BYTE *)(v14 + 1) == 47 )
{
if ( !v16 )
goto LABEL_43;
LABEL_47:
ScriptPtr = v14;
goto LABEL_43;
}
v17 = (_BYTE *)v14;
if ( ((v15 - 123) & 0xFD) == 0 )
{
v17 = (_BYTE *)(v14 + 1);
v15 = *(_BYTE *)(v14 + 1);
}
*v13 = v15;
v15 = v17[1];
++v13;
v14 = (__int64)(v17 + 1);
if ( v15 == 61 || v15 == 44 && !v5 && *v17 != 39 )
{
ScriptPtr = (__int64)(v17 + 2);
goto LABEL_43;
}
if ( v4 == v14 )
break;
a2 = (_DWORD)sc_String + 1023;
if ( v13 == sc_String + 1023 )
goto LABEL_47;
}
ScriptPtr = v4;
goto LABEL_43;
}
v18 = (__int64)(v9 + 1);
v19 = v9 + 2;
ScriptPtr = v18;
while ( 2 )
{
if ( v12 != 34 )
{
v20 = (__int64)v19;
if ( v12 == 92 )
goto LABEL_51;
goto LABEL_50;
}
if ( *(v19 - 2) == 92 )
{
LABEL_50:
*v13 = v12;
v20 = (__int64)v19;
++v13;
LABEL_51:
if ( (char *)v4 == v19 || v13 == sc_String + 1023 )
goto LABEL_59;
v12 = *v19;
LOBYTE(v2) = 1;
++v19;
continue;
}
break;
}
if ( (_BYTE)v2 )
ScriptPtr = (__int64)(v19 - 1);
v20 = ScriptPtr;
LABEL_59:
ScriptPtr = v20 + 1;
LABEL_43:
*v13 = 0;
return 1;
}

original_code:
_Bool SC_GetString(void)
{
    char *text;
    _Bool foundToken = 0;
    if (AlreadyGot)
    {
        AlreadyGot = 0;
        return 1;
    }
    if (ScriptPtr >= ScriptEndPtr)
    {
        sc_End = 1;
        return 0;
    }
    while (!foundToken)
    {
        while (ScriptPtr < ScriptEndPtr && (*ScriptPtr <= 32 || *ScriptPtr == '='
            || (*ScriptPtr == ',' && !SkipComma && *(ScriptPtr - 1) != '\'')))
            if (*ScriptPtr++ == '\n')
                sc_Line++;
        if (ScriptPtr >= ScriptEndPtr)
        {
            sc_End = 1;
            return 0;
        }
        if (*ScriptPtr != ';' && *ScriptPtr != '/' && *(ScriptPtr + 1) != '/')
            foundToken = 1;
        else
        {
            while (*ScriptPtr++ != '\n')
                if (ScriptPtr >= ScriptEndPtr)
                {
                    sc_End = 1;
                    return 0;
                }
            sc_Line++;
        }
    }
    text = sc_String;
    if (*ScriptPtr == '"')
    {
        ScriptPtr++;
        while (*ScriptPtr != '"' || *(ScriptPtr - 1) == '\\')
        {
            if (*ScriptPtr != '\\')
                *text++ = *ScriptPtr++;
            else
                ScriptPtr++;
            if (ScriptPtr == ScriptEndPtr || text == &sc_String[1024 - 1])
                break;
        }
        ScriptPtr++;
    }
    else
        while (*ScriptPtr > 32 && *ScriptPtr != ';' && *ScriptPtr != '/' && *(ScriptPtr + 1) != '/')
        {
            if (*ScriptPtr == '{' || *ScriptPtr == '}')
                ScriptPtr++;
            *text++ = *ScriptPtr++;
            if (*ScriptPtr == '=' || (*ScriptPtr == ',' && !SkipComma && *(ScriptPtr - 1) != '\''))
            {
                ScriptPtr++;
                break;
            }
            if (ScriptPtr == ScriptEndPtr || text == &sc_String[1024 - 1])
                break;
        }
    *text = '\0';
    return 1;
}

canonical_original_code:
_Bool SC_GetString()
{
    char *text;
    _Bool foundToken = 0;
    if (AlreadyGot)
    {
        AlreadyGot = 0;
        return 1;
    }
    if (ScriptPtr >= ScriptEndPtr)
    {
        sc_End = 1;
        return 0;
    }
    while (!foundToken)
    {
        while (ScriptPtr < ScriptEndPtr && (*ScriptPtr <= 32 || *ScriptPtr == '='
            || (*ScriptPtr == ',' && !SkipComma && *(ScriptPtr - 1) != '\'')))
            if (*ScriptPtr++ == '\n')
                sc_Line++;
        if (ScriptPtr >= ScriptEndPtr)
        {
            sc_End = 1;
            return 0;
        }
        if (*ScriptPtr != ';' && *ScriptPtr != '/' && *(ScriptPtr + 1) != '/')
            foundToken = 1;
        else
        {
            while (*ScriptPtr++ != '\n')
                if (ScriptPtr >= ScriptEndPtr)
                {
                    sc_End = 1;
                    return 0;
                }
            sc_Line++;
        }
    }
    text = sc_String;
    if (*ScriptPtr == '"')
    {
        ScriptPtr++;
        while (*ScriptPtr != '"' || *(ScriptPtr - 1) == '\\')
        {
            if (*ScriptPtr != '\\')
                *text++ = *ScriptPtr++;
            else
                ScriptPtr++;
            if (ScriptPtr == ScriptEndPtr || text == &sc_String[1024 - 1])
                break;
        }
        ScriptPtr++;
    }
    else
        while (*ScriptPtr > 32 && *ScriptPtr != ';' && *ScriptPtr != '/' && *(ScriptPtr + 1) != '/')
        {
            if (*ScriptPtr == '{' || *ScriptPtr == '}')
                ScriptPtr++;
            *text++ = *ScriptPtr++;
            if (*ScriptPtr == '=' || (*ScriptPtr == ',' && !SkipComma && *(ScriptPtr - 1) != '\''))
            {
                ScriptPtr++;
                break;
            }
            if (ScriptPtr == ScriptEndPtr || text == &sc_String[1024 - 1])
                break;
        }
    *text = '\0';
    return 1;
}

variable_types:
text
char *


decompiled_code:
void __fastcall SC_MustGetString(__int64 a1, int a2)
{
if ( !(unsigned __int8)SC_GetString(a1, a2) )
SC_ScriptError();
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1, int a2)
{
if ( !(unsigned __int8)func3(a1, a2) )
func0();
}

original_code:
void SC_MustGetString(void)
{
    if (!SC_GetString())
        SC_ScriptError();
}

canonical_original_code:
void SC_MustGetString()
{
    if (!SC_GetString())
        SC_ScriptError();
}


decompiled_code:
__int64 __fastcall SC_GetNumber(__int64 a1, int a2)
{
unsigned int v2; // er12

v2 = SC_GetString(a1, a2);
if ( (_BYTE)v2 )
sc_Number = strtol(sc_String, 0LL, 0);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, int a2)
{
unsigned int v2; // er12

v2 = func3(a1, a2);
if ( (_BYTE)v2 )
sc_Number = strtol(sc_String, 0LL, 0);
return v2;
}

original_code:
_Bool SC_GetNumber(void)
{
    if (SC_GetString())
    {
        sc_Number = strtol(sc_String, ((void *)0), 0);
        return 1;
    }
    else
        return 0;
}

canonical_original_code:
_Bool SC_GetNumber()
{
    if (SC_GetString())
    {
        sc_Number = strtol(sc_String, ((void *)0), 0);
        return 1;
    }
    else
        return 0;
}


decompiled_code:
void __fastcall SC_MustGetNumber(__int64 a1, int a2)
{
if ( !(unsigned __int8)SC_GetNumber(a1, a2) )
SC_ScriptError();
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2)
{
if ( !(unsigned __int8)func5(a1, a2) )
func0();
}

original_code:
void SC_MustGetNumber(void)
{
    if (!SC_GetNumber())
        SC_ScriptError();
}

canonical_original_code:
void SC_MustGetNumber()
{
    if (!SC_GetNumber())
        SC_ScriptError();
}


decompiled_code:
void SC_UnGet()
{
AlreadyGot = 1;
}

canonical_decompiled_code:
void func7()
{
AlreadyGot = 1;
}

original_code:
void SC_UnGet(void)
{
    AlreadyGot = 1;
}

canonical_original_code:
void SC_UnGet()
{
    AlreadyGot = 1;
}


decompiled_code:
__int64 __fastcall SC_Compare(__int64 a1)
{
return M_StringCompare(a1, sc_String);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
return M_StringCompare(a1, sc_String);
}

original_code:
_Bool SC_Compare(const char *text)
{
    return M_StringCompare(text, sc_String);
}

canonical_original_code:
_Bool SC_Compare(char *text)
{
    return M_StringCompare(text, sc_String);
}


decompiled_code:
__int64 __fastcall SC_MatchString(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rbx

v2 = *a1;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( !(unsigned __int8)SC_Compare(v2) )
{
v2 = a1[++v3];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 *a1)
{
__int64 v2; // rdi
__int64 v3; // rbx

v2 = *a1;
if ( !v2 )
return 0xFFFFFFFFLL;
v3 = 0LL;
while ( !(unsigned __int8)func8(v2) )
{
v2 = a1[++v3];
if ( !v2 )
return 0xFFFFFFFFLL;
}
return (unsigned int)v3;
}

original_code:
int SC_MatchString(char **strings)
{
    for (int i = 0; *strings; i++)
        if (SC_Compare(*strings++))
            return i;
    return -1;
}

variable_types:
strings
char **


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

if ( gamecontroller )
result = SDL_GameControllerClose();
return result;
}

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

if ( gamecontroller )
result = SDL_GameControllerClose();
return result;
}

original_code:
void I_ShutdownGameController(void)
{
    if (!gamecontroller)
        return;
    ;
    SDL_GameControllerClose(gamecontroller);
}

canonical_original_code:
void I_ShutdownGameController()
{
    if (!gamecontroller)
        return;
    ;
    SDL_GameControllerClose(gamecontroller);
}


decompiled_code:
void __fastcall I_GameControllerRumble(int a1)
{
int v1; // eax

if ( gamecontrollerrumbles )
{
v1 = MIN_constprop_0(a1);
if ( !v1 || lasteventtype == 5 && (idlechainsawrumblestrength == v1 || currentstrength <= v1) )
{
currentstrength = v1;
SDL_GameControllerRumble(gamecontroller, (unsigned __int16)v1, (unsigned __int16)v1, 0xFFFFFFFFLL);
}
}
}

canonical_decompiled_code:
void __fastcall func2(int a1)
{
int v1; // eax

if ( gamecontrollerrumbles )
{
v1 = func0(a1);
if ( !v1 || lasteventtype == 5 && (idlechainsawrumblestrength == v1 || currentstrength <= v1) )
{
currentstrength = v1;
SDL_GameControllerRumble(gamecontroller, (unsigned __int16)v1, (unsigned __int16)v1, 0xFFFFFFFFLL);
}
}
}

original_code:
void I_GameControllerRumble(int strength)
{
    if (!gamecontrollerrumbles)
        return;
    if (!(strength = MIN(strength, (65535)))
        || (lasteventtype == ev_controller
            && (strength == idlechainsawrumblestrength || strength >= currentstrength)))
    {
        currentstrength = strength;
        SDL_GameControllerRumble(gamecontroller, currentstrength, currentstrength, (4294967295U));
    }
}

variable_types: strength int


decompiled_code:
void I_UpdateGameControllerRumble()
{
int v0; // eax
int v1; // edx
int v2; // ecx
int v3; // eax

if ( gamecontrollerrumbles )
{
if ( lasteventtype != 5 )
{
SDL_GameControllerRumble(gamecontroller, 0LL, 0LL, 0LL);
return;
}
v0 = weaponrumbletics;
v1 = damagerumbletics;
v2 = barrelrumbletics;
if ( weaponrumbletics && (--weaponrumbletics, v0 == 1) )
{
if ( !damagerumbletics )
{
if ( !barrelrumbletics )
goto LABEL_18;
LABEL_8:
v3 = pickuprumbletics;
--barrelrumbletics;
if ( v2 == 1 )
{
if ( !pickuprumbletics )
goto LABEL_18;
goto LABEL_10;
}
LABEL_14:
if ( !v3 )
return;
LABEL_10:
pickuprumbletics = v3 - 1;
if ( v3 != 1 )
return;
LABEL_18:
currentstrength = idlechainsawrumblestrength;
SDL_GameControllerRumble(
gamecontroller,
(unsigned __int16)idlechainsawrumblestrength,
(unsigned __int16)idlechainsawrumblestrength,
0xFFFFFFFFLL);
return;
}
}
else if ( !damagerumbletics )
{
goto LABEL_13;
}
--damagerumbletics;
if ( v1 == 1 )
{
if ( !barrelrumbletics )
{
v3 = pickuprumbletics;
if ( !pickuprumbletics )
goto LABEL_18;
goto LABEL_10;
}
goto LABEL_8;
}
LABEL_13:
v3 = pickuprumbletics;
if ( !barrelrumbletics )
goto LABEL_14;
goto LABEL_8;
}
}

canonical_decompiled_code:
void func3()
{
int v0; // eax
int v1; // edx
int v2; // ecx
int v3; // eax

if ( gamecontrollerrumbles )
{
if ( lasteventtype != 5 )
{
SDL_GameControllerRumble(gamecontroller, 0LL, 0LL, 0LL);
return;
}
v0 = weaponrumbletics;
v1 = damagerumbletics;
v2 = barrelrumbletics;
if ( weaponrumbletics && (--weaponrumbletics, v0 == 1) )
{
if ( !damagerumbletics )
{
if ( !barrelrumbletics )
goto LABEL_18;
LABEL_8:
v3 = pickuprumbletics;
--barrelrumbletics;
if ( v2 == 1 )
{
if ( !pickuprumbletics )
goto LABEL_18;
goto LABEL_10;
}
LABEL_14:
if ( !v3 )
return;
LABEL_10:
pickuprumbletics = v3 - 1;
if ( v3 != 1 )
return;
LABEL_18:
currentstrength = idlechainsawrumblestrength;
SDL_GameControllerRumble(
gamecontroller,
(unsigned __int16)idlechainsawrumblestrength,
(unsigned __int16)idlechainsawrumblestrength,
0xFFFFFFFFLL);
return;
}
}
else if ( !damagerumbletics )
{
goto LABEL_13;
}
--damagerumbletics;
if ( v1 == 1 )
{
if ( !barrelrumbletics )
{
v3 = pickuprumbletics;
if ( !pickuprumbletics )
goto LABEL_18;
goto LABEL_10;
}
goto LABEL_8;
}
LABEL_13:
v3 = pickuprumbletics;
if ( !barrelrumbletics )
goto LABEL_14;
goto LABEL_8;
}
}

original_code:
void I_UpdateGameControllerRumble(void)
{
    if (!gamecontrollerrumbles)
        return;
    if (lasteventtype == ev_controller)
    {
        if ((weaponrumbletics && !--weaponrumbletics && !damagerumbletics && !barrelrumbletics)
            || (damagerumbletics && !--damagerumbletics && !barrelrumbletics && !pickuprumbletics)
            || (barrelrumbletics && !--barrelrumbletics && !pickuprumbletics)
            || (pickuprumbletics && !--pickuprumbletics))
        {
            currentstrength = idlechainsawrumblestrength;
            SDL_GameControllerRumble(gamecontroller, currentstrength, currentstrength, (4294967295U));
        }
    }
    else
        SDL_GameControllerRumble(gamecontroller, 0, 0, 0);
}

canonical_original_code:
void I_UpdateGameControllerRumble()
{
    if (!gamecontrollerrumbles)
        return;
    if (lasteventtype == ev_controller)
    {
        if ((weaponrumbletics && !--weaponrumbletics && !damagerumbletics && !barrelrumbletics)
            || (damagerumbletics && !--damagerumbletics && !barrelrumbletics && !pickuprumbletics)
            || (barrelrumbletics && !--barrelrumbletics && !pickuprumbletics)
            || (pickuprumbletics && !--pickuprumbletics))
        {
            currentstrength = idlechainsawrumblestrength;
            SDL_GameControllerRumble(gamecontroller, currentstrength, currentstrength, (4294967295U));
        }
    }
    else
        SDL_GameControllerRumble(gamecontroller, 0, 0, 0);
}


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

if ( gamecontrollerrumbles )
result = SDL_GameControllerRumble(gamecontroller, 0LL, 0LL, 0LL);
return result;
}

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

if ( gamecontrollerrumbles )
result = SDL_GameControllerRumble(gamecontroller, 0LL, 0LL, 0LL);
return result;
}

original_code:
void I_StopGameControllerRumble(void)
{
    if (!gamecontrollerrumbles)
        return;
    SDL_GameControllerRumble(gamecontroller, 0, 0, 0);
}

canonical_original_code:
void I_StopGameControllerRumble()
{
    if (!gamecontrollerrumbles)
        return;
    SDL_GameControllerRumble(gamecontroller, 0, 0, 0);
}


decompiled_code:
void I_SetGameControllerHorizontalSensitivity()
{
if ( joy_sensitivity_horizontal == 0.0 )
gamecontrollerhorizontalsensitivity = 0;
else
*(float *)&gamecontrollerhorizontalsensitivity = (float)(0.0078125 * (float)(joy_sensitivity_horizontal * 4.0))
+ 0.2;
}

canonical_decompiled_code:
void func5()
{
if ( joy_sensitivity_horizontal == 0.0 )
gamecontrollerhorizontalsensitivity = 0;
else
*(float *)&gamecontrollerhorizontalsensitivity = (float)(0.0078125 * (float)(joy_sensitivity_horizontal * 4.0))
+ 0.2;
}

original_code:
void I_SetGameControllerHorizontalSensitivity(void)
{
    gamecontrollerhorizontalsensitivity = (!joy_sensitivity_horizontal ? 0.0f :
        4.0f * joy_sensitivity_horizontal / 128.0f + 0.2f);
}

canonical_original_code:
void I_SetGameControllerHorizontalSensitivity()
{
    gamecontrollerhorizontalsensitivity = (!joy_sensitivity_horizontal ? 0.0f :
        4.0f * joy_sensitivity_horizontal / 128.0f + 0.2f);
}


decompiled_code:
void I_SetGameControllerVerticalSensitivity()
{
if ( joy_sensitivity_vertical == 0.0 )
gamecontrollerverticalsensitivity = 0;
else
*(float *)&gamecontrollerverticalsensitivity = (float)(0.0078125 * (float)(joy_sensitivity_vertical * 4.0)) + 0.2;
}

canonical_decompiled_code:
void func6()
{
if ( joy_sensitivity_vertical == 0.0 )
gamecontrollerverticalsensitivity = 0;
else
*(float *)&gamecontrollerverticalsensitivity = (float)(0.0078125 * (float)(joy_sensitivity_vertical * 4.0)) + 0.2;
}

original_code:
void I_SetGameControllerVerticalSensitivity(void)
{
    gamecontrollerverticalsensitivity = (!joy_sensitivity_vertical ? 0.0f :
        4.0f * joy_sensitivity_vertical / 128.0f + 0.2f);
}

canonical_original_code:
void I_SetGameControllerVerticalSensitivity()
{
    gamecontrollerverticalsensitivity = (!joy_sensitivity_vertical ? 0.0f :
        4.0f * joy_sensitivity_vertical / 128.0f + 0.2f);
}


decompiled_code:
__int64 I_SetGameControllerLeftDeadZone()
{
float v0; // xmm0_4
__int64 result; // rax

v0 = (float)(32767.0 * joy_deadzone_left) / 100.0;
result = (unsigned int)(int)v0;
gamecontrollerleftdeadzone = (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func7()
{
float v0; // xmm0_4
__int64 result; // rax

v0 = (float)(32767.0 * joy_deadzone_left) / 100.0;
result = (unsigned int)(int)v0;
gamecontrollerleftdeadzone = (int)v0;
return result;
}

original_code:
void I_SetGameControllerLeftDeadZone(void)
{
    gamecontrollerleftdeadzone = (short)(joy_deadzone_left * 0x7fff / 100.0f);
}

canonical_original_code:
void I_SetGameControllerLeftDeadZone()
{
    gamecontrollerleftdeadzone = (short)(joy_deadzone_left * 0x7fff / 100.0f);
}


decompiled_code:
__int64 I_SetGameControllerRightDeadZone()
{
float v0; // xmm0_4
__int64 result; // rax

v0 = (float)(32767.0 * joy_deadzone_right) / 100.0;
result = (unsigned int)(int)v0;
gamecontrollerrightdeadzone = (int)v0;
return result;
}

canonical_decompiled_code:
__int64 func8()
{
float v0; // xmm0_4
__int64 result; // rax

v0 = (float)(32767.0 * joy_deadzone_right) / 100.0;
result = (unsigned int)(int)v0;
gamecontrollerrightdeadzone = (int)v0;
return result;
}

original_code:
void I_SetGameControllerRightDeadZone(void)
{
    gamecontrollerrightdeadzone = (short)(joy_deadzone_right * 0x7fff / 100.0f);
}

canonical_original_code:
void I_SetGameControllerRightDeadZone()
{
    gamecontrollerrightdeadzone = (short)(joy_deadzone_right * 0x7fff / 100.0f);
}


decompiled_code:
void I_InitGameController()
{
int v0; // ebx
unsigned int v1; // ebp
__int64 v2; // rax
const char *v3; // rsi
char v4; // bl

if ( !gamecontrollerconnected )
{
SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI_PS4_RUMBLE", &unk_418, 2LL);
SDL_SetHintWithPriority("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", &unk_418, 2LL);
v0 = SDL_NumJoysticks();
if ( v0 > 0 )
{
v1 = 0;
while ( !(unsigned int)SDL_IsGameController(v1) )
{
if ( v0 == ++v1 )
return;
}
v2 = SDL_GameControllerOpen(v1);
gamecontrollerconnected = 1;
gamecontroller = v2;
v3 = (const char *)SDL_GameControllerName(v2);
if ( v3 )
v4 = C_OutputNoRepeat("A controller called \"%s\" is connected.", v3);
else
v4 = C_OutputNoRepeat("A controller is connected.");
if ( (unsigned int)SDL_GameControllerRumble(gamecontroller, 0LL, 0LL, 0LL) )
{
if ( !v4 && (joy_rumble_pickup || joy_rumble_weapons | joy_rumble_damage | joy_rumble_barrels) )
C_Warning(1LL, "This controller isn't going to rumble.");
}
else
{
gamecontrollerrumbles = 1;
}
I_SetGameControllerLeftDeadZone();
I_SetGameControllerRightDeadZone();
I_SetGameControllerHorizontalSensitivity();
I_SetGameControllerVerticalSensitivity();
}
}
}

canonical_decompiled_code:
void func9()
{
int v0; // ebx
unsigned int v1; // ebp
__int64 v2; // rax
const char *v3; // rsi
char v4; // bl

if ( !gamecontrollerconnected )
{
SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI_PS4_RUMBLE", &unk_418, 2LL);
SDL_SetHintWithPriority("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", &unk_418, 2LL);
v0 = SDL_NumJoysticks();
if ( v0 > 0 )
{
v1 = 0;
while ( !(unsigned int)SDL_IsGameController(v1) )
{
if ( v0 == ++v1 )
return;
}
v2 = SDL_GameControllerOpen(v1);
gamecontrollerconnected = 1;
gamecontroller = v2;
v3 = (const char *)SDL_GameControllerName(v2);
if ( v3 )
v4 = C_OutputNoRepeat("A controller called \"%s\" is connected.", v3);
else
v4 = C_OutputNoRepeat("A controller is connected.");
if ( (unsigned int)SDL_GameControllerRumble(gamecontroller, 0LL, 0LL, 0LL) )
{
if ( !v4 && (joy_rumble_pickup || joy_rumble_weapons | joy_rumble_damage | joy_rumble_barrels) )
C_Warning(1LL, "This controller isn't going to rumble.");
}
else
{
gamecontrollerrumbles = 1;
}
func7();
func8();
func5();
func6();
}
}
}

original_code:
void I_InitGameController(void)
{
    if (gamecontrollerconnected)
        return;
    SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI_PS4_RUMBLE", "1", SDL_HINT_OVERRIDE);
    SDL_SetHintWithPriority("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1", SDL_HINT_OVERRIDE);
    for (int i = 0, numjoysticks = SDL_NumJoysticks(); i < numjoysticks; i++)
        if (SDL_IsGameController(i))
        {
            const char *name;
            _Bool repeated;
            gamecontroller = SDL_GameControllerOpen(i);
            gamecontrollerconnected = 1;
            if ((name = SDL_GameControllerName(gamecontroller)))
                repeated = C_OutputNoRepeat("A controller called \"%s\" is connected.", name);
            else
                repeated = C_OutputNoRepeat("A controller is connected.");
            if (!SDL_GameControllerRumble(gamecontroller, 0, 0, 0))
                gamecontrollerrumbles = 1;
            else if (!repeated && (joy_rumble_barrels || joy_rumble_damage || joy_rumble_pickup || joy_rumble_weapons))
                C_Warning(1, "This controller isn't going to rumble.");
            I_SetGameControllerLeftDeadZone();
            I_SetGameControllerRightDeadZone();
            I_SetGameControllerHorizontalSensitivity();
            I_SetGameControllerVerticalSensitivity();
            ;
            return;
        }
}

canonical_original_code:
void I_InitGameController()
{
    if (gamecontrollerconnected)
        return;
    SDL_SetHintWithPriority("SDL_JOYSTICK_HIDAPI_PS4_RUMBLE", "1", SDL_HINT_OVERRIDE);
    SDL_SetHintWithPriority("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1", SDL_HINT_OVERRIDE);
    for (int i = 0; int numjoysticks = SDL_NumJoysticks(); i < numjoysticks; i++)
        if (SDL_IsGameController(i))
        {
            char *name;
            _Bool repeated;
            gamecontroller = SDL_GameControllerOpen(i);
            gamecontrollerconnected = 1;
            if ((name = SDL_GameControllerName(gamecontroller)))
                repeated = C_OutputNoRepeat("A controller called \"%s\" is connected.", name);
            else
                repeated = C_OutputNoRepeat("A controller is connected.");
            if (!SDL_GameControllerRumble(gamecontroller, 0, 0, 0))
                gamecontrollerrumbles = 1;
            else if (!repeated && (joy_rumble_barrels || joy_rumble_damage || joy_rumble_pickup || joy_rumble_weapons))
                C_Warning(1, "This controller isn't going to rumble.");
            I_SetGameControllerLeftDeadZone();
            I_SetGameControllerRightDeadZone();
            I_SetGameControllerHorizontalSensitivity();
            I_SetGameControllerVerticalSensitivity();
            ;
            return;
        }
}

variable_types: numjoysticks int


decompiled_code:
__int64 __fastcall M_CheckParmWithArgs(__int64 a1, int a2)
{
unsigned int v2; // er12
__int64 i; // rbx

if ( a2 >= myargc - 1 )
return 0LL;
v2 = a2;
for ( i = 8LL * a2; !(unsigned __int8)M_StringCompare(a1, *(_QWORD *)(myargv + i)); i += 8LL )
{
if ( myargc - 1 <= (int)++v2 )
return 0LL;
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
unsigned int v2; // er12
__int64 i; // rbx

if ( a2 >= myargc - 1 )
return 0LL;
v2 = a2;
for ( i = 8LL * a2; !(unsigned __int8)M_StringCompare(a1, *(_QWORD *)(myargv + i)); i += 8LL )
{
if ( myargc - 1 <= (int)++v2 )
return 0LL;
}
return v2;
}

original_code:
int M_CheckParmWithArgs(const char *check, int start)
{
    for (int i = start; i < myargc - 1; i++)
        if (M_StringCompare(check, myargv[i]))
            return i;
    return 0;
}

canonical_original_code:
int M_CheckParmWithArgs(char *check, int start)
{
    for (int i = start; i < myargc - 1; i++)
        if (M_StringCompare(check, myargv[i]))
            return i;
    return 0;
}

variable_types:
check
char *

variable_types: start int


decompiled_code:
__int64 __fastcall M_CheckParmsWithArgs(_BYTE *a1, _BYTE *a2, _BYTE *a3, int a4)
{
unsigned int v5; // er12
__int64 v6; // rbx

if ( a4 < myargc - 1 )
{
v5 = a4;
v6 = 8LL * a4;
do
{
if ( *a1 && (unsigned __int8)M_StringCompare(a1, *(_QWORD *)(myargv + v6)) )
return v5;
if ( *a2 )
{
if ( (unsigned __int8)M_StringCompare(a2, *(_QWORD *)(myargv + v6)) )
return v5;
if ( !*a3 )
goto LABEL_5;
}
else if ( !*a3 )
{
goto LABEL_5;
}
if ( (unsigned __int8)M_StringCompare(a3, *(_QWORD *)(myargv + v6)) )
return v5;
LABEL_5:
++v5;
v6 += 8LL;
}
while ( myargc - 1 > (int)v5 );
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_BYTE *a1, _BYTE *a2, _BYTE *a3, int a4)
{
unsigned int v5; // er12
__int64 v6; // rbx

if ( a4 < myargc - 1 )
{
v5 = a4;
v6 = 8LL * a4;
do
{
if ( *a1 && (unsigned __int8)M_StringCompare(a1, *(_QWORD *)(myargv + v6)) )
return v5;
if ( *a2 )
{
if ( (unsigned __int8)M_StringCompare(a2, *(_QWORD *)(myargv + v6)) )
return v5;
if ( !*a3 )
goto LABEL_5;
}
else if ( !*a3 )
{
goto LABEL_5;
}
if ( (unsigned __int8)M_StringCompare(a3, *(_QWORD *)(myargv + v6)) )
return v5;
LABEL_5:
++v5;
v6 += 8LL;
}
while ( myargc - 1 > (int)v5 );
}
return 0LL;
}

original_code:
int M_CheckParmsWithArgs(const char *check1, const char *check2, const char *check3, int start)
{
    for (int i = start; i < myargc - 1; i++)
        if ((*check1 && M_StringCompare(check1, myargv[i]))
            || (*check2 && M_StringCompare(check2, myargv[i]))
            || (*check3 && M_StringCompare(check3, myargv[i])))
            return i;
    return 0;
}

canonical_original_code:
int M_CheckParmsWithArgs(char *check1, char *check2, char *check3, int start)
{
    for (int i = start; i < myargc - 1; i++)
        if ((*check1 && M_StringCompare(check1, myargv[i]))
            || (*check2 && M_StringCompare(check2, myargv[i]))
            || (*check3 && M_StringCompare(check3, myargv[i])))
            return i;
    return 0;
}


decompiled_code:
__int64 __fastcall M_CheckParm(__int64 a1)
{
__int64 v1; // rbx
int v2; // er12

if ( myargc <= 1 )
return 0LL;
v1 = 8LL;
v2 = 1;
while ( !(unsigned __int8)M_StringCompare(a1, *(_QWORD *)(myargv + v1)) )
{
++v2;
v1 += 8LL;
if ( myargc <= v2 )
return 0LL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 v1; // rbx
int v2; // er12

if ( myargc <= 1 )
return 0LL;
v1 = 8LL;
v2 = 1;
while ( !(unsigned __int8)M_StringCompare(a1, *(_QWORD *)(myargv + v1)) )
{
++v2;
v1 += 8LL;
if ( myargc <= v2 )
return 0LL;
}
return (unsigned int)v2;
}

original_code:
int M_CheckParm(const char *check)
{
    for (int i = 1; i < myargc; i++)
        if (M_StringCompare(check, myargv[i]))
            return i;
    return 0;
}

canonical_original_code:
int M_CheckParm(char *check)
{
    for (int i = 1; i < myargc; i++)
        if (M_StringCompare(check, myargv[i]))
            return i;
    return 0;
}


EnsureSpritesCapacity

decompiled_code:
void __fastcall EnsureSpritesCapacity(int a1)
{
int i; // er14
char *v3; // rdi
int v4; // ebx
__int64 v5; // rax

for ( i = numsprites; numsprites <= a1; i = numsprites )
{
v4 = 2 * i;
numsprites = 2 * i;
if ( first_allocation_0 )
{
first_allocation_0 = 0;
sprnames = (__int64)malloc(8LL * v4);
v3 = (char *)memcpy((void *)sprnames, original_sprnames, 8LL * i);
}
else
{
v5 = I_Realloc(sprnames, 8LL * v4);
v4 = numsprites;
sprnames = v5;
v3 = (char *)v5;
}
memset(&v3[8 * i], 0, 8LL * (v4 - i));
sprnames_state = (void *)I_Realloc(sprnames_state, numsprites);
memset((char *)sprnames_state + i, 0, numsprites - i);
}
}

canonical_decompiled_code:
void __fastcall func0(int a1)
{
int i; // er14
char *v3; // rdi
int v4; // ebx
__int64 v5; // rax

for ( i = numsprites; numsprites <= a1; i = numsprites )
{
v4 = 2 * i;
numsprites = 2 * i;
if ( first_allocation_0 )
{
first_allocation_0 = 0;
sprnames = (__int64)malloc(8LL * v4);
v3 = (char *)memcpy((void *)sprnames, original_sprnames, 8LL * i);
}
else
{
v5 = I_Realloc(sprnames, 8LL * v4);
v4 = numsprites;
sprnames = v5;
v3 = (char *)v5;
}
memset(&v3[8 * i], 0, 8LL * (v4 - i));
sprnames_state = (void *)I_Realloc(sprnames_state, numsprites);
memset((char *)sprnames_state + i, 0, numsprites - i);
}
}

original_code:
static void EnsureSpritesCapacity(const int limit)
{
    static _Bool first_allocation = 1;
    while (limit >= numsprites)
    {
        const int old_numsprites = numsprites;
        numsprites *= 2;
        if (first_allocation)
        {
            first_allocation = 0;
            sprnames = malloc(numsprites * sizeof(*sprnames));
            memcpy(sprnames, original_sprnames, old_numsprites * sizeof(*sprnames));
        }
        else
            sprnames = I_Realloc(sprnames, numsprites * sizeof(*sprnames));
        memset(sprnames + old_numsprites, 0, (numsprites - old_numsprites) * sizeof(*sprnames));
        sprnames_state = I_Realloc(sprnames_state, numsprites * sizeof(*sprnames_state));
        memset(sprnames_state + old_numsprites, 0,
            (numsprites - old_numsprites) * sizeof(*sprnames_state));
    }
}

canonical_original_code:
static void EnsureSpritesCapacity(int limit)
{
    static _Bool first_allocation = 1;
    while (limit >= numsprites)
    {
        int old_numsprites = numsprites;
        numsprites *= 2;
        if (first_allocation)
        {
            first_allocation = 0;
            sprnames = malloc(numsprites * sizeof(*sprnames));
            memcpy(sprnames, original_sprnames, old_numsprites * sizeof(*sprnames));
        }
        else
            sprnames = I_Realloc(sprnames, numsprites * sizeof(*sprnames));
        memset(sprnames + old_numsprites, 0, (numsprites - old_numsprites) * sizeof(*sprnames));
        sprnames_state = I_Realloc(sprnames_state, numsprites * sizeof(*sprnames_state));
        memset(sprnames_state + old_numsprites, 0,
            (numsprites - old_numsprites) * sizeof(*sprnames_state));
    }
}

variable_types: limit int


InitSprites

decompiled_code:
void *InitSprites()
{
__int64 v0; // rbx
char *v1; // rax
char **v2; // rdx
char *v3; // rdi
__int64 *v4; // rbp
__int64 v5; // rax
size_t v6; // rdi
void *result; // rax

v0 = 0LL;
sprnames = (__int64)original_sprnames;
numsprites = 246;
deh_spritenames_size = 247;
v1 = (char *)malloc(0x7B8uLL);
v2 = original_sprnames;
for ( deh_spritenames = v1; ; v1 = (char *)deh_spritenames )
{
v3 = v2[v0];
v4 = (__int64 *)&v1[8 * v0++];
v5 = M_StringDuplicate(v3);
v6 = numsprites;
*v4 = v5;
if ( (int)v6 <= (int)v0 )
break;
v2 = (char **)sprnames;
}
*((_QWORD *)deh_spritenames + v6) = 0LL;
result = calloc(v6, 1uLL);
sprnames_state = result;
return result;
}

canonical_decompiled_code:
void *func1()
{
__int64 v0; // rbx
char *v1; // rax
char **v2; // rdx
char *v3; // rdi
__int64 *v4; // rbp
__int64 v5; // rax
size_t v6; // rdi
void *result; // rax

v0 = 0LL;
sprnames = (__int64)original_sprnames;
numsprites = 246;
deh_spritenames_size = 247;
v1 = (char *)malloc(0x7B8uLL);
v2 = original_sprnames;
for ( deh_spritenames = v1; ; v1 = (char *)deh_spritenames )
{
v3 = v2[v0];
v4 = (__int64 *)&v1[8 * v0++];
v5 = M_StringDuplicate(v3);
v6 = numsprites;
*v4 = v5;
if ( (int)v6 <= (int)v0 )
break;
v2 = (char **)sprnames;
}
*((_QWORD *)deh_spritenames + v6) = 0LL;
result = calloc(v6, 1uLL);
sprnames_state = result;
return result;
}

original_code:
void InitSprites(void)
{
    sprnames = original_sprnames;
    numsprites = NUMSPRITES;
    deh_spritenames_size = numsprites + 1;
    deh_spritenames = malloc(deh_spritenames_size * sizeof(*deh_spritenames));
    for (int i = 0; i < numsprites; i++)
        deh_spritenames[i] = M_StringDuplicate(sprnames[i]);
    deh_spritenames[numsprites] = ((void *)0);
    sprnames_state = calloc(numsprites, sizeof(*sprnames_state));
}

canonical_original_code:
void InitSprites()
{
    sprnames = original_sprnames;
    numsprites = NUMSPRITES;
    deh_spritenames_size = numsprites + 1;
    deh_spritenames = malloc(deh_spritenames_size * sizeof(*deh_spritenames));
    for (int i = 0; i < numsprites; i++)
        deh_spritenames[i] = M_StringDuplicate(sprnames[i]);
    deh_spritenames[numsprites] = ((void *)0);
    sprnames_state = calloc(numsprites, sizeof(*sprnames_state));
}


FreeSprites

decompiled_code:
void FreeSprites()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp

v0 = deh_spritenames;
if ( deh_spritenames_size > 0 )
{
v1 = (void **)deh_spritenames;
v2 = (void **)((char *)deh_spritenames + 8 * (unsigned int)(deh_spritenames_size - 1) + 8);
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != v2 );
}
free(v0);
free(sprnames_state);
}

canonical_decompiled_code:
void func2()
{
void *v0; // r12
void **v1; // rbx
void **v2; // rbp

v0 = deh_spritenames;
if ( deh_spritenames_size > 0 )
{
v1 = (void **)deh_spritenames;
v2 = (void **)((char *)deh_spritenames + 8 * (unsigned int)(deh_spritenames_size - 1) + 8);
do
{
if ( *v1 )
free(*v1);
++v1;
}
while ( v1 != v2 );
}
free(v0);
free(sprnames_state);
}

original_code:
void FreeSprites(void)
{
    for (int i = 0; i < deh_spritenames_size; i++)
        if (deh_spritenames[i])
            free(deh_spritenames[i]);
    free(deh_spritenames);
    free(sprnames_state);
}

canonical_original_code:
void FreeSprites()
{
    for (int i = 0; i < deh_spritenames_size; i++)
        if (deh_spritenames[i])
            free(deh_spritenames[i]);
    free(deh_spritenames);
    free(sprnames_state);
}


decompiled_code:
__int64 __fastcall dsdh_GetDehSpriteIndex(char *s2)
{
__int64 v1; // rbp
__int64 v2; // r13
_BYTE *v3; // r15
__int64 v5; // rbx
const char *v6; // rdi
unsigned int v7; // er12

v1 = numsprites;
if ( numsprites <= 0 )
return (unsigned int)-1;
v2 = sprnames;
v3 = sprnames_state;
v5 = 0LL;
while ( 1 )
{
v6 = *(const char **)(v2 + 8 * v5);
v7 = v5;
if ( v6 )
{
if ( !strncasecmp(v6, s2, 4uLL) && !v3[v5] )
break;
}
if ( ++v5 == v1 )
return (unsigned int)-1;
}
v3[v5] = 1;
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
__int64 v1; // rbp
__int64 v2; // r13
_BYTE *v3; // r15
__int64 v5; // rbx
const char *v6; // rdi
unsigned int v7; // er12

v1 = numsprites;
if ( numsprites <= 0 )
return (unsigned int)-1;
v2 = sprnames;
v3 = sprnames_state;
v5 = 0LL;
while ( 1 )
{
v6 = *(const char **)(v2 + 8 * v5);
v7 = v5;
if ( v6 )
{
if ( !strncasecmp(v6, s2, 4uLL) && !v3[v5] )
break;
}
if ( ++v5 == v1 )
return (unsigned int)-1;
}
v3[v5] = 1;
return v7;
}

original_code:
int dsdh_GetDehSpriteIndex(const char *key)
{
    for (int i = 0; i < numsprites; i++)
        if (sprnames[i] && !strncasecmp(sprnames[i], key, 4) && !sprnames_state[i])
        {
            sprnames_state[i] = 1;
            return i;
        }
    return -1;
}

canonical_original_code:
int dsdh_GetDehSpriteIndex(char *key)
{
    for (int i = 0; i < numsprites; i++)
        if (sprnames[i] && !strncasecmp(sprnames[i], key, 4) && !sprnames_state[i])
        {
            sprnames_state[i] = 1;
            return i;
        }
    return -1;
}

variable_types:
key
char *


decompiled_code:
__int64 __fastcall dsdh_GetOriginalSpriteIndex(char *nptr)
{
_QWORD *v2; // r13
const char *v3; // rdi
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbx
const unsigned __int16 *v7; // rdx
char *v8; // rax
unsigned int v9; // er12

v2 = deh_spritenames;
v3 = *(const char **)deh_spritenames;
if ( *(_QWORD *)deh_spritenames )
{
v4 = 0LL;
while ( strncasecmp(v3, nptr, 4uLL) )
{
v3 = (const char *)v2[++v4];
if ( !v3 )
goto LABEL_6;
}
result = (unsigned int)v4;
}
else
{
LABEL_6:
v6 = *nptr;
if ( (_BYTE)v6 )
{
v7 = *_ctype_b_loc();
v8 = nptr;
while ( (v7[v6] & 0x800) != 0 )
{
v6 = *++v8;
if ( !(_BYTE)v6 )
goto LABEL_11;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_11:
v9 = atoi(nptr);
EnsureSpritesCapacity(v9);
result = v9;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *nptr)
{
_QWORD *v2; // r13
const char *v3; // rdi
__int64 v4; // rbx
__int64 result; // rax
__int64 v6; // rbx
const unsigned __int16 *v7; // rdx
char *v8; // rax
unsigned int v9; // er12

v2 = deh_spritenames;
v3 = *(const char **)deh_spritenames;
if ( *(_QWORD *)deh_spritenames )
{
v4 = 0LL;
while ( strncasecmp(v3, nptr, 4uLL) )
{
v3 = (const char *)v2[++v4];
if ( !v3 )
goto LABEL_6;
}
result = (unsigned int)v4;
}
else
{
LABEL_6:
v6 = *nptr;
if ( (_BYTE)v6 )
{
v7 = *_ctype_b_loc();
v8 = nptr;
while ( (v7[v6] & 0x800) != 0 )
{
v6 = *++v8;
if ( !(_BYTE)v6 )
goto LABEL_11;
}
result = 0xFFFFFFFFLL;
}
else
{
LABEL_11:
v9 = atoi(nptr);
func0(v9);
result = v9;
}
}
return result;
}

original_code:
int dsdh_GetOriginalSpriteIndex(const char *key)
{
    int limit;
    for (int i = 0; deh_spritenames[i]; i++)
        if (!strncasecmp(deh_spritenames[i], key, 4))
            return i;
    for (const char *c = key; *c; c++)
        if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISdigit))
            return -1;
    limit = atoi(key);
    EnsureSpritesCapacity(limit);
    return limit;
}

canonical_original_code:
int dsdh_GetOriginalSpriteIndex(char *key)
{
    int limit;
    for (int i = 0; deh_spritenames[i]; i++)
        if (!strncasecmp(deh_spritenames[i], key, 4))
            return i;
    for (char *c = key; *c; c++)
        if (!((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISdigit))
            return -1;
    limit = atoi(key);
    EnsureSpritesCapacity(limit);
    return limit;
}

variable_types:
c
char *


ABS

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

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

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

variable_types: a int


MAX

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 >= (int)a1 )
result = a2;
return result;
}

original_code:
__attribute__((const)) static inline int MAX(int a, int b)
{
    return (a > b ? a : b);
}

variable_types: b int


MIN

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

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

result = a1;
if ( (int)a2 <= (int)a1 )
result = a2;
return result;
}

original_code:
__attribute__((const)) static inline int MIN(int a, int b)
{
    return (a < b ? a : b);
}


FixedDiv

decompiled_code:
__int64 __fastcall FixedDiv(int a1, int a2)
{
int v2; // eax
int v3; // ecx
int v4; // er8
__int64 result; // rax

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

canonical_decompiled_code:
__int64 __fastcall func3(int a1, int a2)
{
int v2; // eax
int v3; // ecx
int v4; // er8
__int64 result; // rax

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

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

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


decompiled_code:
__int64 __fastcall P_DivlineSide(int a1, int a2, _DWORD *a3)
{
int v3; // ecx
int v4; // eax
int v5; // er8
__int64 result; // rax
unsigned int v7; // eax
int v8; // edi
int v9; // esi

v3 = a3[2];
if ( v3 )
{
v4 = a3[3];
v5 = a3[1];
if ( v4 )
{
v8 = (v4 >> 16) * ((a1 - *a3) >> 16);
v9 = (v3 >> 16) * ((a2 - v5) >> 16);
result = v8 < v9;
if ( v8 == v9 )
result = 2LL;
}
else
{
result = 2LL;
if ( a2 != v5 )
{
if ( a2 <= v5 )
{
v7 = a3[2];
return v7 >> 31;
}
result = v3 > 0;
}
}
}
else
{
result = 2LL;
if ( *a3 != a1 )
{
v7 = a3[3];
if ( *a3 < a1 )
return v7 >> 31;
result = (int)v7 > 0;
}
}
return result;
}

original_code:
static int P_DivlineSide(const fixed_t x, const fixed_t y, const divline_t *node)
{
    if (!node->dx)
        return (x == node->x ? 2 : (x <= node->x ? (node->dy > 0) : (node->dy < 0)));
    else if (!node->dy)
        return (y == node->y ? 2 : (y <= node->y ? (node->dx < 0) : (node->dx > 0)));
    else
    {
        const fixed_t left = (node->dy >> 16) * ((x - node->x) >> 16);
        const fixed_t right = ((y - node->y) >> 16) * (node->dx >> 16);
        return (left == right ? 2 : (left < right));
    }
}

canonical_original_code:
static int P_DivlineSide(int x, int y, struct divline_t *node)
{
    if (!node->dx)
        return (x == node->x ? 2 : (x <= node->x ? (node->dy > 0) : (node->dy < 0)));
    else if (!node->dy)
        return (y == node->y ? 2 : (y <= node->y ? (node->dx < 0) : (node->dx > 0)));
    else
    {
        int left = (node->dy >> 16) * ((x - node->x) >> 16);
        int right = ((y - node->y) >> 16) * (node->dx >> 16);
        return (left == right ? 2 : (left < right));
    }
}

variable_types: x int

variable_types: y int

variable_types:
node
struct divline_t { int x; int dx; } *

variable_types: left int

variable_types: right int