//
// sub_1002A77D8 from 0x1002a77d8 to 0x1002a7f20 (1864 bytes)
//
// 4 xrefs:
// > GJBaseGameLayer::checkCollisions @ 0x1002834d8
// > GJBaseGameLayer::sortSectionVector @ 0x10028fe64
// > sub_1002A77D8 @ 0x1002a7c58
// > sub_1003F823C @ 0x1003f8800
//
// 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 11:02:16 +0000
//
int8x16_t __fastcall sub_1002A77D8(
__int64 *a1,
__int64 a2,
__int64 (__fastcall **a3)(__int64, __int64),
__int64 a4,
char a5)
{
__int64 *v8; // x21
__int64 *v9; // x24
__int64 *v10; // x25
__int64 v11; // x27
__int64 v12; // x8
__int64 v13; // x23
unsigned __int64 v14; // x8
__int64 *v15; // x26
__int64 (__fastcall *v16)(__int64, __int64); // x9
char v17; // w27
int v18; // w0
__int64 v19; // x8
char v20; // w27
int v21; // w0
__int64 v22; // x8
__int64 v23; // x8
__int64 v24; // x8
__int64 v25; // x8
__int64 v26; // x8
__int64 *v27; // x27
char v28; // w28
int v29; // w0
__int64 v30; // x8
__int64 v31; // x8
__int64 v32; // x8
char v33; // w28
int v34; // w0
__int64 v35; // x8
__int64 v36; // x8
__int64 v37; // x8
char v38; // w28
int v39; // w0
__int64 v40; // x9
__int64 v41; // x8
int v42; // w0
__int64 v43; // x9
int v44; // w0
__int64 v45; // x9
__int64 v46; // x26
char v47; // w1
char v48; // w28
char v49; // w22
int v50; // w0
__int64 v51; // x8
int8x16_t result; // q0
char v54; // w22
int v55; // w0
__int64 v56; // x8
__int64 v57; // x8
__int64 v58; // x8
LABEL_1:
v8 = (__int64 *)(a2 - 8);
v9 = (__int64 *)(a2 - 16);
v10 = (__int64 *)(a2 - 24);
v11 = (__int64)a1;
LABEL_2:
v12 = 1 - a4;
while ( 1 )
{
a1 = (__int64 *)v11;
v13 = v12;
v14 = (a2 - v11) >> 3;
if ( (__int64)v14 <= 2 )
break;
switch ( v14 )
{
case 3uLL:
v49 = (*a3)(v11 + 8, v11);
v50 = (*a3)((__int64)v8, v11 + 8);
if ( (v49 & 1) != 0 )
{
v51 = *(_QWORD *)v11;
if ( v50 )
goto LABEL_76;
*(_QWORD *)v11 = *(_QWORD *)(v11 + 8);
*(_QWORD *)(v11 + 8) = v51;
if ( !(unsigned int)(*a3)((__int64)v8, v11 + 8) )
return result;
v51 = *(_QWORD *)(v11 + 8);
*(_QWORD *)(v11 + 8) = *v8;
LABEL_77:
*v8 = v51;
return result;
}
if ( !v50 )
return result;
v57 = *(_QWORD *)(v11 + 8);
*(_QWORD *)(v11 + 8) = *v8;
*v8 = v57;
goto LABEL_96;
case 4uLL:
v54 = (*a3)(v11 + 8, v11);
v55 = (*a3)(v11 + 16, v11 + 8);
if ( (v54 & 1) != 0 )
{
v56 = *(_QWORD *)v11;
if ( v55 )
{
*(_QWORD *)v11 = *(_QWORD *)(v11 + 16);
*(_QWORD *)(v11 + 16) = v56;
}
else
{
*(_QWORD *)v11 = *(_QWORD *)(v11 + 8);
*(_QWORD *)(v11 + 8) = v56;
if ( (unsigned int)(*a3)(v11 + 16, v11 + 8) )
*(int8x16_t *)(v11 + 8) = vextq_s8(*(int8x16_t *)(v11 + 8), *(int8x16_t *)(v11 + 8), 8u);
}
}
else if ( v55 )
{
*(int8x16_t *)(v11 + 8) = vextq_s8(*(int8x16_t *)(v11 + 8), *(int8x16_t *)(v11 + 8), 8u);
if ( (unsigned int)(*a3)(v11 + 8, v11) )
*(int8x16_t *)v11 = vextq_s8(*(int8x16_t *)v11, *(int8x16_t *)v11, 8u);
}
if ( !(unsigned int)(*a3)((__int64)v8, v11 + 16) )
return result;
v58 = *(_QWORD *)(v11 + 16);
*(_QWORD *)(v11 + 16) = *v8;
*v8 = v58;
if ( !(unsigned int)(*a3)(v11 + 16, v11 + 8) )
return result;
*(int8x16_t *)(v11 + 8) = vextq_s8(*(int8x16_t *)(v11 + 8), *(int8x16_t *)(v11 + 8), 8u);
LABEL_96:
if ( (unsigned int)(*a3)(v11 + 8, v11) )
{
result = vextq_s8(*(int8x16_t *)v11, *(int8x16_t *)v11, 8u);
*(int8x16_t *)v11 = result;
}
return result;
case 5uLL:
sub_1002A7F20(v11, v11 + 8, v11 + 16, v11 + 24, a2 - 8, a3);
return result;
}
LABEL_10:
if ( (__int64)v14 <= 23 )
{
if ( (a5 & 1) != 0 )
sub_1002A810C(v11, a2, a3);
else
sub_1002A81D8(v11, a2, a3);
return result;
}
if ( v13 == 1 )
{
if ( v11 != a2 )
sub_1002A887C(v11, a2, a2, a3);
return result;
}
v15 = (__int64 *)(v11 + 8 * (v14 >> 1));
v16 = *a3;
if ( v14 >= 0x81 )
{
v17 = v16(v11 + 8 * (v14 >> 1), v11);
v18 = (*a3)(a2 - 8, (__int64)v15);
if ( (v17 & 1) != 0 )
{
v19 = *a1;
if ( v18 )
{
*a1 = *v8;
goto LABEL_27;
}
*a1 = *v15;
*v15 = v19;
if ( (unsigned int)(*a3)(a2 - 8, (__int64)v15) )
{
v19 = *v15;
*v15 = *v8;
LABEL_27:
*v8 = v19;
}
}
else if ( v18 )
{
v23 = *v15;
*v15 = *v8;
*v8 = v23;
if ( (unsigned int)(*a3)((__int64)v15, (__int64)a1) )
{
v24 = *a1;
*a1 = *v15;
*v15 = v24;
}
}
v27 = v15 - 1;
v28 = (*a3)((__int64)(v15 - 1), (__int64)(a1 + 1));
v29 = (*a3)(a2 - 16, (__int64)(v15 - 1));
if ( (v28 & 1) != 0 )
{
v30 = a1[1];
if ( v29 )
{
a1[1] = *v9;
goto LABEL_39;
}
a1[1] = *v27;
*v27 = v30;
if ( (unsigned int)(*a3)(a2 - 16, (__int64)(v15 - 1)) )
{
v30 = *v27;
*v27 = *v9;
LABEL_39:
*v9 = v30;
}
}
else if ( v29 )
{
v31 = *v27;
*v27 = *v9;
*v9 = v31;
if ( (unsigned int)(*a3)((__int64)(v15 - 1), (__int64)(a1 + 1)) )
{
v32 = a1[1];
a1[1] = *v27;
*v27 = v32;
}
}
v33 = (*a3)((__int64)(v15 + 1), (__int64)(a1 + 2));
v34 = (*a3)(a2 - 24, (__int64)(v15 + 1));
if ( (v33 & 1) != 0 )
{
v35 = a1[2];
if ( v34 )
{
a1[2] = *v10;
goto LABEL_48;
}
a1[2] = v15[1];
v15[1] = v35;
if ( (unsigned int)(*a3)(a2 - 24, (__int64)(v15 + 1)) )
{
v35 = v15[1];
v15[1] = *v10;
LABEL_48:
*v10 = v35;
}
}
else if ( v34 )
{
v36 = v15[1];
v15[1] = *v10;
*v10 = v36;
if ( (unsigned int)(*a3)((__int64)(v15 + 1), (__int64)(a1 + 2)) )
{
v37 = a1[2];
a1[2] = v15[1];
v15[1] = v37;
}
}
v38 = (*a3)((__int64)v15, (__int64)(v15 - 1));
v39 = (*a3)((__int64)(v15 + 1), (__int64)v15);
if ( (v38 & 1) != 0 )
{
v40 = *v27;
if ( v39 )
{
v41 = *v15;
*v27 = v15[1];
v15[1] = v40;
LABEL_58:
v45 = *a1;
*a1 = v41;
*v15 = v45;
goto LABEL_59;
}
*v27 = *v15;
*v15 = v40;
v44 = (*a3)((__int64)(v15 + 1), (__int64)v15);
v41 = *v15;
if ( !v44 )
goto LABEL_58;
v43 = v15[1];
*v15 = v43;
v15[1] = v41;
}
else
{
v41 = *v15;
if ( !v39 )
goto LABEL_58;
*v15 = v15[1];
v15[1] = v41;
v42 = (*a3)((__int64)v15, (__int64)(v15 - 1));
v41 = *v15;
if ( !v42 )
goto LABEL_58;
v43 = *v27;
*v27 = v41;
*v15 = v43;
}
v41 = v43;
goto LABEL_58;
}
v20 = v16(v11, v11 + 8 * (v14 >> 1));
v21 = (*a3)(a2 - 8, (__int64)a1);
if ( (v20 & 1) != 0 )
{
v22 = *v15;
if ( v21 )
{
*v15 = *v8;
LABEL_36:
*v8 = v22;
goto LABEL_59;
}
*v15 = *a1;
*a1 = v22;
if ( (unsigned int)(*a3)(a2 - 8, (__int64)a1) )
{
v22 = *a1;
*a1 = *v8;
goto LABEL_36;
}
}
else if ( v21 )
{
v25 = *a1;
*a1 = *v8;
*v8 = v25;
if ( (unsigned int)(*a3)((__int64)a1, (__int64)v15) )
{
v26 = *v15;
*v15 = *a1;
*a1 = v26;
}
}
LABEL_59:
if ( (a5 & 1) == 0 && ((*a3)((__int64)(a1 - 1), (__int64)a1) & 1) == 0 )
{
v11 = sub_1002A8288(a1, a2, a3);
goto LABEL_66;
}
v46 = sub_1002A83AC(a1, a2, a3);
if ( (v47 & 1) == 0 )
goto LABEL_64;
v48 = sub_1002A84D8(a1, v46, a3);
v11 = v46 + 8;
if ( (unsigned int)sub_1002A84D8(v46 + 8, a2, a3) )
{
a4 = -v13;
a2 = v46;
if ( (v48 & 1) != 0 )
return result;
goto LABEL_1;
}
v12 = v13 + 1;
if ( (v48 & 1) == 0 )
{
LABEL_64:
sub_1002A77D8(a1, v46, a3, -v13, a5 & 1);
v11 = v46 + 8;
LABEL_66:
a5 = 0;
a4 = -v13;
goto LABEL_2;
}
}
if ( v14 < 2 )
return result;
if ( v14 != 2 )
goto LABEL_10;
if ( (unsigned int)(*a3)(a2 - 8, v11) )
{
v51 = *(_QWORD *)v11;
LABEL_76:
*(_QWORD *)v11 = *v8;
goto LABEL_77;
}
return result;
}