repo: bradharding/doomretro

decompiled_code:
__int64 __fastcall P_CrossBSPNode(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
int v3; // eax
bool v4; // zf
int v5; // edi

while ( a1 >= 0 )
{
v1 = nodes + 56LL * a1;
v2 = (int)R_PointOnSide((unsigned int)dword_68C, (unsigned int)dword_690, v1);
if ( (_DWORD)v2 != (unsigned int)R_PointOnSide((unsigned int)dword_684, (unsigned int)dword_688, v1) )
{
if ( !(unsigned __int8)P_CrossBSPNode(*(unsigned int *)(v1 + 4LL * (int)v2 + 48)) )
return 0LL;
v2 = (int)(v2 ^ 1);
}
a1 = *(_DWORD *)(v1 + 4 * v2 + 48);
}
v3 = a1 & 0x7FFFFFFF;
v4 = a1 == -1;
v5 = 0;
if ( !v4 )
v5 = v3;
return P_CrossSubsector(v5);
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
__int64 v1; // rbp
__int64 v2; // rbx
int v3; // eax
bool v4; // zf
int v5; // edi

while ( a1 >= 0 )
{
v1 = nodes + 56LL * a1;
v2 = (int)R_PointOnSide((unsigned int)dword_68C, (unsigned int)dword_690, v1);
if ( (_DWORD)v2 != (unsigned int)R_PointOnSide((unsigned int)dword_684, (unsigned int)dword_688, v1) )
{
if ( !(unsigned __int8)func6(*(unsigned int *)(v1 + 4LL * (int)v2 + 48)) )
return 0LL;
v2 = (int)(v2 ^ 1);
}
a1 = *(_DWORD *)(v1 + 4 * v2 + 48);
}
v3 = a1 & 0x7FFFFFFF;
v4 = a1 == -1;
v5 = 0;
if ( !v4 )
v5 = v3;
return func5(v5);
}

original_code:
static _Bool P_CrossBSPNode(int bspnum)
{
    while (!(bspnum & 0x80000000))
    {
        const node_t *bsp = nodes + bspnum;
        const int side1 = R_PointOnSide(los.strace.x, los.strace.y, bsp);
        const int side2 = R_PointOnSide(los.t2x, los.t2y, bsp);
        if (side1 == side2)
            bspnum = bsp->children[side1];
        else if (!P_CrossBSPNode(bsp->children[side1]))
            return 0;
        else
            bspnum = bsp->children[side1 ^ 1];
    }
    return P_CrossSubsector(bspnum == -1 ? 0 : (bspnum & ~0x80000000));
}

canonical_original_code:
static _Bool P_CrossBSPNode(int bspnum)
{
    while (!(bspnum & 0x80000000))
    {
        struct node_t *bsp = nodes + bspnum;
        int side1 = R_PointOnSide(los.strace.x, los.strace.y, bsp);
        int side2 = R_PointOnSide(los.t2x, los.t2y, bsp);
        if (side1 == side2)
            bspnum = bsp->children[side1];
        else if (!P_CrossBSPNode(bsp->children[side1]))
            return 0;
        else
            bspnum = bsp->children[side1 ^ 1];
    }
    return P_CrossSubsector(bspnum == -1 ? 0 : (bspnum & ~0x80000000));
}

variable_types: bspnum int

variable_types: struct node_t { int x; int dx; int bbox[2][4]; int children[2]; } *