//
// sub_140669040 from 0x140669040 to 0x14066924f (527 bytes)
//
// 6 xrefs:
// > sub_140668E10 @ 0x140668ecc
// > ??> @ 0x1408ea2a4
// > ??> @ 0x1408ea2e0
// > ??> @ 0x1408ea304
// > ??> @ 0x1408ea314
// > ??> @ 0x140931f10
//
// 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:35:51 +0000
//
__int64 *__fastcall sub_140669040(__int64 **a1, unsigned __int64 a2, __int64 a3)
{
__int64 v5; // rbx
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rcx
unsigned __int64 v8; // rax
__int64 v9; // r12
__int64 *v10; // rax
__int64 *v11; // r15
unsigned __int64 v12; // rcx
__int64 *v13; // rax
__int64 *v14; // r10
__int64 *v15; // rax
_QWORD *v16; // r9
__int64 v17; // r8
__int64 v18; // rdx
__int64 v19; // rcx
__int64 *v20; // rbx
__int64 *i; // rsi
__int64 *v22; // r8
if ( a2 > 0xAAAAAAAAAAAAAAALL )
sub_14005A170();
v5 = ((char *)a1[1] - (char *)*a1) / 24;
v6 = ((char *)a1[2] - (char *)*a1) / 24;
v7 = v6 >> 1;
if ( v6 <= 0xAAAAAAAAAAAAAAALL - (v6 >> 1) )
{
v8 = v7 + v6;
if ( v7 + v6 >= a2 )
{
if ( v8 > 0xAAAAAAAAAAAAAAALL )
sub_140009CF0(v7, v6, a3);
}
else
{
v8 = a2;
}
}
else
{
v8 = 0xAAAAAAAAAAAAAAALL;
}
v9 = 3 * v8;
v10 = sub_14003D460(24 * v8);
v11 = v10;
v12 = a2 - v5;
if ( a2 != v5 )
{
v13 = &v10[2 * v5 + 2 + v5];
do
{
*(v13 - 2) = 0;
*(v13 - 1) = 0;
*v13 = 0;
v13 += 3;
--v12;
}
while ( v12 );
}
v14 = a1[1];
v15 = *a1;
if ( *a1 != v14 )
{
v16 = v11 + 2;
do
{
v17 = v15[2];
v16 += 3;
v18 = v15[1];
v19 = *v15;
v15[2] = 0;
v15[1] = 0;
*v15 = 0;
v15 += 3;
*(v16 - 5) = v19;
*(v16 - 4) = v18;
*(v16 - 3) = v17;
}
while ( v15 != v14 );
}
v20 = *a1;
if ( *a1 )
{
for ( i = a1[1]; v20 != i; v20 += 3 )
sub_14003EA90(v20);
v22 = *a1;
if ( (unsigned __int64)(24 * (((char *)a1[2] - (char *)*a1) / 24)) >= 0x1000 )
{
if ( (unsigned __int64)v22 - *(v22 - 1) - 8 > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
v22 = (__int64 *)*(v22 - 1);
}
j_j_free(v22);
}
*a1 = v11;
a1[1] = &v11[3 * a2];
a1[2] = &v11[v9];
return &v11[v9];
}