//
// __crt_mbstring::__mbsrtowcs_utf8 from 0x18013daac to 0x18013dc22 (374 bytes)
//
// 3 xrefs:
// > write_double_translated_ansi_nolock @ 0x18013fbb0
// > write_double_translated_ansi_nolock @ 0x18013fc18
// > ??> @ 0x180203b18
//
// 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 __crt_mbstring::__mbsrtowcs_utf8(
__crt_mbstring *this,
wchar_t *a2,
const char **a3,
unsigned __int64 a4)
{
__int64 v4; // rdi
const char **v6; // rbp
__crt_mbstring *v9; // rbx
__int64 v10; // r8
unsigned __int64 v11; // rax
__int16 v12; // cx
unsigned int v13; // ecx
__int64 i; // rbx
__int64 v16; // r8
unsigned __int64 v17; // rax
struct _Mbstatet *v18; // [rsp+20h] [rbp-28h]
unsigned int v19; // [rsp+50h] [rbp+8h] BYREF
v4 = *(_QWORD *)a2;
v6 = a3;
if ( !this )
{
for ( i = 0; ; ++i )
{
if ( *(_BYTE *)v4 )
v16 = *(_BYTE *)(v4 + 1) ? (*(_BYTE *)(v4 + 2) != 0) + 3LL : 2LL;
else
v16 = 1;
v17 = __crt_mbstring::__mbrtoc32_utf8(nullptr, (char32_t *)v4, (const char *)v16, a4, v18);
if ( v17 == -1 )
break;
if ( !v17 )
return i;
if ( v17 == 4 )
++i;
v4 += v17;
}
goto LABEL_18;
}
v9 = this;
if ( a3 )
{
while ( 1 )
{
if ( *(_BYTE *)v4 )
v10 = *(_BYTE *)(v4 + 1) ? (*(_BYTE *)(v4 + 2) != 0) + 3LL : 2LL;
else
v10 = 1;
v11 = __crt_mbstring::__mbrtoc32_utf8((__crt_mbstring *)&v19, (char32_t *)v4, (const char *)v10, a4, v18);
if ( v11 == -1 )
break;
if ( !v11 )
{
v4 = 0;
*(_WORD *)v9 = 0;
goto LABEL_14;
}
v12 = v19;
if ( v19 > 0xFFFF )
{
if ( (unsigned __int64)v6 <= 1 )
goto LABEL_14;
v13 = v19 - 0x10000;
v19 = v13;
v6 = (const char **)((char *)v6 - 1);
*(_WORD *)v9 = (v13 >> 10) | 0xD800;
v9 = (__crt_mbstring *)((char *)v9 + 2);
v12 = v13 & 0x3FF | 0xDC00;
}
*(_WORD *)v9 = v12;
v4 += v11;
v9 = (__crt_mbstring *)((char *)v9 + 2);
v6 = (const char **)((char *)v6 - 1);
if ( !v6 )
goto LABEL_14;
}
*(_QWORD *)a2 = v4;
LABEL_18:
*errno() = 42;
return -1;
}
LABEL_14:
*(_QWORD *)a2 = v4;
return (v9 - this) >> 1;
}