//
// sub_BDDDC8 from 0xbdddc8 to 0xbde648 (2176 bytes)
//
// 1 xrefs:
// > png_read_filter_row @ 0xbe2a34
//
// 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
//
unsigned __int64 __fastcall sub_BDDDC8(__int64 a1, unsigned __int64 a2, _BYTE *a3)
{
unsigned __int64 v3; // x14
unsigned __int64 v4; // x11
_BYTE *v5; // x7
unsigned __int64 v6; // x6
_BYTE *v7; // x3
unsigned __int64 v8; // x8
unsigned __int64 v9; // x4
__int64 v10; // x5
int8x16_t *v11; // x12
uint8x16_t *v12; // x9
uint8x16_t *v13; // x13
unsigned __int64 v14; // x6
uint8x16_t v15; // t1
uint8x16_t v16; // q1
uint8x16_t v17; // t1
uint16x8_t v18; // q3
uint16x8_t v19; // q2
uint16x8_t v20; // q1
uint16x8_t v21; // q0
unsigned __int64 result; // x0
unsigned __int64 v23; // x11
__int64 v24; // x10
unsigned __int64 v25; // x17
unsigned __int64 v26; // x15
_BYTE *v27; // x9
unsigned __int8 *v28; // x8
_BYTE *v29; // x13
int v30; // w4
int v31; // w7
char v32; // w6
int v33; // t1
signed int v34; // w5
signed int v35; // w0
signed int v36; // w3
__int64 v37; // x3
unsigned __int64 v38; // x14
__int64 v39; // x4
unsigned __int64 v40; // x5
uint8x16_t *v41; // x16
uint8x8_t *v42; // x13
uint8x16_t *v43; // x12
uint8x8_t *v44; // x6
uint16x8_t v45; // q10
uint16x8_t v46; // q13
uint16x8_t v47; // q11
uint16x8_t v48; // q7
uint16x8_t v49; // q21
uint16x8_t v50; // q19
int8x16_t v51; // q22
int8x16_t v52; // q0
int8x16_t v53; // q23
int8x16_t v54; // q2
int8x16_t v55; // q21
int8x16_t v56; // q26
int8x16_t v57; // q24
int8x16_t v58; // q27
int8x16_t v59; // q25
int8x16_t v60; // q3
int8x16_t v61; // q19
int8x16_t v62; // q20
int32x4_t v63; // q30
int32x4_t v64; // q12
int32x4_t v65; // q9
int32x4_t v66; // q11
int32x4_t v67; // q13
int32x4_t v68; // q18
int32x4_t v69; // q10
int32x4_t v70; // q16
int32x4_t v71; // q7
int32x4_t v72; // q17
int32x4_t v73; // q5
int32x4_t v74; // q4
int32x4_t v75; // q29
int32x4_t v76; // q28
int32x4_t v77; // q8
int32x4_t v78; // q6
int32x4_t v79; // q18
int32x4_t v80; // q9
int8x16_t v81; // q3
uint16x8_t v82; // q8
uint16x8_t v83; // q1
int v84; // w2
int v85; // w5
char v86; // w4
int v87; // t1
int v88; // w3
int v89; // w1
__int64 v90; // x8
unsigned __int64 v91; // x11
__int64 v92; // x10
int v93; // w4
int v94; // w7
int v95; // w6
int v96; // w5
signed int v97; // w3
v3 = ((unsigned __int64)((unsigned int)*(unsigned __int8 *)(a1 + 19) + 7) >> 3) & 0x3F;
v4 = a2 + v3;
if ( a2 < a2 + v3 )
{
v5 = (_BYTE *)(a2 + 1);
if ( v3 > 0x11 && ((unsigned __int64)a3 >= a2 + 16 || a2 >= (unsigned __int64)(a3 + 16)) )
{
v6 = -(__int64)a2 & 0xF;
if ( v3 <= v6 )
v6 = ((unsigned __int64)((unsigned int)*(unsigned __int8 *)(a1 + 19) + 7) >> 3) & 0x3F;
if ( v6 )
{
v7 = a3 + 1;
*(_BYTE *)a2 += *a3;
if ( v6 != 1 )
{
v7 = a3 + 2;
v5 = (_BYTE *)(a2 + 2);
*(_BYTE *)(a2 + 1) += a3[1];
if ( v6 != 2 )
{
v7 = a3 + 3;
v5 = (_BYTE *)(a2 + 3);
*(_BYTE *)(a2 + 2) += a3[2];
if ( v6 != 3 )
{
v7 = a3 + 4;
v5 = (_BYTE *)(a2 + 4);
*(_BYTE *)(a2 + 3) += a3[3];
if ( v6 != 4 )
{
v7 = a3 + 5;
v5 = (_BYTE *)(a2 + 5);
*(_BYTE *)(a2 + 4) += a3[4];
if ( v6 != 5 )
{
v7 = a3 + 6;
v5 = (_BYTE *)(a2 + 6);
*(_BYTE *)(a2 + 5) += a3[5];
if ( v6 != 6 )
{
v7 = a3 + 7;
v5 = (_BYTE *)(a2 + 7);
*(_BYTE *)(a2 + 6) += a3[6];
if ( v6 != 7 )
{
v7 = a3 + 8;
v5 = (_BYTE *)(a2 + 8);
*(_BYTE *)(a2 + 7) += a3[7];
if ( v6 != 8 )
{
v7 = a3 + 9;
v5 = (_BYTE *)(a2 + 9);
*(_BYTE *)(a2 + 8) += a3[8];
if ( v6 != 9 )
{
v7 = a3 + 10;
v5 = (_BYTE *)(a2 + 10);
*(_BYTE *)(a2 + 9) += a3[9];
if ( v6 != 10 )
{
v7 = a3 + 11;
v5 = (_BYTE *)(a2 + 11);
*(_BYTE *)(a2 + 10) += a3[10];
if ( v6 != 11 )
{
v7 = a3 + 12;
v5 = (_BYTE *)(a2 + 12);
*(_BYTE *)(a2 + 11) += a3[11];
if ( v6 != 12 )
{
v7 = a3 + 13;
v5 = (_BYTE *)(a2 + 13);
*(_BYTE *)(a2 + 12) += a3[12];
if ( v6 != 13 )
{
v7 = a3 + 14;
v5 = (_BYTE *)(a2 + 14);
*(_BYTE *)(a2 + 13) += a3[13];
if ( v6 == 15 )
{
v7 = a3 + 15;
v5 = (_BYTE *)(a2 + 15);
*(_BYTE *)(a2 + 14) += a3[14];
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
v7 = a3;
v5 = (_BYTE *)a2;
}
v8 = v3 - v6;
v9 = ((v3 - v6 - 16) >> 4) + 1;
v10 = 16 * v9;
if ( v3 - 1 - v6 <= 0xE )
goto LABEL_81;
v11 = (int8x16_t *)(a2 + v6);
v12 = (uint8x16_t *)&a3[v6];
v13 = (uint8x16_t *)(a2 + v6);
v14 = 0;
do
{
v15 = *v13++;
v16 = v15;
++v14;
v17 = *v12++;
v18 = vmovl_u8((uint8x8_t)v16.n128_u64[0]);
v19 = vmovl_u8((uint8x8_t)v17.n128_u64[0]);
v20 = vmovl_high_u8(v16);
v21 = vmovl_high_u8(v17);
*v11++ = vmovn_hight_s16(
vmovn_s16(
vmovn_hight_s32(
vmovn_s32(vaddl_u16((uint16x4_t)v19.n128_u64[0], (uint16x4_t)v18.n128_u64[0])),
vaddl_high_u16(v19, v18))),
vmovn_hight_s32(
vmovn_s32(vaddl_u16((uint16x4_t)v21.n128_u64[0], (uint16x4_t)v20.n128_u64[0])),
vaddl_high_u16(v21, v20)));
}
while ( v14 < v9 );
v5 += v10;
v7 += v10;
if ( v8 != v10 )
{
LABEL_81:
*v5 += *v7;
if ( v4 > (unsigned __int64)(v5 + 1) )
{
v5[1] += v7[1];
if ( v4 > (unsigned __int64)(v5 + 2) )
{
v5[2] += v7[2];
if ( v4 > (unsigned __int64)(v5 + 3) )
{
v5[3] += v7[3];
if ( v4 > (unsigned __int64)(v5 + 4) )
{
v5[4] += v7[4];
if ( v4 > (unsigned __int64)(v5 + 5) )
{
v5[5] += v7[5];
if ( v4 > (unsigned __int64)(v5 + 6) )
{
v5[6] += v7[6];
if ( v4 > (unsigned __int64)(v5 + 7) )
{
v5[7] += v7[7];
if ( v4 > (unsigned __int64)(v5 + 8) )
{
v5[8] += v7[8];
if ( v4 > (unsigned __int64)(v5 + 9) )
{
v5[9] += v7[9];
if ( v4 > (unsigned __int64)(v5 + 10) )
{
v5[10] += v7[10];
if ( v4 > (unsigned __int64)(v5 + 11) )
{
v5[11] += v7[11];
if ( v4 > (unsigned __int64)(v5 + 12) )
{
v5[12] += v7[12];
if ( v4 > (unsigned __int64)(v5 + 13) )
{
v5[13] += v7[13];
if ( v4 > (unsigned __int64)(v5 + 14) )
v5[14] += v7[14];
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
v90 = 0;
do
{
*(_BYTE *)(a2 + v90) += a3[v90];
++v90;
}
while ( v90 != v3 );
}
a3 += v3;
a2 += v3;
}
result = *(_QWORD *)(a1 + 8) - v3;
v23 = v4 + result;
if ( v23 > a2 )
{
v24 = -(__int64)v3;
v25 = v23 - a2;
if ( ((unsigned __int64)&a3[-v3] >= a2 + 16 || a2 >= (unsigned __int64)&a3[16 - v3])
&& (a2 - v3 >= a2 + 16 || (__int64)(16 - v3) <= 0)
&& (a2 >= (unsigned __int64)(a3 + 16) || (unsigned __int64)a3 >= a2 + 16)
&& v25 > 0x10 )
{
v26 = -(__int64)a2 & 0xF;
if ( v25 <= v26 )
v26 = v23 - a2;
if ( v26 )
{
v27 = (_BYTE *)(a2 + v26);
v28 = a3;
v29 = (_BYTE *)a2;
do
{
v30 = v28[-v3];
v31 = (unsigned __int8)v29[-v3];
v33 = *v28++;
v32 = v33;
v34 = abs32(v31 - v30);
v35 = abs32(v33 - v30);
v36 = abs32(v33 - v30 + v31 - v30);
if ( v35 > v34 )
v35 = v34;
else
v32 = v29[-v3];
if ( v35 <= v36 )
LOBYTE(v30) = v32;
*v29++ += v30;
}
while ( v29 != v27 );
}
else
{
v28 = a3;
v27 = (_BYTE *)a2;
}
result = ((v25 - v26 - 16) >> 4) + 1;
v37 = 16 * result;
if ( v23 - (a2 + 1) - v26 <= 0xE )
goto LABEL_82;
v38 = v26 - v3;
v39 = 0;
v40 = 0;
do
{
v41 = (uint8x16_t *)&a3[v39 + v38];
v42 = (uint8x8_t *)&a3[v39 + v26];
v43 = (uint8x16_t *)(a2 + v39 + v38);
v44 = (uint8x8_t *)(a2 + v39 + v26);
++v40;
v39 += 16;
v45 = vmovl_high_u8(*v41);
v46 = vmovl_high_u8(*v43);
v47 = vmovl_u8((uint8x8_t)v42->n64_u64[0]);
v48 = vmovl_high_u8(*(uint8x16_t *)v42->n64_u64);
v49 = vmovl_u8((uint8x8_t)v41->n128_u64[0]);
v50 = vmovl_u8((uint8x8_t)v43->n128_u64[0]);
v51 = vmovl_u16((uint16x4_t)v45.n128_u64[0]);
v52 = vmovl_high_u16(v45);
v53 = vmovl_u16((uint16x4_t)v49.n128_u64[0]);
v54 = vmovl_high_u16(v46);
v55 = vmovl_high_u16(v49);
v56 = vmovl_u16((uint16x4_t)v50.n128_u64[0]);
v57 = vmovl_u16((uint16x4_t)v46.n128_u64[0]);
v58 = vmovl_u16((uint16x4_t)v47.n128_u64[0]);
v59 = vmovl_u16((uint16x4_t)v48.n128_u64[0]);
v60 = vmovl_high_u16(v48);
v61 = vmovl_high_u16(v50);
v62 = vmovl_high_u16(v47);
v63 = vsubq_s32(v54, v52);
v64 = vsubq_s32(v60, v52);
v65 = vsubq_s32(v58, v53);
v66 = vsubq_s32(v62, v55);
v67 = vsubq_s32(v59, v51);
v68 = vsubq_s32(v56, v53);
v69 = vsubq_s32(v61, v55);
v70 = vsubq_s32(v57, v51);
v71 = vabsq_s32(v65);
v72 = vabsq_s32(v68);
v73 = vabsq_s32(v67);
v74 = vabsq_s32(v64);
v75 = vabsq_s32(v69);
v76 = vabsq_s32(v70);
v77 = vabsq_s32(v63);
v78 = vabsq_s32(v66);
v79 = vaddq_s32(v65, v68);
v80 = vminq_s32(v77, v74);
v81 = vbslq_s8(vcgtq_s32(v74, v77), v60, v54);
v82 = vmovl_u8((uint8x8_t)v44->n64_u64[0]);
v83 = vmovl_high_u8(*(uint8x16_t *)v44->n64_u64);
*(int8x16_t *)v44->n64_u64 = vmovn_hight_s16(
vmovn_s16(
vmovn_hight_s32(
vmovn_s32(
vaddq_s32(
vmovl_u16((uint16x4_t)v82.n128_u64[0]),
vbslq_s8(
vcgtq_s32(vminq_s32(v72, v71), vabsq_s32(v79)),
v53,
vbslq_s8(vcgtq_s32(v71, v72), v58, v56)))),
vaddq_s32(
vmovl_high_u16(v82),
vbslq_s8(
vcgtq_s32(vminq_s32(v75, v78), vabsq_s32(vaddq_s32(v66, v69))),
v55,
vbslq_s8(vcgtq_s32(v78, v75), v62, v61))))),
vmovn_hight_s32(
vmovn_s32(
vaddq_s32(
vmovl_u16((uint16x4_t)v83.n128_u64[0]),
vbslq_s8(
vcgtq_s32(vminq_s32(v76, v73), vabsq_s32(vaddq_s32(v67, v70))),
v51,
vbslq_s8(vcgtq_s32(v73, v76), v59, v57)))),
vaddq_s32(
vmovl_high_u16(v83),
vbslq_s8(vcgtq_s32(v80, vabsq_s32(vaddq_s32(v64, v63))), v52, v81))));
}
while ( result > v40 );
v27 += v37;
v28 += v37;
if ( v25 - v26 != v37 )
{
LABEL_82:
do
{
v84 = v28[v24];
v85 = (unsigned __int8)v27[v24];
v87 = *v28++;
v86 = v87;
v88 = abs32(v85 - v84);
LODWORD(result) = abs32(v87 - v84);
v89 = abs32(v87 - v84 + v85 - v84);
if ( (int)result > v88 )
{
result = (unsigned int)v88;
}
else
{
v86 = v27[v24];
result = (unsigned int)result;
}
if ( (int)result <= v89 )
LOBYTE(v84) = v86;
*v27++ += v84;
}
while ( v23 > (unsigned __int64)v27 );
}
}
else
{
v91 = v23 - a2;
v92 = 0;
do
{
v93 = (unsigned __int8)a3[v92 - v3];
v94 = *(unsigned __int8 *)(a2 - v3 + v92);
v95 = (unsigned __int8)a3[v92];
v96 = abs32(v94 - v93);
v97 = abs32(v95 - v93);
result = abs32(v95 - v93 + v94 - v93);
if ( v97 <= v96 )
LOBYTE(v95) = *(_BYTE *)(a2 - v3 + v92);
if ( v96 > v97 )
v96 = v97;
if ( v96 <= (int)result )
LOBYTE(v93) = v95;
*(_BYTE *)(a2 + v92++) += v93;
}
while ( v92 != v91 );
}
}
return result;
}