//
// sub_100652190 from 0x100652190 to 0x1006522c5 (309 bytes)
//
// 3 xrefs:
// > MusicDownloadManager::createCustomSFXFolder @ 0x100652003
// > MusicDownloadManager::createCustomSFXPlacement @ 0x100652380
// > sub_100656D80 @ 0x100656dba
//
// 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 12:34:49 +0000
//
unsigned __int64 __fastcall sub_100652190(_QWORD *a1, unsigned __int8 *a2)
{
char v2; // cl
unsigned __int8 *v3; // r14
unsigned __int64 v4; // rbx
unsigned __int64 result; // rax
unsigned __int8 *v6; // rdx
unsigned __int8 *v7; // rsi
unsigned __int64 v8; // r9
unsigned __int64 v9; // r12
__int64 v10; // r8
unsigned __int64 v12; // r8
size_t v13; // rbx
char *v14; // rdi
char *v15; // rdi
size_t v16; // r15
char *v17; // rax
v2 = *a2;
v3 = a2 + 1;
v4 = *a2 >> 1;
result = *((_QWORD *)a2 + 1);
v6 = *((unsigned __int8 **)a2 + 2);
v7 = v6;
if ( (v2 & 1) == 0 )
v7 = v3;
v8 = result;
if ( (v2 & 1) == 0 )
v8 = v4;
if ( v8 )
{
v9 = 0;
while ( v7[v9] == 32 )
{
if ( v8 == ++v9 )
goto LABEL_21;
}
if ( v9 != -1 )
{
while ( v8 )
{
v10 = v8 - 1;
if ( v7[--v8] != 32 )
{
if ( (v2 & 1) == 0 )
goto LABEL_14;
LABEL_24:
v4 = result;
v3 = v6;
if ( result < v9 )
goto LABEL_25;
goto LABEL_15;
}
}
v10 = -1;
if ( (v2 & 1) != 0 )
goto LABEL_24;
LABEL_14:
if ( v9 > v4 )
LABEL_25:
sub_100056810();
LABEL_15:
v12 = v10 - v9 + 1;
v13 = v4 - v9;
if ( v13 >= v12 )
v13 = v12;
if ( v13 >= 0xFFFFFFFFFFFFFFF8LL )
sub_100003630();
if ( v13 >= 0x17 )
{
v16 = 26;
if ( (v13 | 7) != 0x17 )
v16 = (v13 | 7) + 1;
v17 = (char *)operator new(v16);
a1[2] = v17;
*a1 = v16 + 1;
a1[1] = v13;
v14 = v17;
}
else
{
result = (unsigned int)(2 * v13);
*(_BYTE *)a1 = 2 * v13;
v14 = (char *)a1 + 1;
if ( !v13 )
goto LABEL_30;
}
result = (unsigned __int64)memmove(v14, &v3[v9], v13);
LABEL_30:
v15 = &v14[v13];
goto LABEL_22;
}
}
LABEL_21:
*(_BYTE *)a1 = 0;
v15 = (char *)a1 + 1;
LABEL_22:
*v15 = 0;
return result;
}