//
// EditorUI::onGoToFreeLayer from 0x1401b5560 to 0x1401b569d (317 bytes)
//
// 3 xrefs:
// > EditorUI::handleEditorAction @ 0x1401c3819
// > EditorUI::init @ 0x1401abe99
// > ??> @ 0x14091a1d4
//
// 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 11:27:57 +0000
//
// Hidden C++ exception states: #wind=3
__int64 __fastcall EditorUI::onGoToFreeLayer(__int64 a1)
{
_QWORD *v2; // rax
__int16 NextFreeEditorLayer; // bp
void *v4; // rcx
_QWORD **v5; // rdi
_QWORD *v6; // rcx
_QWORD *v7; // rbx
int v9; // [rsp+30h] [rbp-48h] BYREF
void *v10; // [rsp+38h] [rbp-40h]
__int64 v11; // [rsp+40h] [rbp-38h]
void *Block[2]; // [rsp+48h] [rbp-30h] BYREF
__int64 v13; // [rsp+58h] [rbp-20h]
__int64 v14; // [rsp+60h] [rbp-18h]
__int64 v15; // [rsp+68h] [rbp-10h]
v11 = 0;
v2 = operator new(0x18u);
*v2 = v2;
v2[1] = v2;
v10 = v2;
*(_OWORD *)Block = 0;
v13 = 0;
v14 = 7;
v15 = 8;
v9 = 1065353216;
sub_14003F200((__int64)Block, 0x10u, (unsigned __int64)v2);
NextFreeEditorLayer = LevelEditorLayer::getNextFreeEditorLayer(*(_QWORD *)(a1 + 1512), &v9);
v4 = Block[0];
if ( Block[0] )
{
if ( ((v13 - (unsigned __int64)Block[0]) & 0xFFFFFFFFFFFFFFF8uLL) >= 0x1000 )
{
v4 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v4 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v4);
}
v5 = (_QWORD **)v10;
**((_QWORD **)v10 + 1) = 0;
v6 = *v5;
if ( *v5 )
{
do
{
v7 = (_QWORD *)*v6;
j_j_free(v6);
v6 = v7;
}
while ( v7 );
}
j_j_free(v5);
*(_WORD *)(*(_QWORD *)(a1 + 1512) + 14866LL) = NextFreeEditorLayer;
return EditorUI::updateGroupIDLabel(a1);
}