//
// __crt_mbstring::__c32rtomb_utf8 from 0x18013d968 to 0x18013da1b (179 bytes)
//
// 3 xrefs:
// > _wctomb_s_l @ 0x1801374ad
// > __crt_mbstring::__c32rtomb_utf8 @ 0x18013da1c
// > ??> @ 0x180203af4
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 10:55:03 +0000
//
__int64 __fastcall __crt_mbstring::__c32rtomb_utf8(__crt_mbstring *this, char *a2, _QWORD *a3, struct _Mbstatet *a4)
{
__int64 v5; // r9
char v6; // r10
__int64 v7; // r11
char v8; // al
if ( !this )
goto LABEL_2;
if ( !(_DWORD)a2 )
{
*(_BYTE *)this = 0;
LABEL_2:
*a3 = 0;
return 1;
}
if ( ((unsigned int)a2 & 0xFFFFFF80) == 0 )
{
*(_BYTE *)this = (_BYTE)a2;
return 1;
}
if ( ((unsigned int)a2 & 0xFFFFF800) == 0 )
{
v5 = 1;
v6 = -64;
goto LABEL_16;
}
if ( ((unsigned int)a2 & 0xFFFF0000) == 0 )
{
if ( (unsigned int)((_DWORD)a2 - 55296) > 0x7FF )
{
v5 = 2;
v6 = -32;
goto LABEL_16;
}
LABEL_19:
*a3 = 0;
*errno() = 42;
return -1;
}
if ( ((unsigned int)a2 & 0xFFE00000) != 0 || (unsigned int)a2 > 0x10FFFF )
goto LABEL_19;
v5 = 3;
v6 = -16;
LABEL_16:
v7 = v5;
do
{
v8 = (char)a2;
LODWORD(a2) = (unsigned int)a2 >> 6;
*((_BYTE *)this + v7--) = v8 & 0x3F | 0x80;
}
while ( v7 );
*(_BYTE *)this = v6 | (unsigned __int8)a2;
*a3 = 0;
return v5 + 1;
}