//
// sub_1004E81D8 from 0x1004e81d8 to 0x1004e86b8 (1248 bytes)
//
// 2 xrefs:
// > sub_1004E7FB8 @ 0x1004e8040
// > sub_1004E8810 @ 0x1004e8874
//
// 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:06:41 +0000
//
void __fastcall sub_1004E81D8(__int64 a1, const std::string *a2, __int64 *a3)
{
__int64 v6; // x20
__int64 i; // x22
__int64 size; // x8
const std::string *v9; // x9
std::string::size_type v10; // x2
__int64 v11; // x9
int v12; // w10
signed __int64 v13; // x8
unsigned __int8 *v14; // x9
int v15; // t1
__int64 v16; // x0
__int128 *v17; // x0
const std::string *v18; // x26
unsigned __int8 v19; // w28
void **v20; // x20
__int64 v21; // x21
char *v22; // x23
signed __int64 v23; // x22
void **v24; // x27
int v25; // w24
__int64 v26; // x8
void **v27; // x0
__int64 v28; // x8
void **v29; // x0
void **v30; // x25
unsigned int v31; // w20
int v32; // w21
__int64 j; // x20
__int64 k; // x19
__int64 v35; // [xsp+10h] [xbp-140h]
void *v36[2]; // [xsp+18h] [xbp-138h] BYREF
unsigned __int8 v37; // [xsp+2Fh] [xbp-121h]
_BYTE __a[40]; // [xsp+40h] [xbp-110h] BYREF
__int128 v39; // [xsp+68h] [xbp-E8h]
void *v40; // [xsp+78h] [xbp-D8h] BYREF
signed __int64 v41; // [xsp+80h] [xbp-D0h]
unsigned __int8 v42; // [xsp+8Fh] [xbp-C1h]
char __str[16]; // [xsp+90h] [xbp-C0h] BYREF
void *__p[2]; // [xsp+A0h] [xbp-B0h] BYREF
__int128 v45; // [xsp+B0h] [xbp-A0h]
__int128 v46; // [xsp+C0h] [xbp-90h]
__int128 v47; // [xsp+D0h] [xbp-80h]
__int64 v48; // [xsp+E0h] [xbp-70h]
v6 = *a3;
for ( i = a3[1]; i != v6; sub_10000A738((__int64)a3, i) )
i -= 56;
a3[1] = v6;
if ( *(_DWORD *)(a1 + 376)
&& *(_QWORD *)(GameManager::sharedState() + 552)
&& *(_QWORD *)(*(_QWORD *)(GameManager::sharedState() + 552) + 3272LL) )
{
size = HIBYTE(a2->__r_.__value_.__r.__words[2]);
if ( (size & 0x80u) == 0LL )
v9 = a2;
else
v9 = (const std::string *)a2->__r_.__value_.__r.__words[0];
if ( (size & 0x80u) != 0LL )
size = a2->__r_.__value_.__l.__size_;
if ( !size )
goto LABEL_22;
v10 = 0;
while ( v9->__r_.__value_.__s.__data_[v10] == 32 )
{
if ( size == ++v10 )
goto LABEL_22;
}
if ( v10 == -1 )
{
LABEL_22:
sub_100009900(__p, "");
}
else
{
v11 = (__int64)&v9[-1].__r_.__value_.__r.__words[2] + 7;
while ( size )
{
v12 = *(unsigned __int8 *)(v11 + size--);
if ( v12 != 32 )
goto LABEL_75;
}
size = -1;
LABEL_75:
std::string::basic_string((std::string *)__p, a2, v10, size - v10 + 1, (std::allocator *)__a);
}
sub_10004B424((char *)__p, (__int64 *)&v40);
if ( SBYTE7(v45) < 0 )
operator delete(__p[0]);
v13 = v42;
if ( (v42 & 0x80u) != 0 )
v13 = v41;
if ( !v13 )
goto LABEL_87;
v14 = (unsigned __int8 *)&v40;
if ( (v42 & 0x80u) != 0 )
v14 = (unsigned __int8 *)v40;
while ( 1 )
{
v15 = *v14++;
if ( (unsigned int)(v15 - 123) >= 0xFFFFFFE6 )
break;
if ( !--v13 )
goto LABEL_87;
}
v16 = GameManager::sharedState();
v17 = sub_100400EBC(*(_QWORD *)(*(_QWORD *)(v16 + 552) + 3272LL), *(_DWORD *)(a1 + 376));
if ( !*((_QWORD *)v17 + 3) )
goto LABEL_87;
v35 = a1;
v48 = 0;
v46 = 0u;
v47 = 0u;
*(_OWORD *)__p = 0u;
v45 = 0u;
v18 = *((const std::string **)v17 + 2);
if ( v18 )
{
while ( 1 )
{
sub_10004B424((char *)&v18[1], (__int64 *)v36);
v19 = v37;
if ( (v37 & 0x80u) == 0 )
v20 = v36;
else
v20 = (void **)v36[0];
if ( (v37 & 0x80u) == 0 )
v21 = v37;
else
v21 = (__int64)v36[1];
if ( (v42 & 0x80u) == 0 )
v22 = (char *)&v40;
else
v22 = (char *)v40;
if ( (v42 & 0x80u) == 0 )
v23 = v42;
else
v23 = v41;
if ( !v23 )
goto LABEL_58;
if ( v21 >= v23 )
break;
LABEL_64:
if ( (v19 & 0x80) != 0 )
LABEL_65:
operator delete(v36[0]);
LABEL_66:
v18 = (const std::string *)v18->__r_.__value_.__r.__words[0];
if ( !v18 )
goto LABEL_71;
}
v24 = (void **)((char *)v20 + v21);
v25 = *v22;
v26 = v21;
v27 = v20;
while ( 1 )
{
v28 = v26 - v23;
if ( v28 == -1 )
goto LABEL_68;
v29 = (void **)memchr(v27, v25, v28 + 1);
if ( !v29 )
goto LABEL_68;
v30 = v29;
if ( !memcmp(v29, v22, v23) )
break;
v27 = (void **)((char *)v30 + 1);
v26 = (char *)v24 - ((char *)v30 + 1);
if ( v26 < v23 )
goto LABEL_68;
}
if ( v30 == v24 )
{
LABEL_68:
if ( (v19 & 0x80) == 0 )
goto LABEL_66;
goto LABEL_65;
}
if ( (char *)v30 - (char *)v20 == -1 )
goto LABEL_64;
if ( v30 != v20 )
{
v31 = 2;
goto LABEL_59;
}
LABEL_58:
v31 = v21 != v23;
LABEL_59:
v39 = 0u;
memset(&__a[8], 0, 32);
*(_DWORD *)__a = v18->__r_.__value_.__r.__words[2];
snprintf(__str, 0x10u, "%d:", *(_DWORD *)__a);
std::string::assign((std::string *)&__a[32], __str);
std::string::operator=((std::string *)&__a[8], v18 + 1);
sub_1004C2B5C((__int64)&__p[3 * v31], (__int64)__a);
if ( SHIBYTE(v39) < 0 )
operator delete(*(void **)&__a[32]);
if ( (__a[31] & 0x80000000) != 0 )
operator delete(*(void **)&__a[8]);
v19 = v37;
goto LABEL_64;
}
LABEL_71:
if ( GameManager::sharedState() )
{
v32 = *(_DWORD *)(GameManager::sharedState() + 1148);
memset(__a, 0, 32);
*(_DWORD *)&__a[32] = 1065353216;
if ( v32 )
goto LABEL_78;
}
else
{
memset(__a, 0, 32);
*(_DWORD *)&__a[32] = 1065353216;
}
sub_1004E6A64(*(_DWORD *)(v35 + 376), (unsigned __int64)v36);
sub_100151324((__int64)__a, (__int64 *)v36);
sub_1000184EC((__int64)v36);
v32 = 0;
LABEL_78:
for ( j = 0; j != 72; j += 24 )
{
if ( v32 == 1 )
{
sub_1004EA8A4();
}
else if ( v32 == 2 )
{
sub_1004E8DA8();
}
else
{
v36[0] = __a;
sub_1004EC49C();
}
sub_1004EDD38(a3, a3[1]);
}
sub_1000184EC((__int64)__a);
for ( k = 6; k != -3; k -= 3 )
{
*(_QWORD *)__a = &__p[k];
sub_10013BA64((void ***)__a);
}
LABEL_87:
if ( (char)v42 < 0 )
operator delete(v40);
}
}