//
// GJBaseGameLayer::sortGroups from 0x9ca59c to 0x9ca9a4 (1032 bytes)
//
// 2 xrefs:
// > GJBaseGameLayer::updateSpecialGroupData @ 0x9f3c68
// > ??> @ 0xa27d8
//
// This function is hookable on this platform (idp: arm, 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:58:35 +0000
//
__int64 __fastcall GJBaseGameLayer::sortGroups(GJBaseGameLayer *this)
{
__int64 v2; // x0
__int64 v3; // x0
unsigned int *v4; // x1
_DWORD **v5; // x19
__int64 v6; // x0
char *v7; // x23
_DWORD *v8; // x20
int v9; // w24
int v10; // w0
_DWORD *v11; // x19
cocos2d::CCObject *Group; // x20
__int64 v13; // x0
unsigned int *v14; // x1
__int64 v15; // x0
_QWORD *v16; // x0
_QWORD *v17; // x19
void *v18; // x0
int v20; // w3
unsigned __int64 v21; // x20
unsigned __int64 v22; // x25
unsigned __int64 v23; // x22
__int64 *v24; // x0
unsigned __int64 v25; // x1
unsigned __int64 v26; // x1
float v27; // s0
_BOOL8 v28; // x2
__int64 v29; // x0
unsigned __int64 v30; // x2
unsigned __int64 v31; // x1
_QWORD *v32; // x0
_QWORD *v33; // x0
unsigned __int64 v34; // x1
unsigned __int64 v35; // x2
unsigned __int64 v36; // x0
int v37; // [xsp+74h] [xbp+74h] BYREF
void *v38[3]; // [xsp+78h] [xbp+78h] BYREF
void *v39; // [xsp+90h] [xbp+90h] BYREF
unsigned __int64 v40; // [xsp+98h] [xbp+98h]
void *v41; // [xsp+A0h] [xbp+A0h] BYREF
__int64 v42; // [xsp+A8h] [xbp+A8h]
float v43; // [xsp+B0h] [xbp+B0h]
v39 = nullptr;
v2 = *((_QWORD *)this + 409);
v40 = 0;
v41 = nullptr;
v42 = 0;
v43 = 1.0;
if ( v2 && *(_BYTE *)(v2 + 454) )
{
v3 = *((_QWORD *)this + 410);
if ( v3 )
{
v4 = *(unsigned int **)(v3 + 56);
if ( *v4 )
{
v5 = *((_DWORD ***)v4 + 2);
v6 = 8LL * *v4 - 8;
v7 = (char *)v5 + v6;
if ( v5 <= (_DWORD **)((char *)v5 + v6) )
{
v8 = *v5;
v9 = 1;
if ( *v5 )
goto LABEL_7;
}
}
}
goto LABEL_22;
}
v13 = *((_QWORD *)this + 410);
if ( !v13 )
goto LABEL_25;
v14 = *(unsigned int **)(v13 + 56);
if ( !*v14 )
goto LABEL_25;
v5 = *((_DWORD ***)v14 + 2);
v15 = 8LL * *v14 - 8;
v7 = (char *)v5 + v15;
if ( v5 > (_DWORD **)((char *)v5 + v15) || (v8 = *v5, v9 = 0, !*v5) )
{
LABEL_12:
v11 = v41;
if ( v41 )
{
do
{
Group = GJBaseGameLayer::getGroup(this, v11[4]);
if ( (unsigned int)cocos2d::CCArray::count(Group) > 1 )
qsort(
*(void **)(*((_QWORD *)Group + 7) + 16LL),
**((unsigned int **)Group + 7),
8u,
(int (*)(const void *, const void *))xCompPosition);
v11 = *(_DWORD **)v11;
}
while ( v11 );
goto LABEL_23;
}
goto LABEL_25;
}
do
{
LABEL_7:
v10 = v8[257];
if ( v10 == 1268 )
{
if ( v9 )
goto LABEL_9;
v20 = v8[366];
v21 = v40;
v37 = v20;
v22 = v20;
if ( v40 )
{
v23 = v20 & (v40 - 1);
if ( ((v40 - 1) & v40) != 0 )
v23 = v20 % v40;
v24 = *((__int64 **)v39 + v23);
if ( v24 )
{
while ( 1 )
{
v24 = (__int64 *)*v24;
if ( !v24 )
break;
v25 = v24[1];
v26 = ((v40 - 1) & v40) != 0 ? v25 % v40 : (v40 - 1) & v25;
if ( v23 != v26 )
break;
if ( v20 == *((_DWORD *)v24 + 4) )
goto LABEL_9;
}
}
}
else
{
v23 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(__int64)&v39,
v20,
&v37,
(__int64)v38);
v27 = (float)(unsigned __int64)(v42 + 1);
if ( v27 > (float)((float)v21 * v43) )
{
v28 = 1;
v29 = 2 * v21;
if ( v21 > 2 )
v28 = ((v21 - 1) & v21) != 0;
}
else
{
if ( v21 )
goto LABEL_44;
v28 = 1;
v29 = 0;
}
v30 = v28 + v29;
v31 = vcvtps_u32_f32(v27 / v43);
if ( v31 < v30 )
v31 = v30;
std::__hash_table,std::equal_to,std::allocator>::rehash((unsigned __int64)&v39, v31);
v21 = v40;
if ( ((v21 - 1) & v21) != 0 )
{
v23 = v22 % v40;
v32 = *((_QWORD **)v39 + v22 % v40);
if ( v32 )
goto LABEL_45;
goto LABEL_60;
}
v23 = v22 & (v40 - 1);
LABEL_44:
v32 = *((_QWORD **)v39 + v23);
if ( v32 )
{
LABEL_45:
*(_QWORD *)v38[0] = *v32;
*v32 = v38[0];
LABEL_46:
++v42;
goto LABEL_9;
}
LABEL_60:
*(_QWORD *)v38[0] = v41;
v41 = v38[0];
*((_QWORD *)v39 + v23) = &v41;
if ( *(_QWORD *)v38[0] )
{
v35 = *(_QWORD *)(*(_QWORD *)v38[0] + 8LL);
if ( ((v21 - 1) & v21) != 0 )
v36 = v35 % v21;
else
v36 = (v21 - 1) & v35;
*((void **)v39 + v36) = v38[0];
}
goto LABEL_46;
}
if ( v10 == 3607 && !*((_BYTE *)this + 12236) )
{
v33 = *((_QWORD **)this + 1566);
v34 = *((_QWORD *)this + 1567);
v38[0] = v8;
if ( (unsigned __int64)v33 >= v34 )
{
std::vector::__push_back_slow_path(
(__int64)this + 12520,
v38);
}
else
{
if ( v33 )
{
*v33 = v8;
v33 = *((_QWORD **)this + 1566);
}
*((_QWORD *)this + 1566) = v33 + 1;
}
}
LABEL_9:
if ( v7 < (char *)++v5 )
break;
v8 = *v5;
}
while ( *v5 );
if ( !v9 )
goto LABEL_12;
LABEL_22:
GJBaseGameLayer::sortAllGroupsX(this);
LABEL_23:
v16 = v41;
if ( v41 )
{
do
{
v17 = (_QWORD *)*v16;
operator delete(v16);
v16 = v17;
}
while ( v17 );
}
LABEL_25:
v18 = v39;
v39 = nullptr;
if ( v18 )
operator delete(v18);
return _stack_chk_guard;
}