//
// sub_C5CB18 from 0xc5cb18 to 0xc5ce84 (876 bytes)
//
// 1 xrefs:
// > sub_C5C614 @ 0xc5c894
//
// 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_C5CB18(__int64 a1, _WORD *a2, __int64 a3)
{
__int64 result; // x0
__int64 v4; // x21
__int64 v5; // x20
_WORD *v6; // x19
__int64 v7; // x2
__int64 v8; // x4
unsigned __int64 v9; // x5
unsigned __int64 v10; // x3
__int64 v11; // x11
_WORD *v12; // x1
unsigned __int64 v13; // x16
unsigned __int64 v14; // x5
__int64 v15; // x15
unsigned __int64 v16; // x13
unsigned __int64 v17; // x14
int16x8_t *v18; // x12
int16x8_t *v19; // x3
int16x8_t *v20; // x13
int16x8_t v21; // t1
int16x8_t v22; // q1
int16x8_t v23; // t1
__int64 i; // x1
result = *(_QWORD *)(a1 + 848);
v4 = *(_QWORD *)(result + 8);
v5 = a3 / 2;
v6 = a2;
if ( v4 < a3 / 2 )
{
TIFFSwabArrayOfShort(a2, a3 / 2);
result = 2 * v4;
v7 = v5 - v4;
v8 = v4 - 4;
do
{
if ( (unsigned __int64)v4 <= 4 )
{
switch ( (int)v4 )
{
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 ( v8 > 0 )
{
v9 = (unsigned __int64)v6 + result;
if ( (2 * v4 + 16 <= 0 || (_WORD *)((char *)v6 + result) >= v6 + 8) && (unsigned __int64)v8 > 0xB )
{
v10 = -(__int64)((v9 >> 1) & 7) & 7;
if ( v10 > v8 )
v10 = v4 - 4;
if ( v10 )
{
v11 = v4 - 5;
v12 = v6 + 1;
*(_WORD *)v9 += *v6;
if ( v10 != 1 )
{
v11 = v4 - 6;
v12[v4] += v6[1];
v12 = v6 + 2;
if ( v10 != 2 )
{
v11 = v4 - 7;
v12[v4] += v6[2];
v12 = v6 + 3;
if ( v10 != 3 )
{
v11 = v4 - 8;
v12[v4] += v6[3];
v12 = v6 + 4;
if ( v10 != 4 )
{
v11 = v4 - 9;
v12[v4] += v6[4];
v12 = v6 + 5;
if ( v10 != 5 )
{
v11 = v4 - 10;
v12[v4] += v6[5];
v12 = v6 + 6;
if ( v10 == 7 )
{
v11 = v4 - 11;
v12[v4] += v6[6];
v12 = v6 + 7;
}
}
}
}
}
}
}
else
{
v11 = v4 - 4;
v12 = v6;
}
v13 = v8 - v10;
v14 = ((v8 - v10 - 8) >> 3) + 1;
v15 = 8 * v14;
if ( v4 - 5 - v10 <= 6 )
goto LABEL_21;
v16 = result + 2 * v10;
v17 = 0;
v18 = (int16x8_t *)&v6[v10];
v19 = (int16x8_t *)&v6[v10 + v4];
v20 = (int16x8_t *)((char *)v6 + 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[v4] += *v12;
if ( v11 - 1 > 0 )
{
v12[v4 + 1] += v12[1];
if ( v11 != 2 )
{
v12[v4 + 2] += v12[2];
if ( v11 != 3 )
{
v12[v4 + 3] += v12[3];
if ( v11 != 4 )
{
v12[v4 + 4] += v12[4];
if ( v11 != 5 )
{
v12[v4 + 5] += v12[5];
if ( v11 != 6 )
v12[v4 + 6] += v12[6];
}
}
}
}
}
}
}
else
{
for ( i = 0; i != v8; ++i )
*(_WORD *)(v9 + 2 * i) += v6[i];
}
v6 = (_WORD *)((char *)v6 + result - 8);
}
LABEL_29:
v6[v4] += *v6;
++v6;
LABEL_30:
v6[v4] += *v6;
++v6;
LABEL_31:
v6[v4] += *v6;
++v6;
LABEL_32:
v6[v4] += *v6;
++v6;
}
v7 -= v4;
}
while ( v7 > 0 );
}
return result;
}