//
// sub_D021B4 from 0xd021b4 to 0xd02400 (588 bytes)
//
// 1 xrefs:
// > ??> @ 0x111eb90
//
// 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
//
__int64 __fastcall sub_D021B4(__int64 a1, __int64 a2, unsigned __int8 a3, __int64 a4, wchar_t a5, unsigned __int8 a6)
{
int v6; // w24
__int64 v7; // x23
int v11; // w25
int v12; // w21
__int64 v14; // x27
__int64 v15; // x28
__int64 v16; // x0
__int64 v17; // x28
__int64 v18; // x0
__int64 v19; // x25
int v20; // w27
_DWORD *v21; // x0
wchar_t v22[4]; // [xsp+0h] [xbp+0h] BYREF
_DWORD *v23; // [xsp+68h] [xbp+68h]
v6 = *(_DWORD *)(a4 + 24);
v7 = a2;
v11 = a6;
v12 = a3;
if ( (v6 & 1) == 0 )
return sub_D01F0C(a1, a2, a3, a4, a5, a6);
v14 = sub_CEA974(&qword_124B678);
v15 = *(_QWORD *)(*(_QWORD *)(a4 + 208) + 24LL);
v16 = *(_QWORD *)(v15 + 8 * v14);
if ( v16 )
{
if ( !v11 )
goto LABEL_6;
}
else
{
v21 = operator new(0x150u);
v21[2] = 0;
*(_QWORD *)v21 = off_111EEA0;
*((_QWORD *)v21 + 2) = 0;
*((_QWORD *)v21 + 3) = 0;
*((_BYTE *)v21 + 32) = 0;
*((_QWORD *)v21 + 5) = 0;
*((_QWORD *)v21 + 6) = 0;
*((_QWORD *)v21 + 7) = 0;
*((_QWORD *)v21 + 8) = 0;
v21[18] = 0;
v21[19] = 0;
*((_BYTE *)v21 + 328) = 0;
v23 = v21;
sub_CFE36C((__int64)v21, a4 + 208);
sub_CEA7E4(*(_QWORD *)(a4 + 208), v23, v14);
v16 = *(_QWORD *)(v15 + 8 * v14);
if ( !v11 )
{
LABEL_6:
LODWORD(v19) = *(_DWORD *)(v16 + 64);
v17 = *(_QWORD *)(v16 + 56);
v18 = *(_QWORD *)(a4 + 16);
v19 = (int)v19;
if ( v18 > (int)v19 )
goto LABEL_7;
LABEL_12:
*(_QWORD *)(a4 + 16) = 0;
if ( v12 )
return v7;
goto LABEL_13;
}
}
LODWORD(v19) = *(_DWORD *)(v16 + 48);
v17 = *(_QWORD *)(v16 + 40);
v18 = *(_QWORD *)(a4 + 16);
v19 = (int)v19;
if ( v18 <= (int)v19 )
goto LABEL_12;
LABEL_7:
v20 = v18 - v19;
wmemset(v22, a5, v18 - v19);
*(_QWORD *)(a4 + 16) = 0;
if ( (v6 & 0xB0) != 0x20 )
{
if ( v12 || v20 != (*(__int64 (__fastcall **)(__int64, wchar_t *, _QWORD))(*(_QWORD *)a2 + 96LL))(a2, v22, v20) )
return v7;
LABEL_13:
(*(__int64 (__fastcall **)(__int64, __int64, __int64))(*(_QWORD *)a2 + 96LL))(a2, v17, v19);
return v7;
}
if ( !v12 && v19 == (*(__int64 (__fastcall **)(__int64, __int64, __int64))(*(_QWORD *)a2 + 96LL))(a2, v17, v19) )
(*(__int64 (__fastcall **)(__int64, wchar_t *, _QWORD))(*(_QWORD *)a2 + 96LL))(a2, v22, v20);
return v7;
}