//
// GJBaseGameLayer::addRemapTargets from 0x9c4914 to 0x9c4f98 (1668 bytes)
//
// 7 xrefs:
// > PlayLayer::optimizeColorGroups @ 0x704db0
// > PlayLayer::optimizeOpacityGroups @ 0x704f4c
// > PlayLayer::scanDynamicSaveObjects @ 0x705110
// > GJBaseGameLayer::calculateColorGroups @ 0x9c5044
// > GJBaseGameLayer::optimizeMoveGroups @ 0x9c5244
// > GJBaseGameLayer::optimizeMoveGroups @ 0x9c5290
// > ??> @ 0x67c00
//
// 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:31 +0000
//
__int64 __fastcall GJBaseGameLayer::addRemapTargets(__int64 a1, __int64 **a2)
{
__int64 v2; // x2
int *v3; // x22
float v4; // s2
float v5; // s0
_BOOL8 v6; // x2
__int64 v7; // x0
unsigned __int64 v8; // x2
unsigned __int64 v9; // x1
unsigned __int64 v10; // x19
unsigned __int64 v11; // x20
_QWORD *v12; // x0
_QWORD *v13; // x0
int v14; // w3
unsigned __int64 v15; // x21
unsigned __int64 v16; // x19
unsigned __int64 v17; // x23
unsigned __int64 v18; // x20
__int64 *v19; // x0
unsigned __int64 v20; // x1
unsigned __int64 v21; // x1
float v22; // s2
float v23; // s0
_BOOL8 v24; // x2
__int64 v25; // x0
unsigned __int64 v26; // x2
unsigned __int64 v27; // x1
void **v28; // x0
_QWORD *v29; // x0
int v30; // w3
unsigned __int64 v31; // x21
unsigned __int64 v32; // x23
__int64 *v33; // x0
unsigned __int64 v34; // x1
__int64 *v35; // x21
__int64 *v36; // x22
char *v37; // x1
char *i; // x0
char *v39; // x19
char *v40; // x2
unsigned __int64 v41; // x22
__int64 *j; // x19
__int64 v43; // x0
int v44; // w2
int v45; // w1
char *v46; // x0
void *v47; // x0
__int64 v49; // x1
unsigned __int64 v50; // x2
unsigned __int64 v51; // x0
__int64 v52; // x1
unsigned __int64 v53; // x2
unsigned __int64 v54; // x0
__int64 v55; // [xsp+68h] [xbp+68h]
__int64 v56; // [xsp+70h] [xbp+70h]
void *v58[3]; // [xsp+80h] [xbp+80h] BYREF
void *v59; // [xsp+98h] [xbp+98h] BYREF
char *v60; // [xsp+A0h] [xbp+A0h]
char *v61; // [xsp+A8h] [xbp+A8h]
void *v62[2]; // [xsp+B0h] [xbp+B0h] BYREF
void *v63; // [xsp+C0h] [xbp+C0h]
__int64 v64; // [xsp+C8h] [xbp+C8h]
float v65; // [xsp+D0h] [xbp+D0h]
v2 = *(_QWORD *)(a1 + 2088);
v55 = *(_QWORD *)(a1 + 2096);
v62[0] = nullptr;
v62[1] = nullptr;
v56 = v2;
v63 = nullptr;
v64 = 0;
v65 = 1.0;
if ( v2 != v55 )
{
while ( 1 )
{
v3 = *(int **)(v56 + 16);
if ( v3 )
break;
LABEL_44:
v56 += 40;
if ( v55 == v56 )
goto LABEL_45;
}
while ( 1 )
{
LABEL_33:
v29 = (_QWORD *)std::unordered_map>::operator[]((unsigned __int64)v62, v3 + 4);
v30 = v3[5];
v31 = (unsigned __int64)v29;
v10 = v29[1];
v32 = v30;
if ( v10 )
{
v11 = (v10 - 1) & v30;
if ( ((v10 - 1) & v10) != 0 )
v11 = v30 % v10;
v33 = *(__int64 **)(*v29 + 8 * v11);
if ( v33 )
{
while ( 1 )
{
v33 = (__int64 *)*v33;
if ( !v33 )
break;
v34 = v33[1];
if ( ((v10 - 1) & v10) != 0 )
{
if ( v11 != v34 % v10 )
break;
}
else if ( v11 != ((v10 - 1) & v34) )
{
break;
}
if ( v30 == *((_DWORD *)v33 + 4) )
goto LABEL_15;
}
}
}
else
{
v11 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
v31,
v30,
v3 + 5,
(__int64)v58);
v4 = *(float *)(v31 + 32);
v5 = (float)(unsigned __int64)(*(_QWORD *)(v31 + 24) + 1LL);
if ( v5 > (float)((float)v10 * v4) )
{
v6 = 1;
v7 = 2 * v10;
if ( v10 > 2 )
v6 = ((v10 - 1) & v10) != 0;
}
else
{
if ( v10 )
goto LABEL_12;
v6 = 1;
v7 = 0;
}
v8 = v6 + v7;
v9 = vcvtps_u32_f32(v5 / v4);
if ( v9 < v8 )
v9 = v8;
std::__hash_table,std::equal_to,std::allocator>::rehash(v31, v9);
v10 = *(_QWORD *)(v31 + 8);
if ( ((v10 - 1) & v10) == 0 )
{
v11 = (v10 - 1) & v32;
LABEL_12:
v12 = *(_QWORD **)(*(_QWORD *)v31 + 8 * v11);
if ( !v12 )
goto LABEL_87;
goto LABEL_13;
}
v11 = v32 % v10;
v12 = *(_QWORD **)(*(_QWORD *)v31 + 8 * (v32 % v10));
if ( !v12 )
{
LABEL_87:
*(_QWORD *)v58[0] = *(_QWORD *)(v31 + 16);
v52 = *(_QWORD *)v31;
*(void **)(v31 + 16) = v58[0];
*(_QWORD *)(v52 + 8 * v11) = v31 + 16;
if ( *(_QWORD *)v58[0] )
{
v53 = *(_QWORD *)(*(_QWORD *)v58[0] + 8LL);
if ( ((v10 - 1) & v10) != 0 )
v54 = v53 % v10;
else
v54 = (v10 - 1) & v53;
*(void **)(*(_QWORD *)v31 + 8 * v54) = v58[0];
}
goto LABEL_14;
}
LABEL_13:
*(_QWORD *)v58[0] = *v12;
*v12 = v58[0];
LABEL_14:
++*(_QWORD *)(v31 + 24);
LABEL_15:
v13 = (_QWORD *)std::unordered_map>::operator[]((unsigned __int64)v62, v3 + 5);
v14 = v3[4];
v15 = (unsigned __int64)v13;
v16 = v13[1];
v17 = v14;
if ( v16 )
{
v18 = (v16 - 1) & v14;
if ( ((v16 - 1) & v16) != 0 )
v18 = v14 % v16;
v19 = *(__int64 **)(*v13 + 8 * v18);
if ( v19 )
{
while ( 1 )
{
v19 = (__int64 *)*v19;
if ( !v19 )
break;
v20 = v19[1];
v21 = ((v16 - 1) & v16) != 0 ? v20 % v16 : (v16 - 1) & v20;
if ( v18 != v21 )
break;
if ( v14 == *((_DWORD *)v19 + 4) )
{
v3 = *(int **)v3;
if ( v3 )
goto LABEL_33;
goto LABEL_44;
}
}
}
}
else
{
v18 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
v15,
v14,
v3 + 4,
(__int64)&v59);
v22 = *(float *)(v15 + 32);
v23 = (float)(unsigned __int64)(*(_QWORD *)(v15 + 24) + 1LL);
if ( v23 > (float)((float)v16 * v22) )
{
v24 = 1;
v25 = 2 * v16;
if ( v16 > 2 )
v24 = ((v16 - 1) & v16) != 0;
}
else
{
if ( v16 )
goto LABEL_30;
v24 = 1;
v25 = 0;
}
v26 = v24 + v25;
v27 = vcvtps_u32_f32(v23 / v22);
if ( v27 < v26 )
v27 = v26;
std::__hash_table,std::equal_to,std::allocator>::rehash(v15, v27);
v16 = *(_QWORD *)(v15 + 8);
if ( ((v16 - 1) & v16) == 0 )
{
v18 = (v16 - 1) & v17;
LABEL_30:
v28 = *(void ***)(*(_QWORD *)v15 + 8 * v18);
if ( !v28 )
goto LABEL_82;
goto LABEL_31;
}
v18 = v17 % v16;
v28 = *(void ***)(*(_QWORD *)v15 + 8 * (v17 % v16));
if ( !v28 )
{
LABEL_82:
*(_QWORD *)v59 = *(_QWORD *)(v15 + 16);
v49 = *(_QWORD *)v15;
*(_QWORD *)(v15 + 16) = v59;
*(_QWORD *)(v49 + 8 * v18) = v15 + 16;
if ( *(_QWORD *)v59 )
{
v50 = *(_QWORD *)(*(_QWORD *)v59 + 8LL);
if ( ((v16 - 1) & v16) != 0 )
v51 = v50 % v16;
else
v51 = (v16 - 1) & v50;
*(_QWORD *)(*(_QWORD *)v15 + 8 * v51) = v59;
}
goto LABEL_32;
}
LABEL_31:
*(_QWORD *)v59 = *v28;
*v28 = v59;
LABEL_32:
++*(_QWORD *)(v15 + 24);
v3 = *(int **)v3;
if ( !v3 )
goto LABEL_44;
}
}
LABEL_45:
v59 = nullptr;
v60 = nullptr;
v35 = (__int64 *)(a2 + 1);
v36 = *a2;
v61 = nullptr;
if ( v36 == (__int64 *)(a2 + 1) )
goto LABEL_71;
v37 = nullptr;
for ( i = nullptr; i == v37; i = v39 )
{
std::vector::__push_back_slow_path((__int64)&v59, (_DWORD *)v36 + 7);
v39 = v60;
v36 = std::__tree_next *>(v36);
if ( v35 == v36 )
goto LABEL_53;
LABEL_50:
v37 = v61;
}
if ( i )
{
*(_DWORD *)i = *((_DWORD *)v36 + 7);
i = v60;
}
v60 = i + 4;
v39 = i + 4;
v36 = std::__tree_next *>(v36);
if ( v35 != v36 )
goto LABEL_50;
LABEL_53:
v40 = (char *)v59;
if ( (v39 - (_BYTE *)v59) >> 2 )
{
v41 = 0;
do
{
LODWORD(v58[0]) = *(_DWORD *)&v40[4 * v41];
if ( std::__hash_table>,std::__unordered_map_hasher>,std::hash,true>,std::__unordered_map_equal>,std::equal_to,true>,std::allocator>>>::find(
v62,
(int *)v58) )
{
for ( j = *(__int64 **)(std::unordered_map>::operator[](
(unsigned __int64)v62,
(int *)v58)
+ 16); j; j = (__int64 *)*j )
{
v43 = *v35;
if ( *v35 )
{
v44 = *((_DWORD *)j + 4);
while ( 1 )
{
while ( 1 )
{
v45 = *(_DWORD *)(v43 + 28);
if ( v45 <= v44 )
break;
v43 = *(_QWORD *)v43;
if ( !v43 )
goto LABEL_61;
}
if ( v45 >= v44 )
break;
v43 = *(_QWORD *)(v43 + 8);
if ( !v43 )
goto LABEL_61;
}
}
else
{
LABEL_61:
std::__tree::__emplace_unique_key_args(a2, (int *)j + 4, (_DWORD *)j + 4);
v46 = v60;
if ( v60 == v61 )
{
std::vector::__push_back_slow_path((__int64)&v59, (_DWORD *)j + 4);
}
else
{
if ( v60 )
{
*(_DWORD *)v60 = *((_DWORD *)j + 4);
v46 = v60;
}
v60 = v46 + 4;
}
}
}
}
v40 = (char *)v59;
++v41;
}
while ( v41 < (v60 - (_BYTE *)v59) >> 2 );
}
if ( v40 )
{
if ( v40 != v60 )
v60 += 4 * ~((unsigned __int64)(v60 - 4 - v40) >> 2);
operator delete(v40);
}
LABEL_71:
sub_998FF8(v63);
v47 = v62[0];
v62[0] = nullptr;
if ( v47 )
operator delete(v47);
return _stack_chk_guard;
}