//
// sub_1009164B0 from 0x1009164b0 to 0x100916840 (912 bytes)
//
// 4 xrefs:
// > sub_100915250 @ 0x10091590c
// > sub_100915250 @ 0x1009159bb
// > sub_100915250 @ 0x100915c34
// > sub_1009164B0 @ 0x1009164f6
//
// 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:12 +0000
//
__int64 __fastcall sub_1009164B0(int *a1, int *a2, __int64 a3, __int64 a4, int a5)
{
int *v7; // r14
__int64 v8; // r12
__int64 result; // rax
unsigned __int64 v10; // r13
__int64 v11; // r13
int *v12; // r14
__int64 v13; // r14
int *v14; // rbx
int *v15; // rdx
char v16; // al
int *v17; // rsi
__int64 v18; // rax
__int64 v19; // r12
char v20; // dl
__int64 v21; // r14
char v22; // bl
bool v23; // zf
unsigned __int64 v24; // r15
__int64 v25; // rbx
unsigned __int64 v26; // r15
int *v27; // rbx
unsigned __int64 v28; // r12
__int64 v29; // rbx
__int64 v31; // [rsp+0h] [rbp-50h] BYREF
int *v32; // [rsp+8h] [rbp-48h]
__int64 v33; // [rsp+10h] [rbp-40h]
int *v34; // [rsp+18h] [rbp-38h] BYREF
_QWORD v35[6]; // [rsp+20h] [rbp-30h] BYREF
LODWORD(v33) = a5;
v7 = a2;
v35[0] = a1;
v34 = a2;
while ( 2 )
{
--a4;
v8 = (char *)v7 - (char *)a1;
result = 0x6DB6DB6DB6DB6DB7LL;
v10 = 0x6DB6DB6DB6DB6DB7LL * (((char *)v7 - (char *)a1) >> 3);
switch ( v10 )
{
case 0uLL:
case 1uLL:
return result;
case 2uLL:
v34 = v7 - 14;
result = sub_100912CC0((__int64)(v7 - 12), *(v7 - 14), (__int64)(a1 + 2), *a1);
if ( (_BYTE)result )
return sub_100916860(v35, &v34);
return result;
case 3uLL:
v34 = v7 - 14;
return sub_1009169E0(a1, a1 + 14, v7 - 14, a3);
case 4uLL:
v34 = v7 - 14;
return sub_100916AD0(a1, a1 + 14, a1 + 28, v7 - 14, a3);
case 5uLL:
v34 = v7 - 14;
return sub_100916B90(a1, a1 + 14, a1 + 28, a1 + 42, v7 - 14, a3);
default:
if ( v8 <= 1343 )
{
if ( (v33 & 1) != 0 )
return sub_100916C90(a1, v7, a3);
else
return sub_100917060(a1, v7, a3);
}
if ( a4 != -1 )
{
v11 = 56 * (v10 >> 1);
v12 = v7 - 14;
if ( (unsigned __int64)v8 < 0x1C01 )
{
sub_1009169E0(&a1[(unsigned __int64)v11 / 4], a1, v12, a3);
if ( (v33 & 1) != 0 )
{
LABEL_11:
v17 = v34;
goto LABEL_12;
}
}
else
{
sub_1009169E0(a1, &a1[(unsigned __int64)v11 / 4], v12, a3);
v13 = a4;
v14 = v34;
sub_1009169E0(v35[0] + 56LL, v35[0] + v11 - 56, v34 - 28, a3);
v15 = v14 - 42;
a4 = v13;
sub_1009169E0(v35[0] + 112LL, v35[0] + v11 + 56, v15, a3);
sub_1009169E0(v35[0] + v11 - 56, v11 + v35[0], v35[0] + v11 + 56, a3);
v31 = v35[0] + v11;
sub_100916860(v35, &v31);
if ( (v33 & 1) != 0 )
goto LABEL_11;
}
v16 = sub_100912CC0(v35[0] - 48LL, *(_DWORD *)(v35[0] - 56LL), v35[0] + 8LL, *(_DWORD *)v35[0]);
v17 = v34;
if ( v16 )
{
LABEL_12:
v18 = sub_100917960(v35[0], v17, a3);
v19 = v18;
if ( (v20 & 1) == 0 )
goto LABEL_2;
v21 = a4;
v22 = sub_100917EE0(v35[0], v18, a3);
result = sub_100917EE0(v19 + 56, v34, a3);
if ( (_BYTE)result )
{
if ( v22 )
return result;
v34 = (int *)v19;
a1 = (int *)v35[0];
a4 = v21;
v7 = (int *)v19;
}
else
{
v23 = v22 == 0;
a4 = v21;
if ( v23 )
{
LABEL_2:
sub_1009164B0(v35[0], v19, a3, a4, v33 & 1);
v35[0] = v19 + 56;
LODWORD(v33) = 0;
a1 = (int *)(v19 + 56);
v7 = v34;
continue;
}
a1 = (int *)(v19 + 56);
v35[0] = v19 + 56;
v7 = v34;
}
}
else
{
a1 = (int *)sub_100917400(v35[0], v34, a3);
v35[0] = a1;
v7 = v34;
}
continue;
}
if ( a1 != v7 )
{
v33 = a3;
v24 = (v10 - 2) >> 1;
v25 = 14 * v24;
v26 = v24 + 1;
v27 = &a1[v25];
v32 = a1;
do
{
sub_1009181F0(a1, v33, v10, v27);
a1 = v32;
v27 -= 14;
--v26;
}
while ( v26 );
v28 = 0x6DB6DB6DB6DB6DB7LL * ((unsigned __int64)v8 >> 3);
v29 = v33;
do
{
sub_100918470(a1, v7, v29, v28);
a1 = v32;
v7 -= 14;
result = v28 - 1;
}
while ( v28-- > 2 );
}
return result;
}
}
}