//
// sub_10091D490 from 0x10091d490 to 0x10091d9bf (1327 bytes)
//
// 3 xrefs:
// > sub_100915250 @ 0x1009158a9
// > sub_100915250 @ 0x100915958
// > sub_100915250 @ 0x100915a07
//
// 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:38:15 +0000
//
__int64 __fastcall sub_10091D490(_QWORD *a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5)
{
__int64 v5; // rbx
unsigned __int64 v7; // r12
__int64 v8; // r13
unsigned __int64 v9; // r12
__int64 v10; // r15
char *v11; // rax
__int64 v12; // r15
__int64 v13; // r13
__int64 v14; // rax
unsigned __int64 v15; // r15
unsigned __int64 v16; // rdx
__int64 v17; // rcx
__int64 v18; // r15
unsigned __int64 v19; // r13
__int64 v20; // rcx
unsigned __int64 v21; // rdx
unsigned __int64 v22; // r12
__int64 v23; // r15
__int64 v24; // r12
__int64 v25; // rax
char *v26; // r13
__int64 v27; // r12
__int64 v28; // r14
__int64 v29; // r15
char *v30; // rdi
__int64 v31; // rax
char *v32; // rdi
char *v33; // r14
char *v34; // r15
void **v35; // r13
void **v36; // rax
__int64 v37; // r15
__int64 v38; // rax
__int64 v40; // [rsp+8h] [rbp-68h]
void *__p; // [rsp+10h] [rbp-60h] BYREF
char *v42; // [rsp+18h] [rbp-58h]
char *v43; // [rsp+20h] [rbp-50h]
char *v44; // [rsp+28h] [rbp-48h]
_QWORD *v45; // [rsp+30h] [rbp-40h]
__int64 v46; // [rsp+38h] [rbp-38h]
_QWORD *v47; // [rsp+40h] [rbp-30h]
v5 = a2;
if ( a5 <= 0 )
return v5;
v7 = a1[1];
if ( 0x6DB6DB6DB6DB6DB7LL * ((__int64)(a1[2] - v7) >> 3) < a5 )
{
v8 = *a1;
v9 = a5 + 0x6DB6DB6DB6DB6DB7LL * ((__int64)(v7 - *a1) >> 3);
if ( v9 > 0x492492492492492LL )
sub_1008DC450();
if ( 0xDB6DB6DB6DB6DB6ELL * ((a1[2] - v8) >> 3) > v9 )
v9 = 0xDB6DB6DB6DB6DB6ELL * ((a1[2] - v8) >> 3);
if ( (unsigned __int64)(0x6DB6DB6DB6DB6DB7LL * ((a1[2] - v8) >> 3)) >= 0x249249249249249LL )
v9 = 0x492492492492492LL;
v45 = a1;
v47 = a1;
if ( v9 )
{
if ( v9 > 0x492492492492492LL )
sub_10001ADB0();
v10 = a5;
v11 = (char *)operator new(56 * v9);
a5 = v10;
}
else
{
v11 = nullptr;
}
__p = v11;
v26 = &v11[8 * ((a2 - v8) >> 3)];
v43 = v26;
v42 = v26;
v44 = &v11[56 * v9];
v27 = 56 * a5;
v46 = (__int64)&v26[56 * a5];
v28 = a3 + 48;
v29 = 0;
do
{
*(_DWORD *)&v26[v29] = *(_DWORD *)(v28 + v29 - 48);
v30 = &v26[v29 + 8];
if ( (*(_BYTE *)(v28 + v29 - 40) & 1) != 0 )
{
sub_10001AD30(v30, *(const void **)(v28 + v29 - 24), *(_QWORD *)(v28 + v29 - 32));
}
else
{
v31 = v28 + v29 - 40;
*(_QWORD *)&v26[v29 + 24] = *(_QWORD *)(v31 + 16);
*(_OWORD *)v30 = *(_OWORD *)v31;
}
v32 = &v26[v29 + 32];
if ( (*(_BYTE *)(v28 + v29 - 16) & 1) != 0 )
{
sub_10001AD30(v32, *(const void **)(v28 + v29), *(_QWORD *)(v28 + v29 - 8));
}
else
{
*(_QWORD *)&v26[v29 + 48] = *(_QWORD *)(v28 + v29);
*(_OWORD *)v32 = *(_OWORD *)(v28 + v29 - 16);
}
v29 += 56;
}
while ( v27 != v29 );
v43 = (char *)v46;
v5 = sub_10091DA20(v47, &__p, a2);
v33 = v42;
while ( 1 )
{
while ( 1 )
{
v34 = v43;
if ( v43 == v33 )
{
if ( __p )
operator delete(__p);
return v5;
}
v43 -= 56;
if ( (*(v34 - 24) & 1) == 0 )
break;
operator delete(*((void **)v34 - 1));
if ( (*(v34 - 48) & 1) != 0 )
goto LABEL_45;
}
if ( (*(v34 - 48) & 1) != 0 )
LABEL_45:
operator delete(*((void **)v34 - 4));
}
}
v12 = v7 - a2;
if ( 0x6DB6DB6DB6DB6DB7LL * ((__int64)(v7 - a2) >> 3) >= a5 )
{
v18 = 56 * a5;
v19 = v7 - 56 * a5;
v20 = a1[1];
if ( v7 >= 56 * a5 )
{
v21 = v7 - 56 * a5;
v20 = a1[1];
do
{
*(_DWORD *)v20 = *(_DWORD *)v21;
*(_QWORD *)(v20 + 24) = *(_QWORD *)(v21 + 24);
*(_OWORD *)(v20 + 8) = *(_OWORD *)(v21 + 8);
*(_OWORD *)(v21 + 8) = 0;
*(_QWORD *)(v21 + 24) = 0;
*(_QWORD *)(v20 + 48) = *(_QWORD *)(v21 + 48);
*(_OWORD *)(v20 + 32) = *(_OWORD *)(v21 + 32);
*(_OWORD *)(v21 + 32) = 0;
*(_QWORD *)(v21 + 48) = 0;
v21 += 56LL;
v20 += 56;
}
while ( v21 < v7 );
}
a1[1] = v20;
if ( v7 != a2 + 56 * a5 )
{
v22 = v7 - 56;
do
{
*(_DWORD *)v22 = *(_DWORD *)(v19 - 56);
if ( (*(_BYTE *)(v22 + 8) & 1) != 0 )
operator delete(*(void **)(v22 + 24));
*(_QWORD *)(v22 + 24) = *(_QWORD *)(v19 - 48 + 16);
*(_OWORD *)(v22 + 8) = *(_OWORD *)(v19 - 48);
*(_WORD *)(v19 - 48) = 0;
if ( (*(_BYTE *)(v22 + 32) & 1) != 0 )
operator delete(*(void **)(v22 + 48));
*(_QWORD *)(v22 + 48) = *(_QWORD *)(v19 - 8);
*(_OWORD *)(v22 + 32) = *(_OWORD *)(v19 - 24);
*(_WORD *)(v19 - 24) = 0;
v22 -= 56LL;
v19 -= 56LL;
}
while ( v19 != a2 );
}
v23 = a3 + v18;
v24 = 0;
do
{
*(_DWORD *)(a2 + v24) = *(_DWORD *)(a3 + v24);
std::string::operator=((std::string *)(a2 + v24 + 8), (const std::string *)(a3 + v24 + 8));
std::string::operator=((std::string *)(a2 + v24 + 32), (const std::string *)(a3 + v24 + 32));
v25 = a3 + v24 + 56;
v24 += 56;
}
while ( v25 != v23 );
}
else
{
v46 = a5;
v47 = a1;
v40 = a3 + v12;
v13 = sub_1008DC970((__int64)a1, a3 + v12, a4, v7);
a1[1] = v13;
if ( v12 > 0 )
{
v14 = a2 + 56 * v46;
v15 = v13 - 56 * v46;
if ( v15 >= v7 )
{
v17 = v13;
}
else
{
v16 = v13 - 56 * v46;
v17 = v13;
do
{
*(_DWORD *)v17 = *(_DWORD *)v16;
*(_QWORD *)(v17 + 24) = *(_QWORD *)(v16 + 24);
*(_OWORD *)(v17 + 8) = *(_OWORD *)(v16 + 8);
*(_OWORD *)(v16 + 8) = 0;
*(_QWORD *)(v16 + 24) = 0;
*(_QWORD *)(v17 + 48) = *(_QWORD *)(v16 + 48);
*(_OWORD *)(v17 + 32) = *(_OWORD *)(v16 + 32);
*(_OWORD *)(v16 + 32) = 0;
*(_QWORD *)(v16 + 48) = 0;
v16 += 56LL;
v17 += 56;
}
while ( v16 < v7 );
}
a1[1] = v17;
if ( v13 != v14 )
{
v35 = (void **)(v13 - 8);
do
{
*((_DWORD *)v35 - 12) = *(_DWORD *)(v15 - 56);
if ( (*(_BYTE *)(v35 - 5) & 1) != 0 )
operator delete(*(v35 - 3));
v36 = v35 - 5;
v36[2] = *(void **)(v15 - 48 + 16);
*(_OWORD *)v36 = *(_OWORD *)(v15 - 48);
*(_WORD *)(v15 - 48) = 0;
if ( (*(_BYTE *)(v35 - 2) & 1) != 0 )
operator delete(*v35);
*v35 = *(void **)(v15 - 8);
*((_OWORD *)v35 - 1) = *(_OWORD *)(v15 - 24);
*(_WORD *)(v15 - 24) = 0;
v35 -= 7;
v15 -= 56LL;
}
while ( v15 != a2 );
}
v37 = 0;
do
{
*(_DWORD *)(a2 + v37) = *(_DWORD *)(a3 + v37);
std::string::operator=((std::string *)(a2 + v37 + 8), (const std::string *)(a3 + v37 + 8));
std::string::operator=((std::string *)(a2 + v37 + 32), (const std::string *)(a3 + v37 + 32));
v38 = a3 + v37 + 56;
v37 += 56;
}
while ( v38 != v40 );
}
}
return v5;
}