//
// sub_C851E0 from 0xc851e0 to 0xc852ac (204 bytes)
//
// 3 xrefs:
// > sub_C6F208 @ 0xc6f430
// > sub_C6F208 @ 0xc6f938
// > sub_C6F208 @ 0xc6ffe8
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
__int64 __fastcall sub_C851E0(__int64 a1, unsigned int a2, unsigned int a3, unsigned __int8 *a4, __int64 a5)
{
int v6; // w6
__int64 v8; // x5
int v9; // w2
__int64 v10; // x1
__int64 result; // x0
__int64 v12; // x6
unsigned int v13; // w8
unsigned int v14; // w7
v6 = *(_DWORD *)(a1 + 4);
v8 = *(unsigned int *)(a1 + 8);
v9 = 8 >> v6;
v10 = *(_QWORD *)(a1 + 16);
if ( 8 >> v6 > 7 )
return off_1260540(a4, v10, a5, a2, a3, v8);
result = (unsigned int)((1 << v6) - 1);
if ( (int)a2 < (int)a3 )
{
do
{
v12 = 0;
v13 = 0;
if ( (int)v8 > 0 )
{
do
{
if ( ((unsigned int)result & (unsigned int)v12) == 0 )
v13 = *a4++;
v14 = v13 & ((1 << v9) - 1);
v13 >>= v9;
*(_BYTE *)(a5 + v12++) = BYTE1(*(_DWORD *)(v10 + 4LL * v14));
}
while ( (int)v8 > (int)v12 );
a5 += (unsigned int)(v8 - 1) + 1LL;
}
++a2;
}
while ( a2 != a3 );
}
return result;
}