//
// std::set,std::allocator>::insert from 0x315002 to 0x315096 (148 bytes)
//
// 10 xrefs:
// > PlayLayer::optimizeColorGroups @ 0x3163a6
// > PlayLayer::optimizeOpacityGroups @ 0x31647a
// > PlayLayer::scanDynamicSaveObjects @ 0x317400
// > PlayLayer::scanDynamicSaveObjects @ 0x317410
// > GJBaseGameLayer::calculateColorGroups @ 0x488c64
// > GJBaseGameLayer::optimizeMoveGroups @ 0x488d92
// > GJBaseGameLayer::optimizeMoveGroups @ 0x488db2
// > GJBaseGameLayer::optimizeMoveGroups @ 0x488dc2
// > GJBaseGameLayer::optimizeMoveGroups @ 0x488df0
// > GJBaseGameLayer::optimizeMoveGroups @ 0x488e2a
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
int __fastcall std::set::insert(int a1, _DWORD *a2, _DWORD *a3)
{
_DWORD *v4; // r1
_DWORD *v7; // r4
int v8; // r3
_DWORD *v9; // r2
int v10; // r5
char v11; // r3
_BOOL4 v12; // r8
v4 = (_DWORD *)a2[2];
v7 = a2 + 1;
v8 = 1;
while ( v4 )
{
v7 = v4;
if ( *a3 >= v4[4] )
{
v9 = (_DWORD *)v4[3];
v8 = 0;
}
else
{
v9 = (_DWORD *)v4[2];
v8 = 1;
}
v4 = v9;
}
if ( v8 )
{
if ( v7 == (_DWORD *)a2[3] )
goto LABEL_13;
v10 = sub_762018(v7);
}
else
{
v10 = (int)v7;
}
if ( *(_DWORD *)(v10 + 16) >= *a3 )
{
v11 = 0;
goto LABEL_17;
}
LABEL_13:
v12 = v7 == a2 + 1 || *a3 < v7[4];
v10 = operator new(0x14u);
*(_DWORD *)(v10 + 16) = *a3;
sub_7620E8(v12, v10, v7, a2 + 1);
++a2[5];
v11 = 1;
LABEL_17:
*(_DWORD *)a1 = v10;
*(_BYTE *)(a1 + 4) = v11;
return a1;
}