//
// GJBaseGameLayer::optimizeMoveGroups from 0x9c513c to 0x9c5568 (1068 bytes)
//
// 3 xrefs:
// > LevelEditorLayer::onResumePlaytest @ 0x796238
// > GJBaseGameLayer::updateSpecialGroupData @ 0x9f3c70
// > ??> @ 0x91ed0
//
// 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:32 +0000
//
__int64 __fastcall GJBaseGameLayer::optimizeMoveGroups(GJBaseGameLayer *this)
{
__int64 v2; // x0
unsigned int *v3; // x1
_QWORD *v4; // x19
_QWORD *v5; // x23
_DWORD *v6; // x20
int v7; // w0
__int64 **v8; // x0
__int64 *i; // x19
GameObject *MainObject; // x1
__int64 *j; // x20
cocos2d::CCObject *Group; // x0
unsigned int *v13; // x0
GameObject **v14; // x19
GameObject **k; // x21
__int64 m; // x23
__int64 v17; // x0
__int64 v18; // x21
unsigned int v19; // w19
unsigned int v20; // w20
__int64 v21; // x1
cocos2d::CCObject *v22; // x0
void *v23; // x19
void *v24; // x19
int v26; // w0
int v27; // [xsp+64h] [xbp+64h] BYREF
__int64 *v28; // [xsp+68h] [xbp+68h] BYREF
_QWORD v29[2]; // [xsp+70h] [xbp+70h] BYREF
__int64 *v30; // [xsp+80h] [xbp+80h] BYREF
_QWORD v31[2]; // [xsp+88h] [xbp+88h] BYREF
v2 = *((_QWORD *)this + 410);
v29[0] = 0;
v29[1] = 0;
v28 = v29;
v31[0] = 0;
v31[1] = 0;
v30 = v31;
if ( v2 )
{
v3 = *(unsigned int **)(v2 + 56);
if ( *v3 )
{
v4 = *((_QWORD **)v3 + 2);
v5 = &v4[*v3 - 1];
if ( v4 <= v5 )
{
v6 = (_DWORD *)*v4;
if ( *v4 )
{
while ( 1 )
{
v7 = v6[257];
if ( v7 == 2915 )
{
v8 = &v28;
LABEL_12:
v27 = v6[366];
std::__tree::__emplace_unique_key_args(v8, &v27, &v27);
goto LABEL_13;
}
if ( v7 <= 2915 )
break;
if ( v7 == 3016 )
goto LABEL_52;
if ( v7 <= 3016 )
{
if ( (unsigned int)(v7 - 3006) <= 2 )
{
v26 = v6[385];
if ( !v26 )
v26 = v6[367];
v27 = v26;
if ( v26 > 0 )
std::__tree::__emplace_unique_key_args(&v28, &v27, &v27);
}
goto LABEL_13;
}
if ( v7 == 3661 )
goto LABEL_52;
LABEL_13:
if ( v5 >= ++v4 )
{
v6 = (_DWORD *)*v4;
if ( *v4 )
continue;
}
goto LABEL_15;
}
if ( v7 == 1346 )
{
v27 = v6[366];
std::__tree::__emplace_unique_key_args(&v30, &v27, &v27);
v27 = v6[367];
std::__tree::__emplace_unique_key_args(&v28, &v27, &v27);
v27 = v6[389];
std::__tree::__emplace_unique_key_args(&v28, &v27, &v27);
goto LABEL_13;
}
if ( v7 <= 1346 )
{
if ( v7 == 901 )
{
v27 = v6[367];
std::__tree::__emplace_unique_key_args(&v28, &v27, &v27);
v27 = v6[382];
std::__tree::__emplace_unique_key_args(&v28, &v27, &v27);
}
goto LABEL_13;
}
if ( v7 != 1347 )
{
if ( v7 != 2067 )
goto LABEL_13;
v27 = v6[367];
std::__tree::__emplace_unique_key_args(&v28, &v27, &v27);
v8 = &v30;
goto LABEL_12;
}
LABEL_52:
v27 = v6[367];
std::__tree::__emplace_unique_key_args(&v28, &v27, &v27);
goto LABEL_13;
}
}
}
}
LABEL_15:
GJBaseGameLayer::addRemapTargets((__int64)this, &v28);
for ( i = v28; i != v29; i = std::__tree_next *>(i) )
{
MainObject = (GameObject *)GJBaseGameLayer::tryGetMainObject((cocos2d::CCDictionary **)this, *((_DWORD *)i + 7));
if ( MainObject )
GJBaseGameLayer::moveObjectToStaticGroup(this, MainObject);
}
GJBaseGameLayer::addRemapTargets((__int64)this, &v30);
for ( j = v30; j != v31; j = std::__tree_next *>(j) )
{
Group = GJBaseGameLayer::getGroup(this, *((_DWORD *)j + 7));
if ( Group )
{
v13 = *((unsigned int **)Group + 7);
if ( *v13 )
{
v14 = *((GameObject ***)v13 + 2);
for ( k = &v14[*v13 - 1]; k >= v14; ++v14 )
{
if ( !*v14 )
break;
GJBaseGameLayer::moveObjectToStaticGroup(this, *v14);
}
}
}
}
for ( m = 0; m != 80000; m += 8 )
{
v17 = *(_QWORD *)(*((_QWORD *)this + 458) + m);
if ( v17 )
{
v18 = *(_QWORD *)(v17 + 56);
if ( *(_DWORD *)v18 )
{
v19 = 0;
v20 = 0;
do
{
while ( 1 )
{
v21 = *(_QWORD *)(v18 + 16);
v22 = *(cocos2d::CCObject **)(v21 + 8LL * v19);
if ( !*((_BYTE *)v22 + 1290) )
break;
*(_QWORD *)(v21 + 8LL * v20) = v22;
++v19;
++v20;
if ( *(_DWORD *)v18 <= v19 )
goto LABEL_33;
}
cocos2d::CCObject::release(v22);
++v19;
}
while ( *(_DWORD *)v18 > v19 );
LABEL_33:
*(_DWORD *)v18 = v20;
}
else
{
*(_DWORD *)v18 = 0;
}
}
}
v23 = (void *)v31[0];
if ( v31[0] )
{
std::__tree::destroy((__int64)&v30, *(_QWORD **)v31[0]);
std::__tree::destroy((__int64)&v30, *(_QWORD **)&byte_8[(_QWORD)v23]);
operator delete(v23);
}
v24 = (void *)v29[0];
if ( v29[0] )
{
std::__tree::destroy((__int64)&v28, *(_QWORD **)v29[0]);
std::__tree::destroy((__int64)&v28, *(_QWORD **)&byte_8[(_QWORD)v24]);
operator delete(v24);
}
return _stack_chk_guard;
}