//
// sub_778470 from 0x778470 to 0x77850a (154 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
//
const wchar_t **__fastcall sub_778470(const wchar_t **a1, int *a2, unsigned int a3, size_t a4)
{
int v5; // r7
unsigned int v7; // r1
size_t v8; // r2
size_t v10; // r4
const wchar_t *v11; // r3
int v12; // r2
size_t v13; // r9
v5 = *a2;
v7 = *(_DWORD *)(*a2 - 12);
if ( a3 > v7 )
sub_7732C4("%s: __pos (which is %zu) > this->size() (which is %zu)", "basic_string::append", a3, v7);
v8 = v7 - a3;
if ( v8 >= a4 )
v8 = a4;
v10 = v8;
if ( v8 )
{
v11 = *a1;
v12 = *(*a1 - 3);
v13 = v10 + v12;
if ( v10 + v12 > *(*a1 - 2) || *(v11 - 1) > 0 )
{
sub_778308(a1, v10 + v12);
v11 = *a1;
v5 = *a2;
v12 = *(*a1 - 3);
}
if ( v10 == 1 )
{
v11[v12] = *(_DWORD *)(v5 + 4 * a3);
}
else
{
wmemcpy((wchar_t *)&v11[v12], (const wchar_t *)(v5 + 4 * a3), v10);
v11 = *a1;
}
if ( v11 - 3 != (const wchar_t *)&unk_ACDDAC )
{
*((_DWORD *)v11 - 3) = v13;
*((_DWORD *)v11 - 1) = 0;
v11[v13] = 0;
}
}
return a1;
}