//
// sub_10057EC28 from 0x10057ec28 to 0x10057efa4 (892 bytes)
//
// 1 xrefs:
// > ??> @ 0x1009aaf98
//
// 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 11:08:28 +0000
//
__int64 __fastcall sub_10057EC28(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
__int64 v5; // x21
char v6; // w22
unsigned int v7; // w8
__int64 v11; // x8
int v12; // w25
__int64 v13; // x24
unsigned int v14; // w24
__int64 v15; // x0
__int64 v16; // x21
__int64 v17; // x0
unsigned int *v19; // x8
char v20; // w9
char v21; // w25
char v22; // w9
char v23; // w8
__int64 v24; // x0
__int64 v25; // x0
__int64 v26; // x0
__int64 v27; // x0
__int64 v28; // x0
__int64 v29; // x0
unsigned __int8 v30; // [xsp+Fh] [xbp-41h] BYREF
if ( (*(_BYTE *)(a1 + 60) & 0x80) != 0 )
return 30;
v5 = *(_QWORD *)(a1 + 40);
if ( !v5 )
return 31;
v6 = a4;
v7 = atomic_load((unsigned int *)(v5 + 272));
if ( v7 == 7 && a4 == 0 )
return 46;
sub_100568CC4(*(_QWORD *)(a1 + 8), 8u);
v11 = *(_QWORD *)(a1 + 24);
if ( v11 )
v12 = *(_DWORD *)(v11 + 72);
else
v12 = 0;
sub_100568CE4(*(_QWORD *)(a1 + 8), 8u);
if ( !*(_QWORD *)(a1 + 24) )
return 0;
if ( (v12 & 0x40000) != 0 && a3 == 2 && (_DWORD)a2 && (v12 & 0x200000) == 0 )
{
v14 = *(_DWORD *)(v5 + 64) - *(_DWORD *)(*(_QWORD *)(v5 + 384) + 68LL);
if ( v14 <= (unsigned int)a2 && *(_DWORD *)(v5 + 396) + v14 > (unsigned int)a2 )
{
sub_100568CC4(*(_QWORD *)(a1 + 8), 8u);
v15 = *(_QWORD *)(a1 + 192);
v16 = (unsigned int)a2 - v14;
if ( v15 )
(*(void (__fastcall **)(__int64, __int64))(*(_QWORD *)v15 + 128LL))(v15, v16 << 32);
sub_100568CE4(*(_QWORD *)(a1 + 8), 8u);
v13 = 0;
*(_DWORD *)(a1 + 144) = 0;
*(_DWORD *)(a1 + 148) = v16;
*(_DWORD *)(a1 + 72) = 0;
*(_DWORD *)(a1 + 76) = a2;
return v13;
}
v19 = (unsigned int *)(v5 + 88);
v22 = atomic_load((unsigned int *)(v5 + 88));
if ( (v22 & 0x80) == 0 )
goto LABEL_33;
LABEL_43:
v25 = *(_QWORD *)(a1 + 192);
if ( !v25
|| (v13 = (*(__int64 (__fastcall **)(__int64, __int64))(*(_QWORD *)v25 + 128LL))(v25, a2 << 32), !(_DWORD)v13) )
{
v13 = 0;
*(_DWORD *)(a1 + 72) = 0;
*(_DWORD *)(a1 + 76) = a2;
*(_DWORD *)(a1 + 144) = 0;
*(_DWORD *)(a1 + 148) = a2;
*(_DWORD *)(a1 + 160) = 0;
*(_QWORD *)(a1 + 152) = 0;
}
return v13;
}
if ( a3 == 16 )
{
sub_100568CC4(*(_QWORD *)(a1 + 8), 8u);
v17 = *(_QWORD *)(a1 + 192);
if ( v17 )
(*(void (__fastcall **)(__int64, __int64, __int64, _QWORD))(*(_QWORD *)v17 + 216LL))(v17, a2, 16, 0);
sub_100568CE4(*(_QWORD *)(a1 + 8), 8u);
return 0;
}
v19 = (unsigned int *)(v5 + 88);
v20 = atomic_load((unsigned int *)(v5 + 88));
if ( v20 < 0 )
goto LABEL_43;
if ( a3 == 2 )
{
LABEL_33:
if ( *(_DWORD *)(v5 + 192) == *(_DWORD *)(*(_QWORD *)(v5 + 96) + 284LL) )
{
v23 = atomic_load(v19);
if ( (v23 & 0x10) == 0 )
{
v13 = 0;
if ( (*(_BYTE *)(a1 + 60) & 0x40) == 0 || (v12 & 0x10000) != 0 )
return v13;
}
}
v21 = 1;
goto LABEL_38;
}
v21 = 0;
LABEL_38:
if ( (*(_BYTE *)(v5 + 46) & 1) != 0 && (v6 & 1) == 0 )
{
sub_100568CC4(*(_QWORD *)(a1 + 8), 8u);
*(_DWORD *)(a1 + 60) |= 0x4000u;
sub_100568CE4(*(_QWORD *)(a1 + 8), 8u);
v24 = *(_QWORD *)(a1 + 192);
if ( v24 )
(*(void (__fastcall **)(__int64, __int64))(*(_QWORD *)v24 + 88LL))(v24, 1);
sub_1005EA71C(*(_QWORD *)(v5 + 384), 0, *(unsigned int *)(*(_QWORD *)(v5 + 384) + 68LL));
sub_10057EFA4(*(_QWORD *)(*(_QWORD *)(v5 + 264) + 16LL), v5, v5, (unsigned int)a2 | ((unsigned __int64)a3 << 32));
return 0;
}
v30 = 0;
if ( (v6 & 1) == 0 )
{
sub_100568CC4(*(_QWORD *)(a1 + 8), 9u);
v26 = (*(__int64 (__fastcall **)(_QWORD, unsigned __int8 *))(**(_QWORD **)(a1 + 192) + 96LL))(
*(_QWORD *)(a1 + 192),
&v30);
if ( (_DWORD)v26 )
{
v13 = v26;
LABEL_61:
sub_100568CE4(*(_QWORD *)(a1 + 8), 9u);
return v13;
}
v27 = *(_QWORD *)(a1 + 192);
if ( v27 )
(*(void (__fastcall **)(__int64, __int64))(*(_QWORD *)v27 + 88LL))(v27, 1);
}
v13 = sub_1005E843C(v5);
if ( !(_DWORD)v13 )
{
sub_100568CC4(*(_QWORD *)(a1 + 8), 8u);
v28 = *(_QWORD *)(a1 + 192);
if ( v28 )
(*(void (__fastcall **)(__int64, _QWORD))(*(_QWORD *)v28 + 128LL))(v28, 0);
sub_100568CE4(*(_QWORD *)(a1 + 8), 8u);
*(_QWORD *)(a1 + 144) = 0;
*(_QWORD *)(a1 + 152) = 0;
*(_DWORD *)(a1 + 160) = 0;
if ( (v21 & 1) != 0 )
*(_DWORD *)(a1 + 76) = a2;
else
sub_100585FE0(*(_QWORD *)(v5 + 96), a1 + 76, 2);
v13 = sub_1005E83A8(v5);
}
if ( (v6 & 1) == 0 )
{
v29 = *(_QWORD *)(a1 + 192);
if ( v29 )
(*(void (__fastcall **)(__int64, _QWORD))(*(_QWORD *)v29 + 88LL))(v29, v30);
goto LABEL_61;
}
return v13;
}