//
// sub_D1FC14 from 0xd1fc14 to 0xd1fd68 (340 bytes)
//
// 2 xrefs:
// > ??> @ 0x121e330
// > ??> @ 0x121ed40
//
// 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_D1FC14(
__int64 a1,
mbstate_t *a2,
wchar_t *a3,
unsigned __int64 a4,
wchar_t **a5,
char *a6,
unsigned __int64 a7,
char **a8)
{
wchar_t *v8; // x19
char *v11; // x20
__int64 result; // x0
size_t v16; // x21
size_t v17; // x0
char s[8]; // [xsp+60h] [xbp+60h] BYREF
mbstate_t ps; // [xsp+68h] [xbp+68h] BYREF
v8 = a3;
v11 = a6;
ps = *a2;
if ( !&a6[__ctype_get_mb_cur_max() * ((__int64)(a4 - (_QWORD)a3) >> 2) - a7] )
{
if ( a4 <= (unsigned __int64)v8 )
{
LABEL_16:
result = 0;
goto LABEL_10;
}
while ( 1 )
{
v17 = wcrtomb(v11, *v8, &ps);
if ( v17 == -1 )
goto LABEL_9;
++v8;
*a2 = ps;
v11 += v17;
if ( a4 <= (unsigned __int64)v8 )
goto LABEL_16;
}
}
result = a4 > (unsigned __int64)v8;
if ( a4 > (unsigned __int64)v8 && (unsigned __int64)v11 < a7 )
{
while ( 1 )
{
v16 = wcrtomb(s, *v8, &ps);
if ( v16 == -1 )
break;
if ( v16 > a7 - (unsigned __int64)v11 )
{
result = 1;
goto LABEL_10;
}
memcpy(v11, s, v16);
v11 += v16;
*a2 = ps;
++v8;
if ( a7 <= (unsigned __int64)v11 || a4 <= (unsigned __int64)v8 )
{
result = a4 > (unsigned __int64)v8;
goto LABEL_10;
}
}
LABEL_9:
result = 2;
}
LABEL_10:
*a5 = v8;
*a8 = v11;
return result;
}