//
// sub_140372450 from 0x140372450 to 0x1403725a6 (342 bytes)
//
// 5 xrefs:
// > GJEffectManager::saveToState @ 0x14036e75f
// > sub_14052D490 @ 0x14052d59c
// > ??> @ 0x1408bbbac
// > ??> @ 0x1408bbbbc
// > ??> @ 0x140921e18
//
// 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:31:00 +0000
//
__int64 __fastcall sub_140372450(__int64 a1, unsigned __int64 a2)
{
char *v2; // rdi
const void *v4; // r8
__int64 result; // rax
unsigned __int64 v7; // rbp
__int64 v8; // rcx
unsigned __int64 v9; // rdx
unsigned __int64 v10; // rcx
unsigned __int64 v11; // rdi
_QWORD *v12; // r14
unsigned __int64 v13; // rbx
size_t v14; // rbx
v2 = *(char **)(a1 + 8);
v4 = *(const void **)a1;
result = (unsigned __int64)((unsigned __int128)((__int64)&v2[-*(_QWORD *)a1] * (__int128)0x7878787878787879LL) >> 64) >> 63;
v7 = (__int64)&v2[-*(_QWORD *)a1] / 68;
if ( a2 >= v7 )
{
if ( a2 > v7 )
{
v8 = *(_QWORD *)(a1 + 16) - (_QWORD)v4;
result = (unsigned __int64)((unsigned __int128)(v8 * (__int128)0x7878787878787879LL) >> 64) >> 63;
v9 = v8 / 68;
if ( a2 <= v8 / 68 )
{
v13 = a2 - v7;
if ( v13 )
{
v14 = 68 * v13;
result = (__int64)memset(v2, 0, v14);
v2 += v14;
}
*(_QWORD *)(a1 + 8) = v2;
}
else
{
if ( a2 > 0x3C3C3C3C3C3C3C3LL )
sub_14005A170();
v10 = v9 >> 1;
if ( v9 <= 0x3C3C3C3C3C3C3C3LL - (v9 >> 1) )
{
v11 = v9 + v10;
if ( v9 + v10 >= a2 )
{
if ( v11 > 0x3C3C3C3C3C3C3C3LL )
sub_140009CF0(v10, v9, 0x3C3C3C3C3C3C3C3LL);
}
else
{
v11 = a2;
}
}
else
{
v11 = 0x3C3C3C3C3C3C3C3LL;
}
v12 = sub_14003D460(68 * v11);
if ( a2 != v7 )
memset((char *)v12 + 68 * v7, 0, 68 * (a2 - v7));
memmove(v12, *(const void **)a1, *(_QWORD *)(a1 + 8) - *(_QWORD *)a1);
return sub_140378E30(a1, v12, a2, v11);
}
}
}
else
{
result = (__int64)v4 + 68 * a2;
*(_QWORD *)(a1 + 8) = result;
}
return result;
}