//
// sub_C5A60C from 0xc5a60c to 0xc5a940 (820 bytes)
//
// 2 xrefs:
// > sub_C5C614 @ 0xc5c81c
// > sub_C5C614 @ 0xc5c884
//
// 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_C5A60C(__int64 a1, _WORD *a2, __int64 a3)
{
__int64 result; // x0
__int64 v4; // x2
unsigned __int64 v5; // x3
__int64 v6; // x2
__int64 v7; // x6
__int64 v8; // x9
unsigned __int64 v9; // x7
unsigned __int64 v10; // x5
unsigned __int64 v11; // x13
_WORD *v12; // x4
unsigned __int64 v13; // x18
unsigned __int64 v14; // x7
__int64 v15; // x17
unsigned __int64 v16; // x15
unsigned __int64 v17; // x16
int16x8_t *v18; // x14
int16x8_t *v19; // x5
int16x8_t *v20; // x15
int16x8_t v21; // t1
int16x8_t v22; // q1
int16x8_t v23; // t1
__int64 i; // x4
result = *(_QWORD *)(a1 + 848);
v4 = a3 / 2;
v5 = *(_QWORD *)(result + 8);
if ( (__int64)v5 < v4 )
{
result = 2 * v5;
v6 = v4 - v5;
v7 = v5 - 4;
v8 = 2 * v5 - 8;
do
{
if ( v5 <= 4 )
{
switch ( (int)v5 )
{
case 0:
break;
case 1:
goto LABEL_32;
case 2:
goto LABEL_31;
case 3:
goto LABEL_30;
case 4:
goto LABEL_29;
}
}
else
{
if ( v7 > 0 )
{
v9 = (unsigned __int64)a2 + result;
if ( ((__int64)(2 * v5 + 16) <= 0 || (_WORD *)((char *)a2 + result) >= a2 + 8) && (unsigned __int64)v7 > 0xB )
{
v10 = -(__int64)((v9 >> 1) & 7) & 7;
if ( v10 > v7 )
v10 = v5 - 4;
if ( v10 )
{
v11 = v5 - 5;
v12 = a2 + 1;
*(_WORD *)v9 += *a2;
if ( v10 != 1 )
{
v11 = v5 - 6;
v12[v5] += a2[1];
v12 = a2 + 2;
if ( v10 != 2 )
{
v11 = v5 - 7;
v12[v5] += a2[2];
v12 = a2 + 3;
if ( v10 != 3 )
{
v11 = v5 - 8;
v12[v5] += a2[3];
v12 = a2 + 4;
if ( v10 != 4 )
{
v11 = v5 - 9;
v12[v5] += a2[4];
v12 = a2 + 5;
if ( v10 != 5 )
{
v11 = v5 - 10;
v12[v5] += a2[5];
v12 = a2 + 6;
if ( v10 == 7 )
{
v11 = v5 - 11;
v12[v5] += a2[6];
v12 = a2 + 7;
}
}
}
}
}
}
}
else
{
v11 = v5 - 4;
v12 = a2;
}
v13 = v7 - v10;
v14 = ((v7 - v10 - 8) >> 3) + 1;
v15 = 8 * v14;
if ( v5 - 5 - v10 <= 6 )
goto LABEL_21;
v16 = result + 2 * v10;
v17 = 0;
v18 = (int16x8_t *)&a2[v10];
v19 = (int16x8_t *)&a2[v10 + v5];
v20 = (int16x8_t *)((char *)a2 + v16);
do
{
v21 = *v18++;
v22 = v21;
++v17;
v23 = *v19++;
*v20++ = vaddq_s16(v23, v22);
}
while ( v17 < v14 );
v12 += 8 * v14;
v11 -= v15;
if ( v13 != v15 )
{
LABEL_21:
v12[v5] += *v12;
if ( (__int64)(v11 - 1) > 0 )
{
v12[v5 + 1] += v12[1];
if ( v11 != 2 )
{
v12[v5 + 2] += v12[2];
if ( v11 != 3 )
{
v12[v5 + 3] += v12[3];
if ( v11 != 4 )
{
v12[v5 + 4] += v12[4];
if ( v11 != 5 )
{
v12[v5 + 5] += v12[5];
if ( v11 != 6 )
v12[v5 + 6] += v12[6];
}
}
}
}
}
}
a2 = (_WORD *)((char *)a2 + v8);
}
else
{
for ( i = 0; i != v7; ++i )
*(_WORD *)(v9 + 2 * i) += a2[i];
a2 = (_WORD *)((char *)a2 + v8);
}
}
LABEL_29:
a2[v5] += *a2;
++a2;
LABEL_30:
a2[v5] += *a2;
++a2;
LABEL_31:
a2[v5] += *a2;
++a2;
LABEL_32:
a2[v5] += *a2;
++a2;
}
v6 -= v5;
}
while ( v6 > 0 );
}
return result;
}