//
// __crt_mbstring::__c16rtomb_utf8 from 0x18013d8c4 to 0x18013d967 (163 bytes)
//
// 3 xrefs:
// > __crt_mbstring::__wcsrtombs_utf8 @ 0x180137164
// > __crt_mbstring::__wcsrtombs_utf8 @ 0x1801371d8
// > ??> @ 0x180203ae8
//
// 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
//
unsigned __int64 __fastcall __crt_mbstring::__c16rtomb_utf8(
__crt_mbstring *this,
char *a2,
_DWORD *a3,
struct _Mbstatet *a4)
{
struct _Mbstatet *v4; // r9
_DWORD *v5; // rbx
unsigned __int16 v6; // dx
unsigned __int64 result; // rax
char *v8; // rdx
__int64 v9; // [rsp+40h] [rbp+18h] BYREF
v4 = (struct _Mbstatet *)(unsigned __int16)a2;
v5 = &unk_1801F5728;
if ( a3 )
v5 = a3;
v6 = (_WORD)a2 + 9216;
if ( *v5 )
{
if ( v6 > 0x3FFu )
goto LABEL_5;
v9 = 0;
result = __crt_mbstring::__c32rtomb_utf8(this, (char *)(*v5 + ((unsigned int)v4 & 0xFFFF23FF)), (char32_t)&v9, v4);
*(_QWORD *)v5 = 0;
}
else
{
if ( v6 <= 0x3FFu )
{
LABEL_5:
*(_QWORD *)v5 = 0;
*errno() = 42;
return -1;
}
v8 = (char *)(unsigned int)v4;
LOWORD(v4) = (_WORD)v4 + 10240;
if ( (unsigned __int16)v4 > 0x3FFu )
{
return __crt_mbstring::__c32rtomb_utf8(this, v8, (char32_t)v5, v4);
}
else
{
*v5 = (((_DWORD)v8 << 10) & 0xFC9FFC00) + 0x10000;
return 0;
}
}
return result;
}