//
// ThreadViewPopup::sortMessagesByID from 0x1400da890 to 0x1400dac93 (1027 bytes)
//
// 2 xrefs:
// > ThreadViewPopup::threadMessagesFinished @ 0x1400df6ce
// > ??> @ 0x14091487c
//
// This function is hookable on this platform (idp: pc, 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:26:28 +0000
//
// Hidden C++ exception states: #wind=2
void __fastcall ThreadViewPopup::sortMessagesByID(__int64 a1)
{
__int64 v1; // r15
signed int i; // r14d
struct cocos2d::CCObject *v3; // rax
__int64 v4; // r8
struct cocos2d::CCObject *v5; // r15
__int64 v6; // rsi
unsigned __int64 v7; // r13
unsigned __int64 v8; // rcx
unsigned __int64 v9; // rdx
unsigned __int64 v10; // rcx
unsigned __int64 v11; // rax
__int64 v12; // r12
_QWORD *v13; // rdi
void *v14; // rcx
__int64 v15; // rdi
__int64 v16; // rcx
unsigned __int64 v17; // rbx
__int64 v18; // rax
char *v19; // rax
cocos2d::CCArray *v20; // rsi
unsigned __int64 v21; // rbx
struct cocos2d::CCObject **j; // rdx
signed int k; // edi
cocos2d::CCArray *v24; // rbx
struct cocos2d::CCObject *v25; // rax
void *v26; // rcx
void *Src[2]; // [rsp+30h] [rbp-D0h]
char *v28; // [rsp+40h] [rbp-C0h]
char *Block; // [rsp+50h] [rbp-B0h]
char v31; // [rsp+60h] [rbp-A0h] BYREF
v1 = a1;
*(_OWORD *)Src = 0;
v28 = nullptr;
for ( i = 0; i < (int)cocos2d::CCArray::count(*(cocos2d::CCArray **)(a1 + 752)); v1 = a1 )
{
v3 = cocos2d::CCArray::objectAtIndex(*(cocos2d::CCArray **)(v1 + 752), i);
v5 = v3;
if ( Src[1] == v28 )
{
v6 = ((char *)Src[1] - (char *)Src[0]) >> 3;
if ( v6 == 0x1FFFFFFFFFFFFFFFLL )
sub_14005A170();
v7 = v6 + 1;
v8 = (v28 - (char *)Src[0]) >> 3;
v9 = v8 >> 1;
if ( v8 <= 0x1FFFFFFFFFFFFFFFLL - (v8 >> 1) )
{
v11 = v9 + v8;
v10 = v6 + 1;
if ( v11 >= v7 )
v10 = v11;
if ( v10 > 0x1FFFFFFFFFFFFFFFLL )
sub_140009CF0(v10, v9, v4);
}
else
{
v10 = 0x1FFFFFFFFFFFFFFFLL;
}
v12 = v10;
v13 = sub_14003D460(8 * v10);
v13[v6] = v5;
memmove(v13, Src[0], (char *)Src[1] - (char *)Src[0]);
v14 = Src[0];
if ( Src[0] )
{
if ( ((v28 - (char *)Src[0]) & 0xFFFFFFFFFFFFFFF8uLL) >= 0x1000 )
{
v14 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v14 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v14);
}
Src[0] = v13;
Src[1] = &v13[v7];
v28 = (char *)&v13[v12];
}
else
{
*(_QWORD *)Src[1] = v3;
Src[1] = (char *)Src[1] + 8;
}
++i;
}
v15 = ((char *)Src[1] - (char *)Src[0]) >> 3;
if ( v15 <= 32 )
{
sub_140100470(Src[0]);
goto LABEL_31;
}
v17 = v15 - v15 / 2;
v18 = 0x7FFFFFFFFFFFFFFFLL;
if ( v17 != 0x7FFFFFFFFFFFFFFFLL )
v18 = v15 - v15 / 2;
if ( v17 > 0x200 )
{
v17 = v18;
if ( (unsigned __int64)v18 > 0x1FFFFFFFFFFFFFFFLL || v18 <= 0 )
{
LABEL_26:
v19 = nullptr;
}
else
{
while ( 1 )
{
v19 = (char *)operator new(8 * v17, (const struct std::nothrow_t *)&unk_1406ED620);
if ( v19 )
break;
v17 >>= 1;
if ( !v17 )
goto LABEL_26;
}
if ( v17 > 0x200 )
goto LABEL_29;
}
j_free(v19);
v17 = 512;
}
v19 = &v31;
LABEL_29:
Block = v19;
sub_140100560(Src[0], Src[1], v15, (_DWORD)v19, v17, (__int64)sub_1400DA860);
if ( v17 > 0x200 )
j_free(Block);
LABEL_31:
v20 = (cocos2d::CCArray *)cocos2d::CCArray::create(v16);
v21 = 0;
for ( j = (struct cocos2d::CCObject **)Src[0];
v21 < ((char *)Src[1] - (char *)Src[0]) >> 3;
j = (struct cocos2d::CCObject **)Src[0] )
{
cocos2d::CCArray::addObject(v20, j[v21++]);
}
cocos2d::CCArray::removeAllObjects(*(cocos2d::CCArray **)(v1 + 752));
for ( k = 0; k < (int)cocos2d::CCArray::count(v20); ++k )
{
v24 = *(cocos2d::CCArray **)(v1 + 752);
v25 = cocos2d::CCArray::objectAtIndex(v20, k);
cocos2d::CCArray::addObject(v24, v25);
}
v26 = Src[0];
if ( Src[0] )
{
if ( ((v28 - (char *)Src[0]) & 0xFFFFFFFFFFFFFFF8uLL) >= 0x1000 )
{
v26 = *((void **)Src[0] - 1);
if ( (unsigned __int64)((char *)Src[0] - (char *)v26 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free(v26);
}
}