//
// sub_100981080 from 0x100981080 to 0x1009812af (559 bytes)
//
// 1 xrefs:
// > sub_10097E2F0 @ 0x10097e94b
//
// 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:39:00 +0000
//
__int64 __fastcall sub_100981080(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // rdx
__int64 **v4; // rbx
unsigned int v5; // r15d
size_t v6; // r15
const void *v7; // r12
unsigned int v8; // r13d
size_t v9; // r13
__int64 *v10; // rsi
size_t v11; // r14
int v12; // eax
bool v13; // cl
int v14; // eax
bool v15; // cl
unsigned __int8 v16; // al
__int64 v17; // rbx
__int64 v18; // rdi
__int64 v19; // rax
__int64 v20; // r12
__int64 *v21; // rcx
__int64 *v22; // rax
__int64 *v23; // rcx
bool v24; // zf
const void *v25; // [rsp+8h] [rbp-58h]
unsigned __int8 *v27; // [rsp+20h] [rbp-40h]
__int64 **v28; // [rsp+28h] [rbp-38h]
result = (*(__int64 (__fastcall **)(__int64))(*(_QWORD *)a2 + 64LL))(a2);
if ( (int)result < 0 )
return result;
v3 = *(_QWORD *)(a1 + 848);
if ( (int)result >= (int)((unsigned __int64)(*(_QWORD *)(a1 + 856) - v3) >> 7) )
return result;
v27 = (unsigned __int8 *)(((unsigned __int64)(unsigned int)result << 7) + v3);
v28 = (__int64 **)(a1 + 944);
v4 = *(__int64 ***)(a1 + 952);
if ( !v4 )
{
LABEL_21:
sub_1005913C0(v28, v27, (__int64)v27);
v16 = 1;
LABEL_22:
v17 = a1;
goto LABEL_23;
}
v5 = *v27;
if ( (v5 & 1) != 0 )
{
v6 = *((_QWORD *)v27 + 1);
v7 = *((const void **)v27 + 2);
}
else
{
v6 = v5 >> 1;
v7 = v27 + 1;
}
v25 = v7;
while ( 1 )
{
v8 = *((unsigned __int8 *)v4 + 32);
if ( (v8 & 1) != 0 )
{
v9 = (size_t)v4[5];
v10 = v4[6];
}
else
{
v9 = v8 >> 1;
v10 = (__int64 *)((char *)v4 + 33);
}
v11 = v6;
if ( v9 < v6 )
v11 = v9;
v12 = memcmp(v7, v10, v11);
v13 = v6 < v9;
if ( v12 )
v13 = v12 < 0;
if ( v13 )
goto LABEL_8;
v14 = memcmp(v10, v7, v11);
v15 = v9 < v6;
if ( v14 )
v15 = v14 < 0;
if ( !v15 )
break;
++v4;
LABEL_8:
v4 = (__int64 **)*v4;
v7 = v25;
if ( !v4 )
goto LABEL_21;
}
v19 = sub_100309350((__int64)v28, v27);
if ( v19 == a1 + 952 )
{
v16 = 0;
goto LABEL_22;
}
v20 = v19;
v21 = *(__int64 **)(v19 + 8);
v17 = a1;
if ( v21 )
{
do
{
v22 = v21;
v21 = (__int64 *)*v21;
}
while ( v21 );
}
else
{
v23 = (__int64 *)v19;
do
{
v22 = (__int64 *)v23[2];
v24 = *v22 == (_QWORD)v23;
v23 = v22;
}
while ( !v24 );
}
if ( *v28 == (__int64 *)v20 )
*v28 = v22;
--*(_QWORD *)(a1 + 960);
sub_1001454C0(*(__int64 **)(a1 + 952), (__int64 *)v20);
if ( (*(_BYTE *)(v20 + 32) & 1) != 0 )
operator delete(*(void **)(v20 + 48));
operator delete((void *)v20);
v16 = 0;
LABEL_23:
result = CCMenuItemToggler::toggle(a2, v16);
v18 = *(_QWORD *)(v17 + 992);
if ( v18 )
return sub_10029CC00(v18, *(_DWORD *)(v17 + 960));
return result;
}