//
// std::__ndk1::__stable_sort std::__ndk1::__stable_sort std::__ndk1::__stable_sort OptionsScrollLayer::init @ 0xb8852c
// > std::__ndk1::__stable_sort_move std::__ndk1::__stable_sort_move ??> @ 0x5ce18
//
// 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:02:32 +0000
//
unsigned __int64 __fastcall std::__stable_sort(
unsigned __int64 result,
unsigned __int64 *a2,
unsigned __int8 (__fastcall **a3)(unsigned __int64, unsigned __int64, __int64),
__int64 a4,
unsigned __int64 *a5,
signed __int64 a6)
{
unsigned __int64 *v7; // x22
unsigned __int64 *v10; // x19
signed __int64 v12; // x26
__int64 v13; // x21
unsigned __int64 v14; // x27
unsigned __int64 v15; // x1
__int64 v16; // x3
unsigned __int64 *v17; // x21
unsigned __int64 *v18; // x23
unsigned __int64 *v19; // x20
unsigned __int64 v20; // t1
unsigned __int64 v21; // t1
signed __int64 v22; // x20
unsigned __int64 *i; // x21
unsigned __int64 v24; // x23
unsigned __int64 *v25; // x19
unsigned __int64 *v26; // x20
unsigned __int64 *v27; // x1
unsigned __int64 v28; // x0
unsigned __int64 v29; // x5
unsigned __int64 *v30; // x3
unsigned __int64 *v31; // x2
unsigned __int64 v32; // x1
__int64 v33; // x4
__int128 v34; // t1
bool v35; // zf
unsigned __int64 *v36; // x22
unsigned __int64 *v37; // x20
unsigned __int64 *v38; // x1
unsigned __int64 *v39; // x1
unsigned __int64 v40; // x0
unsigned __int64 v41; // x5
unsigned __int64 *v42; // x3
unsigned __int64 *v43; // x2
unsigned __int64 v44; // x1
__int64 v45; // x4
__int128 v46; // t1
unsigned __int64 *v47; // x22
unsigned __int64 *v48; // x19
unsigned __int64 *v49; // x1
v7 = (unsigned __int64 *)result;
v10 = a5;
if ( (a4 & 0x8000000000000000LL) == 0 )
{
if ( a4 <= 1 )
return result;
if ( a4 == 2 )
{
result = ((unsigned __int8 (__fastcall *)(_QWORD, _QWORD))*a3)(*(a2 - 1), *(_QWORD *)result);
if ( (_BYTE)result )
{
result = *v7;
*v7 = *(a2 - 1);
*(a2 - 1) = result;
}
return result;
}
}
if ( a4 <= 128 )
{
if ( a2 != (unsigned __int64 *)result )
{
for ( i = (unsigned __int64 *)(result + 8); a2 != i; *v25 = v24 )
{
v24 = *i;
if ( v7 == i )
{
LABEL_26:
v25 = v7;
}
else
{
v25 = i;
while ( 1 )
{
v26 = v25 - 1;
result = ((unsigned __int8 (__fastcall *)(unsigned __int64, _QWORD))*a3)(v24, *(v25 - 1));
if ( !(_BYTE)result )
break;
result = *(v25 - 1);
*v25-- = result;
if ( v7 == v26 )
goto LABEL_26;
}
}
++i;
}
}
}
else
{
v12 = a4 >> 1;
v13 = a4 >> 1;
v14 = result + v13 * 8;
v15 = result + v13 * 8;
v16 = a4 >> 1;
if ( a4 > a6 )
{
v22 = a4 - v12;
std::__stable_sort(
result,
v15,
a3,
v16,
a5,
a6);
std::__stable_sort(
&v7[v13],
a2,
a3,
v22,
v10,
a6);
return std::__inplace_merge(
(unsigned __int64)v7,
&v7[v13],
a2,
a3,
v12,
v22,
v10,
a6);
}
std::__stable_sort_move(
result,
v15,
a3,
v16);
v17 = &v10[v13];
v18 = &v10[a4];
result = std::__stable_sort_move(
v14,
a2,
a3,
a4 - v12);
if ( v10 == v17 )
{
v19 = v10;
}
else
{
if ( v17 == v18 )
{
LABEL_39:
v39 = v10 + 1;
v40 = (unsigned __int64)((char *)v17 - (char *)(v10 + 1)) >> 3;
v41 = v40 + 1;
if ( v40 + 1 > 0xA && (v7 >= v10 + 2 || v10 >= v7 + 2) )
{
v42 = v10;
v43 = v7;
result = ((v40 - 1) >> 1) + 1;
v44 = 0;
v45 = 2 * result;
do
{
v46 = *(_OWORD *)v42;
v42 += 2;
++v44;
*(_OWORD *)v43 = v46;
v43 += 2;
}
while ( result > v44 );
if ( v41 != v45 )
{
result = v10[2 * result];
v7[v45] = result;
}
}
else
{
do
{
result = *v10;
v35 = v17 == v39;
*v7 = *v10;
v47 = v7 + 1;
v48 = v39;
v49 = v39 + 1;
if ( v35 )
break;
result = *v48;
v35 = v17 == v49;
*v47 = *v48;
v7 = v47 + 1;
v10 = v49;
v39 = v49 + 1;
}
while ( !v35 );
}
return result;
}
v19 = v17;
while ( 1 )
{
if ( ((unsigned __int8 (__fastcall *)(unsigned __int64, unsigned __int64))*a3)(*v19, *v10) )
{
v20 = *v19++;
result = v20;
}
else
{
v21 = *v10++;
result = v21;
}
*v7++ = result;
if ( v17 == v10 )
break;
if ( v18 == v19 )
goto LABEL_39;
}
}
if ( v18 != v19 )
{
v27 = v19 + 1;
v28 = (unsigned __int64)((char *)v18 - (char *)(v19 + 1)) >> 3;
v29 = v28 + 1;
if ( v28 + 1 > 0xA && (v19 >= v7 + 2 || v7 >= v19 + 2) )
{
v30 = v19;
v31 = v7;
result = ((v28 - 1) >> 1) + 1;
v32 = 0;
v33 = 2 * result;
do
{
v34 = *(_OWORD *)v30;
v30 += 2;
++v32;
*(_OWORD *)v31 = v34;
v31 += 2;
}
while ( v32 < result );
if ( v29 != v33 )
{
result = v19[2 * result];
v7[v33] = result;
}
}
else
{
do
{
result = *v19;
v35 = v18 == v27;
*v7 = *v19;
v36 = v7 + 1;
v37 = v27;
v38 = v27 + 1;
if ( v35 )
break;
result = *v37;
v35 = v18 == v38;
*v36 = *v37;
v7 = v36 + 1;
v19 = v38;
v27 = v38 + 1;
}
while ( !v35 );
}
}
}
return result;
}