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