//
// sub_ED21E0 from 0xed21e0 to 0xed27d4 (1524 bytes)
//
// 1 xrefs:
// > sub_ED27D4 @ 0xed28c4
//
// This function is hookable on this platform (idp: arm, 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 13:11:41 +0000
//
void __fastcall sub_ED21E0(__int64 a1, _BYTE *a2, signed __int64 byte_count)
{
int v4; // w22
signed __int64 v5; // x21
void *v6; // x23
__int64 v7; // x20
__int64 v8; // x5
_BYTE *v9; // x0
signed __int64 v10; // x4
__int64 v11; // x11
unsigned __int64 v12; // x3
signed __int64 v13; // x6
_BYTE *v14; // x1
unsigned __int64 v15; // x14
unsigned __int64 v16; // x11
__int64 v17; // x13
unsigned __int64 v18; // x15
int8x16_t *v19; // x12
int8x16_t *v20; // x3
int8x16_t *v21; // x16
int8x16_t v22; // t1
int8x16_t v23; // q1
int8x16_t v24; // t1
_BYTE *v25; // x3
__int64 v26; // x1
_BYTE *v27; // x5
__int64 v28; // x4
unsigned int v29; // w0
_BYTE *v30; // x2
__int64 v31; // x1
v4 = *(unsigned __int16 *)(a1 + 116) >> 3;
v5 = *(_QWORD *)(*(_QWORD *)(a1 + 848) + 8LL);
v6 = TIFFmalloc(byte_count);
v7 = byte_count / (unsigned __int16)v4;
if ( v6 )
{
if ( v5 < byte_count )
{
v8 = v5 - 4;
v9 = a2;
v10 = byte_count;
do
{
if ( (unsigned __int64)v5 <= 4 )
{
switch ( (int)v5 )
{
case 0:
break;
case 1:
v26 = 1;
goto LABEL_49;
case 2:
v26 = 2;
goto LABEL_48;
case 3:
v26 = 3;
goto LABEL_47;
case 4:
v26 = 4;
goto LABEL_46;
}
}
else
{
if ( v8 <= 0 )
{
v26 = v5;
}
else
{
v11 = (__int64)&v9[v5];
if ( (&v9[v5] >= v9 + 16 || v5 + 16 <= 0) && (unsigned __int64)v8 > 0x12 )
{
v12 = -v11 & 0xF;
if ( v12 > v8 )
v12 = v5 - 4;
if ( v12 )
{
v13 = v5 - 5;
v14 = v9 + 1;
*(_BYTE *)v11 += *v9;
if ( v12 != 1 )
{
v13 = v5 - 6;
v14[v5] += v9[1];
v14 = v9 + 2;
if ( v12 != 2 )
{
v13 = v5 - 7;
v14[v5] += v9[2];
v14 = v9 + 3;
if ( v12 != 3 )
{
v13 = v5 - 8;
v14[v5] += v9[3];
v14 = v9 + 4;
if ( v12 != 4 )
{
v13 = v5 - 9;
v14[v5] += v9[4];
v14 = v9 + 5;
if ( v12 != 5 )
{
v13 = v5 - 10;
v14[v5] += v9[5];
v14 = v9 + 6;
if ( v12 != 6 )
{
v13 = v5 - 11;
v14[v5] += v9[6];
v14 = v9 + 7;
if ( v12 != 7 )
{
v13 = v5 - 12;
v14[v5] += v9[7];
v14 = v9 + 8;
if ( v12 != 8 )
{
v13 = v5 - 13;
v14[v5] += v9[8];
v14 = v9 + 9;
if ( v12 != 9 )
{
v13 = v5 - 14;
v14[v5] += v9[9];
v14 = v9 + 10;
if ( v12 != 10 )
{
v13 = v5 - 15;
v14[v5] += v9[10];
v14 = v9 + 11;
if ( v12 != 11 )
{
v13 = v5 - 16;
v14[v5] += v9[11];
v14 = v9 + 12;
if ( v12 != 12 )
{
v13 = v5 - 17;
v14[v5] += v9[12];
v14 = v9 + 13;
if ( v12 != 13 )
{
v13 = v5 - 18;
v14[v5] += v9[13];
v14 = v9 + 14;
if ( v12 == 15 )
{
v13 = v5 - 19;
v14[v5] += v9[14];
v14 = v9 + 15;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
v13 = v5 - 4;
v14 = v9;
}
v15 = v8 - v12;
v16 = ((v8 - v12 - 16) >> 4) + 1;
v17 = 16 * v16;
if ( v5 - 5 - v12 > 0xE )
{
v18 = 0;
v19 = (int8x16_t *)&v9[v12 + v5];
v20 = (int8x16_t *)&v9[v12];
v21 = v19;
do
{
v22 = *v20++;
v23 = v22;
++v18;
v24 = *v19++;
*v21++ = vaddq_s8(v24, v23);
}
while ( v16 > v18 );
v14 += v17;
v13 -= v17;
if ( v17 == v15 )
goto LABEL_57;
}
v14[v5] += *v14;
if ( v13 - 1 <= 0 )
goto LABEL_57;
v14[v5 + 1] += v14[1];
if ( v13 == 2 )
goto LABEL_57;
v14[v5 + 2] += v14[2];
if ( v13 == 3 )
goto LABEL_57;
v14[v5 + 3] += v14[3];
if ( v13 == 4 )
goto LABEL_57;
v14[v5 + 4] += v14[4];
if ( v13 == 5 )
goto LABEL_57;
v14[v5 + 5] += v14[5];
if ( v13 == 6 )
goto LABEL_57;
v14[v5 + 6] += v14[6];
if ( v13 == 7
|| (v14[v5 + 7] += v14[7], v13 == 8)
|| (v14[v5 + 8] += v14[8], v13 == 9)
|| (v14[v5 + 9] += v14[9], v13 == 10)
|| (v14[v5 + 10] += v14[10], v13 == 11)
|| (v14[v5 + 11] += v14[11], v13 == 12)
|| (v14[v5 + 12] += v14[12], v13 == 13)
|| (v14[v5 + 13] += v14[13], v13 == 14) )
{
LABEL_57:
v25 = &v9[v8];
}
else
{
v25 = &v9[v8];
v14[v5 + 14] += v14[14];
}
}
else
{
v25 = &v9[v8];
do
{
v9[v5] += *v9;
++v9;
}
while ( v9 != v25 );
}
v9 = v25;
v26 = v5;
}
LABEL_46:
v9[v26] += *v9;
++v9;
LABEL_47:
v9[v26] += *v9;
++v9;
LABEL_48:
v9[v26] += *v9;
++v9;
LABEL_49:
v9[v26] += *v9;
++v9;
}
v10 -= v5;
}
while ( v5 < v10 );
}
TIFFmemcpy(v6, a2, byte_count);
v27 = a2;
v28 = 0;
if ( v7 > 0 )
{
do
{
if ( v4 )
{
v29 = v4 - 1;
v30 = v27;
do
{
v31 = v29--;
*v30++ = *((_BYTE *)v6 + v28 + v31 * v7);
}
while ( v29 != -1 );
}
++v28;
v27 += (unsigned __int16)v4;
}
while ( v28 != v7 );
}
TIFFfree(v6);
}
}