//
// sub_100097670 from 0x100097670 to 0x1000977c4 (340 bytes)
//
// 1 xrefs:
// > sub_100089410 @ 0x100089c38
//
// 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:20:10 +0000
//
unsigned __int64 __fastcall sub_100097670(unsigned __int64 *a1, char *a2, __int64 a3, unsigned __int64 a4)
{
char *v6; // rdi
__int64 v7; // rax
unsigned __int64 v8; // r12
unsigned __int64 v9; // rax
__int64 v10; // r13
unsigned __int64 result; // rax
char *v12; // r12
size_t v13; // r14
size_t v14; // rdx
char *v15; // r13
size_t v16; // r14
v6 = (char *)*a1;
v7 = a1[2];
if ( 0xCF3CF3CF3CF3CF3DLL * ((v7 - (__int64)v6) >> 3) < a4 )
{
if ( v6 )
{
a1[1] = (unsigned __int64)v6;
v8 = a4;
operator delete(v6);
a4 = v8;
*(_OWORD *)a1 = 0;
a1[2] = 0;
v7 = 0;
}
if ( a4 > 0x186186186186186LL )
goto LABEL_22;
v9 = 0xCF3CF3CF3CF3CF3DLL * (v7 >> 3);
if ( 2 * v9 > a4 )
a4 = 2 * v9;
if ( v9 >= 0xC30C30C30C30C3LL )
a4 = 0x186186186186186LL;
if ( a4 > 0x186186186186186LL )
LABEL_22:
sub_1000977D0(v6);
v10 = 168 * a4;
result = (unsigned __int64)operator new(168 * a4);
v12 = (char *)result;
*a1 = result;
a1[1] = result;
a1[2] = result + v10;
v13 = a3 - (_QWORD)a2;
if ( v13 )
result = (unsigned __int64)memcpy((void *)result, a2, v13);
LABEL_17:
a1[1] = (unsigned __int64)&v12[v13];
return result;
}
v12 = (char *)a1[1];
v14 = v12 - v6;
result = 0xCF3CF3CF3CF3CF3DLL * ((v12 - v6) >> 3);
if ( result < a4 )
{
v15 = &a2[v14];
if ( v12 != v6 )
{
result = (unsigned __int64)memmove(v6, a2, v14);
v12 = (char *)a1[1];
}
v13 = a3 - (_QWORD)v15;
if ( v13 )
result = (unsigned __int64)memmove(v12, v15, v13);
goto LABEL_17;
}
v16 = a3 - (_QWORD)a2;
if ( v16 )
result = (unsigned __int64)memmove(v6, a2, v16);
a1[1] = (unsigned __int64)&v6[v16];
return result;
}