//
// GJBaseGameLayer::optimizeMoveGroups from 0x1000f3d20 to 0x1000f45a1 (2177 bytes)
//
// 2 xrefs:
// > LevelEditorLayer::onResumePlaytest @ 0x1000c6bc2
// > GJBaseGameLayer::updateSpecialGroupData @ 0x1000f36c1
//
// 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:21:12 +0000
//
void __fastcall GJBaseGameLayer::optimizeMoveGroups(_QWORD *a1)
{
__int64 v1; // rbx
__int64 v2; // rax
unsigned int *v3; // rax
_QWORD *v4; // r14
__int64 **v5; // rcx
char *v6; // rbx
_DWORD *v7; // r13
int v8; // eax
int v9; // r12d
__int64 v10; // rax
_QWORD *v11; // rbx
_QWORD *v12; // r15
int v13; // eax
int v14; // r12d
__int64 v15; // rax
_QWORD *v16; // r13
_QWORD *v17; // rbx
int v18; // eax
_DWORD *v19; // rax
__int64 *v20; // rcx
int v21; // r12d
__int64 v22; // rax
__int128 *v23; // rbx
__int128 *v24; // r15
int v25; // eax
_DWORD *v26; // rax
int v27; // r12d
__int64 v28; // rax
_QWORD *v29; // rbx
_QWORD *v30; // r15
__int64 v31; // rcx
int v32; // ecx
_DWORD *v33; // rax
int v34; // eax
__int64 v35; // rax
int v36; // eax
int v37; // r12d
__int64 v38; // rax
_QWORD *v39; // rbx
_QWORD *v40; // r15
__int64 v41; // rcx
int v42; // ecx
_DWORD *v43; // rax
int v44; // eax
int v45; // r12d
__int64 v46; // rax
_QWORD *v47; // rbx
_QWORD *v48; // r15
int v49; // eax
_DWORD *v50; // rax
int v51; // r12d
__int64 v52; // rax
__int128 *v53; // rbx
__int128 *v54; // r15
int v55; // eax
__int64 *v56; // r14
__int64 v57; // rdi
__int64 *v58; // rdx
__int64 MainObject; // rax
__int64 *v60; // rcx
__int64 *v61; // rax
bool v62; // zf
__int64 v63; // rbx
__int64 v64; // r14
__int64 v65; // rax
_QWORD *v66; // r15
unsigned int *v67; // rax
__int64 v68; // rcx
_QWORD *v69; // rax
__int64 v70; // r14
unsigned int v71; // r15d
__int64 v72; // rdi
int GroupID; // eax
__int64 v74; // r13
__int64 v75; // r12
__int64 v76; // rbx
_QWORD *v77; // rcx
__int64 *v78; // rdx
__int64 *v79; // rcx
__int64 *v80; // rax
unsigned __int64 v81; // [rsp+8h] [rbp-78h]
__int64 *v82; // [rsp+10h] [rbp-70h]
unsigned __int64 v83; // [rsp+18h] [rbp-68h]
_QWORD *v84; // [rsp+18h] [rbp-68h]
__int64 **v85; // [rsp+20h] [rbp-60h] BYREF
__int128 v86; // [rsp+28h] [rbp-58h] BYREF
_QWORD *v87; // [rsp+38h] [rbp-48h]
__int64 **v88; // [rsp+40h] [rbp-40h] BYREF
_OWORD v89[3]; // [rsp+48h] [rbp-38h] BYREF
v1 = (__int64)a1;
v89[0] = 0;
v88 = (__int64 **)v89;
v86 = 0;
v85 = (__int64 **)&v86;
v2 = a1[410];
v87 = a1;
if ( v2 )
{
v3 = *(unsigned int **)(v2 + 56);
if ( *v3 )
{
v4 = *((_QWORD **)v3 + 2);
v83 = (unsigned __int64)&v4[*v3 - 1];
do
{
v7 = (_DWORD *)*v4;
if ( !*v4 )
break;
v8 = v7[257];
if ( v8 > 3005 )
{
if ( (unsigned int)(v8 - 3006) >= 3 )
{
if ( v8 != 3661 && v8 != 3016 )
goto LABEL_6;
LABEL_27:
v14 = v7[367];
v15 = *(_QWORD *)&v89[0];
v16 = v89;
LABEL_29:
v17 = v16;
if ( v15 )
{
do
{
v16 = (_QWORD *)v15;
v18 = *(_DWORD *)(v15 + 28);
if ( v14 < v18 )
{
v15 = *v16;
goto LABEL_29;
}
if ( v14 <= v18 )
goto LABEL_6;
v15 = v16[1];
}
while ( v15 );
v17 = v16 + 1;
}
v19 = operator new(0x20u);
v19[7] = v14;
*(_OWORD *)v19 = 0;
*((_QWORD *)v19 + 2) = v16;
*v17 = v19;
v20 = *v88;
if ( !*v88 )
goto LABEL_4;
LABEL_93:
v88 = (__int64 **)v20;
goto LABEL_4;
}
v9 = v7[385];
if ( v9 )
{
if ( v9 <= 0 )
goto LABEL_6;
}
else
{
v9 = v7[367];
if ( v9 <= 0 )
goto LABEL_6;
}
v35 = *(_QWORD *)&v89[0];
v11 = v89;
LABEL_69:
v12 = v11;
if ( v35 )
{
do
{
v11 = (_QWORD *)v35;
v36 = *(_DWORD *)(v35 + 28);
if ( v9 < v36 )
{
v35 = *v11;
goto LABEL_69;
}
if ( v9 <= v36 )
goto LABEL_6;
v35 = v11[1];
}
while ( v35 );
v12 = v11 + 1;
}
}
else if ( v8 <= 1346 )
{
if ( v8 == 901 )
{
v37 = v7[367];
v38 = *(_QWORD *)&v89[0];
v39 = v89;
v40 = v89;
if ( *(_QWORD *)&v89[0] )
{
v41 = *(_QWORD *)&v89[0];
while ( 1 )
{
while ( 1 )
{
v39 = (_QWORD *)v41;
v42 = *(_DWORD *)(v41 + 28);
if ( v37 >= v42 )
break;
v41 = *v39;
v40 = v39;
if ( !*v39 )
goto LABEL_82;
}
if ( v37 <= v42 )
break;
v41 = v39[1];
if ( !v41 )
{
v40 = v39 + 1;
goto LABEL_82;
}
}
}
else
{
LABEL_82:
v43 = operator new(0x20u);
v43[7] = v37;
*(_OWORD *)v43 = 0;
*((_QWORD *)v43 + 2) = v39;
*v40 = v43;
if ( *v88 )
v88 = (__int64 **)*v88;
sub_10001B680(*(__int64 **)&v89[0], (__int64 *)v43);
++*((_QWORD *)&v89[0] + 1);
v38 = *(_QWORD *)&v89[0];
}
v9 = v7[382];
v11 = v89;
LABEL_87:
v12 = v11;
if ( v38 )
{
do
{
v11 = (_QWORD *)v38;
v44 = *(_DWORD *)(v38 + 28);
if ( v9 < v44 )
{
v38 = *v11;
goto LABEL_87;
}
if ( v9 <= v44 )
goto LABEL_6;
v38 = v11[1];
}
while ( v38 );
v12 = v11 + 1;
}
}
else
{
if ( v8 != 1346 )
goto LABEL_6;
v21 = v7[366];
v22 = v86;
v23 = &v86;
LABEL_40:
v24 = v23;
if ( v22 )
{
do
{
v23 = (__int128 *)v22;
v25 = *(_DWORD *)(v22 + 28);
if ( v21 < v25 )
{
v22 = *(_QWORD *)v23;
goto LABEL_40;
}
if ( v21 <= v25 )
goto LABEL_48;
v22 = *((_QWORD *)v23 + 1);
}
while ( v22 );
v24 = (__int128 *)((char *)v23 + 8);
}
v26 = operator new(0x20u);
v26[7] = v21;
*(_OWORD *)v26 = 0;
*((_QWORD *)v26 + 2) = v23;
*(_QWORD *)v24 = v26;
if ( *v85 )
v85 = (__int64 **)*v85;
sub_10001B680((__int64 *)v86, (__int64 *)v26);
++*((_QWORD *)&v86 + 1);
LABEL_48:
v27 = v7[367];
v28 = *(_QWORD *)&v89[0];
v29 = v89;
v30 = v89;
if ( *(_QWORD *)&v89[0] )
{
v31 = *(_QWORD *)&v89[0];
while ( 1 )
{
while ( 1 )
{
v29 = (_QWORD *)v31;
v32 = *(_DWORD *)(v31 + 28);
if ( v27 >= v32 )
break;
v31 = *v29;
v30 = v29;
if ( !*v29 )
goto LABEL_55;
}
if ( v27 <= v32 )
break;
v31 = v29[1];
if ( !v31 )
{
v30 = v29 + 1;
goto LABEL_55;
}
}
}
else
{
LABEL_55:
v33 = operator new(0x20u);
v33[7] = v27;
*(_OWORD *)v33 = 0;
*((_QWORD *)v33 + 2) = v29;
*v30 = v33;
if ( *v88 )
v88 = (__int64 **)*v88;
sub_10001B680(*(__int64 **)&v89[0], (__int64 *)v33);
++*((_QWORD *)&v89[0] + 1);
v28 = *(_QWORD *)&v89[0];
}
v9 = v7[389];
v11 = v89;
LABEL_60:
v12 = v11;
if ( v28 )
{
do
{
v11 = (_QWORD *)v28;
v34 = *(_DWORD *)(v28 + 28);
if ( v9 < v34 )
{
v28 = *v11;
goto LABEL_60;
}
if ( v9 <= v34 )
goto LABEL_6;
v28 = v11[1];
}
while ( v28 );
v12 = v11 + 1;
}
}
}
else
{
if ( v8 == 1347 )
goto LABEL_27;
if ( v8 == 2067 )
{
v45 = v7[367];
v46 = *(_QWORD *)&v89[0];
v47 = v89;
LABEL_96:
v48 = v47;
if ( v46 )
{
do
{
v47 = (_QWORD *)v46;
v49 = *(_DWORD *)(v46 + 28);
if ( v45 < v49 )
{
v46 = *v47;
goto LABEL_96;
}
if ( v45 <= v49 )
goto LABEL_104;
v46 = v47[1];
}
while ( v46 );
v48 = v47 + 1;
}
v50 = operator new(0x20u);
v50[7] = v45;
*(_OWORD *)v50 = 0;
*((_QWORD *)v50 + 2) = v47;
*v48 = v50;
if ( *v88 )
v88 = (__int64 **)*v88;
sub_10001B680(*(__int64 **)&v89[0], (__int64 *)v50);
++*((_QWORD *)&v89[0] + 1);
LABEL_104:
v51 = v7[366];
v52 = v86;
v53 = &v86;
LABEL_106:
v54 = v53;
if ( v52 )
{
do
{
v53 = (__int128 *)v52;
v55 = *(_DWORD *)(v52 + 28);
if ( v51 < v55 )
{
v52 = *(_QWORD *)v53;
goto LABEL_106;
}
if ( v51 <= v55 )
goto LABEL_6;
v52 = *((_QWORD *)v53 + 1);
}
while ( v52 );
v54 = (__int128 *)((char *)v53 + 8);
}
v19 = operator new(0x20u);
v19[7] = v51;
*(_OWORD *)v19 = 0;
*((_QWORD *)v19 + 2) = v53;
*(_QWORD *)v54 = v19;
if ( *v85 )
v85 = (__int64 **)*v85;
v5 = (__int64 **)&v86;
v6 = (char *)&v86 + 8;
goto LABEL_5;
}
if ( v8 != 2915 )
goto LABEL_6;
v9 = v7[366];
v10 = *(_QWORD *)&v89[0];
v11 = v89;
LABEL_15:
v12 = v11;
if ( v10 )
{
do
{
v11 = (_QWORD *)v10;
v13 = *(_DWORD *)(v10 + 28);
if ( v9 < v13 )
{
v10 = *v11;
goto LABEL_15;
}
if ( v9 <= v13 )
goto LABEL_6;
v10 = v11[1];
}
while ( v10 );
v12 = v11 + 1;
}
}
v19 = operator new(0x20u);
v19[7] = v9;
*(_OWORD *)v19 = 0;
*((_QWORD *)v19 + 2) = v11;
*v12 = v19;
v20 = *v88;
if ( *v88 )
goto LABEL_93;
LABEL_4:
v5 = (__int64 **)v89;
v6 = (char *)v89 + 8;
LABEL_5:
sub_10001B680(*v5, (__int64 *)v19);
++*(_QWORD *)v6;
LABEL_6:
++v4;
v1 = (__int64)v87;
}
while ( (unsigned __int64)v4 <= v83 );
}
}
GJBaseGameLayer::addRemapTargets(v1, (__int64 **)&v88);
v56 = (__int64 *)v88;
if ( v88 != (__int64 **)v89 )
{
do
{
MainObject = GJBaseGameLayer::tryGetMainObject(v1);
if ( MainObject )
GJBaseGameLayer::moveObjectToStaticGroup(v1, MainObject);
v60 = (__int64 *)v56[1];
if ( v60 )
{
do
{
v61 = v60;
v60 = (__int64 *)*v60;
}
while ( v60 );
}
else
{
do
{
v61 = (__int64 *)v56[2];
v62 = *v61 == (_QWORD)v56;
v56 = v61;
}
while ( !v62 );
}
v56 = v61;
}
while ( v61 != (__int64 *)v89 );
}
v57 = v1;
GJBaseGameLayer::addRemapTargets(v1, (__int64 **)&v85);
v58 = (__int64 *)v85;
if ( v85 != (__int64 **)&v86 )
{
while ( 1 )
{
v82 = v58;
v63 = *((unsigned int *)v58 + 7);
if ( (int)v63 >= 9999 )
v63 = 9999;
if ( (int)v63 <= 0 )
v63 = 0;
v64 = *(_QWORD *)(v87[452] + 8 * v63);
if ( v64
|| (v65 = sub_1007FE900(v57),
v66 = v87,
v64 = v65,
v57 = v87[449],
cocos2d::CCDictionary::setObject_1(v57, v65, v63),
(*(_QWORD *)(v66[452] + 8 * v63) = v64) != 0) )
{
v67 = *(unsigned int **)(v64 + 56);
v68 = *v67;
if ( *v67 )
break;
}
LABEL_152:
v78 = v82;
v79 = (__int64 *)v82[1];
if ( v79 )
{
do
{
v80 = v79;
v79 = (__int64 *)*v79;
}
while ( v79 );
}
else
{
do
{
v80 = (__int64 *)v78[2];
v62 = *v80 == (_QWORD)v78;
v78 = v80;
}
while ( !v62 );
}
v58 = v80;
if ( v80 == (__int64 *)&v86 )
goto LABEL_116;
}
v69 = *((_QWORD **)v67 + 2);
v81 = (unsigned __int64)&v69[v68 - 1];
while ( 1 )
{
v70 = *v69;
if ( !*v69 )
goto LABEL_152;
v84 = v69;
if ( *(_BYTE *)(v70 + 1290) == 1 )
{
*(_BYTE *)(v70 + 1290) = 0;
if ( *(__int16 *)(v70 + 1168) > 0 )
break;
}
LABEL_134:
v69 = v84 + 1;
if ( (unsigned __int64)(v84 + 1) > v81 )
goto LABEL_152;
}
v71 = 0;
while ( 1 )
{
v72 = v70;
GroupID = GameObject::getGroupID(v70, v71);
v74 = (unsigned int)GroupID;
if ( GroupID >= 9999 )
v74 = 9999;
if ( (int)v74 <= 0 )
v74 = 0;
v75 = *(_QWORD *)(v87[455] + 8 * v74);
if ( v75 )
{
v76 = *(_QWORD *)(v87[458] + 8 * v74);
if ( !v76 )
goto LABEL_147;
}
else
{
v75 = sub_1007FE900(v70);
v72 = v87[450];
cocos2d::CCDictionary::setObject_1(v72, v75, v74);
v77 = v87;
*(_QWORD *)(v87[455] + 8 * v74) = v75;
v76 = *(_QWORD *)(v77[458] + 8 * v74);
if ( !v76 )
{
LABEL_147:
v76 = sub_1007FE900(v72);
cocos2d::CCDictionary::setObject_1(v87[451], v76, v74);
*(_QWORD *)(v87[458] + 8 * v74) = v76;
}
}
if ( !(unsigned __int8)sub_1007FF080(v75, v70) )
sub_1007FEBF0(v75, v70);
v57 = v76;
sub_1007FF140(v76, v70, 1);
if ( (int)++v71 >= *(__int16 *)(v70 + 1168) )
goto LABEL_134;
}
}
LABEL_116:
sub_10001ADF0((__int64)&v85, (_QWORD *)v86);
sub_10001ADF0((__int64)&v88, *(_QWORD **)&v89[0]);
}