//
// sub_C5A02C from 0xc5a02c to 0xc5a60c (1504 bytes)
//
// 1 xrefs:
// > sub_C5C614 @ 0xc5c7c8
//
// 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_C5A02C(__int64 a1, unsigned __int8 *a2, __int64 a3)
{
__int64 result; // x0
__int64 v4; // x2
__int64 v5; // x7
unsigned __int8 *v6; // x5
__int64 v7; // x5
unsigned __int64 v8; // x4
unsigned __int8 *v9; // x6
_BYTE *v10; // x3
unsigned __int64 v11; // x12
unsigned __int64 v12; // x5
__int64 v13; // x11
unsigned __int64 v14; // x13
int8x16_t *v15; // x10
int8x16_t *v16; // x4
int8x16_t *v17; // x14
int8x16_t v18; // t1
int8x16_t v19; // q1
int8x16_t v20; // t1
unsigned __int8 *v21; // x4
__int64 v22; // x3
__int64 v23; // x2
int v24; // w5
int v25; // w4
int v26; // w3
int v27; // w1
int v28; // w4
int v29; // w5
unsigned __int8 *v30; // x3
int v31; // w6
int v32; // w7
unsigned __int8 *v33; // x1
int v34; // w0
result = *(_QWORD *)(*(_QWORD *)(a1 + 848) + 8LL);
if ( result < a3 )
{
if ( result == 3 )
{
v23 = a3 - 3;
v24 = *a2;
v25 = a2[1];
v26 = a2[2];
for ( result = (__int64)(a2 + 3); v23 > 0; result += 3 )
{
v23 -= 3;
v27 = *(unsigned __int8 *)(result + 2);
v24 += *(unsigned __int8 *)result;
v25 += *(unsigned __int8 *)(result + 1);
*(_BYTE *)result = v24;
*(_BYTE *)(result + 1) = v25;
v26 += v27;
*(_BYTE *)(result + 2) = v26;
}
}
else
{
if ( result != 4 )
{
v4 = a3 - result;
v5 = result - 4;
while ( result != 1 )
{
if ( result == 2 )
{
v22 = 2;
goto LABEL_50;
}
if ( result )
{
v6 = (unsigned __int8 *)(result + 1);
if ( v5 > 0 )
{
v7 = (__int64)&a2[result];
if ( (&a2[result] >= a2 + 16 || result + 16 <= 0) && (unsigned __int64)v5 > 0x12 )
{
v8 = -v7 & 0xF;
if ( v8 > v5 )
v8 = result - 4;
if ( v8 )
{
v9 = (unsigned __int8 *)(result - 5);
v10 = a2 + 1;
*(_BYTE *)v7 += *a2;
if ( v8 != 1 )
{
v9 = (unsigned __int8 *)(result - 6);
v10[result] += a2[1];
v10 = a2 + 2;
if ( v8 != 2 )
{
v9 = (unsigned __int8 *)(result - 7);
v10[result] += a2[2];
v10 = a2 + 3;
if ( v8 != 3 )
{
v9 = (unsigned __int8 *)(result - 8);
v10[result] += a2[3];
v10 = a2 + 4;
if ( v8 != 4 )
{
v9 = (unsigned __int8 *)(result - 9);
v10[result] += a2[4];
v10 = a2 + 5;
if ( v8 != 5 )
{
v9 = (unsigned __int8 *)(result - 10);
v10[result] += a2[5];
v10 = a2 + 6;
if ( v8 != 6 )
{
v9 = (unsigned __int8 *)(result - 11);
v10[result] += a2[6];
v10 = a2 + 7;
if ( v8 != 7 )
{
v9 = (unsigned __int8 *)(result - 12);
v10[result] += a2[7];
v10 = a2 + 8;
if ( v8 != 8 )
{
v9 = (unsigned __int8 *)(result - 13);
v10[result] += a2[8];
v10 = a2 + 9;
if ( v8 != 9 )
{
v9 = (unsigned __int8 *)(result - 14);
v10[result] += a2[9];
v10 = a2 + 10;
if ( v8 != 10 )
{
v9 = (unsigned __int8 *)(result - 15);
v10[result] += a2[10];
v10 = a2 + 11;
if ( v8 != 11 )
{
v9 = (unsigned __int8 *)(result - 16);
v10[result] += a2[11];
v10 = a2 + 12;
if ( v8 != 12 )
{
v9 = (unsigned __int8 *)(result - 17);
v10[result] += a2[12];
v10 = a2 + 13;
if ( v8 != 13 )
{
v9 = (unsigned __int8 *)(result - 18);
v10[result] += a2[13];
v10 = a2 + 14;
if ( v8 == 15 )
{
v9 = (unsigned __int8 *)(result - 19);
v10[result] += a2[14];
v10 = a2 + 15;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
v9 = (unsigned __int8 *)(result - 4);
v10 = a2;
}
v11 = v5 - v8;
v12 = ((v5 - v8 - 16) >> 4) + 1;
v13 = 16 * v12;
if ( result - 5 - v8 <= 0xE )
goto LABEL_33;
v14 = 0;
v15 = (int8x16_t *)&a2[v8 + result];
v16 = (int8x16_t *)&a2[v8];
v17 = v15;
do
{
v18 = *v16++;
v19 = v18;
++v14;
v20 = *v15++;
*v17++ = vaddq_s8(v20, v19);
}
while ( v12 > v14 );
v10 += v13;
v9 -= v13;
if ( v13 == v11 )
{
v6 = (unsigned __int8 *)(result + 1);
v21 = &a2[v5];
}
else
{
LABEL_33:
v6 = (unsigned __int8 *)(result + 1);
v10[result] += *v10;
if ( (__int64)(v9 - 1) <= 0 )
goto LABEL_56;
v6[(_QWORD)v10] += v10[1];
if ( v9 == (_BYTE *)&dword_0 + 2 )
goto LABEL_56;
v10[result + 2] += v10[2];
if ( v9 == (_BYTE *)&dword_0 + 3 )
goto LABEL_56;
v10[result + 3] += v10[3];
if ( v9 == (unsigned __int8 *)&byte_4 )
goto LABEL_56;
v10[result + 4] += v10[4];
if ( v9 == (unsigned __int8 *)&byte_5 )
goto LABEL_56;
v10[result + 5] += v10[5];
if ( v9 == (unsigned __int8 *)&byte_6 )
goto LABEL_56;
v10[result + 6] += v10[6];
if ( v9 == (unsigned __int8 *)&byte_7
|| (v10[result + 7] += v10[7], v9 == (unsigned __int8 *)byte_8)
|| (v10[result + 8] += v10[8], v9 == (unsigned __int8 *)byte_9)
|| (v10[result + 9] += v10[9], v9 == (unsigned __int8 *)&byte_9[1])
|| (v10[result + 10] += v10[10], v9 == (unsigned __int8 *)&byte_9[2])
|| (v10[result + 11] += v10[11], v9 == (unsigned __int8 *)&byte_9[3])
|| (v10[result + 12] += v10[12], v9 == (unsigned __int8 *)&byte_9[4])
|| (v10[result + 13] += v10[13], v9 == (unsigned __int8 *)&byte_9[5]) )
{
LABEL_56:
v21 = &a2[v5];
}
else
{
v21 = &a2[v5];
v10[result + 14] += v10[14];
}
}
}
else
{
v21 = &a2[v5];
do
{
a2[result] += *a2;
++a2;
}
while ( a2 != v21 );
v6 = (unsigned __int8 *)(result + 1);
}
a2 = v21;
}
v22 = result;
a2[result] += *a2;
v6[(_QWORD)a2] += a2[1];
a2 += 2;
LABEL_50:
a2[v22] += *a2;
++a2;
LABEL_51:
a2[v22] += *a2;
++a2;
}
v4 -= result;
if ( v4 <= 0 )
return result;
}
v22 = 1;
goto LABEL_51;
}
v28 = *a2;
v29 = a2[1];
v30 = a2 + 4;
v31 = a2[2];
v32 = a2[3];
if ( a3 > 4 )
{
v33 = &a2[((a3 - 5) & 0xFFFFFFFFFFFFFFFCLL) + 8];
do
{
v34 = *v30;
v30 += 4;
v28 += v34;
result = *(v30 - 1);
v29 += *(v30 - 3);
v31 += *(v30 - 2);
*(v30 - 4) = v28;
v32 += result;
*(v30 - 3) = v29;
*(v30 - 2) = v31;
*(v30 - 1) = v32;
}
while ( v30 != v33 );
}
}
}
return result;
}