//
// sub_50966 from 0x50966 to 0x509ce (104 bytes)
//
// 2 xrefs:
// > sub_4FE54 @ 0x4ffac
// > sub_4FE54 @ 0x4ffbe
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
int __fastcall sub_50966(_DWORD *a1, _DWORD *a2, _DWORD *a3)
{
_DWORD *v3; // r3
_DWORD *v4; // r3
int result; // r0
if ( (a2[6] & 4) != 0 )
{
v3 = a2;
LABEL_5:
while ( 1 )
{
a2 = v3;
if ( a3[7] <= v3[7] )
break;
v3 = (_DWORD *)v3[14];
if ( !v3 )
goto LABEL_7;
}
v4 = (_DWORD *)v3[11];
if ( v4 )
{
if ( (_DWORD *)v4[14] == a2 )
{
v4[14] = a3;
if ( (v4[6] & a2[6] & 4) != 0 )
a3[6] |= 0x10u;
}
else if ( (_DWORD *)v4[12] == a2 )
{
v4[12] = a3;
}
else
{
v4[13] = a3;
}
}
else
{
*a1 = a3;
}
a3[14] = a2;
a3[11] = v4;
a2[11] = a3;
}
else
{
v3 = (_DWORD *)a2[14];
if ( v3 )
goto LABEL_5;
LABEL_7:
a2[14] = a3;
a3[11] = a2;
a2 = a3;
}
result = a2[6] | 0x10;
a2[6] = result;
return result;
}