//
// parseLevelLeaderboardKey from 0x719bd4 to 0x719f28 (852 bytes)
//
// 2 xrefs:
// > GameLevelManager::onGetLevelLeaderboardCompleted @ 0x719f94
// > ??> @ 0xb7738
//
// 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 parseLevelLeaderboardKey(_QWORD *a1, int *a2, int *a3, int *a4)
{
__int64 v6; // x20
__int64 v7; // x3
unsigned __int64 v8; // x19
__int64 v9; // x25
_QWORD *v10; // x0
void *v11; // x0
unsigned int *v12; // x1
int v13; // w2
void *v14; // x0
__int64 *v15; // x19
__int64 *v16; // x20
__int64 v17; // x1
__int64 *v18; // x0
unsigned int *v19; // x1
int v20; // w2
void *v21; // x0
unsigned int *v22; // x1
int v23; // w2
__int64 v27; // [xsp+88h] [xbp+88h] BYREF
void *p; // [xsp+90h] [xbp+90h] BYREF
_QWORD *v29; // [xsp+98h] [xbp+98h]
_QWORD *v30; // [xsp+A0h] [xbp+A0h]
if ( !*(_QWORD *)(*a1 - 24LL) )
return _stack_chk_guard;
p = nullptr;
v29 = nullptr;
v30 = nullptr;
v6 = sub_D168E0((int)a1, "_", 0, 1u);
v7 = v6;
v8 = 0;
v9 = *(_QWORD *)(*a1 - 24LL);
while ( 1 )
{
sub_D14F84(&v27, a1, v8, v7);
if ( v9 == v8 && !*(_QWORD *)(v27 - 24) )
goto LABEL_11;
v10 = v29;
if ( v29 == v30 )
break;
if ( v29 )
{
sub_D18D28(v29);
v10 = v29;
}
v29 = v10 + 1;
LABEL_11:
if ( v6 == -1 )
goto LABEL_19;
LABEL_12:
v8 = v6 + 1;
v6 = sub_D168E0((int)a1, "_", (int)v6 + 1, 1u);
v11 = (void *)(v27 - 24);
if ( (__int64 *)(v27 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v12 = (unsigned int *)(v27 - 8);
do
v13 = __ldaxr(v12);
while ( __stlxr(v13 - 1, v12) );
}
else
{
v13 = *(_DWORD *)(v27 - 8);
*(_DWORD *)(v27 - 8) = v13 - 1;
}
if ( v13 <= 0 )
operator delete(v11);
}
v7 = v6 - v8;
if ( *(_QWORD *)(*a1 - 24LL) < v8 )
sub_D13C5C(
"%s: __pos (which is %zu) > this->size() (which is %zu)",
"basic_string::substr",
v8,
*(_QWORD *)(*a1 - 24LL));
}
std::vector::_M_emplace_back_aux((__int64)&p, (__int64)&v27);
if ( v6 != -1 )
goto LABEL_12;
LABEL_19:
v14 = (void *)(v27 - 24);
if ( (__int64 *)(v27 - 24) != &qword_124B6B0 )
{
if ( &pthread_create )
{
v22 = (unsigned int *)(v27 - 8);
do
v23 = __ldaxr(v22);
while ( __stlxr(v23 - 1, v22) );
}
else
{
v23 = *(_DWORD *)(v27 - 8);
*(_DWORD *)(v27 - 8) = v23 - 1;
}
if ( v23 <= 0 )
operator delete(v14);
}
v15 = (__int64 *)p;
v16 = v29;
if ( ((char *)v29 - (_BYTE *)p) >> 3 == 4 )
{
*a2 = atoi(*(const char **)&byte_8[(_QWORD)p]);
*a3 = atoi(*(const char **)((char *)&word_10 + (_QWORD)v15));
*a4 = atoi(*(const char **)((char *)&off_18 + (_QWORD)v15));
}
if ( v15 == v16 )
{
v21 = v15;
}
else
{
do
{
v17 = *v15;
v18 = (__int64 *)(*v15 - 24);
if ( v18 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v19 = (unsigned int *)(v17 - 8);
do
v20 = __ldaxr(v19);
while ( __stlxr(v20 - 1, v19) );
}
else
{
v20 = *(_DWORD *)(v17 - 8);
*(_DWORD *)(v17 - 8) = v20 - 1;
}
if ( v20 <= 0 )
operator delete(v18);
}
++v15;
}
while ( v16 != v15 );
v21 = p;
}
if ( v21 )
operator delete(v21);
return _stack_chk_guard;
}