//
// sub_100596B20 from 0x100596b20 to 0x100596cbb (411 bytes)
//
// 6 xrefs:
// > MusicDownloadManager::generateCustomContentURL @ 0x100591351
// > MusicDownloadManager::generateCustomContentURL @ 0x1005913a0
// > MusicDownloadManager::generateCustomContentURL @ 0x1005913ef
// > MusicDownloadManager::generateCustomContentURL @ 0x10059143e
// > ObjectManager::replaceAllOccurencesOfString @ 0x1007967d6
// > ObjectManager::replaceAllOccurencesOfString @ 0x100796dc4
//
// 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
//
int __fastcall sub_100596B20(std::string *a1, unsigned __int8 *a2, unsigned __int8 *a3)
{
std::string *v3; // r14
std::string::size_type v4; // r12
unsigned int v5; // r15d
std::string::value_type *data; // rax
std::string::size_type size; // r15
unsigned int v8; // r13d
signed __int64 v9; // r13
char *v10; // rbx
signed __int64 v11; // rdx
char *v12; // r15
char *v13; // r12
int v14; // r14d
size_t v15; // rdx
char *v16; // r12
unsigned int v17; // r8d
const std::string::value_type *v18; // rcx
std::string::size_type v19; // r8
unsigned int v20; // eax
__int64 v21; // rax
char *__s2; // [rsp+8h] [rbp-58h]
std::string::value_type *__s; // [rsp+18h] [rbp-48h]
unsigned __int8 *v26; // [rsp+20h] [rbp-40h]
std::string::value_type *v27; // [rsp+30h] [rbp-30h]
v3 = a1;
__s2 = (char *)(a2 + 1);
__s = (std::string::value_type *)(a3 + 1);
v4 = 0;
v26 = a2;
v5 = (unsigned int)a1->__r_.__value_.__l.0;
if ( (v5 & 1) == 0 )
goto LABEL_5;
LABEL_2:
data = v3->__r_.__value_.__l.__data_;
v27 = data;
size = v3->__r_.__value_.__l.__size_;
v8 = *a2;
if ( (v8 & 1) != 0 )
{
while ( 1 )
{
v10 = *((char **)a2 + 2);
v9 = *((_QWORD *)a2 + 1);
v11 = size - v4;
if ( size < v4 )
break;
LABEL_7:
if ( v9 )
{
if ( v11 >= v9 )
{
LODWORD(data) = (_DWORD)v27;
v12 = &v27[size];
v13 = &v27[v4];
v14 = *v10;
while ( 1 )
{
v15 = v11 - v9 + 1;
if ( !v15 )
break;
data = (std::string::value_type *)memchr(v13, v14, v15);
if ( !data )
break;
v16 = data;
LODWORD(data) = memcmp(data, v10, v9);
if ( !(_DWORD)data )
{
if ( v16 == v12 )
return (int)data;
v4 = v16 - v27;
goto LABEL_17;
}
v13 = v16 + 1;
v11 = v12 - v13;
if ( v12 - v13 < v9 )
return (int)data;
}
}
return (int)data;
}
LABEL_17:
if ( v4 == -1 )
return (int)data;
v17 = *a3;
if ( (v17 & 1) != 0 )
{
v18 = *((const std::string::value_type **)a3 + 2);
v19 = *((_QWORD *)a3 + 1);
}
else
{
v19 = v17 >> 1;
v18 = __s;
}
v3 = a1;
std::string::replace(a1, v4, v9, v18, v19);
v20 = *a3;
if ( (v20 & 1) != 0 )
v21 = *((_QWORD *)a3 + 1);
else
v21 = v20 >> 1;
a2 = v26;
v4 += v21;
v5 = (unsigned int)a1->__r_.__value_.__l.0;
if ( (v5 & 1) != 0 )
goto LABEL_2;
LABEL_5:
size = v5 >> 1;
LODWORD(data) = (_DWORD)a1 + 1;
v27 = a1->__r_.__value_.__s.__data_;
v8 = *a2;
if ( (v8 & 1) == 0 )
goto LABEL_3;
}
}
else
{
LABEL_3:
v9 = v8 >> 1;
v10 = __s2;
v11 = size - v4;
if ( size >= v4 )
goto LABEL_7;
}
return (int)data;
}