//
// sub_10015AEF8 from 0x10015aef8 to 0x10015b06c (372 bytes)
//
// 6 xrefs:
// > MusicDownloadManager::generateCustomContentURL @ 0x100157760
// > MusicDownloadManager::generateCustomContentURL @ 0x1001577b0
// > MusicDownloadManager::generateCustomContentURL @ 0x100157800
// > MusicDownloadManager::generateCustomContentURL @ 0x100157850
// > ObjectManager::replaceAllOccurencesOfString @ 0x10024d980
// > ObjectManager::replaceAllOccurencesOfString @ 0x10024db70
//
// 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
//
std::string *__fastcall sub_10015AEF8(std::string *this, char *a2, __int64 a3)
{
std::string *v4; // x21
std::string::size_type v5; // x22
std::string::size_type size; // x8
std::string *v7; // x27
std::string::size_type v8; // x26
std::string::size_type v9; // x28
char *v10; // x23
signed __int64 v11; // x24
signed __int64 v12; // x9
std::string *v13; // x19
int v14; // w22
std::string *v15; // x25
std::string::size_type v16; // x2
int v17; // w9
const std::string::value_type *v18; // x3
std::string::size_type v19; // x4
__int64 v20; // x8
std::string::size_type v23; // [xsp+8h] [xbp-58h]
v4 = this;
v5 = 0;
size = HIBYTE(this->__r_.__value_.__r.__words[2]);
if ( (size & 0x80u) == 0LL )
v7 = this;
else
v7 = (std::string *)this->__r_.__value_.__r.__words[0];
if ( (size & 0x80u) != 0LL )
size = this->__r_.__value_.__l.__size_;
v8 = a2[23];
v9 = *((_QWORD *)a2 + 1);
if ( (v8 & 0x80000000) == 0LL )
v10 = a2;
else
v10 = *(char **)a2;
if ( (v8 & 0x80000000) == 0LL )
v11 = a2[23];
else
v11 = *((_QWORD *)a2 + 1);
v23 = v8 >> 63;
while ( !v11 )
{
LABEL_23:
if ( v5 != -1 )
{
if ( (v23 & 1) != 0 )
v16 = v9;
else
v16 = v8;
v17 = *(char *)(a3 + 23);
if ( v17 >= 0 )
v18 = (const std::string::value_type *)a3;
else
v18 = *(const std::string::value_type **)a3;
if ( v17 >= 0 )
v19 = *(unsigned __int8 *)(a3 + 23);
else
v19 = *(_QWORD *)(a3 + 8);
this = std::string::replace(v4, v5, v16, v18, v19);
v20 = *(unsigned __int8 *)(a3 + 23);
if ( (v20 & 0x80u) != 0LL )
v20 = *(_QWORD *)(a3 + 8);
v5 += v20;
size = HIBYTE(v4->__r_.__value_.__r.__words[2]);
if ( (size & 0x80u) == 0LL )
v7 = v4;
else
v7 = (std::string *)v4->__r_.__value_.__r.__words[0];
if ( (size & 0x80u) != 0LL )
size = v4->__r_.__value_.__l.__size_;
v8 = a2[23];
v23 = v8 >> 63;
v9 = *((_QWORD *)a2 + 1);
v10 = (v8 & 0x80000000) == 0LL ? a2 : *(char **)a2;
v11 = (v8 & 0x80000000) == 0LL ? a2[23] : *((_QWORD *)a2 + 1);
if ( size >= v5 )
continue;
}
return this;
}
v12 = size - v5;
if ( (__int64)(size - v5) >= v11 )
{
v13 = (std::string *)((char *)v7 + size);
this = (std::string *)((char *)v7 + v5);
v14 = *v10;
do
{
if ( v12 - v11 == -1 )
break;
this = (std::string *)memchr(this, v14, v12 - v11 + 1);
if ( !this )
break;
v15 = this;
this = (std::string *)memcmp(this, v10, v11);
if ( !(_DWORD)this )
{
if ( v15 == v13 )
return this;
v5 = (char *)v15 - (char *)v7;
goto LABEL_23;
}
this = (std::string *)((char *)&v15->__r_.__value_.__l.__data_ + 1);
v12 = (char *)v13 - ((char *)&v15->__r_.__value_.__l.__data_ + 1);
}
while ( v12 >= v11 );
}
return this;
}