//
// LevelEditorLayer::getNextFreeControlID from 0x7b338c to 0x7b3898 (1292 bytes)
//
// 3 xrefs:
// > IDNameBrowserPopup::onFormNextFree @ 0xcde86c
// > IDNameInput::onNextFree @ 0xce4698
// > ??> @ 0x9b788
//
// 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:53:52 +0000
//
__int64 __fastcall LevelEditorLayer::getNextFreeControlID(LevelEditorLayer *a1, __int64 a2)
{
LevelSettingsObject *v3; // x0
__int64 i; // x21
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
int v13; // w3
unsigned __int64 v14; // x22
__int64 *v15; // x0
unsigned __int64 v16; // x1
__int64 AllObjects; // x0
unsigned int *v18; // x1
__int64 *v19; // x19
__int64 v20; // x0
char *v21; // x22
__int64 v22; // x0
unsigned int NextHighestID; // w20
_QWORD *v24; // x0
_QWORD *v25; // x19
void *v26; // x0
unsigned __int64 v28; // x2
unsigned __int64 v29; // x0
int v30; // w3
unsigned __int64 v31; // x20
unsigned __int64 v32; // x24
unsigned __int64 v33; // x21
__int64 *v34; // x0
unsigned __int64 v35; // x1
unsigned __int64 v36; // x1
float v37; // s0
_BOOL8 v38; // x2
__int64 v39; // x0
unsigned __int64 v40; // x2
unsigned __int64 v41; // x1
void **v42; // x0
unsigned __int64 v43; // x1
unsigned __int64 v44; // x20
_QWORD v45[3]; // [xsp+60h] [xbp+60h] BYREF
void *v46; // [xsp+78h] [xbp+78h] BYREF
void *v47; // [xsp+90h] [xbp+90h] BYREF
unsigned __int64 v48; // [xsp+98h] [xbp+98h]
void *v49; // [xsp+A0h] [xbp+A0h] BYREF
__int64 v50; // [xsp+A8h] [xbp+A8h]
float v51; // [xsp+B0h] [xbp+B0h]
v47 = nullptr;
v48 = 0;
v49 = nullptr;
v50 = 0;
v51 = 1.0;
LevelEditorLayer::addExclusionList((__int64)a1, a2, (unsigned __int64)&v47);
v3 = *((LevelSettingsObject **)a1 + 409);
if ( v3 )
{
for ( i = LevelSettingsObject::getIDNames(v3, 6)[2]; i; i = *(_QWORD *)i )
{
LABEL_15:
v13 = *(_DWORD *)(i + 16);
v10 = v48;
v14 = v13;
if ( v48 )
{
v11 = v13 & (v48 - 1);
if ( ((v48 - 1) & v48) != 0 )
v11 = v13 % v48;
v15 = *((__int64 **)v47 + v11);
if ( v15 )
{
while ( 1 )
{
v15 = (__int64 *)*v15;
if ( !v15 )
break;
v16 = v15[1];
if ( ((v48 - 1) & v48) != 0 )
{
if ( v11 != v16 % v48 )
break;
}
else if ( v11 != ((v48 - 1) & v16) )
{
break;
}
if ( v13 == *((_DWORD *)v15 + 4) )
{
i = *(_QWORD *)i;
if ( i )
goto LABEL_15;
goto LABEL_24;
}
}
}
}
else
{
v11 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(__int64)&v47,
v13,
(_DWORD *)(i + 16),
(__int64)v45);
v5 = (float)(unsigned __int64)(v50 + 1);
if ( v5 > (float)((float)v10 * v51) )
{
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 / v51);
if ( v9 < v8 )
v9 = v8;
std::__hash_table,std::equal_to,std::allocator>::rehash((unsigned __int64)&v47, v9);
v10 = v48;
if ( ((v10 - 1) & v10) == 0 )
{
v11 = v14 & (v48 - 1);
LABEL_12:
v12 = *((_QWORD **)v47 + v11);
if ( !v12 )
goto LABEL_40;
goto LABEL_13;
}
v11 = v14 % v48;
v12 = *((_QWORD **)v47 + v14 % v48);
if ( !v12 )
{
LABEL_40:
*(_QWORD *)v45[0] = v49;
v49 = (void *)v45[0];
*((_QWORD *)v47 + v11) = &v49;
if ( *(_QWORD *)v45[0] )
{
v28 = *(_QWORD *)(*(_QWORD *)v45[0] + 8LL);
if ( ((v10 - 1) & v10) != 0 )
v29 = v28 % v10;
else
v29 = (v10 - 1) & v28;
*((_QWORD *)v47 + v29) = v45[0];
}
goto LABEL_14;
}
LABEL_13:
*(_QWORD *)v45[0] = *v12;
*v12 = v45[0];
LABEL_14:
++v50;
}
}
LABEL_24:
AllObjects = LevelEditorLayer::getAllObjects(a1);
if ( AllObjects )
{
v18 = *(unsigned int **)(AllObjects + 56);
if ( *v18 )
{
v19 = *((__int64 **)v18 + 2);
v20 = 8LL * *v18 - 8;
v21 = (char *)v19 + v20;
if ( v19 <= (__int64 *)((char *)v19 + v20) )
{
v22 = *v19;
if ( *v19 )
{
while ( 1 )
{
if ( *(_DWORD *)(v22 + 1248) != 1 )
goto LABEL_29;
v30 = *(_DWORD *)(v22 + 1672);
LODWORD(v45[0]) = v30;
if ( v30 <= 0 )
goto LABEL_29;
v31 = v48;
v32 = v30;
if ( v48 )
{
v33 = v30 & (v48 - 1);
if ( ((v48 - 1) & v48) != 0 )
v33 = v30 % v48;
v34 = *((__int64 **)v47 + v33);
if ( v34 )
{
while ( 1 )
{
v34 = (__int64 *)*v34;
if ( !v34 )
break;
v35 = v34[1];
v36 = ((v48 - 1) & v48) != 0 ? v35 % v48 : (v48 - 1) & v35;
if ( v33 != v36 )
break;
if ( v30 == *((_DWORD *)v34 + 4) )
goto LABEL_29;
}
}
}
else
{
v33 = 0;
}
std::__hash_table,std::equal_to,std::allocator>::__construct_node_hash(
(__int64)&v47,
v30,
v45,
(__int64)&v46);
v37 = (float)(unsigned __int64)(v50 + 1);
if ( v37 > (float)((float)v31 * v51) )
{
v38 = 1;
v39 = 2 * v31;
if ( v31 > 2 )
v38 = ((v31 - 1) & v31) != 0;
}
else
{
if ( v31 )
goto LABEL_61;
v38 = 1;
v39 = 0;
}
v40 = v38 + v39;
v41 = vcvtps_u32_f32(v37 / v51);
if ( v41 < v40 )
v41 = v40;
std::__hash_table,std::equal_to,std::allocator>::rehash(
(unsigned __int64)&v47,
v41);
v31 = v48;
if ( ((v31 - 1) & v31) == 0 )
{
v33 = v32 & (v48 - 1);
LABEL_61:
v42 = *((void ***)v47 + v33);
if ( !v42 )
goto LABEL_71;
goto LABEL_62;
}
v33 = v32 % v48;
v42 = *((void ***)v47 + v32 % v48);
if ( !v42 )
{
LABEL_71:
*(_QWORD *)v46 = v49;
v49 = v46;
*((_QWORD *)v47 + v33) = &v49;
if ( *(_QWORD *)v46 )
{
v43 = *(_QWORD *)(*(_QWORD *)v46 + 8LL);
if ( ((v31 - 1) & v31) != 0 )
v44 = v43 % v31;
else
v44 = (v31 - 1) & v43;
*((_QWORD *)v47 + v44) = v46;
}
goto LABEL_63;
}
LABEL_62:
*(_QWORD *)v46 = *v42;
*v42 = v46;
LABEL_63:
++v50;
LABEL_29:
if ( v21 >= (char *)++v19 )
{
v22 = *v19;
if ( *v19 )
continue;
}
break;
}
}
}
}
}
NextHighestID = findNextHighestID(1, 1000, &v47);
v24 = v49;
if ( v49 )
{
do
{
v25 = (_QWORD *)*v24;
operator delete(v24);
v24 = v25;
}
while ( v25 );
}
v26 = v47;
v47 = nullptr;
if ( v26 )
operator delete(v26);
return NextHighestID;
}