//
// sub_CE5680 from 0xce5680 to 0xce58c8 (584 bytes)
//
// 1 xrefs:
// > ??> @ 0x111df28
//
// 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
//
_QWORD *__fastcall sub_CE5680(
__int64 a1,
_QWORD *a2,
__int64 a3,
_QWORD *a4,
__int64 a5,
__int64 a6,
_DWORD *a7,
__int64 a8)
{
_QWORD *v15; // x21
_QWORD *v16; // x26
int v17; // w1
int v18; // w20
int v19; // w20
int v20; // w0
char *v21; // x20
char *v22; // x21
unsigned int *v24; // x20
int v25; // w0
bool v26; // zf
char *v28; // [xsp+68h] [xbp+68h]
char *v29; // [xsp+80h] [xbp+80h] BYREF
__int64 v30; // [xsp+88h] [xbp+88h] BYREF
v29 = &byte_124B6C8;
sub_D15888(&v29, 32);
v15 = sub_CE49F4(a1, a2, a3, a4, a5, a6, a7, (__int64 *)&v29);
v16 = v15;
v18 = v17;
v28 = v29;
v30 = sub_CEA2B4();
std::__convert_to_v(v28, a8, a7, &v30);
if ( v15 && (v18 != -1 || v15[2] < v15[3] || (*(unsigned int (__fastcall **)(_QWORD *))(*v15 + 72LL))(v15) != -1) )
{
v19 = 0;
if ( !a4 )
goto LABEL_6;
goto LABEL_4;
}
v16 = nullptr;
v19 = 1;
if ( a4 )
{
LABEL_4:
v20 = 0;
if ( (_DWORD)a5 != -1
|| a4[2] >= a4[3] && (v26 = (*(unsigned int (__fastcall **)(_QWORD *))(*a4 + 72LL))(a4) == -1, v20 = 1, v26) )
{
if ( v19 == v20 )
goto LABEL_12;
}
else if ( !v19 )
{
goto LABEL_12;
}
LABEL_6:
v21 = v29;
v22 = v29 - 24;
if ( v29 - 24 == (char *)&qword_124B6B0 )
return v16;
goto LABEL_13;
}
LABEL_12:
v21 = v29;
*a7 |= 2u;
v22 = v21 - 24;
if ( v21 - 24 == (char *)&qword_124B6B0 )
return v16;
LABEL_13:
if ( &pthread_create )
{
v24 = (unsigned int *)(v21 - 8);
do
v25 = __ldaxr(v24);
while ( __stlxr(v25 - 1, v24) );
}
else
{
v25 = *((_DWORD *)v21 - 2);
*((_DWORD *)v21 - 2) = v25 - 1;
}
if ( v25 <= 0 )
operator delete(v22);
return v16;
}