original_code:
void Z_Free(void *ptr)
{
    memblock_t *block;
    if (!ptr)
        return;
    block = (memblock_t *)((char *)ptr - headersize);
    if (block->user)
        *block->user = ((void *)0);
    if (block == block->next)
        blockbytag[block->tag] = ((void *)0);
    else if (blockbytag[block->tag] == block)
        blockbytag[block->tag] = block->next;
    block->prev->next = block->next;
    block->next->prev = block->prev;
    free(block);
}

canonical_original_code:
void Z_Free(void *ptr)
{
    struct memblock_s *block;
    if (!ptr)
        return;
    block = (struct memblock_s *)((char *)ptr - headersize);
    if (block->user)
        *block->user = ((void *)0);
    if (block == block->next)
        blockbytag[block->tag] = ((void *)0);
    else if (blockbytag[block->tag] == block)
        blockbytag[block->tag] = block->next;
    block->prev->next = block->next;
    block->next->prev = block->prev;
    free(block);
}

variable_types:
ptr
void *

variable_types: struct memblock_s { struct memblock_s *next; struct memblock_s *prev; unsigned long size; void **user; unsigned char tag; } *


repo: bradharding/doomretro

original_code:
void Z_FreeTags(int lowtag, int hightag)
{
    if (lowtag <= PU_FREE)
        lowtag = PU_FREE + 1;
    if (hightag > PU_CACHE)
        hightag = PU_CACHE;
    for (; lowtag <= hightag; lowtag++)
    {
        memblock_t *block = blockbytag[lowtag];
        memblock_t *end_block;
        if (!block)
            continue;
        end_block = block->prev;
        while (1)
        {
            memblock_t *next = block->next;
            Z_Free((char *)block + headersize);
            if (block == end_block)
                break;
            block = next;
        }
    }
}

canonical_original_code:
void Z_FreeTags(int lowtag, int hightag)
{
    if (lowtag <= PU_FREE)
        lowtag = PU_FREE + 1;
    if (hightag > PU_CACHE)
        hightag = PU_CACHE;
    for (; lowtag <= hightag; lowtag++)
    {
        struct memblock_s *block = blockbytag[lowtag];
        struct memblock_s *end_block;
        if (!block)
            continue;
        end_block = block->prev;
        while (1)
        {
            struct memblock_s *next = block->next;
            Z_Free((char *)block + headersize);
            if (block == end_block)
                break;
            block = next;
        }
    }
}

variable_types: lowtag int

variable_types: hightag int

return_type: void

user_defined_types: struct memblock_s { struct memblock_s *next; struct memblock_s *prev; unsigned long size; void **user; unsigned char tag; }


decompiled_code:
void *__fastcall Z_Calloc(__int64 a1, __int64 a2, int a3, char *a4)
{
size_t v4; // rbx
void *result; // rax
char *v6; // rax

v4 = a1 * a2;
result = 0LL;
if ( a1 * a2 )
{
v6 = Z_Malloc(v4, a3, a4);
result = memset(v6, 0, v4);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(__int64 a1, __int64 a2, int a3, char *a4)
{
size_t v4; // rbx
void *result; // rax
char *v6; // rax

v4 = a1 * a2;
result = 0LL;
if ( a1 * a2 )
{
v6 = func2(v4, a3, a4);
result = memset(v6, 0, v4);
}
return result;
}

original_code:
void *Z_Calloc(size_t n1, size_t n2, int tag, void **user)
{
    return ((n1 *= n2) ? memset(Z_Malloc(n1, tag, user), 0, n1) : ((void *)0));
}

canonical_original_code:
void *Z_Calloc(unsigned long n1, unsigned long n2, int tag, void **user)
{
    return ((n1 *= n2) ? memset(Z_Malloc(n1, tag, user), 0, n1) : ((void *)0));
}

variable_types: tag int

variable_types:
user
void **

return_type: void *


decompiled_code:
char *__fastcall Z_StringDuplicate(char *src, int a2, char *a3)
{
size_t v4; // rax
char *v5; // rax
char *v6; // rbx

v4 = strlen(src);
v5 = Z_Malloc(v4 + 1, a2, a3);
v6 = v5;
if ( v5 )
strcpy(v5, src);
return v6;
}

canonical_decompiled_code:
char *__fastcall func4(char *src, int a2, char *a3)
{
size_t v4; // rax
char *v5; // rax
char *v6; // rbx

v4 = strlen(src);
v5 = func2(v4 + 1, a2, a3);
v6 = v5;
if ( v5 )
strcpy(v5, src);
return v6;
}

original_code:
char *Z_StringDuplicate(const char *s, int tag, void **user)
{
    char *d = Z_Malloc(strlen(s) + 1, tag, user);
    if (d)
        strcpy(d, s);
    return d;
}

canonical_original_code:
char *Z_StringDuplicate(char *s, int tag, void **user)
{
    char *d = Z_Malloc(strlen(s) + 1, tag, user);
    if (d)
        strcpy(d, s);
    return d;
}

variable_types:
s
char *

variable_types:
d
char *

return_type: char *


original_code:
void Z_ChangeTag(void *ptr, int tag)
{
    memblock_t *block;
    if (!ptr)
        return;
    block = (memblock_t *)((char *)ptr - headersize);
    if (tag == block->tag)
        return;
    if (block == block->next)
        blockbytag[block->tag] = ((void *)0);
    else if (blockbytag[block->tag] == block)
        blockbytag[block->tag] = block->next;
    block->prev->next = block->next;
    block->next->prev = block->prev;
    if (!blockbytag[tag])
    {
        blockbytag[tag] = block;
        block->next = block->prev = block;
    }
    else
    {
        blockbytag[tag]->prev->next = block;
        block->prev = blockbytag[tag]->prev;
        block->next = blockbytag[tag];
        blockbytag[tag]->prev = block;
    }
    block->tag = tag;
}

canonical_original_code:
void Z_ChangeTag(void *ptr, int tag)
{
    struct memblock_s *block;
    if (!ptr)
        return;
    block = (struct memblock_s *)((char *)ptr - headersize);
    if (tag == block->tag)
        return;
    if (block == block->next)
        blockbytag[block->tag] = ((void *)0);
    else if (blockbytag[block->tag] == block)
        blockbytag[block->tag] = block->next;
    block->prev->next = block->next;
    block->next->prev = block->prev;
    if (!blockbytag[tag])
    {
        blockbytag[tag] = block;
        block->next = block->prev = block;
    }
    else
    {
        blockbytag[tag]->prev->next = block;
        block->prev = blockbytag[tag]->prev;
        block->next = blockbytag[tag];
        blockbytag[tag]->prev = block;
    }
    block->tag = tag;
}


decompiled_code:
unsigned __int64 I_GetTime()
{
return 35 * (unsigned int)SDL_GetTicks() / 0x3E8uLL;
}

canonical_decompiled_code:
unsigned __int64 func0()
{
return 35 * (unsigned int)SDL_GetTicks() / 0x3E8uLL;
}

original_code:
uint64_t I_GetTime(void)
{
    return (SDL_GetTicks() * 35 / 1000);
}

canonical_original_code:
unsigned long I_GetTime()
{
    return (SDL_GetTicks() * 35 / 1000);
}

return_type: unsigned long


decompiled_code:
__int64 I_GetTimeMS()
{
return (unsigned int)SDL_GetTicks();
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)SDL_GetTicks();
}

original_code:
uint64_t I_GetTimeMS(void)
{
    return SDL_GetTicks();
}

canonical_original_code:
unsigned long I_GetTimeMS()
{
    return SDL_GetTicks();
}


decompiled_code:
__int64 I_Sleep()
{
return SDL_Delay();
}

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

original_code:
void I_Sleep(int ms)
{
    SDL_Delay(ms);
}

canonical_original_code:
void I_Sleep(int ms)
{
    SDL_Delay(ms);
}

variable_types: ms int


original_code:
size_t mem_fread(void *buf, size_t size, size_t nmemb, MEMFILE *stream)
{
    size_t items;
    if (stream->mode != MODE_READ)
        return -1;
    items = nmemb;
    if (items * size > stream->buflen - stream->position)
        items = (stream->buflen - stream->position) / size;
    memcpy(buf, stream->buf + stream->position, items * size);
    stream->position += (unsigned int)(items * size);
    return items;
}

canonical_original_code:
unsigned long mem_fread(void *buf, unsigned long size, unsigned long nmemb, struct _MEMFILE *stream)
{
    unsigned long items;
    if (stream->mode != MODE_READ)
        return -1;
    items = nmemb;
    if (items * size > stream->buflen - stream->position)
        items = (stream->buflen - stream->position) / size;
    memcpy(buf, stream->buf + stream->position, items * size);
    stream->position += (unsigned int)(items * size);
    return items;
}

variable_types:
buf
void *

variable_types:
size
unsigned long

variable_types:
nmemb
unsigned long

variable_types: struct _MEMFILE { unsigned char *buf; unsigned long buflen; unsigned long alloced; unsigned int position; enum memfile_mode_t { MODE_READ=0, MODE_WRITE=1 } mode; } *

variable_types:
items
unsigned long

user_defined_types: struct _MEMFILE { unsigned char *buf; unsigned long buflen; unsigned long alloced; unsigned int position; enum memfile_mode_t mode; }


original_code:
MEMFILE *mem_fopen_write(void)
{
    MEMFILE *file = Z_Malloc(sizeof(MEMFILE), PU_STATIC, ((void *)0));
    file->alloced = 1024;
    file->buf = Z_Malloc(file->alloced, PU_STATIC, ((void *)0));
    file->buflen = 0;
    file->position = 0;
    file->mode = MODE_WRITE;
    return file;
}

canonical_original_code:
struct _MEMFILE *mem_fopen_write()
{
    struct _MEMFILE *file = Z_Malloc(sizeof(MEMFILE), PU_STATIC, ((void *)0));
    file->alloced = 1024;
    file->buf = Z_Malloc(file->alloced, PU_STATIC, ((void *)0));
    file->buflen = 0;
    file->position = 0;
    file->mode = MODE_WRITE;
    return file;
}

return_type: struct _MEMFILE { unsigned char *buf; unsigned long buflen; unsigned long alloced; unsigned int position; enum memfile_mode_t { MODE_READ=0, MODE_WRITE=1 } mode; } *


original_code:
size_t mem_fwrite(const void *ptr, size_t size, size_t nmemb, MEMFILE *stream)
{
    size_t bytes;
    if (stream->mode != MODE_WRITE)
        return -1;
    bytes = size * nmemb;
    while (stream->alloced - stream->position < bytes)
    {
        unsigned char *newbuf = Z_Malloc(stream->alloced * 2, PU_STATIC, ((void *)0));
        memcpy(newbuf, stream->buf, stream->alloced);
        Z_Free(stream->buf);
        stream->buf = newbuf;
        stream->alloced *= 2;
    }
    memcpy(stream->buf + stream->position, ptr, bytes);
    stream->position += (unsigned int)bytes;
    if (stream->position > stream->buflen)
        stream->buflen = stream->position;
    return nmemb;
}

canonical_original_code:
unsigned long mem_fwrite(void *ptr, unsigned long size, unsigned long nmemb, struct _MEMFILE *stream)
{
    unsigned long bytes;
    if (stream->mode != MODE_WRITE)
        return -1;
    bytes = size * nmemb;
    while (stream->alloced - stream->position < bytes)
    {
        unsigned char *newbuf = Z_Malloc(stream->alloced * 2, PU_STATIC, ((void *)0));
        memcpy(newbuf, stream->buf, stream->alloced);
        Z_Free(stream->buf);
        stream->buf = newbuf;
        stream->alloced *= 2;
    }
    memcpy(stream->buf + stream->position, ptr, bytes);
    stream->position += (unsigned int)bytes;
    if (stream->position > stream->buflen)
        stream->buflen = stream->position;
    return nmemb;
}

variable_types:
bytes
unsigned long

variable_types:
newbuf
unsigned char *

user_defined_types: enum memfile_mode_t { MODE_READ=0, MODE_WRITE=1 }


decompiled_code:
__int64 __fastcall mem_fclose(__int64 a1)
{
if ( *(_DWORD *)(a1 + 28) == 1 )
Z_Free(*(_QWORD *)a1);
return Z_Free(a1);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( *(_DWORD *)(a1 + 28) == 1 )
Z_Free(*(_QWORD *)a1);
return Z_Free(a1);
}

original_code:
void mem_fclose(MEMFILE *stream)
{
    if (stream->mode == MODE_WRITE)
        Z_Free(stream->buf);
    Z_Free(stream);
}

canonical_original_code:
void mem_fclose(struct _MEMFILE *stream)
{
    if (stream->mode == MODE_WRITE)
        Z_Free(stream->buf);
    Z_Free(stream);
}


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

if ( a3 == 1 )
{
a2 += *(_DWORD *)(a1 + 24);
}
else if ( a3 == 2 )
{
a2 += *(_DWORD *)(a1 + 8);
}
else
{
result = 0xFFFFFFFFLL;
if ( a3 )
return result;
}
if ( (unsigned __int64)a2 >= *(_QWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 24) = a2;
return 0LL;
}

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

if ( a3 == 1 )
{
a2 += *(_DWORD *)(a1 + 24);
}
else if ( a3 == 2 )
{
a2 += *(_DWORD *)(a1 + 8);
}
else
{
result = 0xFFFFFFFFLL;
if ( a3 )
return result;
}
if ( (unsigned __int64)a2 >= *(_QWORD *)(a1 + 8) )
return 0xFFFFFFFFLL;
*(_DWORD *)(a1 + 24) = a2;
return 0LL;
}

original_code:
int mem_fseek(MEMFILE *stream, long position, mem_rel_t whence)
{
    unsigned int newpos;
    switch (whence)
    {
        case MEM_SEEK_SET:
            newpos = (int)position;
            break;
        case MEM_SEEK_CUR:
            newpos = (int)(stream->position + position);
            break;
        case MEM_SEEK_END:
            newpos = (int)(stream->buflen + position);
            break;
        default:
            return -1;
    }
    if (newpos < stream->buflen)
    {
        stream->position = newpos;
        return 0;
    }
    return -1;
}

canonical_original_code:
int mem_fseek(struct _MEMFILE *stream, long position, enum mem_rel_t whence)
{
    unsigned int newpos;
    switch (whence)
    {
        case MEM_SEEK_SET:
            newpos = (int)position;
            break;
        case MEM_SEEK_CUR:
            newpos = (int)(stream->position + position);
            break;
        case MEM_SEEK_END:
            newpos = (int)(stream->buflen + position);
            break;
        default:
            return -1;
    }
    if (newpos < stream->buflen)
    {
        stream->position = newpos;
        return 0;
    }
    return -1;
}

variable_types: position long

variable_types: enum mem_rel_t { MEM_SEEK_SET=0, MEM_SEEK_CUR=1, MEM_SEEK_END=2 }

variable_types:
newpos
unsigned int

return_type: int


InitMobjInfo

decompiled_code:
void InitMobjInfo()
{
nummobjtypes = 250;
mobjinfo = (__int64)&original_mobjinfo;
}

canonical_decompiled_code:
void func0()
{
nummobjtypes = 250;
mobjinfo = (__int64)&original_mobjinfo;
}

original_code:
void InitMobjInfo(void)
{
  nummobjtypes = NUMMOBJTYPES;
  mobjinfo = original_mobjinfo;
}

canonical_original_code:
void InitMobjInfo()
{
  nummobjtypes = NUMMOBJTYPES;
  mobjinfo = original_mobjinfo;
}


decompiled_code:
void __fastcall dsdh_EnsureMobjInfoCapacity(int a1)
{
int v1; // ebx
int v2; // ecx
_DWORD *v3; // rax
__int64 v4; // rdx
int v5; // eax

v1 = nummobjtypes;
if ( a1 >= nummobjtypes )
{
while ( 1 )
{
v5 = 2 * v1;
nummobjtypes = 2 * v1;
if ( first_allocation_0 )
{
first_allocation_0 = 0;
mobjinfo = (__int64)malloc(568LL * v5);
memcpy((void *)mobjinfo, &original_mobjinfo, 568LL * v1);
}
else
{
mobjinfo = I_Realloc(mobjinfo, 568LL * v5);
}
memset((void *)(mobjinfo + 568LL * v1), 0, 568LL * (nummobjtypes - v1));
v2 = nummobjtypes;
if ( nummobjtypes > v1 )
{
v3 = (_DWORD *)(mobjinfo + 568LL * v1 + 64);
v4 = mobjinfo + 568 * ((unsigned int)(nummobjtypes - 1 - v1) + (__int64)v1) + 632;
do
{
*v3 = -1;
v3[17] = 0;
v3[18] = 0;
v3[19] = 0;
v3[21] = -1;
v3[22] = 0x400000;
v3 += 142;
}
while ( v3 != (_DWORD *)v4 );
}
if ( a1 < v2 )
break;
v1 = v2;
}
}
}

canonical_decompiled_code:
void __fastcall func1(int a1)
{
int v1; // ebx
int v2; // ecx
_DWORD *v3; // rax
__int64 v4; // rdx
int v5; // eax

v1 = nummobjtypes;
if ( a1 >= nummobjtypes )
{
while ( 1 )
{
v5 = 2 * v1;
nummobjtypes = 2 * v1;
if ( first_allocation_0 )
{
first_allocation_0 = 0;
mobjinfo = (__int64)malloc(568LL * v5);
memcpy((void *)mobjinfo, &original_mobjinfo, 568LL * v1);
}
else
{
mobjinfo = I_Realloc(mobjinfo, 568LL * v5);
}
memset((void *)(mobjinfo + 568LL * v1), 0, 568LL * (nummobjtypes - v1));
v2 = nummobjtypes;
if ( nummobjtypes > v1 )
{
v3 = (_DWORD *)(mobjinfo + 568LL * v1 + 64);
v4 = mobjinfo + 568 * ((unsigned int)(nummobjtypes - 1 - v1) + (__int64)v1) + 632;
do
{
*v3 = -1;
v3[17] = 0;
v3[18] = 0;
v3[19] = 0;
v3[21] = -1;
v3[22] = 0x400000;
v3 += 142;
}
while ( v3 != (_DWORD *)v4 );
}
if ( a1 < v2 )
break;
v1 = v2;
}
}
}

original_code:
void dsdh_EnsureMobjInfoCapacity(const int limit)
{
    static _Bool first_allocation = 1;
    while (limit >= nummobjtypes)
    {
        const int old_nummobjtypes = nummobjtypes;
        nummobjtypes *= 2;
        if (first_allocation)
        {
            first_allocation = 0;
            mobjinfo = malloc(nummobjtypes * sizeof(*mobjinfo));
            memcpy(mobjinfo, original_mobjinfo, old_nummobjtypes * sizeof(*mobjinfo));
        }
        else
            mobjinfo = I_Realloc(mobjinfo, nummobjtypes * sizeof(*mobjinfo));
        memset(mobjinfo + old_nummobjtypes, 0,
            (nummobjtypes - old_nummobjtypes) * sizeof(*mobjinfo));
        for (int i = old_nummobjtypes; i < nummobjtypes; i++)
        {
            mobjinfo[i].droppeditem = MT_NULL;
            mobjinfo[i].infightinggroup = IG_DEFAULT;
            mobjinfo[i].projectilegroup = PG_DEFAULT;
            mobjinfo[i].splashgroup = SG_DEFAULT;
            mobjinfo[i].altspeed = -1;
            mobjinfo[i].meleerange = (64 * (1 << 16));
        }
    }
}

canonical_original_code:
void dsdh_EnsureMobjInfoCapacity(int limit)
{
    static _Bool first_allocation = 1;
    while (limit >= nummobjtypes)
    {
        int old_nummobjtypes = nummobjtypes;
        nummobjtypes *= 2;
        if (first_allocation)
        {
            first_allocation = 0;
            mobjinfo = malloc(nummobjtypes * sizeof(*mobjinfo));
            memcpy(mobjinfo, original_mobjinfo, old_nummobjtypes * sizeof(*mobjinfo));
        }
        else
            mobjinfo = I_Realloc(mobjinfo, nummobjtypes * sizeof(*mobjinfo));
        memset(mobjinfo + old_nummobjtypes, 0,
            (nummobjtypes - old_nummobjtypes) * sizeof(*mobjinfo));
        for (int i = old_nummobjtypes; i < nummobjtypes; i++)
        {
            mobjinfo[i].droppeditem = MT_NULL;
            mobjinfo[i].infightinggroup = IG_DEFAULT;
            mobjinfo[i].projectilegroup = PG_DEFAULT;
            mobjinfo[i].splashgroup = SG_DEFAULT;
            mobjinfo[i].altspeed = -1;
            mobjinfo[i].meleerange = (64 * (1 << 16));
        }
    }
}

variable_types: limit int

variable_types: i int


decompiled_code:
void I_PrintSystemInfo()
{
unsigned int v0; // ebx
int v1; // eax
char *v2; // rbp
const char *v3; // rcx
const char *v4; // rsi

v0 = SDL_GetCPUCount();
v1 = SDL_GetSystemRAM();
v2 = (char *)commify(v1 / 1000);
v3 = (const char *)&unk_28E;
if ( v0 == 1 )
v3 = (const char *)&unk_294;
v4 = (const char *)&unk_290;
if ( v0 == 1 )
v4 = (const char *)&unk_295;
C_Output("There %s %i core%s and %sGB of RAM on this PC.", v4, v0, v3, v2);
free(v2);
}

canonical_decompiled_code:
void func0()
{
unsigned int v0; // ebx
int v1; // eax
char *v2; // rbp
const char *v3; // rcx
const char *v4; // rsi

v0 = SDL_GetCPUCount();
v1 = SDL_GetSystemRAM();
v2 = (char *)commify(v1 / 1000);
v3 = (const char *)&unk_28E;
if ( v0 == 1 )
v3 = (const char *)&unk_294;
v4 = (const char *)&unk_290;
if ( v0 == 1 )
v4 = (const char *)&unk_295;
C_Output("There %s %i core%s and %sGB of RAM on this PC.", v4, v0, v3, v2);
free(v2);
}

original_code:
void I_PrintSystemInfo(void)
{
    const int cores = SDL_GetCPUCount();
    char *RAM = commify(SDL_GetSystemRAM() / 1000);
    C_Output("There %s %i core%s and %sGB of RAM on this " "PC" ".",
        (cores == 1 ? "is" : "are"), cores, (cores == 1 ? "" : "s"), RAM);
    free(RAM);
}

canonical_original_code:
void I_PrintSystemInfo()
{
    int cores = SDL_GetCPUCount();
    char *RAM = commify(SDL_GetSystemRAM() / 1000);
    C_Output("There %s %i core%s and %sGB of RAM on this " "PC" ".",
        (cores == 1 ? "is" : "are"), cores, (cores == 1 ? "" : "s"), RAM);
    free(RAM);
}

variable_types: cores int

variable_types:
RAM
char *


decompiled_code:
void __fastcall __noreturn I_Quit(char a1)
{
if ( a1 )
{
D_FadeScreenToBlack();
S_Shutdown();
M_SaveCVARs();
I_ShutdownKeyboard();
I_ShutdownGameController();
SDL_Quit();
}
W_CloseFiles();
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(char a1)
{
if ( a1 )
{
D_FadeScreenToBlack();
S_Shutdown();
M_SaveCVARs();
I_ShutdownKeyboard();
I_ShutdownGameController();
SDL_Quit();
}
W_CloseFiles();
exit(0);
}

original_code:
void I_Quit(_Bool shutdown)
{
    if (shutdown)
    {
        D_FadeScreenToBlack();
        S_Shutdown();
        M_SaveCVARs();
        I_ShutdownKeyboard();
        I_ShutdownGameController();
        SDL_Quit();
    }
    W_CloseFiles();
    exit(0);
}


decompiled_code:
void __noreturn I_Error(char *format, ...)
{
_BYTE v1[520]; // [rsp+0h] [rbp-2E8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-E0h] BYREF

if ( already_quitting_0 )
exit(-1);
already_quitting_0 = 1;
S_Shutdown();
M_SaveCVARs();
I_ShutdownKeyboard();
I_ShutdownGameController();
SDL_Quit();
W_CloseFiles();
va_start(arg, format);
vfprintf(stderr, format, arg);
fwrite(&unk_298, 1uLL, 2uLL, stderr);
fflush(stderr);
va_end(arg);
va_start(arg, format);
memset(v1, 0, 0x200uLL);
M_vsnprintf(v1, 511LL, format, arg);
M_snprintf(v1, 512LL, &unk_29B, v1);
SDL_ShowSimpleMessageBox(16LL, "DOOM Retro", v1, 0LL);
exit(-1);
}

canonical_decompiled_code:
void __noreturn func2(char *format, ...)
{
_BYTE v1[520]; // [rsp+0h] [rbp-2E8h] BYREF
gcc_va_list arg; // [rsp+208h] [rbp-E0h] BYREF

if ( already_quitting_0 )
exit(-1);
already_quitting_0 = 1;
S_Shutdown();
M_SaveCVARs();
I_ShutdownKeyboard();
I_ShutdownGameController();
SDL_Quit();
W_CloseFiles();
va_start(arg, format);
vfprintf(stderr, format, arg);
fwrite(&unk_298, 1uLL, 2uLL, stderr);
fflush(stderr);
va_end(arg);
va_start(arg, format);
memset(v1, 0, 0x200uLL);
M_vsnprintf(v1, 511LL, format, arg);
M_snprintf(v1, 512LL, &unk_29B, v1);
SDL_ShowSimpleMessageBox(16LL, "DOOM Retro", v1, 0LL);
exit(-1);
}

original_code:
void I_Error(const char *error, ...)
{
    va_list args;
    char msgbuf[512];
    static _Bool already_quitting;
    if (already_quitting)
        exit(-1);
    already_quitting = 1;
    S_Shutdown();
    M_SaveCVARs();
    I_ShutdownKeyboard();
    I_ShutdownGameController();
    SDL_Quit();
    W_CloseFiles();
    __builtin_va_start(args,error);
    vfprintf(stderr, error, args);
    fprintf(stderr, "\n\n");
    __builtin_va_end(args);
    fflush(stderr);
    __builtin_va_start(args,error);
    memset(msgbuf, 0, sizeof(msgbuf));
    M_vsnprintf(msgbuf, sizeof(msgbuf) - 1, error, args);
    __builtin_va_end(args);
    M_snprintf(msgbuf, sizeof(msgbuf), "%s\n", msgbuf);
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "DOOM Retro", msgbuf, ((void *)0));
    exit(-1);
}

canonical_original_code:
void I_Error(char *error, ...)
{
    __builtin_va_list args;
    char msgbuf[512];
    static _Bool already_quitting;
    if (already_quitting)
        exit(-1);
    already_quitting = 1;
    S_Shutdown();
    M_SaveCVARs();
    I_ShutdownKeyboard();
    I_ShutdownGameController();
    SDL_Quit();
    W_CloseFiles();
    __builtin_va_start(args,error);
    vfprintf(stderr, error, args);
    fprintf(stderr, "\n\n");
    __builtin_va_end(args);
    fflush(stderr);
    __builtin_va_start(args,error);
    memset(msgbuf, 0, sizeof(msgbuf));
    M_vsnprintf(msgbuf, sizeof(msgbuf) - 1, error, args);
    __builtin_va_end(args);
    M_snprintf(msgbuf, sizeof(msgbuf), "%s\n", msgbuf);
    SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "DOOM Retro", msgbuf, ((void *)0));
    exit(-1);
}

variable_types:
error
char *

variable_types:
msgbuf
char [512]


decompiled_code:
void *__fastcall I_Realloc(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
if ( a2 )
I_Error("I_Realloc: Failure trying to reallocate %zu bytes", a2);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func3(void *a1, size_t a2)
{
void *result; // rax

result = realloc(a1, a2);
if ( !result )
{
if ( a2 )
func2("I_Realloc: Failure trying to reallocate %zu bytes", a2);
}
return result;
}

original_code:
void *I_Realloc(void *block, size_t size)
{
    void *newp = realloc(block, size);
    if (!newp && size)
        I_Error("I_Realloc: Failure trying to reallocate %zu bytes", size);
    block = newp;
    return block;
}

canonical_original_code:
void *I_Realloc(void *block, unsigned long size)
{
    void *newp = realloc(block, size);
    if (!newp && size)
        I_Error("I_Realloc: Failure trying to reallocate %zu bytes", size);
    block = newp;
    return block;
}

variable_types:
block
void *

variable_types:
newp
void *


decompiled_code:
__int64 __fastcall P_RemoveThinkerDelayed(__int64 *a1)
{
_QWORD *v1; // rcx
__int64 v2; // rdx
__int64 v3; // rax
__int64 v4; // rax
__int64 result; // rax

if ( !*((_DWORD *)a1 + 10) )
{
v1 = (_QWORD *)a1[1];
v2 = a1[4];
v3 = *a1;
*v1 = *a1;
*(_QWORD *)(v3 + 8) = v1;
v4 = a1[3];
currentthinker = v4;
*(_QWORD *)(v2 + 24) = v4;
*(_QWORD *)(v4 + 32) = v2;
result = Z_Free();
}
return result;
}

original_code:
void P_RemoveThinkerDelayed(thinker_t *thinker)
{
    if (!thinker->references)
    {
        thinker_t *next = thinker->next;
        thinker_t *th = thinker->cnext;
        (next->prev = thinker->prev)->next = next;
        (th->cprev = currentthinker = thinker->cprev)->cnext = th;
        Z_Free(thinker);
    }
}

canonical_original_code:
void P_RemoveThinkerDelayed(struct thinker_s *thinker)
{
    if (!thinker->references)
    {
        struct thinker_s *next = thinker->next;
        struct thinker_s *th = thinker->cnext;
        (next->prev = thinker->prev)->next = next;
        (th->cprev = currentthinker = thinker->cprev)->cnext = th;
        Z_Free(thinker);
    }
}

variable_types: struct thinker_s { struct thinker_s *prev; struct thinker_s *next; void (*function)(); struct thinker_s *cprev; struct thinker_s *cnext; unsigned int references; _Bool menu; } *


original_code:
void P_RemoveThinkerDelayed2(thinker_t *thinker)
{
    thinker_t *next = thinker->next;
    thinker_t *th = thinker->cnext;
    (next->prev = thinker->prev)->next = next;
    (th->cprev = currentthinker = thinker->cprev)->cnext = th;
    Z_Free(thinker);
}

canonical_original_code:
void P_RemoveThinkerDelayed2(struct thinker_s *thinker)
{
    struct thinker_s *next = thinker->next;
    struct thinker_s *th = thinker->cnext;
    (next->prev = thinker->prev)->next = next;
    (th->cprev = currentthinker = thinker->cprev)->cnext = th;
    Z_Free(thinker);
}

user_defined_types: struct thinker_s { struct thinker_s *prev; struct thinker_s *next; void (*function)(); struct thinker_s *cprev; struct thinker_s *cnext; unsigned int references; _Bool menu; }


decompiled_code:
void P_InitThinkers()
{
thinkers[4] = (__int64)thinkers;
thinkers[3] = (__int64)thinkers;
thinkers[10] = (__int64)&thinkers[6];
thinkers[9] = (__int64)&thinkers[6];
thinkers[13] = (__int64)&thinkers[12];
thinkers[12] = (__int64)&thinkers[12];
}

canonical_decompiled_code:
void func3()
{
thinkers[4] = (__int64)thinkers;
thinkers[3] = (__int64)thinkers;
thinkers[10] = (__int64)&thinkers[6];
thinkers[9] = (__int64)&thinkers[6];
thinkers[13] = (__int64)&thinkers[12];
thinkers[12] = (__int64)&thinkers[12];
}

original_code:
void P_InitThinkers(void)
{
    thinkers[th_mobj].cprev = thinkers[th_mobj].cnext = &thinkers[th_mobj];
    thinkers[th_misc].cprev = thinkers[th_misc].cnext = &thinkers[th_misc];
    thinkers[th_all].prev = thinkers[th_all].next = &thinkers[th_all];
}

canonical_original_code:
void P_InitThinkers()
{
    thinkers[th_mobj].cprev = thinkers[th_mobj].cnext = &thinkers[th_mobj];
    thinkers[th_misc].cprev = thinkers[th_misc].cnext = &thinkers[th_misc];
    thinkers[th_all].prev = thinkers[th_all].next = &thinkers[th_all];
}


decompiled_code:
void __fastcall P_RemoveThinker(__int64 a1)
{
*(_QWORD *)(a1 + 16) = P_RemoveThinkerDelayed;
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
*(_QWORD *)(a1 + 16) = P_RemoveThinkerDelayed;
}

original_code:
void P_RemoveThinker(thinker_t *thinker)
{
    thinker->function = &P_RemoveThinkerDelayed;
}

canonical_original_code:
void P_RemoveThinker(struct thinker_s *thinker)
{
    thinker->function = &P_RemoveThinkerDelayed;
}


decompiled_code:
void __fastcall P_RemoveThinker2(__int64 a1)
{
*(_QWORD *)(a1 + 16) = P_RemoveThinkerDelayed2;
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1)
{
*(_QWORD *)(a1 + 16) = P_RemoveThinkerDelayed2;
}

original_code:
void P_RemoveThinker2(thinker_t *thinker)
{
    thinker->function = &P_RemoveThinkerDelayed2;
}

canonical_original_code:
void P_RemoveThinker2(struct thinker_s *thinker)
{
    thinker->function = &P_RemoveThinkerDelayed2;
}