repo: bradharding/doomretro

decompiled_code:
__int64 __fastcall P_CrossBSPNode(int a1)
{
int v1; // eax
bool v2; // zf
int v3; // edi
__int64 result; // rax
__int64 v5; // rbp
int v6; // ebx

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

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
int v1; // eax
bool v2; // zf
int v3; // edi
__int64 result; // rax
__int64 v5; // rbp
int v6; // ebx

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

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