//
// sub_D1CF48 from 0xd1cf48 to 0xd1d06c (292 bytes)
//
// 0 xrefs:
//
// 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
//
wchar_t *__fastcall sub_D1CF48(wchar_t *result, __int64 *a2, unsigned __int64 a3, unsigned __int64 a4)
{
__int64 v4; // x21
unsigned __int64 v5; // x5
_QWORD *v7; // x26
unsigned __int64 v8; // x5
const wchar_t *v9; // x22
const wchar_t *v10; // x5
signed __int64 v11; // x19
unsigned __int64 v12; // x25
wchar_t *v13; // x0
wchar_t *v14; // x24
_QWORD *v15; // x23
v4 = *a2;
v5 = *(_QWORD *)(*a2 - 24);
v7 = result;
if ( a3 > v5 )
sub_D13C5C("%s: __pos (which is %zu) > this->size() (which is %zu)", "basic_string::basic_string", a3, v5);
v8 = v5 - a3;
v9 = (const wchar_t *)(v4 + 4 * a3);
if ( v8 > a4 )
v8 = a4;
v10 = (const wchar_t *)(v4 + 4 * (v8 + a3));
if ( v9 == v10 )
{
*(_QWORD *)result = &unk_124B6E8;
}
else
{
if ( v10 && !v9 )
sub_D138D8("basic_string::_S_construct null not valid");
v11 = (char *)v10 - (char *)v9;
v12 = v10 - v9;
v13 = (wchar_t *)sub_D1B424(v12, 0);
v14 = v13;
v15 = v13 + 6;
if ( v12 == 1 )
{
result = (wchar_t *)*(unsigned int *)(v4 + 4 * a3);
v14[6] = (int)result;
}
else
{
result = wmemcpy(v13 + 6, v9, v12);
}
if ( v14 != (wchar_t *)&qword_124B6D0 )
{
v14[4] = 0;
*(_QWORD *)v14 = v12;
*(wchar_t *)((char *)v14 + v11 + 24) = 0;
}
*v7 = v15;
}
return result;
}